diff --git a/src/ast/vector_test.cc b/src/ast/vector_test.cc index 940cdc33a4..7977f3dd26 100644 --- a/src/ast/vector_test.cc +++ b/src/ast/vector_test.cc @@ -65,7 +65,8 @@ TEST_F(AstVectorTest, TypeName) { } TEST_F(AstVectorTest, FriendlyName) { - auto* v = ty.vec3(); + auto* f32 = create(); + auto* v = create(f32, 3); EXPECT_EQ(v->FriendlyName(Symbols()), "vec3"); } diff --git a/src/intrinsic_table_test.cc b/src/intrinsic_table_test.cc index 8349c4b2c7..1e7e51d4e0 100644 --- a/src/intrinsic_table_test.cc +++ b/src/intrinsic_table_test.cc @@ -355,7 +355,7 @@ TEST_F(IntrinsicTableTest, MatchWithNestedAliasUnwrapping) { auto* alias_a = ty.alias("alias_a", ty.bool_()); auto* alias_b = ty.alias("alias_b", alias_a); auto* alias_c = ty.alias("alias_c", alias_b); - auto* vec4_of_c = ty.vec4(alias_c); + auto vec4_of_c = ty.vec4(alias_c); auto* alias_d = ty.alias("alias_d", vec4_of_c); auto* alias_e = ty.alias("alias_e", alias_d); diff --git a/src/program_builder.h b/src/program_builder.h index f6e00ba4d0..805dba38ed 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -45,6 +45,7 @@ #include "src/ast/u32.h" #include "src/ast/uint_literal.h" #include "src/ast/variable_decl_statement.h" +#include "src/ast/vector.h" #include "src/ast/void.h" #include "src/program.h" #include "src/program_id.h" @@ -361,37 +362,40 @@ class ProgramBuilder { /// @param type vector subtype /// @return the tint AST type for a 2-element vector of `type`. - sem::Vector* vec2(sem::Type* type) const { - return builder->create(type, 2u); + typ::Vector vec2(typ::Type type) const { + return {builder->create(type, 2u), + builder->create(type, 2u)}; } /// @param type vector subtype /// @return the tint AST type for a 3-element vector of `type`. - sem::Vector* vec3(sem::Type* type) const { - return builder->create(type, 3u); + typ::Vector vec3(typ::Type type) const { + return {builder->create(type, 3u), + builder->create(type, 3u)}; } /// @param type vector subtype /// @return the tint AST type for a 4-element vector of `type`. - sem::Type* vec4(sem::Type* type) const { - return builder->create(type, 4u); + typ::Vector vec4(typ::Type type) const { + return {builder->create(type, 4u), + builder->create(type, 4u)}; } /// @return the tint AST type for a 2-element vector of the C type `T`. template - sem::Vector* vec2() const { + typ::Vector vec2() const { return vec2(Of()); } /// @return the tint AST type for a 3-element vector of the C type `T`. template - sem::Vector* vec3() const { + typ::Vector vec3() const { return vec3(Of()); } /// @return the tint AST type for a 4-element vector of the C type `T`. template - sem::Type* vec4() const { + typ::Vector vec4() const { return vec4(Of()); } diff --git a/src/sem/vector_type_test.cc b/src/sem/vector_type_test.cc index 099aae6f04..c5402a9eee 100644 --- a/src/sem/vector_type_test.cc +++ b/src/sem/vector_type_test.cc @@ -49,13 +49,14 @@ TEST_F(VectorTest, Is) { } TEST_F(VectorTest, TypeName) { - I32 i32; - Vector v{&i32, 3}; - EXPECT_EQ(v.type_name(), "__vec_3__i32"); + auto* i32 = create(); + auto* v = create(i32, 3); + EXPECT_EQ(v->type_name(), "__vec_3__i32"); } TEST_F(VectorTest, FriendlyName) { - auto* v = ty.vec3(); + auto* f32 = create(); + auto* v = create(f32, 3); EXPECT_EQ(v->FriendlyName(Symbols()), "vec3"); } diff --git a/src/typepair.h b/src/typepair.h index 12f10b94a3..76388807ab 100644 --- a/src/typepair.h +++ b/src/typepair.h @@ -26,6 +26,7 @@ class Bool; class F32; class I32; class U32; +class Vector; class Void; } // namespace ast @@ -34,12 +35,13 @@ class Bool; class F32; class I32; class U32; +class Vector; class Void; } // namespace sem namespace typ { // type-pair -/// Type is a pair of ast::Type and sem::Type pointers used to simplify +/// TypePair is a pair of ast::Type and sem::Type pointers used to simplify /// migration to the new ast::Type nodes. /// /// Type attempts to behave as either an ast::Type or sem::Type: @@ -51,24 +53,24 @@ namespace typ { // type-pair /// * operator->() returns the sem::Type pointer. Later in the migration this /// will switch to returning the ast::Type pointer. template -struct Type { +struct TypePair { /// The ast::Type pointer AST const* const ast = nullptr; /// The sem::Type pointer SEM const* const sem = nullptr; /// Constructor - Type() = default; + TypePair() = default; /// Constructor /// @param a the ast::Type pointer - Type(const AST* a) : ast(a) {} // NOLINT: explicit + TypePair(const AST* a) : ast(a) {} // NOLINT: explicit /// Constructor /// @param s the sem::Type pointer - Type(const SEM* s) : sem(s) {} // NOLINT: explicit + TypePair(const SEM* s) : sem(s) {} // NOLINT: explicit /// Constructor /// @param a the ast::Type pointer /// @param s the sem::Type pointer - Type(const AST* a, const SEM* s) : ast(a), sem(s) {} + TypePair(const AST* a, const SEM* s) : ast(a), sem(s) {} /// @returns the ast::Type pointer operator AST*() const { return const_cast(ast); } @@ -78,11 +80,14 @@ struct Type { SEM* operator->() const { return const_cast(sem); } }; -using Bool = Type; -using F32 = Type; -using I32 = Type; -using U32 = Type; -using Void = Type; +using Type = TypePair; + +using Bool = TypePair; +using F32 = TypePair; +using I32 = TypePair; +using U32 = TypePair; +using Vector = TypePair; +using Void = TypePair; } // namespace typ diff --git a/src/writer/hlsl/generator_impl_type_test.cc b/src/writer/hlsl/generator_impl_type_test.cc index 91c585ce6a..5d8bfd6369 100644 --- a/src/writer/hlsl/generator_impl_type_test.cc +++ b/src/writer/hlsl/generator_impl_type_test.cc @@ -275,7 +275,7 @@ TEST_F(HlslGeneratorImplTest_Type, EmitType_U32) { } TEST_F(HlslGeneratorImplTest_Type, EmitType_Vector) { - auto* vec3 = ty.vec3(); + auto vec3 = ty.vec3(); GeneratorImpl& gen = Build(); diff --git a/src/writer/msl/generator_impl_type_test.cc b/src/writer/msl/generator_impl_type_test.cc index 8f260d7406..e489cba4c7 100644 --- a/src/writer/msl/generator_impl_type_test.cc +++ b/src/writer/msl/generator_impl_type_test.cc @@ -613,7 +613,7 @@ TEST_F(MslGeneratorImplTest, EmitType_U32) { } TEST_F(MslGeneratorImplTest, EmitType_Vector) { - auto* vec3 = ty.vec3(); + auto vec3 = ty.vec3(); GeneratorImpl& gen = Build(); diff --git a/src/writer/spirv/builder_entry_point_test.cc b/src/writer/spirv/builder_entry_point_test.cc index 62d439efe4..78f0818663 100644 --- a/src/writer/spirv/builder_entry_point_test.cc +++ b/src/writer/spirv/builder_entry_point_test.cc @@ -43,7 +43,7 @@ TEST_F(BuilderTest, EntryPoint_Parameters) { // var col : f32 = (coord.x * loc1); // } auto f32 = ty.f32(); - auto* vec4 = ty.vec4(); + auto vec4 = ty.vec4(); auto* coord = Param("coord", vec4, {Builtin(ast::Builtin::kPosition)}); auto* loc1 = Param("loc1", f32, {Location(1u)}); auto* mul = Mul(Expr(MemberAccessor("coord", "x")), Expr("loc1")); diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 23376b2183..3fe65417e6 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -528,7 +528,7 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedU32) { } TEST_F(BuilderTest_Type, GenerateVector) { - auto* vec = ty.vec3(); + auto vec = ty.vec3(); spirv::Builder& b = Build(); @@ -543,7 +543,7 @@ TEST_F(BuilderTest_Type, GenerateVector) { } TEST_F(BuilderTest_Type, ReturnsGeneratedVector) { - auto* vec = ty.vec3(); + auto vec = ty.vec3(); auto i32 = ty.i32(); spirv::Builder& b = Build(); diff --git a/src/writer/wgsl/generator_impl_function_test.cc b/src/writer/wgsl/generator_impl_function_test.cc index b0aa55447f..8edba4095c 100644 --- a/src/writer/wgsl/generator_impl_function_test.cc +++ b/src/writer/wgsl/generator_impl_function_test.cc @@ -140,7 +140,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithDecoration_Multiple) { } TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) { - auto* vec4 = ty.vec4(); + auto vec4 = ty.vec4(); auto* coord = Param("coord", vec4, {Builtin(ast::Builtin::kPosition)}); auto* loc1 = Param("loc1", ty.f32(), {Location(1u)}); auto* func = Func("frag_main", ast::VariableList{coord, loc1}, ty.void_(), diff --git a/src/writer/wgsl/generator_impl_type_test.cc b/src/writer/wgsl/generator_impl_type_test.cc index 8fb335cb1d..296294bb02 100644 --- a/src/writer/wgsl/generator_impl_type_test.cc +++ b/src/writer/wgsl/generator_impl_type_test.cc @@ -303,7 +303,7 @@ TEST_F(WgslGeneratorImplTest, EmitType_U32) { } TEST_F(WgslGeneratorImplTest, EmitType_Vector) { - auto* vec3 = ty.vec3(); + auto vec3 = ty.vec3(); AST().AddConstructedType(ty.alias("make_type_reachable", vec3)); GeneratorImpl& gen = Build();