tint: Allow IdentifierExpressions to be templated
Required for nested template arguments, like `array<vec2<i32>, 2>`
Bug: tint:1810
Change-Id: Ibf24ec8918ef7698232cb2ea0cb786144d6f0604
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119123
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/src/tint/ast/identifier_expression.cc b/src/tint/ast/identifier_expression.cc
index 1f86d9f..ca4e0cb 100644
--- a/src/tint/ast/identifier_expression.cc
+++ b/src/tint/ast/identifier_expression.cc
@@ -27,10 +27,6 @@
: Base(pid, nid, src), identifier(ident) {
TINT_ASSERT(AST, identifier != nullptr);
TINT_ASSERT_PROGRAM_IDS_EQUAL(AST, identifier, program_id);
-
- // It is currently invalid for a templated identifier expression to be used as an identifier
- // expression, as this should parse as a ast::TypeName.
- TINT_ASSERT(AST, !ident->Is<TemplatedIdentifier>());
}
IdentifierExpression::IdentifierExpression(IdentifierExpression&&) = default;
diff --git a/src/tint/ast/identifier_expression_test.cc b/src/tint/ast/identifier_expression_test.cc
index 80742a2..6eb951c 100644
--- a/src/tint/ast/identifier_expression_test.cc
+++ b/src/tint/ast/identifier_expression_test.cc
@@ -18,6 +18,8 @@
namespace tint::ast {
namespace {
+using namespace tint::number_suffixes; // NOLINT
+
using IdentifierExpressionTest = TestHelper;
TEST_F(IdentifierExpressionTest, Creation) {
@@ -25,6 +27,15 @@
EXPECT_EQ(i->identifier->symbol, Symbol(1, ID()));
}
+TEST_F(IdentifierExpressionTest, CreationTemplated) {
+ auto* i = Expr(Ident("ident", true));
+ EXPECT_EQ(i->identifier->symbol, Symbol(1, ID()));
+ auto* tmpl_ident = i->identifier->As<ast::TemplatedIdentifier>();
+ ASSERT_NE(tmpl_ident, nullptr);
+ EXPECT_EQ(tmpl_ident->arguments.Length(), 1_u);
+ EXPECT_TRUE(tmpl_ident->arguments[0]->Is<ast::BoolLiteralExpression>());
+}
+
TEST_F(IdentifierExpressionTest, Creation_WithSource) {
auto* i = Expr(Source{{20, 2}}, "ident");
EXPECT_EQ(i->identifier->symbol, Symbol(1, ID()));
@@ -57,14 +68,5 @@
"internal compiler error");
}
-TEST_F(IdentifierExpressionTest, Assert_IdentifierNotTemplated) {
- EXPECT_FATAL_FAILURE(
- {
- ProgramBuilder b;
- b.create<IdentifierExpression>(b.Ident("ident", "a", "b", "c"));
- },
- "internal compiler error");
-}
-
} // namespace
} // namespace tint::ast
diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h
index 9050783..5455609 100644
--- a/src/tint/program_builder.h
+++ b/src/tint/program_builder.h
@@ -1219,9 +1219,6 @@
/// @return an ast::IdentifierExpression with the given identifier
template <typename IDENTIFIER, typename = traits::EnableIfIsType<IDENTIFIER, ast::Identifier>>
const ast::IdentifierExpression* Expr(const IDENTIFIER* ident) {
- static_assert(!traits::IsType<IDENTIFIER, ast::TemplatedIdentifier>,
- "it is currently invalid for a templated identifier expression to be used as "
- "an identifier expression, as this should parse as an ast::TypeName");
return create<ast::IdentifierExpression>(ident);
}