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

@@ -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) {