diff --git a/src/ast/bitcast_expression.cc b/src/ast/bitcast_expression.cc index b2baa53604..2c23b9d6ec 100644 --- a/src/ast/bitcast_expression.cc +++ b/src/ast/bitcast_expression.cc @@ -26,7 +26,7 @@ BitcastExpression::BitcastExpression(ProgramID program_id, typ::Type type, Expression* expr) : Base(program_id, source), type_(type), expr_(expr) { - TINT_ASSERT(type_.sem); + TINT_ASSERT(type_.ast || type_.sem); TINT_ASSERT(expr_); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(expr, program_id); } @@ -46,8 +46,9 @@ void BitcastExpression::to_str(const sem::Info& sem, std::ostream& out, size_t indent) const { make_indent(out, indent); - out << "Bitcast[" << result_type_str(sem) << "]<" << type_->type_name() - << ">{" << std::endl; + out << "Bitcast[" << result_type_str(sem) << "]<" + << (type_.ast ? type_.ast->type_name() : type_.sem->type_name()) << ">{" + << std::endl; expr_->to_str(sem, out, indent + 2); make_indent(out, indent); out << "}" << std::endl; diff --git a/src/ast/function.cc b/src/ast/function.cc index 403863ff82..ec7b2f021d 100644 --- a/src/ast/function.cc +++ b/src/ast/function.cc @@ -45,7 +45,7 @@ Function::Function(ProgramID program_id, TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(param, program_id); } TINT_ASSERT(symbol_.IsValid()); - TINT_ASSERT(return_type_.sem); + TINT_ASSERT(return_type_.ast || return_type_.sem); for (auto* deco : decorations_) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(deco, program_id); } @@ -92,7 +92,9 @@ void Function::to_str(const sem::Info& sem, std::ostream& out, size_t indent) const { make_indent(out, indent); - out << "Function " << symbol_.to_str() << " -> " << return_type_->type_name() + out << "Function " << symbol_.to_str() << " -> " + << (return_type_.ast ? return_type_.ast->type_name() + : return_type_.sem->type_name()) << std::endl; for (auto* deco : decorations()) { diff --git a/src/ast/struct_member.cc b/src/ast/struct_member.cc index 7fc2fa250b..ca4bde2186 100644 --- a/src/ast/struct_member.cc +++ b/src/ast/struct_member.cc @@ -30,7 +30,7 @@ StructMember::StructMember(ProgramID program_id, symbol_(sym), type_(type), decorations_(std::move(decorations)) { - TINT_ASSERT(type.sem); + TINT_ASSERT(type.ast || type.sem); TINT_ASSERT(symbol_.IsValid()); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id); for (auto* deco : decorations_) { @@ -76,7 +76,9 @@ void StructMember::to_str(const sem::Info& sem, out << "]] "; } - out << symbol_.to_str() << ": " << type_->type_name() << "}" << std::endl; + out << symbol_.to_str() << ": " + << (type_.ast ? type_.ast->type_name() : type_.sem->type_name()) << "}" + << std::endl; } } // namespace ast diff --git a/src/ast/type_constructor_expression.cc b/src/ast/type_constructor_expression.cc index 01c0c739c9..51deb0f963 100644 --- a/src/ast/type_constructor_expression.cc +++ b/src/ast/type_constructor_expression.cc @@ -26,7 +26,7 @@ TypeConstructorExpression::TypeConstructorExpression(ProgramID program_id, typ::Type type, ExpressionList values) : Base(program_id, source), type_(type), values_(std::move(values)) { - TINT_ASSERT(type_.sem); + TINT_ASSERT(type_.ast || type_.sem); for (auto* val : values_) { TINT_ASSERT(val); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(val, program_id); @@ -53,7 +53,8 @@ void TypeConstructorExpression::to_str(const sem::Info& sem, make_indent(out, indent); out << "TypeConstructor[" << result_type_str(sem) << "]{" << std::endl; make_indent(out, indent + 2); - out << type_->type_name() << std::endl; + out << (type_.ast ? type_.ast->type_name() : type_.sem->type_name()) + << std::endl; for (auto* val : values_) { val->to_str(sem, out, indent + 2); diff --git a/src/ast/variable.cc b/src/ast/variable.cc index 3837666f23..69a296423d 100644 --- a/src/ast/variable.cc +++ b/src/ast/variable.cc @@ -41,7 +41,7 @@ Variable::Variable(ProgramID program_id, TINT_ASSERT(symbol_.IsValid()); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(symbol_, program_id); // no type means we must have a constructor to infer it - TINT_ASSERT(type_.sem || constructor); + TINT_ASSERT(type_.ast || type_.sem || constructor); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(constructor, program_id); } @@ -90,9 +90,8 @@ void Variable::info_to_str(const sem::Info& sem, out << (var_sem ? var_sem->StorageClass() : declared_storage_class()) << std::endl; make_indent(out, indent); - if (type_.sem) { - out << type_->type_name() << std::endl; - } + out << (type_.sem ? type_.sem->type_name() : type_.ast->type_name()) + << std::endl; } void Variable::constructor_to_str(const sem::Info& sem, diff --git a/src/inspector/inspector_test.cc b/src/inspector/inspector_test.cc index 8ee6cc4b01..15324a6902 100644 --- a/src/inspector/inspector_test.cc +++ b/src/inspector/inspector_test.cc @@ -173,7 +173,8 @@ class InspectorHelper : public ProgramBuilder { /// @param type type of member /// @returns a string for the member std::string StructMemberName(size_t idx, typ::Type type) { - return std::to_string(idx) + type->type_name(); + return std::to_string(idx) + + (type.sem ? type.sem->type_name() : type.ast->type_name()); } /// Generates a struct type diff --git a/src/program_builder.h b/src/program_builder.h index e910ed17e6..a156f2d6ef 100644 --- a/src/program_builder.h +++ b/src/program_builder.h @@ -861,6 +861,9 @@ class ProgramBuilder { /// @return either type or a pointer to a new ast::TypeName typ::Type MaybeCreateTypename(typ::Type type) const; + /// The ProgramBuilder + ProgramBuilder* const builder; + private: /// CToAST is specialized for various `T` types and each specialization /// contains a single static `get()` method for obtaining the corresponding @@ -869,8 +872,6 @@ class ProgramBuilder { /// `static typ::Type get(Types* t)` template struct CToAST {}; - - ProgramBuilder* const builder; }; ////////////////////////////////////////////////////////////////////////////// diff --git a/src/writer/hlsl/generator_impl_member_accessor_test.cc b/src/writer/hlsl/generator_impl_member_accessor_test.cc index 04efb7da98..9b6d552e74 100644 --- a/src/writer/hlsl/generator_impl_member_accessor_test.cc +++ b/src/writer/hlsl/generator_impl_member_accessor_test.cc @@ -26,63 +26,63 @@ namespace { using ::testing::HasSubstr; using create_type_func_ptr = - sem::Type* (*)(const ProgramBuilder::TypesBuilder& ty); + typ::Type (*)(const ProgramBuilder::TypesBuilder& ty); -inline sem::Type* ty_i32(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_i32(const ProgramBuilder::TypesBuilder& ty) { return ty.i32(); } -inline sem::Type* ty_u32(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_u32(const ProgramBuilder::TypesBuilder& ty) { return ty.u32(); } -inline sem::Type* ty_f32(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_f32(const ProgramBuilder::TypesBuilder& ty) { return ty.f32(); } template -inline sem::Type* ty_vec2(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_vec2(const ProgramBuilder::TypesBuilder& ty) { return ty.vec2(); } template -inline sem::Type* ty_vec3(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_vec3(const ProgramBuilder::TypesBuilder& ty) { return ty.vec3(); } template -inline sem::Type* ty_vec4(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_vec4(const ProgramBuilder::TypesBuilder& ty) { return ty.vec4(); } template -inline sem::Type* ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) { return ty.mat2x2(); } template -inline sem::Type* ty_mat2x3(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_mat2x3(const ProgramBuilder::TypesBuilder& ty) { return ty.mat2x3(); } template -inline sem::Type* ty_mat2x4(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_mat2x4(const ProgramBuilder::TypesBuilder& ty) { return ty.mat2x4(); } template -inline sem::Type* ty_mat3x2(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_mat3x2(const ProgramBuilder::TypesBuilder& ty) { return ty.mat3x2(); } template -inline sem::Type* ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) { return ty.mat3x3(); } template -inline sem::Type* ty_mat3x4(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_mat3x4(const ProgramBuilder::TypesBuilder& ty) { return ty.mat3x4(); } template -inline sem::Type* ty_mat4x2(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_mat4x2(const ProgramBuilder::TypesBuilder& ty) { return ty.mat4x2(); } template -inline sem::Type* ty_mat4x3(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_mat4x3(const ProgramBuilder::TypesBuilder& ty) { return ty.mat4x3(); } template -inline sem::Type* ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) { +inline typ::Type ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) { return ty.mat4x4(); } @@ -155,8 +155,12 @@ struct TypeCase { }; inline std::ostream& operator<<(std::ostream& out, TypeCase c) { ProgramBuilder b; - auto* ty = c.member_type(b.ty); - out << ty->FriendlyName(b.Symbols()); + auto ty = c.member_type(b.ty); + if (ty.sem) { + out << ty.sem->FriendlyName(b.Symbols()); + } else { + out << ty.ast->FriendlyName(b.Symbols()); + } return out; } @@ -246,7 +250,7 @@ TEST_P(HlslGeneratorImplTest_MemberAccessor_StorageBufferStore, Test) { auto p = GetParam(); - auto* type = p.member_type(ty); + auto type = p.member_type(ty); SetupStorageBuffer({ Member("a", ty.i32()),