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>
diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc
index defbb3e..fd502d1 100644
--- a/src/tint/writer/hlsl/generator_impl.cc
+++ b/src/tint/writer/hlsl/generator_impl.cc
@@ -2614,14 +2614,8 @@
bool GeneratorImpl::EmitExpression(std::ostream& out, const ast::Expression* expr) {
if (auto* sem = builder_.Sem().Get(expr)) {
- if (auto* user = sem->As<sem::VariableUser>();
- !user || !user->Variable()->Declaration()->Is<ast::Let>()) {
- // Disable constant inlining if the constant expression is from a 'let' declaration.
- // TODO(crbug.com/tint/1580): Once 'const' is implemented, 'let' will no longer resolve
- // to a shader-creation time constant value, and this can be removed.
- if (auto constant = sem->ConstantValue()) {
- return EmitConstant(out, constant);
- }
+ if (auto constant = sem->ConstantValue()) {
+ return EmitConstant(out, constant);
}
}
return Switch(
@@ -2852,7 +2846,6 @@
return false;
}
},
- [&](const ast::Let* let) { return EmitProgramConstVariable(let); },
[&](const ast::Override* override) { return EmitOverride(override); },
[&](const ast::Const*) {
return true; // Constants are embedded at their use
@@ -4057,25 +4050,6 @@
return true;
}
-bool GeneratorImpl::EmitProgramConstVariable(const ast::Let* let) {
- auto* sem = builder_.Sem().Get(let);
- auto* type = sem->Type();
-
- auto out = line();
- out << "static const ";
- if (!EmitTypeAndName(out, type, ast::StorageClass::kNone, ast::Access::kUndefined,
- builder_.Symbols().NameFor(let->symbol))) {
- return false;
- }
- out << " = ";
- if (!EmitExpression(out, let->constructor)) {
- return false;
- }
- out << ";";
-
- return true;
-}
-
bool GeneratorImpl::EmitOverride(const ast::Override* override) {
auto* sem = builder_.Sem().Get(override);
auto* type = sem->Type();