From 6e7d24d36a73aef4bc64a2855cf3a1b0834d6688 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 9 Jun 2021 14:32:14 +0000 Subject: [PATCH] Add ProgramBuilder::Alias() Combines the calls to ty.alias() and AST().AddConstructedType() Change-Id: I84eaf6275d37141cf8973db7e04d25d9cb9c6351 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53801 Commit-Queue: Ben Clayton Kokoro: Kokoro Reviewed-by: Antonio Maiorano --- src/ast/alias_test.cc | 16 ++++---- src/program_builder.h | 23 +++++++++++ src/resolver/assignment_validation_test.cc | 3 +- src/resolver/control_block_validation_test.cc | 3 +- src/resolver/function_validation_test.cc | 6 +-- .../host_shareable_validation_test.cc | 12 ++---- src/resolver/resolver_test.cc | 15 +++---- src/resolver/storage_class_validation_test.cc | 15 +++---- src/resolver/struct_layout_test.cc | 6 +-- .../struct_pipeline_stage_use_test.cc | 6 +-- src/resolver/struct_storage_class_use_test.cc | 6 +-- src/resolver/type_validation_test.cc | 8 +--- src/resolver/validation_test.cc | 39 ++++++------------ src/resolver/var_let_test.cc | 6 +-- src/resolver/var_let_validation_test.cc | 6 +-- .../hlsl/generator_impl_workgroup_var_test.cc | 3 +- .../spirv/builder_accessor_expression_test.cc | 3 +- .../builder_constructor_expression_test.cc | 3 +- .../spirv/builder_global_variable_test.cc | 6 +-- .../wgsl/generator_impl_alias_type_test.cc | 9 ++-- src/writer/wgsl/generator_impl_type_test.cc | 41 +++++++++---------- 21 files changed, 102 insertions(+), 133 deletions(-) diff --git a/src/ast/alias_test.cc b/src/ast/alias_test.cc index d3c5ec76ef..e55428d624 100644 --- a/src/ast/alias_test.cc +++ b/src/ast/alias_test.cc @@ -35,7 +35,7 @@ using AstAliasTest = TestHelper; TEST_F(AstAliasTest, Create) { auto* u32 = create(); - auto* a = create(Sym("a_type"), u32); + auto* a = Alias("a_type", u32); EXPECT_EQ(a->symbol(), Symbol(1, ID())); EXPECT_EQ(a->type(), u32); } @@ -46,7 +46,7 @@ TEST_F(AstAliasTest, Create) { TEST_F(AstAliasTest, TypeName_LinearTime) { Type* type = ty.i32(); for (int i = 0; i < 1024; i++) { - type = create(Symbols().New(), type); + type = Alias(Symbols().New(), type); } for (int i = 0; i < 16384; i++) { type->type_name(); @@ -54,22 +54,22 @@ TEST_F(AstAliasTest, TypeName_LinearTime) { } TEST_F(AstAliasTest, TypeName) { - auto* at = create(Sym("Particle"), create()); + auto* at = Alias("Particle", create()); EXPECT_EQ(at->type_name(), "__alias_$1__i32"); } TEST_F(AstAliasTest, FriendlyName) { - auto* at = create(Sym("Particle"), create()); + auto* at = Alias("Particle", create()); EXPECT_EQ(at->FriendlyName(Symbols()), "Particle"); } TEST_F(AstAliasTest, UnwrapAll_TwiceAliasPointerTwiceAlias) { auto* u32 = create(); - auto* a = create(Sym("a_type"), u32); - auto* aa = create(Sym("aa_type"), a); + auto* a = create(Sym("a_type"), u32); + auto* aa = create(Sym("aa_type"), a); auto* paa = create(aa, StorageClass::kUniform, Access::kUndefined); - auto* apaa = create(Sym("paa_type"), paa); - auto* aapaa = create(Sym("aapaa_type"), apaa); + auto* apaa = create(Sym("paa_type"), paa); + auto* aapaa = create(Sym("aapaa_type"), apaa); EXPECT_EQ(aapaa->symbol(), Symbol(4, ID())); EXPECT_EQ(aapaa->type(), apaa); diff --git a/src/program_builder.h b/src/program_builder.h index 82814a797e..4a9c3d0272 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -1620,6 +1620,29 @@ class ProgramBuilder { return create(Expr(std::forward(val))); } + /// Creates a ast::Alias registering it with the AST().ConstructedTypes(). + /// @param source the source information + /// @param name the alias name + /// @param type the alias target type + /// @returns the alias type + template + ast::Alias* Alias(const Source& source, NAME&& name, ast::Type* type) { + auto* out = ty.alias(source, std::forward(name), type); + AST().AddConstructedType(out); + return out; + } + + /// Creates a ast::Alias registering it with the AST().ConstructedTypes(). + /// @param name the alias name + /// @param type the alias target type + /// @returns the alias type + template + ast::Alias* Alias(NAME&& name, ast::Type* type) { + auto* out = ty.alias(std::forward(name), type); + AST().AddConstructedType(out); + return out; + } + /// Creates a ast::Struct registering it with the AST().ConstructedTypes(). /// @param source the source information /// @param name the struct name diff --git a/src/resolver/assignment_validation_test.cc b/src/resolver/assignment_validation_test.cc index b270ec9b76..7c124b4864 100644 --- a/src/resolver/assignment_validation_test.cc +++ b/src/resolver/assignment_validation_test.cc @@ -111,8 +111,7 @@ TEST_F(ResolverAssignmentValidationTest, // alias myint = i32; // var a : myint = 2; // a = 2 - auto* myint = ty.alias("myint", ty.i32()); - AST().AddConstructedType(myint); + auto* myint = Alias("myint", ty.i32()); auto* var = Var("a", myint, ast::StorageClass::kNone, Expr(2)); WrapInFunction(var, Assign(Source{{12, 34}}, "a", 2)); diff --git a/src/resolver/control_block_validation_test.cc b/src/resolver/control_block_validation_test.cc index a999fbbf52..a7e7847e83 100644 --- a/src/resolver/control_block_validation_test.cc +++ b/src/resolver/control_block_validation_test.cc @@ -294,7 +294,7 @@ TEST_F(ResolverControlBlockValidationTest, SwitchCaseAlias_Pass) { // default: {} // } - auto* my_int = ty.alias("MyInt", ty.u32()); + auto* my_int = Alias("MyInt", ty.u32()); auto* var = Var("a", my_int, ast::StorageClass::kNone, Expr(2u)); ast::CaseSelectorList default_csl; @@ -304,7 +304,6 @@ TEST_F(ResolverControlBlockValidationTest, SwitchCaseAlias_Pass) { default_csl, block_default)); auto* block = Block(Decl(var), create(Expr("a"), body)); - AST().AddConstructedType(my_int); WrapInFunction(block); diff --git a/src/resolver/function_validation_test.cc b/src/resolver/function_validation_test.cc index 1bb927c016..94e67919db 100644 --- a/src/resolver/function_validation_test.cc +++ b/src/resolver/function_validation_test.cc @@ -230,8 +230,7 @@ TEST_F(ResolverFunctionValidationTest, FunctionTypeMustMatchReturnStatementTypeF32Alias_pass) { // type myf32 = f32; // fn func -> myf32 { return 2.0; } - auto* myf32 = ty.alias("myf32", ty.f32()); - AST().AddConstructedType(myf32); + auto* myf32 = Alias("myf32", ty.f32()); Func("func", ast::VariableList{}, myf32, ast::StatementList{ Return(Source{Source::Location{12, 34}}, Expr(2.f)), @@ -245,8 +244,7 @@ TEST_F(ResolverFunctionValidationTest, FunctionTypeMustMatchReturnStatementTypeF32Alias_fail) { // type myf32 = f32; // fn func -> myf32 { return 2; } - auto* myf32 = ty.alias("myf32", ty.f32()); - AST().AddConstructedType(myf32); + auto* myf32 = Alias("myf32", ty.f32()); Func("func", ast::VariableList{}, myf32, ast::StatementList{ Return(Source{Source::Location{12, 34}}, Expr(2u)), diff --git a/src/resolver/host_shareable_validation_test.cc b/src/resolver/host_shareable_validation_test.cc index 57e6fbc56d..e783f1d89a 100644 --- a/src/resolver/host_shareable_validation_test.cc +++ b/src/resolver/host_shareable_validation_test.cc @@ -66,12 +66,10 @@ TEST_F(ResolverHostShareableValidationTest, BoolVectorMember) { } TEST_F(ResolverHostShareableValidationTest, Aliases) { - auto* a1 = ty.alias("a1", ty.bool_()); - AST().AddConstructedType(a1); + auto* a1 = Alias("a1", ty.bool_()); auto* s = Structure("S", {Member(Source{{12, 34}}, "x", a1)}, {create()}); - auto* a2 = ty.alias("a2", s); - AST().AddConstructedType(a2); + auto* a2 = Alias("a2", s); Global(Source{{56, 78}}, "g", a2, ast::StorageClass::kStorage, ast::Access::kRead, ast::DecorationList{ @@ -122,14 +120,12 @@ TEST_F(ResolverHostShareableValidationTest, NoError) { Member(Source{{2, 1}}, "y1", ty.vec3()), Member(Source{{3, 1}}, "z1", ty.array()), }); - auto* a1 = ty.alias("a1", i1); - AST().AddConstructedType(a1); + auto* a1 = Alias("a1", i1); auto* i2 = Structure("I2", { Member(Source{{4, 1}}, "x2", ty.mat2x2()), Member(Source{{5, 1}}, "y2", i1), }); - auto* a2 = ty.alias("a2", i2); - AST().AddConstructedType(a2); + auto* a2 = Alias("a2", i2); auto* i3 = Structure("I3", { Member(Source{{4, 1}}, "x3", a1), Member(Source{{5, 1}}, "y3", i2), diff --git a/src/resolver/resolver_test.cc b/src/resolver/resolver_test.cc index 91b819594d..f7ed724644 100644 --- a/src/resolver/resolver_test.cc +++ b/src/resolver/resolver_test.cc @@ -293,8 +293,7 @@ TEST_F(ResolverTest, Stmt_VariableDecl) { } TEST_F(ResolverTest, Stmt_VariableDecl_Alias) { - auto* my_int = ty.alias("MyInt", ty.i32()); - AST().AddConstructedType(my_int); + auto* my_int = Alias("MyInt", ty.i32()); auto* var = Var("my_var", my_int, ast::StorageClass::kNone, Expr(2)); auto* init = var->constructor(); @@ -308,10 +307,8 @@ TEST_F(ResolverTest, Stmt_VariableDecl_Alias) { } TEST_F(ResolverTest, Stmt_VariableDecl_AliasRedeclared) { - auto* my_int1 = ty.alias(Source{{12, 34}}, "MyInt", ty.i32()); - auto* my_int2 = ty.alias(Source{{56, 78}}, "MyInt", ty.i32()); - AST().AddConstructedType(my_int1); - AST().AddConstructedType(my_int2); + Alias(Source{{12, 34}}, "MyInt", ty.i32()); + Alias(Source{{56, 78}}, "MyInt", ty.i32()); WrapInFunction(); EXPECT_FALSE(r()->Resolve()); @@ -450,8 +447,7 @@ TEST_F(ResolverTest, Expr_ArrayAccessor_Array) { } TEST_F(ResolverTest, Expr_ArrayAccessor_Alias_Array) { - auto* aary = ty.alias("myarrty", ty.array()); - AST().AddConstructedType(aary); + auto* aary = Alias("myarrty", ty.array()); Global("my_var", aary, ast::StorageClass::kPrivate); @@ -1124,8 +1120,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct) { TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) { auto* st = Structure("S", {Member("first_member", ty.i32()), Member("second_member", ty.f32())}); - auto* alias = ty.alias("alias", st); - AST().AddConstructedType(alias); + auto* alias = Alias("alias", st); Global("my_struct", alias, ast::StorageClass::kInput); auto* mem = MemberAccessor("my_struct", "second_member"); diff --git a/src/resolver/storage_class_validation_test.cc b/src/resolver/storage_class_validation_test.cc index 29c89459e3..033e7f60df 100644 --- a/src/resolver/storage_class_validation_test.cc +++ b/src/resolver/storage_class_validation_test.cc @@ -86,8 +86,7 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferArray) { TEST_F(ResolverStorageClassValidationTest, StorageBufferBoolAlias) { // type a = bool; // var g : a; - auto* a = ty.alias("a", ty.bool_()); - AST().AddConstructedType(a); + auto* a = Alias("a", ty.bool_()); Global(Source{{56, 78}}, "g", a, ast::StorageClass::kStorage, ast::DecorationList{ create(0), @@ -141,10 +140,8 @@ TEST_F(ResolverStorageClassValidationTest, StorageBufferNoError_Aliases) { // var g : a1; auto* s = Structure("S", {Member(Source{{12, 34}}, "x", ty.i32())}, {create()}); - auto* a1 = ty.alias("a1", s); - AST().AddConstructedType(a1); - auto* a2 = ty.alias("a2", a1); - AST().AddConstructedType(a2); + auto* a1 = Alias("a1", s); + auto* a2 = Alias("a2", a1); Global(Source{{56, 78}}, "g", a2, ast::StorageClass::kStorage, ast::Access::kRead, ast::DecorationList{ @@ -208,8 +205,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferArray) { TEST_F(ResolverStorageClassValidationTest, UniformBufferBoolAlias) { // type a = bool; // var g : a; - auto* a = ty.alias("a", ty.bool_()); - AST().AddConstructedType(a); + auto* a = Alias("a", ty.bool_()); Global(Source{{56, 78}}, "g", a, ast::StorageClass::kUniform, ast::DecorationList{ create(0), @@ -261,8 +257,7 @@ TEST_F(ResolverStorageClassValidationTest, UniformBufferNoError_Aliases) { // var g : a1; auto* s = Structure("S", {Member(Source{{12, 34}}, "x", ty.i32())}, {create()}); - auto* a1 = ty.alias("a1", s); - AST().AddConstructedType(a1); + auto* a1 = Alias("a1", s); Global(Source{{56, 78}}, "g", a1, ast::StorageClass::kUniform, ast::DecorationList{ create(0), diff --git a/src/resolver/struct_layout_test.cc b/src/resolver/struct_layout_test.cc index 667020cf4c..be0e808197 100644 --- a/src/resolver/struct_layout_test.cc +++ b/src/resolver/struct_layout_test.cc @@ -52,10 +52,8 @@ TEST_F(ResolverStructLayoutTest, Scalars) { } TEST_F(ResolverStructLayoutTest, Alias) { - auto* alias_a = ty.alias("a", ty.f32()); - AST().AddConstructedType(alias_a); - auto* alias_b = ty.alias("b", ty.f32()); - AST().AddConstructedType(alias_b); + auto* alias_a = Alias("a", ty.f32()); + auto* alias_b = Alias("b", ty.f32()); auto* s = Structure("S", { Member("a", alias_a), diff --git a/src/resolver/struct_pipeline_stage_use_test.cc b/src/resolver/struct_pipeline_stage_use_test.cc index b6d565512b..4c481a5b28 100644 --- a/src/resolver/struct_pipeline_stage_use_test.cc +++ b/src/resolver/struct_pipeline_stage_use_test.cc @@ -158,8 +158,7 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedMultipleStages) { TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderParamViaAlias) { auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})}); - auto* s_alias = ty.alias("S_alias", s); - AST().AddConstructedType(s_alias); + auto* s_alias = Alias("S_alias", s); Func("main", {Param("param", s_alias)}, ty.void_(), {}, {Stage(ast::PipelineStage::kFragment)}); @@ -174,8 +173,7 @@ TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderParamViaAlias) { TEST_F(ResolverPipelineStageUseTest, StructUsedAsShaderReturnTypeViaAlias) { auto* s = Structure("S", {Member("a", ty.f32(), {Location(0)})}); - auto* s_alias = ty.alias("S_alias", s); - AST().AddConstructedType(s_alias); + auto* s_alias = Alias("S_alias", s); Func("main", {}, s_alias, {Return(Construct(s_alias, Expr(0.f)))}, {Stage(ast::PipelineStage::kFragment)}); diff --git a/src/resolver/struct_storage_class_use_test.cc b/src/resolver/struct_storage_class_use_test.cc index 7a83ab07fb..8af99bef8b 100644 --- a/src/resolver/struct_storage_class_use_test.cc +++ b/src/resolver/struct_storage_class_use_test.cc @@ -78,8 +78,7 @@ TEST_F(ResolverStorageClassUseTest, StructReachableFromGlobal) { TEST_F(ResolverStorageClassUseTest, StructReachableViaGlobalAlias) { auto* s = Structure("S", {Member("a", ty.f32())}); - auto* a = ty.alias("A", s); - AST().AddConstructedType(a); + auto* a = Alias("A", s); Global("g", a, ast::StorageClass::kPrivate); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -131,8 +130,7 @@ TEST_F(ResolverStorageClassUseTest, StructReachableFromLocal) { TEST_F(ResolverStorageClassUseTest, StructReachableViaLocalAlias) { auto* s = Structure("S", {Member("a", ty.f32())}); - auto* a = ty.alias("A", s); - AST().AddConstructedType(a); + auto* a = Alias("A", s); WrapInFunction(Var("g", a)); ASSERT_TRUE(r()->Resolve()) << r()->error(); diff --git a/src/resolver/type_validation_test.cc b/src/resolver/type_validation_test.cc index 5c9973e71c..2eb0707753 100644 --- a/src/resolver/type_validation_test.cc +++ b/src/resolver/type_validation_test.cc @@ -338,9 +338,7 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsNotLast_Fail) { // a: u32; //} - auto* alias = ty.alias("RTArr", ty.array()); - AST().AddConstructedType(alias); - + auto* alias = Alias("RTArr", ty.array()); Structure("s", { Member(Source{{12, 34}}, "b", alias), @@ -365,9 +363,7 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsLast_Pass) { // b: RTArr; //} - auto* alias = ty.alias("RTArr", ty.array()); - AST().AddConstructedType(alias); - + auto* alias = Alias("RTArr", ty.array()); Structure("s", { Member("a", ty.u32()), diff --git a/src/resolver/validation_test.cc b/src/resolver/validation_test.cc index 07356a79ef..e271bdc530 100644 --- a/src/resolver/validation_test.cc +++ b/src/resolver/validation_test.cc @@ -1708,8 +1708,7 @@ TEST_F(ResolverValidationTest, } TEST_F(ResolverValidationTest, Expr_Constructor_Vector_Alias_Argument_Error) { - auto* alias = ty.alias("UnsignedInt", ty.u32()); - AST().AddConstructedType(alias); + auto* alias = Alias("UnsignedInt", ty.u32()); Global("uint_var", alias, ast::StorageClass::kInput); auto* tc = vec2(Expr(Source{{12, 34}}, "uint_var")); @@ -1722,10 +1721,8 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vector_Alias_Argument_Error) { } TEST_F(ResolverValidationTest, Expr_Constructor_Vector_Alias_Argument_Success) { - auto* f32_alias = ty.alias("Float32", ty.f32()); - auto* vec2_alias = ty.alias("VectorFloat2", ty.vec2()); - AST().AddConstructedType(f32_alias); - AST().AddConstructedType(vec2_alias); + auto* f32_alias = Alias("Float32", ty.f32()); + auto* vec2_alias = Alias("VectorFloat2", ty.vec2()); Global("my_f32", f32_alias, ast::StorageClass::kInput); Global("my_vec2", vec2_alias, ast::StorageClass::kInput); @@ -1735,8 +1732,7 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vector_Alias_Argument_Success) { } TEST_F(ResolverValidationTest, Expr_Constructor_Vector_ElementTypeAlias_Error) { - auto* f32_alias = ty.alias("Float32", ty.f32()); - AST().AddConstructedType(f32_alias); + auto* f32_alias = Alias("Float32", ty.f32()); // vec2(1.0f, 1u) auto* vec_type = ty.vec(f32_alias, 2); @@ -1754,8 +1750,7 @@ TEST_F(ResolverValidationTest, Expr_Constructor_Vector_ElementTypeAlias_Error) { TEST_F(ResolverValidationTest, Expr_Constructor_Vector_ElementTypeAlias_Success) { - auto* f32_alias = ty.alias("Float32", ty.f32()); - AST().AddConstructedType(f32_alias); + auto* f32_alias = Alias("Float32", ty.f32()); // vec2(1.0f, 1.0f) auto* vec_type = ty.vec(f32_alias, 2); @@ -1768,8 +1763,7 @@ TEST_F(ResolverValidationTest, TEST_F(ResolverValidationTest, Expr_Constructor_Vector_ArgumentElementTypeAlias_Error) { - auto* f32_alias = ty.alias("Float32", ty.f32()); - AST().AddConstructedType(f32_alias); + auto* f32_alias = Alias("Float32", ty.f32()); // vec3(vec(), 1.0f) auto* vec_type = ty.vec(f32_alias, 2); @@ -1786,8 +1780,7 @@ TEST_F(ResolverValidationTest, TEST_F(ResolverValidationTest, Expr_Constructor_Vector_ArgumentElementTypeAlias_Success) { - auto* f32_alias = ty.alias("Float32", ty.f32()); - AST().AddConstructedType(f32_alias); + auto* f32_alias = Alias("Float32", ty.f32()); // vec3(vec(), 1.0f) auto* vec_type = ty.vec(f32_alias, 2); @@ -2017,8 +2010,7 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ElementTypeAlias_Error) { // matNxM(vecM(), ...); with N arguments const auto param = GetParam(); - auto* f32_alias = ty.alias("Float32", ty.f32()); - AST().AddConstructedType(f32_alias); + auto* f32_alias = Alias("Float32", ty.f32()); ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns; i++) { @@ -2043,8 +2035,7 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ElementTypeAlias_Success) { // matNxM(vecM(), ...); with N arguments const auto param = GetParam(); - auto* f32_alias = ty.alias("Float32", ty.f32()); - AST().AddConstructedType(f32_alias); + auto* f32_alias = Alias("Float32", ty.f32()); ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns; i++) { @@ -2062,8 +2053,7 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ElementTypeAlias_Success) { } TEST_F(ResolverValidationTest, Expr_MatrixConstructor_ArgumentTypeAlias_Error) { - auto* alias = ty.alias("VectorUnsigned2", ty.vec2()); - AST().AddConstructedType(alias); + auto* alias = Alias("VectorUnsigned2", ty.vec2()); auto* tc = mat2x2( create( Source{{12, 34}}, ty.MaybeCreateTypename(alias), ExprList()), @@ -2080,8 +2070,7 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentTypeAlias_Success) { const auto param = GetParam(); auto* matrix_type = ty.mat(param.columns, param.rows); auto* vec_type = ty.vec(param.rows); - auto* vec_alias = ty.alias("VectorFloat2", vec_type); - AST().AddConstructedType(vec_alias); + auto* vec_alias = Alias("VectorFloat2", vec_type); ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns; i++) { @@ -2099,8 +2088,7 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentTypeAlias_Success) { TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentElementTypeAlias_Error) { const auto param = GetParam(); auto* matrix_type = ty.mat(param.columns, param.rows); - auto* f32_alias = ty.alias("UnsignedInt", ty.u32()); - AST().AddConstructedType(f32_alias); + auto* f32_alias = Alias("UnsignedInt", ty.u32()); ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns; i++) { @@ -2123,8 +2111,7 @@ TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentElementTypeAlias_Error) { TEST_P(MatrixConstructorTest, Expr_Constructor_ArgumentElementTypeAlias_Success) { const auto param = GetParam(); - auto* f32_alias = ty.alias("Float32", ty.f32()); - AST().AddConstructedType(f32_alias); + auto* f32_alias = Alias("Float32", ty.f32()); ast::ExpressionList args; for (uint32_t i = 1; i <= param.columns; i++) { diff --git a/src/resolver/var_let_test.cc b/src/resolver/var_let_test.cc index a351ac3acb..84b4ae797b 100644 --- a/src/resolver/var_let_test.cc +++ b/src/resolver/var_let_test.cc @@ -39,8 +39,7 @@ TEST_F(ResolverVarLetTest, TypeOfVar) { // } auto* S = Structure("S", {Member("i", ty.i32())}); - auto* A = ty.alias("A", S); - AST().AddConstructedType(A); + auto* A = Alias("A", S); auto* i = Var("i", ty.i32(), ast::StorageClass::kNone); auto* u = Var("u", ty.u32(), ast::StorageClass::kNone); @@ -91,8 +90,7 @@ TEST_F(ResolverVarLetTest, TypeOfLet) { // } auto* S = Structure("S", {Member("i", ty.i32())}); - auto* A = ty.alias("A", S); - AST().AddConstructedType(A); + auto* A = Alias("A", S); auto* v = Var("v", ty.i32(), ast::StorageClass::kNone); auto* i = Const("i", ty.i32(), Expr(1)); diff --git a/src/resolver/var_let_validation_test.cc b/src/resolver/var_let_validation_test.cc index 96ada209d5..0fa67e8bd7 100644 --- a/src/resolver/var_let_validation_test.cc +++ b/src/resolver/var_let_validation_test.cc @@ -80,8 +80,7 @@ TEST_F(ResolverVarLetValidationTest, VarConstructorWrongType) { } TEST_F(ResolverVarLetValidationTest, LetConstructorWrongTypeViaAlias) { - auto* a = ty.alias("I32", ty.i32()); - AST().AddConstructedType(a); + auto* a = Alias("I32", ty.i32()); WrapInFunction(Const(Source{{3, 3}}, "v", a, Expr(2u))); EXPECT_FALSE(r()->Resolve()); @@ -91,8 +90,7 @@ TEST_F(ResolverVarLetValidationTest, LetConstructorWrongTypeViaAlias) { } TEST_F(ResolverVarLetValidationTest, VarConstructorWrongTypeViaAlias) { - auto* a = ty.alias("I32", ty.i32()); - AST().AddConstructedType(a); + auto* a = Alias("I32", ty.i32()); WrapInFunction( Var(Source{{3, 3}}, "v", a, ast::StorageClass::kNone, Expr(2u))); diff --git a/src/writer/hlsl/generator_impl_workgroup_var_test.cc b/src/writer/hlsl/generator_impl_workgroup_var_test.cc index a488f100b3..f48920de0f 100644 --- a/src/writer/hlsl/generator_impl_workgroup_var_test.cc +++ b/src/writer/hlsl/generator_impl_workgroup_var_test.cc @@ -39,8 +39,7 @@ TEST_F(HlslGeneratorImplTest_WorkgroupVar, Basic) { } TEST_F(HlslGeneratorImplTest_WorkgroupVar, Aliased) { - auto* alias = ty.alias("F32", ty.f32()); - AST().AddConstructedType(alias); + auto* alias = Alias("F32", ty.f32()); Global("wg", alias, ast::StorageClass::kWorkgroup); diff --git a/src/writer/spirv/builder_accessor_expression_test.cc b/src/writer/spirv/builder_accessor_expression_test.cc index b7400ee59b..19da1a4daf 100644 --- a/src/writer/spirv/builder_accessor_expression_test.cc +++ b/src/writer/spirv/builder_accessor_expression_test.cc @@ -394,8 +394,7 @@ TEST_F(BuilderTest, MemberAccessor_Nested_WithAlias) { Member("b", ty.f32()), }); - auto* alias = ty.alias("Alias", inner_struct); - AST().AddConstructedType(alias); + auto* alias = Alias("Alias", inner_struct); auto* s_type = Structure("Outer", {Member("inner", alias)}); auto* var = Var("ident", s_type); diff --git a/src/writer/spirv/builder_constructor_expression_test.cc b/src/writer/spirv/builder_constructor_expression_test.cc index 26693313bb..5dd4be6a35 100644 --- a/src/writer/spirv/builder_constructor_expression_test.cc +++ b/src/writer/spirv/builder_constructor_expression_test.cc @@ -93,8 +93,7 @@ TEST_F(SpvBuilderConstructorTest, Type_WithAlias) { // type Int = i32 // cast(2.3f) - auto* alias = ty.alias("Int", ty.i32()); - AST().AddConstructedType(alias); + auto* alias = Alias("Int", ty.i32()); auto* cast = Construct(alias, 2.3f); WrapInFunction(cast); diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index 6cc49f9d6e..9aa0bcaa09 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -441,8 +441,7 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasDeclReadOnly) { auto* A = Structure("A", {Member("a", ty.i32())}, {create()}); - auto* B = ty.alias("B", A); - AST().AddConstructedType(B); + auto* B = Alias("B", A); auto* var = Global("b", B, ast::StorageClass::kStorage, ast::Access::kRead, ast::DecorationList{ create(0), @@ -479,8 +478,7 @@ TEST_F(BuilderTest, GlobalVar_TypeAliasAssignReadOnly) { auto* A = Structure("A", {Member("a", ty.i32())}, {create()}); - auto* B = ty.alias("B", A); - AST().AddConstructedType(B); + auto* B = Alias("B", A); auto* var = Global("b", B, ast::StorageClass::kStorage, ast::Access::kRead, ast::DecorationList{ create(0), diff --git a/src/writer/wgsl/generator_impl_alias_type_test.cc b/src/writer/wgsl/generator_impl_alias_type_test.cc index 4b7311bc85..f71ee45f7b 100644 --- a/src/writer/wgsl/generator_impl_alias_type_test.cc +++ b/src/writer/wgsl/generator_impl_alias_type_test.cc @@ -22,8 +22,7 @@ namespace { using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, EmitAlias_F32) { - auto* alias = ty.alias("a", ty.f32()); - AST().AddConstructedType(alias); + auto* alias = Alias("a", ty.f32()); GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.EmitConstructedType(alias)) << gen.error(); @@ -37,8 +36,7 @@ TEST_F(WgslGeneratorImplTest, EmitConstructedType_Struct) { Member("b", ty.i32()), }); - auto* alias = ty.alias("B", s); - AST().AddConstructedType(alias); + auto* alias = Alias("B", s); GeneratorImpl& gen = Build(); @@ -58,8 +56,7 @@ TEST_F(WgslGeneratorImplTest, EmitAlias_ToStruct) { Member("b", ty.i32()), }); - auto* alias = ty.alias("B", s); - AST().AddConstructedType(alias); + auto* alias = Alias("B", s); GeneratorImpl& gen = Build(); diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc index 5494e7b907..9acd634f2d 100644 --- a/src/writer/wgsl/generator_impl_type_test.cc +++ b/src/writer/wgsl/generator_impl_type_test.cc @@ -26,8 +26,7 @@ namespace { using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, EmitType_Alias) { - auto* alias = ty.alias("alias", ty.f32()); - AST().AddConstructedType(alias); + auto* alias = Alias("alias", ty.f32()); GeneratorImpl& gen = Build(); @@ -37,7 +36,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Alias) { TEST_F(WgslGeneratorImplTest, EmitType_Array) { auto* arr = ty.array(); - AST().AddConstructedType(ty.alias("make_type_reachable", arr)); + Alias("make_type_reachable", arr); GeneratorImpl& gen = Build(); @@ -47,7 +46,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Array) { TEST_F(WgslGeneratorImplTest, EmitType_Array_Decoration) { auto* a = ty.array(ty.bool_(), 4, 16u); - AST().AddConstructedType(ty.alias("make_type_reachable", a)); + Alias("make_type_reachable", a); GeneratorImpl& gen = Build(); @@ -57,7 +56,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Array_Decoration) { TEST_F(WgslGeneratorImplTest, EmitType_RuntimeArray) { auto* a = ty.array(ty.bool_(), 0); - AST().AddConstructedType(ty.alias("make_type_reachable", a)); + Alias("make_type_reachable", a); GeneratorImpl& gen = Build(); @@ -67,7 +66,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_RuntimeArray) { TEST_F(WgslGeneratorImplTest, EmitType_Bool) { auto* bool_ = ty.bool_(); - AST().AddConstructedType(ty.alias("make_type_reachable", bool_)); + Alias("make_type_reachable", bool_); GeneratorImpl& gen = Build(); @@ -77,7 +76,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Bool) { TEST_F(WgslGeneratorImplTest, EmitType_F32) { auto* f32 = ty.f32(); - AST().AddConstructedType(ty.alias("make_type_reachable", f32)); + Alias("make_type_reachable", f32); GeneratorImpl& gen = Build(); @@ -87,7 +86,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_F32) { TEST_F(WgslGeneratorImplTest, EmitType_I32) { auto* i32 = ty.i32(); - AST().AddConstructedType(ty.alias("make_type_reachable", i32)); + Alias("make_type_reachable", i32); GeneratorImpl& gen = Build(); @@ -97,7 +96,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_I32) { TEST_F(WgslGeneratorImplTest, EmitType_Matrix) { auto* mat2x3 = ty.mat2x3(); - AST().AddConstructedType(ty.alias("make_type_reachable", mat2x3)); + Alias("make_type_reachable", mat2x3); GeneratorImpl& gen = Build(); @@ -107,7 +106,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Matrix) { TEST_F(WgslGeneratorImplTest, EmitType_Pointer) { auto* p = ty.pointer(ast::StorageClass::kWorkgroup); - AST().AddConstructedType(ty.alias("make_type_reachable", p)); + Alias("make_type_reachable", p); GeneratorImpl& gen = Build(); @@ -250,7 +249,7 @@ struct S { TEST_F(WgslGeneratorImplTest, EmitType_U32) { auto* u32 = ty.u32(); - AST().AddConstructedType(ty.alias("make_type_reachable", u32)); + Alias("make_type_reachable", u32); GeneratorImpl& gen = Build(); @@ -260,7 +259,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_U32) { TEST_F(WgslGeneratorImplTest, EmitType_Vector) { auto* vec3 = ty.vec3(); - AST().AddConstructedType(ty.alias("make_type_reachable", vec3)); + Alias("make_type_reachable", vec3); GeneratorImpl& gen = Build(); @@ -282,7 +281,7 @@ TEST_P(WgslGenerator_DepthTextureTest, EmitType_DepthTexture) { auto param = GetParam(); auto* d = ty.depth_texture(param.dim); - AST().AddConstructedType(ty.alias("make_type_reachable", d)); + Alias("make_type_reachable", d); GeneratorImpl& gen = Build(); @@ -304,7 +303,7 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_F32) { auto param = GetParam(); auto* t = ty.sampled_texture(param.dim, ty.f32()); - AST().AddConstructedType(ty.alias("make_type_reachable", t)); + Alias("make_type_reachable", t); GeneratorImpl& gen = Build(); @@ -316,7 +315,7 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_I32) { auto param = GetParam(); auto* t = ty.sampled_texture(param.dim, ty.i32()); - AST().AddConstructedType(ty.alias("make_type_reachable", t)); + Alias("make_type_reachable", t); GeneratorImpl& gen = Build(); @@ -328,7 +327,7 @@ TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_U32) { auto param = GetParam(); auto* t = ty.sampled_texture(param.dim, ty.u32()); - AST().AddConstructedType(ty.alias("make_type_reachable", t)); + Alias("make_type_reachable", t); GeneratorImpl& gen = Build(); @@ -351,7 +350,7 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_F32) { auto param = GetParam(); auto* t = ty.multisampled_texture(param.dim, ty.f32()); - AST().AddConstructedType(ty.alias("make_type_reachable", t)); + Alias("make_type_reachable", t); GeneratorImpl& gen = Build(); @@ -363,7 +362,7 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_I32) { auto param = GetParam(); auto* t = ty.multisampled_texture(param.dim, ty.i32()); - AST().AddConstructedType(ty.alias("make_type_reachable", t)); + Alias("make_type_reachable", t); GeneratorImpl& gen = Build(); @@ -375,7 +374,7 @@ TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_U32) { auto param = GetParam(); auto* t = ty.multisampled_texture(param.dim, ty.u32()); - AST().AddConstructedType(ty.alias("make_type_reachable", t)); + Alias("make_type_reachable", t); GeneratorImpl& gen = Build(); @@ -503,7 +502,7 @@ INSTANTIATE_TEST_SUITE_P( TEST_F(WgslGeneratorImplTest, EmitType_Sampler) { auto* sampler = ty.sampler(ast::SamplerKind::kSampler); - AST().AddConstructedType(ty.alias("make_type_reachable", sampler)); + Alias("make_type_reachable", sampler); GeneratorImpl& gen = Build(); @@ -513,7 +512,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_Sampler) { TEST_F(WgslGeneratorImplTest, EmitType_SamplerComparison) { auto* sampler = ty.sampler(ast::SamplerKind::kComparisonSampler); - AST().AddConstructedType(ty.alias("make_type_reachable", sampler)); + Alias("make_type_reachable", sampler); GeneratorImpl& gen = Build();