Remove module-scope let deprecation.

This CL moves module-scope let from a deprecation to an error.

Change-Id: Iffecbb667cf79515234b6510ce7c5bbbb6e673bc
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/108862
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
This commit is contained in:
dan sinclair 2022-11-07 14:20:33 +00:00 committed by Dawn LUCI CQ
parent c027f33cfd
commit 3b2b5484e2
12 changed files with 28 additions and 355 deletions

View File

@ -7,6 +7,7 @@
* `textureDimensions()`, `textureNumLayers()` and `textureNumLevels()` now return unsigned integers / vectors. [tint:1526](crbug.com/tint/1526)
* The `@stage` attribute has been removed. The short forms should be used
instead (`@vertex`, `@fragment`, or `@compute`). [tint:1503](crbug.com/tint/1503)
* Module-scope `let` is now an error. Use module-scope `const` instead. [tint:1580](crbug.com/tint/1584)
### New features

View File

@ -56,16 +56,16 @@ struct BatchInfo {
// various failure modes.
static const char sRenderValidationShaderSource[] = R"(
let kNumDrawIndirectParams = 4u;
const kNumDrawIndirectParams = 4u;
let kIndexCountEntry = 0u;
let kFirstIndexEntry = 2u;
const kIndexCountEntry = 0u;
const kFirstIndexEntry = 2u;
// Bitmasks for BatchInfo::flags
let kDuplicateBaseVertexInstance = 1u;
let kIndexedDraw = 2u;
let kValidationEnabled = 4u;
let kIndirectFirstInstanceEnabled = 8u;
const kDuplicateBaseVertexInstance = 1u;
const kIndexedDraw = 2u;
const kValidationEnabled = 4u;
const kIndirectFirstInstanceEnabled = 8u;
struct BatchInfo {
numIndexBufferElementsLow: u32,

View File

@ -64,7 +64,7 @@ static const char sConvertTimestampsToNanoseconds[] = R"(
@group(0) @binding(1) var<storage, read> availability : AvailabilityArr;
@group(0) @binding(2) var<uniform> params : TimestampParams;
let sizeofTimestamp : u32 = 8u;
const sizeofTimestamp : u32 = 8u;
@compute @workgroup_size(8, 1, 1)
fn main(@builtin(global_invocation_id) GlobalInvocationID : vec3<u32>) {

View File

@ -440,17 +440,17 @@ TEST_P(ClampedOOBDynamicBufferOffsetTests, CheckOOBAccess) {
wgpu::ComputePipeline pipeline;
{
std::ostringstream shader;
shader << "let kArrayLength: u32 = " << kArrayLength << "u;\n";
shader << "const kArrayLength: u32 = " << kArrayLength << "u;\n";
if (GetParam().mOOBRead) {
shader << "let kReadOffset: u32 = " << kOOBOffset << "u;\n";
shader << "const kReadOffset: u32 = " << kOOBOffset << "u;\n";
} else {
shader << "let kReadOffset: u32 = 0u;\n";
shader << "const kReadOffset: u32 = 0u;\n";
}
if (GetParam().mOOBWrite) {
shader << "let kWriteOffset: u32 = " << kOOBOffset << "u;\n";
shader << "const kWriteOffset: u32 = " << kOOBOffset << "u;\n";
} else {
shader << "let kWriteOffset: u32 = 0u;\n";
shader << "const kWriteOffset: u32 = 0u;\n";
}
switch (GetParam().mReadBufferUsage) {
case wgpu::BufferUsage::Uniform:

View File

@ -386,7 +386,7 @@ struct S {
}
var<private> a: S;
let e = 3;
const e = 3;
@group(1) @binding(1) var<uniform> b: S;
fn f() {
*&a = *&b;

View File

@ -615,12 +615,11 @@ Maybe<const ast::Variable*> ParserImpl::global_constant_decl(AttributeList& attr
Source source;
if (match(Token::Type::kConst)) {
use = "'const' declaration";
} else if (match(Token::Type::kLet, &source)) {
use = "'let' declaration";
deprecated(source, "module-scope 'let' has been replaced with 'const'");
} else if (match(Token::Type::kOverride)) {
use = "'override' declaration";
is_overridable = true;
} else if (match(Token::Type::kLet, &source)) {
return add_error(source, "module-scope 'let' is invalid, use 'const'");
} else {
return Failure::kNoMatch;
}

View File

@ -553,94 +553,11 @@ const i : vec2<i32> = vec2<i32>(1, 2;
)");
}
TEST_F(ParserImplErrorTest, GlobalDeclLetInvalidIdentifier) {
EXPECT(
"let ^ : i32 = 1;",
R"(test.wgsl:1:1 warning: use of deprecated language feature: module-scope 'let' has been replaced with 'const'
let ^ : i32 = 1;
TEST_F(ParserImplErrorTest, GlobalDeclLet) {
EXPECT("let a : i32 = 1;",
R"(test.wgsl:1:1 error: module-scope 'let' is invalid, use 'const'
let a : i32 = 1;
^^^
test.wgsl:1:5 error: expected identifier for 'let' declaration
let ^ : i32 = 1;
^
)");
}
TEST_F(ParserImplErrorTest, GlobalDeclLetMissingSemicolon) {
EXPECT(
"let i : i32 = 1",
R"(test.wgsl:1:1 warning: use of deprecated language feature: module-scope 'let' has been replaced with 'const'
let i : i32 = 1
^^^
test.wgsl:1:16 error: expected ';' for 'const' declaration
let i : i32 = 1
^
)");
}
TEST_F(ParserImplErrorTest, GlobalDeclLetMissingLParen) {
EXPECT(
"let i : vec2<i32> = vec2<i32>;",
R"(test.wgsl:1:1 warning: use of deprecated language feature: module-scope 'let' has been replaced with 'const'
let i : vec2<i32> = vec2<i32>;
^^^
test.wgsl:1:30 error: expected '(' for type initializer
let i : vec2<i32> = vec2<i32>;
^
)");
}
TEST_F(ParserImplErrorTest, GlobalDeclLetMissingRParen) {
EXPECT(
"let i : vec2<i32> = vec2<i32>(1., 2.;",
R"(test.wgsl:1:1 warning: use of deprecated language feature: module-scope 'let' has been replaced with 'const'
let i : vec2<i32> = vec2<i32>(1., 2.;
^^^
test.wgsl:1:37 error: expected ')' for type initializer
let i : vec2<i32> = vec2<i32>(1., 2.;
^
)");
}
TEST_F(ParserImplErrorTest, GlobalDeclLetBadConstLiteral) {
EXPECT(
"let i : vec2<i32> = vec2<i32>(!);",
R"(test.wgsl:1:1 warning: use of deprecated language feature: module-scope 'let' has been replaced with 'const'
let i : vec2<i32> = vec2<i32>(!);
^^^
test.wgsl:1:32 error: unable to parse right side of ! expression
let i : vec2<i32> = vec2<i32>(!);
^
)");
}
TEST_F(ParserImplErrorTest, GlobalDeclLetExprMissingLParen) {
EXPECT(
"let i : vec2<i32> = vec2<i32> 1, 2);",
R"(test.wgsl:1:1 warning: use of deprecated language feature: module-scope 'let' has been replaced with 'const'
let i : vec2<i32> = vec2<i32> 1, 2);
^^^
test.wgsl:1:31 error: expected '(' for type initializer
let i : vec2<i32> = vec2<i32> 1, 2);
^
)");
}
TEST_F(ParserImplErrorTest, GlobalDeclLetExprMissingRParen) {
EXPECT(
"let i : vec2<i32> = vec2<i32>(1, 2;",
R"(test.wgsl:1:1 warning: use of deprecated language feature: module-scope 'let' has been replaced with 'const'
let i : vec2<i32> = vec2<i32>(1, 2;
^^^
test.wgsl:1:35 error: expected ')' for type initializer
let i : vec2<i32> = vec2<i32>(1, 2;
^
)");
}

View File

@ -24,79 +24,10 @@ TEST_F(ParserImplTest, GlobalLetDecl) {
EXPECT_FALSE(attrs.errored);
EXPECT_FALSE(attrs.matched);
auto e = p->global_constant_decl(attrs.value);
EXPECT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
auto* const_ = e.value->As<ast::Const>();
ASSERT_NE(const_, nullptr);
EXPECT_EQ(const_->symbol, p->builder().Symbols().Get("a"));
ASSERT_NE(const_->type, nullptr);
EXPECT_TRUE(const_->type->Is<ast::F32>());
EXPECT_EQ(const_->source.range.begin.line, 1u);
EXPECT_EQ(const_->source.range.begin.column, 5u);
EXPECT_EQ(const_->source.range.end.line, 1u);
EXPECT_EQ(const_->source.range.end.column, 6u);
ASSERT_NE(const_->initializer, nullptr);
EXPECT_TRUE(const_->initializer->Is<ast::LiteralExpression>());
}
TEST_F(ParserImplTest, GlobalLetDecl_Inferred) {
auto p = parser("let a = 1.");
auto attrs = p->attribute_list();
EXPECT_FALSE(attrs.errored);
EXPECT_FALSE(attrs.matched);
auto e = p->global_constant_decl(attrs.value);
EXPECT_FALSE(p->has_error()) << p->error();
EXPECT_TRUE(e.matched);
EXPECT_FALSE(e.errored);
auto* const_ = e.value->As<ast::Const>();
ASSERT_NE(const_, nullptr);
EXPECT_EQ(const_->symbol, p->builder().Symbols().Get("a"));
EXPECT_EQ(const_->type, nullptr);
EXPECT_EQ(const_->source.range.begin.line, 1u);
EXPECT_EQ(const_->source.range.begin.column, 5u);
EXPECT_EQ(const_->source.range.end.line, 1u);
EXPECT_EQ(const_->source.range.end.column, 6u);
ASSERT_NE(const_->initializer, nullptr);
EXPECT_TRUE(const_->initializer->Is<ast::LiteralExpression>());
}
TEST_F(ParserImplTest, GlobalLetDecl_InvalidExpression) {
auto p = parser("let a : f32 = if (a) {}");
auto attrs = p->attribute_list();
EXPECT_FALSE(attrs.errored);
EXPECT_FALSE(attrs.matched);
auto e = p->global_constant_decl(attrs.value);
EXPECT_TRUE(p->has_error());
EXPECT_TRUE(e.errored);
EXPECT_FALSE(e.matched);
EXPECT_EQ(e.value, nullptr);
EXPECT_EQ(
p->error(),
R"(1:1: use of deprecated language feature: module-scope 'let' has been replaced with 'const'
1:15: missing initializer for 'let' declaration)");
}
TEST_F(ParserImplTest, GlobalLetDecl_MissingExpression) {
auto p = parser("let a : f32 =");
auto attrs = p->attribute_list();
EXPECT_FALSE(attrs.errored);
EXPECT_FALSE(attrs.matched);
auto e = p->global_constant_decl(attrs.value);
EXPECT_TRUE(p->has_error());
EXPECT_TRUE(e.errored);
EXPECT_FALSE(e.matched);
EXPECT_EQ(e.value, nullptr);
EXPECT_EQ(
p->error(),
R"(1:1: use of deprecated language feature: module-scope 'let' has been replaced with 'const'
1:14: missing initializer for 'let' declaration)");
EXPECT_EQ(p->error(), "1:1: module-scope 'let' is invalid, use 'const'");
}
TEST_F(ParserImplTest, GlobalConstDecl) {

View File

@ -58,44 +58,11 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_MissingSemicolon) {
TEST_F(ParserImplTest, GlobalDecl_GlobalLet) {
auto p = parser("let a : i32 = 2;");
p->global_decl();
ASSERT_FALSE(p->has_error()) << p->error();
auto program = p->program();
ASSERT_EQ(program.AST().GlobalVariables().Length(), 1u);
auto* v = program.AST().GlobalVariables()[0];
EXPECT_EQ(v->symbol, program.Symbols().Get("a"));
}
TEST_F(ParserImplTest, GlobalDecl_GlobalLet_MissingInitializer) {
auto p = parser("let a : vec2<i32>;");
p->global_decl();
ASSERT_TRUE(p->has_error());
EXPECT_EQ(
p->error(),
R"(1:1: use of deprecated language feature: module-scope 'let' has been replaced with 'const'
1:18: expected '=' for 'let' declaration)");
}
TEST_F(ParserImplTest, GlobalDecl_GlobalLet_Invalid) {
auto p = parser("let a : vec2<i32> 1.0;");
p->global_decl();
ASSERT_TRUE(p->has_error());
EXPECT_EQ(
p->error(),
R"(1:1: use of deprecated language feature: module-scope 'let' has been replaced with 'const'
1:19: expected '=' for 'let' declaration)");
}
TEST_F(ParserImplTest, GlobalDecl_GlobalLet_MissingSemicolon) {
auto p = parser("let a : vec2<i32> = vec2<i32>(1, 2)");
p->global_decl();
ASSERT_TRUE(p->has_error());
EXPECT_EQ(
p->error(),
R"(1:1: use of deprecated language feature: module-scope 'let' has been replaced with 'const'
1:36: expected ';' for 'const' declaration)");
auto e = p->global_decl();
EXPECT_TRUE(p->has_error());
EXPECT_FALSE(e.matched);
EXPECT_TRUE(e.errored);
EXPECT_EQ(p->error(), "1:1: module-scope 'let' is invalid, use 'const'");
}
TEST_F(ParserImplTest, GlobalDecl_GlobalConst) {

View File

@ -240,32 +240,6 @@ fn comp_main1() {
EXPECT_EQ(expect, str(got));
}
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;

View File

@ -384,82 +384,6 @@ var<private> a : i32;
EXPECT_EQ(expect, str(got));
}
TEST_F(UnshadowTest, LocalShadowsGlobalLet) {
auto* src = R"(
let a : i32 = 1;
fn X() {
var a = (a == 123);
}
fn Y() {
let a = (a == 321);
}
fn Z() {
const a = 321;
}
)";
auto* expect = R"(
const a : i32 = 1;
fn X() {
var a_1 = (a == 123);
}
fn Y() {
let a_2 = (a == 321);
}
fn Z() {
const a_3 = 321;
}
)";
auto got = Run<Unshadow>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(UnshadowTest, LocalShadowsGlobalLet_OutOfOrder) {
auto* src = R"(
fn X() {
var a = (a == 123);
}
fn Y() {
let a = (a == 321);
}
fn Z() {
const a = 321;
}
let a : i32 = 1;
)";
auto* expect = R"(
fn X() {
var a_1 = (a == 123);
}
fn Y() {
let a_2 = (a == 321);
}
fn Z() {
const a_3 = 321;
}
const a : i32 = 1;
)";
auto got = Run<Unshadow>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(UnshadowTest, LocalShadowsGlobalConst) {
auto* src = R"(
const a : i32 = 1;
@ -732,46 +656,6 @@ fn F(a_1 : bool) {
EXPECT_EQ(expect, str(got));
}
TEST_F(UnshadowTest, ParamShadowsGlobalLet) {
auto* src = R"(
let a : i32 = 1;
fn F(a : bool) {
}
)";
auto* expect = R"(
const a : i32 = 1;
fn F(a_1 : bool) {
}
)";
auto got = Run<Unshadow>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(UnshadowTest, ParamShadowsGlobalLet_OutOfOrder) {
auto* src = R"(
fn F(a : bool) {
}
let a : i32 = 1;
)";
auto* expect = R"(
fn F(a_1 : bool) {
}
const a : i32 = 1;
)";
auto got = Run<Unshadow>(src);
EXPECT_EQ(expect, str(got));
}
TEST_F(UnshadowTest, ParamShadowsGlobalConst) {
auto* src = R"(
const a : i32 = 1;

View File

@ -1,4 +1,4 @@
let shadowDepthTextureSize : f32 = 1024.0;
const shadowDepthTextureSize : f32 = 1024.0;
struct Scene {
lightViewProjMatrix : mat4x4<f32>,