tint: Deprecated module-scope 'let' for 'const'

Enable the parsing of 'const'.
Warn on use of module-scope 'let', and automatically replace with 'const'.

Fixed: tint:1580
Change-Id: I214aabca80686dc6b60ae21a7a57fbfb4898ea83
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93786
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton
2022-06-29 00:55:36 +00:00
committed by Dawn LUCI CQ
parent 03f88e6f49
commit c64ca23d94
224 changed files with 1443 additions and 2495 deletions

View File

@@ -151,7 +151,7 @@ fn f() {
)";
auto* expect = R"(
let N = 16u;
const N = 16u;
fn f() {
var i : u32 = 0u;

View File

@@ -1099,20 +1099,16 @@ struct S1 {
TEST_F(PromoteInitializersToLetTest, NoChangeOnVarDecl) {
auto* src = R"(
struct S {
a : i32,
b : f32,
c : i32,
}
type F = f32;
fn f() {
var local_arr = array<f32, 4u>(0.0, 1.0, 2.0, 3.0);
var local_str = S(1, 2.0, 3);
var local_str = F(3.0);
}
let module_arr : array<f32, 4u> = array<f32, 4u>(0.0, 1.0, 2.0, 3.0);
const module_arr : array<f32, 4u> = array<f32, 4u>(0.0, 1.0, 2.0, 3.0);
let module_str : S = S(1, 2.0, 3);
const module_str : F = F(2.0);
)";
auto* expect = src;
@@ -1127,18 +1123,14 @@ TEST_F(PromoteInitializersToLetTest, NoChangeOnVarDecl_OutOfOrder) {
auto* src = R"(
fn f() {
var local_arr = array<f32, 4u>(0.0, 1.0, 2.0, 3.0);
var local_str = S(1, 2.0, 3);
var local_str = F(3.0);
}
let module_str : S = S(1, 2.0, 3);
const module_str : F = F(2.0);
struct S {
a : i32,
b : f32,
c : i32,
}
type F = f32;
let module_arr : array<f32, 4u> = array<f32, 4u>(0.0, 1.0, 2.0, 3.0);
const module_arr : array<f32, 4u> = array<f32, 4u>(0.0, 1.0, 2.0, 3.0);
)";
auto* expect = src;

View File

@@ -21,7 +21,7 @@ namespace {
using RobustnessTest = TransformTest;
TEST_F(RobustnessTest, Array_Idx_Clamp) {
TEST_F(RobustnessTest, Array_Let_Idx_Clamp) {
auto* src = R"(
var<private> a : array<f32, 3>;
@@ -35,7 +35,7 @@ fn f() {
auto* expect = R"(
var<private> a : array<f32, 3>;
let c : u32 = 1u;
const c : u32 = 1u;
fn f() {
let b : f32 = a[1u];
@@ -47,7 +47,33 @@ fn f() {
EXPECT_EQ(expect, str(got));
}
TEST_F(RobustnessTest, Array_Idx_Clamp_OutOfOrder) {
TEST_F(RobustnessTest, Array_Const_Idx_Clamp) {
auto* src = R"(
var<private> a : array<f32, 3>;
const c : u32 = 1u;
fn f() {
let b : f32 = a[c];
}
)";
auto* expect = R"(
var<private> a : array<f32, 3>;
const c : u32 = 1u;
fn f() {
let b : f32 = a[1u];
}
)";
auto got = Run<Robustness>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RobustnessTest, Array_Let_Idx_Clamp_OutOfOrder) {
auto* src = R"(
fn f() {
let b : f32 = a[c];
@@ -63,7 +89,33 @@ fn f() {
let b : f32 = a[1u];
}
let c : u32 = 1u;
const c : u32 = 1u;
var<private> a : array<f32, 3>;
)";
auto got = Run<Robustness>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(RobustnessTest, Array_Const_Idx_Clamp_OutOfOrder) {
auto* src = R"(
fn f() {
let b : f32 = a[c];
}
const c : u32 = 1u;
var<private> a : array<f32, 3>;
)";
auto* expect = R"(
fn f() {
let b : f32 = a[1u];
}
const c : u32 = 1u;
var<private> a : array<f32, 3>;
)";
@@ -1392,7 +1444,7 @@ struct S {
@group(0) @binding(0) var<storage, read> s : S;
let c : u32 = 1u;
const c : u32 = 1u;
fn f() {
let b : f32 = s.b[c];
@@ -1409,7 +1461,7 @@ struct S {
@group(0) @binding(0) var<storage, read> s : S;
let c : u32 = 1u;
const c : u32 = 1u;
fn f() {
let b : f32 = s.b[min(1u, (arrayLength(&(s.b)) - 1u))];

View File

@@ -186,13 +186,13 @@ fn comp_main1() {
TEST_F(SingleEntryPointTest, GlobalConstants) {
auto* src = R"(
let a : f32 = 1.0;
const a : f32 = 1.0;
let b : f32 = 1.0;
const b : f32 = 1.0;
let c : f32 = 1.0;
const c : f32 = 1.0;
let d : f32 = 1.0;
const d : f32 = 1.0;
@vertex
fn vert_main() -> @builtin(position) vec4<f32> {
@@ -217,7 +217,7 @@ fn comp_main2() {
)";
auto* expect = R"(
let c : f32 = 1.0;
const c : f32 = 1.0;
@compute @workgroup_size(1)
fn comp_main1() {
@@ -238,6 +238,32 @@ TEST_F(SingleEntryPointTest, WorkgroupSizeLetPreserved) {
auto* src = R"(
let size : i32 = 1;
@compute @workgroup_size(size)
fn main() {
}
)";
auto* expect = R"(
const size : i32 = 1;
@compute @workgroup_size(size)
fn main() {
}
)";
SingleEntryPoint::Config cfg("main");
DataMap data;
data.Add<SingleEntryPoint::Config>(cfg);
auto got = Run<SingleEntryPoint>(src, data);
EXPECT_EQ(expect, str(got));
}
TEST_F(SingleEntryPointTest, WorkgroupSizeConstPreserved) {
auto* src = R"(
const size : i32 = 1;
@compute @workgroup_size(size)
fn main() {
}

View File

@@ -402,7 +402,7 @@ fn Z() {
)";
auto* expect = R"(
let a : i32 = 1;
const a : i32 = 1;
fn X() {
var a_1 = (a == 123);
@@ -452,7 +452,7 @@ fn Z() {
const a_3 = 321;
}
let a : i32 = 1;
const a : i32 = 1;
)";
auto got = Run<Unshadow>(src);
@@ -473,7 +473,7 @@ fn Y() {
}
fn Z() {
const a = a;
const a = 321;
}
)";
@@ -489,7 +489,7 @@ fn Y() {
}
fn Z() {
const a_3 = a;
const a_3 = 321;
}
)";
@@ -741,7 +741,7 @@ fn F(a : bool) {
)";
auto* expect = R"(
let a : i32 = 1;
const a : i32 = 1;
fn F(a_1 : bool) {
}
@@ -764,7 +764,7 @@ let a : i32 = 1;
fn F(a_1 : bool) {
}
let a : i32 = 1;
const a : i32 = 1;
)";
auto got = Run<Unshadow>(src);

View File

@@ -484,7 +484,8 @@ TEST_F(VarForDynamicIndexTest, ArrayIndexConstantLet) {
fn f() {
let p = array<i32, 4>(1, 2, 3, 4);
let c = 1;
let x = p[c];
var var_for_index = p;
let x = var_for_index[c];
}
)";
@@ -501,7 +502,8 @@ TEST_F(VarForDynamicIndexTest, MatrixIndexConstantLet) {
fn f() {
let p = mat2x2(1.0, 2.0, 3.0, 4.0);
let c = 1;
let x = p[c];
var var_for_index = p;
let x = var_for_index[c];
}
)";