sem::StructType remove symbol()

The name now lives on the ast::Struct. Use that instead.

Bug: tint:724
Change-Id: I4ee5e9b29973e468edd8df8c5448816b36f0fca6
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/48384
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton 2021-04-20 15:21:21 +00:00 committed by Commit Bot service account
parent 8a8d26bbd9
commit 913a2f4b2a
22 changed files with 87 additions and 100 deletions

View File

@ -398,7 +398,7 @@ std::vector<ResourceBinding> Inspector::GetUniformBufferResourceBindings(
auto* sem = program_->Sem().Get(str); auto* sem = program_->Sem().Get(str);
if (!sem) { if (!sem) {
error_ = "Missing semantic information for structure " + error_ = "Missing semantic information for structure " +
program_->Symbols().NameFor(str->symbol()); program_->Symbols().NameFor(str->impl()->name());
continue; continue;
} }
@ -614,7 +614,7 @@ std::vector<ResourceBinding> Inspector::GetStorageBufferResourceBindingsImpl(
auto* sem = program_->Sem().Get(str); auto* sem = program_->Sem().Get(str);
if (!sem) { if (!sem) {
error_ = "Missing semantic information for structure " + error_ = "Missing semantic information for structure " +
program_->Symbols().NameFor(str->symbol()); program_->Symbols().NameFor(str->impl()->name());
continue; continue;
} }

View File

@ -227,7 +227,7 @@ class InspectorHelper : public ProgramBuilder {
auto sym = Sym(name); auto sym = Sym(name);
auto* str = create<ast::Struct>(sym, members, decos); auto* str = create<ast::Struct>(sym, members, decos);
auto* str_ty = ty.struct_(sym, str); auto* str_ty = ty.struct_(str);
AST().AddConstructedType(str_ty); AST().AddConstructedType(str_ty);
return str_ty; return str_ty;
} }
@ -1829,7 +1829,7 @@ TEST_F(InspectorGetUniformBufferResourceBindingsTest, MissingBlockDeco) {
ast::StructMemberList{Member(StructMemberName(0, ty.i32()), ty.i32())}, ast::StructMemberList{Member(StructMemberName(0, ty.i32()), ty.i32())},
decos); decos);
auto* foo_type = ty.struct_("foo_type", str); auto* foo_type = ty.struct_(str);
AddUniformBuffer("foo_ub", foo_type, 0, 0); AddUniformBuffer("foo_ub", foo_type, 0, 0);
MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", {{0, ty.i32()}}); MakeStructVariableReferenceBodyFunction("ub_func", "foo_ub", {{0, ty.i32()}});

View File

@ -556,13 +556,10 @@ class ProgramBuilder {
return pointer(Of<T>(), storage_class); return pointer(Of<T>(), storage_class);
} }
/// @param name the struct name
/// @param impl the struct implementation /// @param impl the struct implementation
/// @returns a struct pointer /// @returns a struct pointer
template <typename NAME> sem::StructType* struct_(ast::Struct* impl) const {
sem::StructType* struct_(NAME&& name, ast::Struct* impl) const { return builder->create<sem::StructType>(impl);
return builder->create<sem::StructType>(
builder->Sym(std::forward<NAME>(name)), impl);
} }
private: private:
@ -1188,7 +1185,7 @@ class ProgramBuilder {
auto sym = Sym(std::forward<NAME>(name)); auto sym = Sym(std::forward<NAME>(name));
auto* impl = create<ast::Struct>(source, sym, std::move(members), auto* impl = create<ast::Struct>(source, sym, std::move(members),
std::move(decorations)); std::move(decorations));
auto* type = ty.struct_(sym, impl); auto* type = ty.struct_(impl);
AST().AddConstructedType(type); AST().AddConstructedType(type);
return type; return type;
} }
@ -1206,7 +1203,7 @@ class ProgramBuilder {
auto sym = Sym(std::forward<NAME>(name)); auto sym = Sym(std::forward<NAME>(name));
auto* impl = auto* impl =
create<ast::Struct>(sym, std::move(members), std::move(decorations)); create<ast::Struct>(sym, std::move(members), std::move(decorations));
auto* type = ty.struct_(sym, impl); auto* type = ty.struct_(impl);
AST().AddConstructedType(type); AST().AddConstructedType(type);
return type; return type;
} }

View File

@ -948,8 +948,7 @@ sem::Type* ParserImpl::ConvertType(
auto sym = builder_.Symbols().Register(name); auto sym = builder_.Symbols().Register(name);
auto* ast_struct = create<ast::Struct>(Source{}, sym, std::move(ast_members), auto* ast_struct = create<ast::Struct>(Source{}, sym, std::move(ast_members),
std::move(ast_struct_decorations)); std::move(ast_struct_decorations));
auto* result = builder_.create<sem::StructType>(ast_struct);
auto* result = builder_.create<sem::StructType>(sym, ast_struct);
id_to_type_[type_id] = result; id_to_type_[type_id] = result;
if (num_non_writable_members == members.size()) { if (num_non_writable_members == members.size()) {
read_only_struct_types_.insert(result); read_only_struct_types_.insert(result);

View File

@ -339,8 +339,8 @@ Expect<bool> ParserImpl::expect_global_decl() {
if (!expect("struct declaration", Token::Type::kSemicolon)) if (!expect("struct declaration", Token::Type::kSemicolon))
return Failure::kErrored; return Failure::kErrored;
register_constructed(builder_.Symbols().NameFor(str.value->symbol()), register_constructed(
str.value); builder_.Symbols().NameFor(str.value->impl()->name()), str.value);
builder_.AST().AddConstructedType(str.value); builder_.AST().AddConstructedType(str.value);
return true; return true;
} }
@ -1135,9 +1135,8 @@ Maybe<sem::StructType*> ParserImpl::struct_decl(ast::DecorationList& decos) {
return Failure::kErrored; return Failure::kErrored;
auto sym = builder_.Symbols().Register(name.value); auto sym = builder_.Symbols().Register(name.value);
return create<sem::StructType>( return create<sem::StructType>(create<ast::Struct>(
sym, create<ast::Struct>(source, sym, std::move(body.value), source, sym, std::move(body.value), std::move(decos)));
std::move(decos)));
} }
// struct_body_decl // struct_body_decl

View File

@ -104,7 +104,7 @@ type B = A;)");
ASSERT_EQ(program.AST().ConstructedTypes().size(), 2u); ASSERT_EQ(program.AST().ConstructedTypes().size(), 2u);
ASSERT_TRUE(program.AST().ConstructedTypes()[0]->Is<sem::StructType>()); ASSERT_TRUE(program.AST().ConstructedTypes()[0]->Is<sem::StructType>());
auto* str = program.AST().ConstructedTypes()[0]->As<sem::StructType>(); auto* str = program.AST().ConstructedTypes()[0]->As<sem::StructType>();
EXPECT_EQ(str->symbol(), program.Symbols().Get("A")); EXPECT_EQ(str->impl()->name(), program.Symbols().Get("A"));
ASSERT_TRUE(program.AST().ConstructedTypes()[1]->Is<sem::Alias>()); ASSERT_TRUE(program.AST().ConstructedTypes()[1]->Is<sem::Alias>());
auto* alias = program.AST().ConstructedTypes()[1]->As<sem::Alias>(); auto* alias = program.AST().ConstructedTypes()[1]->As<sem::Alias>();
@ -168,7 +168,7 @@ TEST_F(ParserImplTest, GlobalDecl_ParsesStruct) {
ASSERT_TRUE(t->Is<sem::StructType>()); ASSERT_TRUE(t->Is<sem::StructType>());
auto* str = t->As<sem::StructType>(); auto* str = t->As<sem::StructType>();
EXPECT_EQ(str->symbol(), program.Symbols().Get("A")); EXPECT_EQ(str->impl()->name(), program.Symbols().Get("A"));
EXPECT_EQ(str->impl()->members().size(), 2u); EXPECT_EQ(str->impl()->members().size(), 2u);
} }
@ -186,7 +186,7 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithStride) {
ASSERT_TRUE(t->Is<sem::StructType>()); ASSERT_TRUE(t->Is<sem::StructType>());
auto* str = t->As<sem::StructType>(); auto* str = t->As<sem::StructType>();
EXPECT_EQ(str->symbol(), program.Symbols().Get("A")); EXPECT_EQ(str->impl()->name(), program.Symbols().Get("A"));
EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_EQ(str->impl()->members().size(), 1u);
EXPECT_FALSE(str->IsBlockDecorated()); EXPECT_FALSE(str->IsBlockDecorated());
@ -213,7 +213,7 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_WithDecoration) {
ASSERT_TRUE(t->Is<sem::StructType>()); ASSERT_TRUE(t->Is<sem::StructType>());
auto* str = t->As<sem::StructType>(); auto* str = t->As<sem::StructType>();
EXPECT_EQ(str->symbol(), program.Symbols().Get("A")); EXPECT_EQ(str->impl()->name(), program.Symbols().Get("A"));
EXPECT_EQ(str->impl()->members().size(), 1u); EXPECT_EQ(str->impl()->members().size(), 1u);
EXPECT_TRUE(str->IsBlockDecorated()); EXPECT_TRUE(str->IsBlockDecorated());
} }

View File

@ -36,7 +36,7 @@ struct S {
EXPECT_FALSE(s.errored); EXPECT_FALSE(s.errored);
EXPECT_TRUE(s.matched); EXPECT_TRUE(s.matched);
ASSERT_NE(s.value, nullptr); ASSERT_NE(s.value, nullptr);
ASSERT_EQ(s->symbol(), p->builder().Symbols().Register("S")); ASSERT_EQ(s->impl()->name(), p->builder().Symbols().Register("S"));
ASSERT_EQ(s->impl()->members().size(), 2u); ASSERT_EQ(s->impl()->members().size(), 2u);
EXPECT_EQ(s->impl()->members()[0]->symbol(), EXPECT_EQ(s->impl()->members()[0]->symbol(),
p->builder().Symbols().Register("a")); p->builder().Symbols().Register("a"));
@ -60,7 +60,7 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithDecoration) {
EXPECT_FALSE(s.errored); EXPECT_FALSE(s.errored);
EXPECT_TRUE(s.matched); EXPECT_TRUE(s.matched);
ASSERT_NE(s.value, nullptr); ASSERT_NE(s.value, nullptr);
ASSERT_EQ(s->symbol(), p->builder().Symbols().Register("B")); ASSERT_EQ(s->impl()->name(), p->builder().Symbols().Register("B"));
ASSERT_EQ(s->impl()->members().size(), 2u); ASSERT_EQ(s->impl()->members().size(), 2u);
EXPECT_EQ(s->impl()->members()[0]->symbol(), EXPECT_EQ(s->impl()->members()[0]->symbol(),
p->builder().Symbols().Register("a")); p->builder().Symbols().Register("a"));
@ -87,7 +87,7 @@ TEST_F(ParserImplTest, StructDecl_ParsesWithMultipleDecoration) {
EXPECT_FALSE(s.errored); EXPECT_FALSE(s.errored);
EXPECT_TRUE(s.matched); EXPECT_TRUE(s.matched);
ASSERT_NE(s.value, nullptr); ASSERT_NE(s.value, nullptr);
ASSERT_EQ(s->symbol(), p->builder().Symbols().Register("S")); ASSERT_EQ(s->impl()->name(), p->builder().Symbols().Register("S"));
ASSERT_EQ(s->impl()->members().size(), 2u); ASSERT_EQ(s->impl()->members().size(), 2u);
EXPECT_EQ(s->impl()->members()[0]->symbol(), EXPECT_EQ(s->impl()->members()[0]->symbol(),
p->builder().Symbols().Register("a")); p->builder().Symbols().Register("a"));

View File

@ -38,8 +38,8 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) {
TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) { TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
auto p = parser("type a = B"); auto p = parser("type a = B");
sem::StructType str(p->builder().Symbols().Get("B"), {}); auto* str = Structure(p->builder().Symbols().Register("B"), {});
p->register_constructed("B", &str); p->register_constructed("B", str);
auto t = p->type_alias(); auto t = p->type_alias();
EXPECT_FALSE(p->has_error()); EXPECT_FALSE(p->has_error());
@ -52,8 +52,8 @@ TEST_F(ParserImplTest, TypeDecl_ParsesStruct_Ident) {
ASSERT_TRUE(alias->type()->Is<sem::StructType>()); ASSERT_TRUE(alias->type()->Is<sem::StructType>());
auto* s = alias->type()->As<sem::StructType>(); auto* s = alias->type()->As<sem::StructType>();
EXPECT_EQ(s->symbol(), p->builder().Symbols().Get("B")); EXPECT_EQ(s->impl()->name(), p->builder().Symbols().Get("B"));
EXPECT_EQ(s->symbol(), p->builder().Symbols().Get("B")); EXPECT_EQ(s->impl()->name(), p->builder().Symbols().Get("B"));
} }
TEST_F(ParserImplTest, TypeDecl_MissingIdent) { TEST_F(ParserImplTest, TypeDecl_MissingIdent) {

View File

@ -116,7 +116,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_Read) {
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(Sym("S"), members, decos); auto* str = create<ast::Struct>(Sym("S"), members, decos);
auto* s = ty.struct_("S", str); auto* s = ty.struct_(str);
p->register_constructed("S", s); p->register_constructed("S", s);
@ -141,7 +141,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_ParsesWithAccessDeco_ReadWrite) {
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(Sym("S"), members, decos); auto* str = create<ast::Struct>(Sym("S"), members, decos);
auto* s = ty.struct_("S", str); auto* s = ty.struct_(str);
p->register_constructed("S", s); p->register_constructed("S", s);
@ -166,7 +166,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDecoFail) {
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(Sym("S"), members, decos); auto* str = create<ast::Struct>(Sym("S"), members, decos);
auto* s = ty.struct_("S", str); auto* s = ty.struct_(str);
p->register_constructed("S", s); p->register_constructed("S", s);
@ -188,7 +188,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_MultipleAccessDeco_MultiBlock_Fail) {
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(Sym("S"), members, decos); auto* str = create<ast::Struct>(Sym("S"), members, decos);
auto* s = ty.struct_("S", str); auto* s = ty.struct_(str);
p->register_constructed("S", s); p->register_constructed("S", s);
@ -226,7 +226,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_NonAccessDecoFail) {
decos.push_back(block_deco); decos.push_back(block_deco);
auto* str = create<ast::Struct>(Sym("S"), members, decos); auto* str = create<ast::Struct>(Sym("S"), members, decos);
auto* s = ty.struct_("S", str); auto* s = ty.struct_(str);
p->register_constructed("S", s); p->register_constructed("S", s);

View File

@ -133,7 +133,7 @@ TEST_P(ArrayDecorationTest, IsValid) {
auto* s = create<ast::Struct>( auto* s = create<ast::Struct>(
Sym("mystruct"), members, Sym("mystruct"), members,
ast::DecorationList{create<ast::StructBlockDecoration>()}); ast::DecorationList{create<ast::StructBlockDecoration>()});
auto* s_ty = ty.struct_("mystruct", s); auto* s_ty = ty.struct_(s);
AST().AddConstructedType(s_ty); AST().AddConstructedType(s_ty);
WrapInFunction(); WrapInFunction();
@ -170,7 +170,7 @@ TEST_P(StructDecorationTest, IsValid) {
auto* s = create<ast::Struct>(Sym("mystruct"), ast::StructMemberList{}, auto* s = create<ast::Struct>(Sym("mystruct"), ast::StructMemberList{},
ast::DecorationList{createDecoration( ast::DecorationList{createDecoration(
Source{{12, 34}}, *this, params.kind)}); Source{{12, 34}}, *this, params.kind)});
auto* s_ty = ty.struct_("mystruct", s); auto* s_ty = ty.struct_(s);
AST().AddConstructedType(s_ty); AST().AddConstructedType(s_ty);
WrapInFunction(); WrapInFunction();
@ -210,7 +210,7 @@ TEST_P(StructMemberDecorationTest, IsValid) {
createDecoration(Source{{12, 34}}, *this, params.kind)})}; createDecoration(Source{{12, 34}}, *this, params.kind)})};
auto* s = auto* s =
create<ast::Struct>(Sym("mystruct"), members, ast::DecorationList{}); create<ast::Struct>(Sym("mystruct"), members, ast::DecorationList{});
auto* s_ty = ty.struct_("mystruct", s); auto* s_ty = ty.struct_(s);
AST().AddConstructedType(s_ty); AST().AddConstructedType(s_ty);
WrapInFunction(); WrapInFunction();

View File

@ -2009,12 +2009,12 @@ bool Resolver::ValidateStructure(const sem::StructType* st) {
return false; return false;
} }
if (!st->IsBlockDecorated()) { if (!st->IsBlockDecorated()) {
diagnostics_.add_error("v-0015", diagnostics_.add_error(
"a struct containing a runtime-sized array " "v-0015",
"requires the [[block]] attribute: '" + "a struct containing a runtime-sized array "
builder_->Symbols().NameFor(st->symbol()) + "requires the [[block]] attribute: '" +
"'", builder_->Symbols().NameFor(st->impl()->name()) + "'",
member->source()); member->source());
return false; return false;
} }

View File

@ -894,7 +894,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct) {
Member("second_member", ty.f32())}, Member("second_member", ty.f32())},
ast::DecorationList{}); ast::DecorationList{});
auto* st = ty.struct_("S", strct); auto* st = ty.struct_(strct);
Global("my_struct", st, ast::StorageClass::kInput); Global("my_struct", st, ast::StorageClass::kInput);
auto* mem = MemberAccessor("my_struct", "second_member"); auto* mem = MemberAccessor("my_struct", "second_member");
@ -924,7 +924,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_Struct_Alias) {
Member("second_member", ty.f32())}, Member("second_member", ty.f32())},
ast::DecorationList{}); ast::DecorationList{});
auto* st = ty.struct_("alias", strct); auto* st = ty.struct_(strct);
auto* alias = ty.alias("alias", st); auto* alias = ty.alias("alias", st);
Global("my_struct", alias, ast::StorageClass::kInput); Global("my_struct", alias, ast::StorageClass::kInput);
@ -1004,14 +1004,14 @@ TEST_F(ResolverTest, Expr_Accessor_MultiLevel) {
auto* strctB = create<ast::Struct>( auto* strctB = create<ast::Struct>(
Sym("B"), ast::StructMemberList{Member("foo", ty.vec4<f32>())}, Sym("B"), ast::StructMemberList{Member("foo", ty.vec4<f32>())},
ast::DecorationList{}); ast::DecorationList{});
auto* stB = ty.struct_("B", strctB); auto* stB = ty.struct_(strctB);
sem::Vector vecB(stB, 3); sem::Vector vecB(stB, 3);
auto* strctA = auto* strctA =
create<ast::Struct>(Sym("A"), ast::StructMemberList{Member("mem", &vecB)}, create<ast::Struct>(Sym("A"), ast::StructMemberList{Member("mem", &vecB)},
ast::DecorationList{}); ast::DecorationList{});
auto* stA = ty.struct_("A", strctA); auto* stA = ty.struct_(strctA);
Global("c", stA, ast::StorageClass::kInput); Global("c", stA, ast::StorageClass::kInput);
auto* mem = MemberAccessor( auto* mem = MemberAccessor(
@ -1035,7 +1035,7 @@ TEST_F(ResolverTest, Expr_MemberAccessor_InBinaryOp) {
Member("second_member", ty.f32())}, Member("second_member", ty.f32())},
ast::DecorationList{}); ast::DecorationList{});
auto* st = ty.struct_("S", strct); auto* st = ty.struct_(strct);
Global("my_struct", st, ast::StorageClass::kInput); Global("my_struct", st, ast::StorageClass::kInput);
auto* expr = Add(MemberAccessor("my_struct", "first_member"), auto* expr = Add(MemberAccessor("my_struct", "first_member"),

View File

@ -320,7 +320,7 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsLast_Pass) {
Member("rt", ty.array<f32>())}, Member("rt", ty.array<f32>())},
decos); decos);
auto* struct_type = ty.struct_("Foo", st); auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type); AST().AddConstructedType(struct_type);
WrapInFunction(); WrapInFunction();
@ -341,7 +341,7 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsLastNoBlock_Fail) {
Member(Source{{12, 34}}, "rt", ty.array<f32>())}, Member(Source{{12, 34}}, "rt", ty.array<f32>())},
decos); decos);
auto* struct_type = ty.struct_("Foo", st); auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type); AST().AddConstructedType(struct_type);
WrapInFunction(); WrapInFunction();
@ -366,7 +366,7 @@ TEST_F(ResolverTypeValidationTest, RuntimeArrayIsNotLast_Fail) {
auto* st = create<ast::Struct>( auto* st = create<ast::Struct>(
Sym("Foo"), ast::StructMemberList{rt, Member("vf", ty.f32())}, decos); Sym("Foo"), ast::StructMemberList{rt, Member("vf", ty.f32())}, decos);
auto* struct_type = ty.struct_("Foo", st); auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type); AST().AddConstructedType(struct_type);
@ -445,7 +445,7 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsNotLast_Fail) {
Member("a", ty.u32())}, Member("a", ty.u32())},
decos); decos);
auto* struct_type = ty.struct_("s", st); auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type); AST().AddConstructedType(struct_type);
WrapInFunction(); WrapInFunction();
@ -473,7 +473,7 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsLast_Pass) {
Sym("s"), Sym("s"),
ast::StructMemberList{Member("a", ty.u32()), Member("b", alias)}, decos); ast::StructMemberList{Member("a", ty.u32()), Member("b", alias)}, decos);
auto* struct_type = ty.struct_("s", st); auto* struct_type = ty.struct_(st);
AST().AddConstructedType(struct_type); AST().AddConstructedType(struct_type);
WrapInFunction(); WrapInFunction();

View File

@ -23,26 +23,24 @@ TINT_INSTANTIATE_TYPEINFO(tint::sem::StructType);
namespace tint { namespace tint {
namespace sem { namespace sem {
StructType::StructType(const Symbol& sym, ast::Struct* impl) StructType::StructType(ast::Struct* impl) : struct_(impl) {}
: symbol_(sym), struct_(impl) {}
StructType::StructType(StructType&&) = default; StructType::StructType(StructType&&) = default;
StructType::~StructType() = default; StructType::~StructType() = default;
std::string StructType::type_name() const { std::string StructType::type_name() const {
return "__struct_" + symbol_.to_str(); return impl()->type_name();
} }
std::string StructType::FriendlyName(const SymbolTable& symbols) const { std::string StructType::FriendlyName(const SymbolTable& symbols) const {
return symbols.NameFor(symbol_); return impl()->FriendlyName(symbols);
} }
StructType* StructType::Clone(CloneContext* ctx) const { StructType* StructType::Clone(CloneContext* ctx) const {
// Clone arguments outside of create() call to have deterministic ordering // Clone arguments outside of create() call to have deterministic ordering
auto sym = ctx->Clone(symbol());
auto* str = ctx->Clone(impl()); auto* str = ctx->Clone(impl());
return ctx->dst->create<StructType>(sym, str); return ctx->dst->create<StructType>(str);
} }
} // namespace sem } // namespace sem

View File

@ -27,16 +27,12 @@ namespace sem {
class StructType : public Castable<StructType, Type> { class StructType : public Castable<StructType, Type> {
public: public:
/// Constructor /// Constructor
/// @param sym the symbol representing the struct
/// @param impl the struct data /// @param impl the struct data
StructType(const Symbol& sym, ast::Struct* impl); explicit StructType(ast::Struct* impl);
/// Move constructor /// Move constructor
StructType(StructType&&); StructType(StructType&&);
~StructType() override; ~StructType() override;
/// @returns the struct symbol
const Symbol& symbol() const { return symbol_; }
/// @returns true if the struct has a block decoration /// @returns true if the struct has a block decoration
bool IsBlockDecorated() const { return struct_->IsBlockDecorated(); } bool IsBlockDecorated() const { return struct_->IsBlockDecorated(); }
@ -57,7 +53,6 @@ class StructType : public Castable<StructType, Type> {
StructType* Clone(CloneContext* ctx) const override; StructType* Clone(CloneContext* ctx) const override;
private: private:
Symbol const symbol_;
ast::Struct* const struct_; ast::Struct* const struct_;
uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const; uint64_t LargestMemberBaseAlignment(MemoryLayout mem_layout) const;

View File

@ -27,7 +27,7 @@ TEST_F(StructTypeTest, Creation) {
auto* impl = auto* impl =
create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{}); create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
auto* ptr = impl; auto* ptr = impl;
auto* s = ty.struct_(name, impl); auto* s = ty.struct_(impl);
EXPECT_EQ(s->impl(), ptr); EXPECT_EQ(s->impl(), ptr);
} }
@ -35,7 +35,7 @@ TEST_F(StructTypeTest, Is) {
auto name = Sym("S"); auto name = Sym("S");
auto* impl = auto* impl =
create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{}); create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
auto* s = ty.struct_(name, impl); auto* s = ty.struct_(impl);
sem::Type* ty = s; sem::Type* ty = s;
EXPECT_FALSE(ty->Is<AccessControl>()); EXPECT_FALSE(ty->Is<AccessControl>());
EXPECT_FALSE(ty->Is<Alias>()); EXPECT_FALSE(ty->Is<Alias>());
@ -56,7 +56,7 @@ TEST_F(StructTypeTest, TypeName) {
auto name = Sym("my_struct"); auto name = Sym("my_struct");
auto* impl = auto* impl =
create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{}); create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
auto* s = ty.struct_(name, impl); auto* s = ty.struct_(impl);
EXPECT_EQ(s->type_name(), "__struct_$1"); EXPECT_EQ(s->type_name(), "__struct_$1");
} }
@ -64,7 +64,7 @@ TEST_F(StructTypeTest, FriendlyName) {
auto name = Sym("my_struct"); auto name = Sym("my_struct");
auto* impl = auto* impl =
create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{}); create<ast::Struct>(name, ast::StructMemberList{}, ast::DecorationList{});
auto* s = ty.struct_(name, impl); auto* s = ty.struct_(impl);
EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct"); EXPECT_EQ(s->FriendlyName(Symbols()), "my_struct");
} }

View File

@ -81,11 +81,11 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
} }
// Redeclare the struct. // Redeclare the struct.
auto new_struct_name = ctx.Clone(struct_ty->symbol()); auto new_struct_name = ctx.Clone(struct_ty->impl()->name());
auto* new_struct = ctx.dst->create<sem::StructType>( auto* new_struct =
new_struct_name, ctx.dst->create<ast::Struct>( ctx.dst->create<sem::StructType>(ctx.dst->create<ast::Struct>(
new_struct_name, new_struct_members, new_struct_name, new_struct_members,
ctx.Clone(struct_ty->impl()->decorations()))); ctx.Clone(struct_ty->impl()->decorations())));
ctx.Replace(struct_ty, new_struct); ctx.Replace(struct_ty, new_struct);
} }
} }
@ -176,10 +176,9 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
// Create the new struct type. // Create the new struct type.
auto in_struct_name = ctx.dst->Symbols().New(); auto in_struct_name = ctx.dst->Symbols().New();
auto* in_struct = ctx.dst->create<sem::StructType>( auto* in_struct =
in_struct_name, ctx.dst->create<sem::StructType>(ctx.dst->create<ast::Struct>(
ctx.dst->create<ast::Struct>(in_struct_name, new_struct_members, in_struct_name, new_struct_members, ast::DecorationList{}));
ast::DecorationList{}));
ctx.InsertBefore(ctx.src->AST().GlobalDeclarations(), func, in_struct); ctx.InsertBefore(ctx.src->AST().GlobalDeclarations(), func, in_struct);
// Create a new function parameter using this struct type. // Create a new function parameter using this struct type.
@ -223,10 +222,9 @@ Output CanonicalizeEntryPointIO::Run(const Program* in, const DataMap&) {
// Create the new struct type. // Create the new struct type.
auto out_struct_name = ctx.dst->Symbols().New(); auto out_struct_name = ctx.dst->Symbols().New();
auto* out_struct = ctx.dst->create<sem::StructType>( auto* out_struct =
out_struct_name, ctx.dst->create<sem::StructType>(ctx.dst->create<ast::Struct>(
ctx.dst->create<ast::Struct>(out_struct_name, new_struct_members, out_struct_name, new_struct_members, ast::DecorationList{}));
ast::DecorationList{}));
ctx.InsertBefore(ctx.src->AST().GlobalDeclarations(), func, out_struct); ctx.InsertBefore(ctx.src->AST().GlobalDeclarations(), func, out_struct);
new_ret_type = out_struct; new_ret_type = out_struct;

View File

@ -126,11 +126,11 @@ void Spirv::HandleEntryPointIOTypes(CloneContext& ctx) const {
} }
// Redeclare the struct. // Redeclare the struct.
auto new_struct_name = ctx.Clone(struct_ty->symbol()); auto new_struct_name = ctx.Clone(struct_ty->impl()->name());
auto* new_struct = ctx.dst->create<sem::StructType>( auto* new_struct =
new_struct_name, ctx.dst->create<ast::Struct>( ctx.dst->create<sem::StructType>(ctx.dst->create<ast::Struct>(
new_struct_name, new_struct_members, new_struct_name, new_struct_members,
ctx.Clone(struct_ty->impl()->decorations()))); ctx.Clone(struct_ty->impl()->decorations())));
ctx.Replace(struct_ty, new_struct); ctx.Replace(struct_ty, new_struct);
} }
} }

View File

@ -221,7 +221,8 @@ bool GeneratorImpl::EmitConstructedType(std::ostream& out,
out << " " << builder_.Symbols().NameFor(alias->symbol()) << ";" out << " " << builder_.Symbols().NameFor(alias->symbol()) << ";"
<< std::endl; << std::endl;
} else if (auto* str = ty->As<sem::StructType>()) { } else if (auto* str = ty->As<sem::StructType>()) {
if (!EmitStructType(out, str, builder_.Symbols().NameFor(str->symbol()))) { if (!EmitStructType(out, str,
builder_.Symbols().NameFor(str->impl()->name()))) {
return false; return false;
} }
} else { } else {
@ -1709,8 +1710,9 @@ bool GeneratorImpl::EmitEntryPointData(
auto* type = var->Type()->UnwrapIfNeeded(); auto* type = var->Type()->UnwrapIfNeeded();
if (auto* strct = type->As<sem::StructType>()) { if (auto* strct = type->As<sem::StructType>()) {
out << "ConstantBuffer<" << builder_.Symbols().NameFor(strct->symbol()) out << "ConstantBuffer<"
<< "> " << builder_.Symbols().NameFor(decl->symbol()) << builder_.Symbols().NameFor(strct->impl()->name()) << "> "
<< builder_.Symbols().NameFor(decl->symbol())
<< RegisterAndSpace('b', binding_point) << ";" << std::endl; << RegisterAndSpace('b', binding_point) << ";" << std::endl;
} else { } else {
// TODO(dsinclair): There is outstanding spec work to require all uniform // TODO(dsinclair): There is outstanding spec work to require all uniform
@ -2450,7 +2452,7 @@ bool GeneratorImpl::EmitType(std::ostream& out,
} }
out << "State"; out << "State";
} else if (auto* str = type->As<sem::StructType>()) { } else if (auto* str = type->As<sem::StructType>()) {
out << builder_.Symbols().NameFor(str->symbol()); out << builder_.Symbols().NameFor(str->impl()->name());
} else if (auto* tex = type->As<sem::Texture>()) { } else if (auto* tex = type->As<sem::Texture>()) {
auto* storage = tex->As<sem::StorageTexture>(); auto* storage = tex->As<sem::StorageTexture>();
auto* multism = tex->As<sem::MultisampledTexture>(); auto* multism = tex->As<sem::MultisampledTexture>();

View File

@ -1950,7 +1950,7 @@ bool GeneratorImpl::EmitType(sem::Type* type, const std::string& name) {
} else if (auto* str = type->As<sem::StructType>()) { } else if (auto* str = type->As<sem::StructType>()) {
// The struct type emits as just the name. The declaration would be emitted // The struct type emits as just the name. The declaration would be emitted
// as part of emitting the constructed types. // as part of emitting the constructed types.
out_ << program_->Symbols().NameFor(str->symbol()); out_ << program_->Symbols().NameFor(str->impl()->name());
} else if (auto* tex = type->As<sem::Texture>()) { } else if (auto* tex = type->As<sem::Texture>()) {
if (tex->Is<sem::DepthTexture>()) { if (tex->Is<sem::DepthTexture>()) {
out_ << "depth"; out_ << "depth";
@ -2046,7 +2046,7 @@ bool GeneratorImpl::EmitStructType(const sem::StructType* str) {
// TODO(dsinclair): Block decoration? // TODO(dsinclair): Block decoration?
// if (str->impl()->decoration() != ast::Decoration::kNone) { // if (str->impl()->decoration() != ast::Decoration::kNone) {
// } // }
out_ << "struct " << program_->Symbols().NameFor(str->symbol()) << " {" out_ << "struct " << program_->Symbols().NameFor(str->impl()->name()) << " {"
<< std::endl; << std::endl;
auto* sem_str = program_->Sem().Get(str); auto* sem_str = program_->Sem().Get(str);

View File

@ -3150,11 +3150,10 @@ bool Builder::GenerateStructType(sem::StructType* struct_type,
auto struct_id = result.to_i(); auto struct_id = result.to_i();
auto* impl = struct_type->impl(); auto* impl = struct_type->impl();
if (struct_type->symbol().IsValid()) { if (struct_type->impl()->name().IsValid()) {
push_debug( push_debug(spv::Op::OpName, {Operand::Int(struct_id),
spv::Op::OpName, Operand::String(builder_.Symbols().NameFor(
{Operand::Int(struct_id), struct_type->impl()->name()))});
Operand::String(builder_.Symbols().NameFor(struct_type->symbol()))});
} }
OperandList ops; OperandList ops;

View File

@ -433,7 +433,7 @@ bool GeneratorImpl::EmitType(sem::Type* type) {
} else if (auto* str = type->As<sem::StructType>()) { } else if (auto* str = type->As<sem::StructType>()) {
// The struct, as a type, is just the name. We should have already emitted // The struct, as a type, is just the name. We should have already emitted
// the declaration through a call to |EmitStructType| earlier. // the declaration through a call to |EmitStructType| earlier.
out_ << program_->Symbols().NameFor(str->symbol()); out_ << program_->Symbols().NameFor(str->impl()->name());
} else if (auto* texture = type->As<sem::Texture>()) { } else if (auto* texture = type->As<sem::Texture>()) {
out_ << "texture_"; out_ << "texture_";
if (texture->Is<sem::DepthTexture>()) { if (texture->Is<sem::DepthTexture>()) {
@ -518,7 +518,7 @@ bool GeneratorImpl::EmitStructType(const sem::StructType* str) {
program_->to_str(deco, out_, 0); program_->to_str(deco, out_, 0);
out_ << "]]" << std::endl; out_ << "]]" << std::endl;
} }
out_ << "struct " << program_->Symbols().NameFor(str->symbol()) << " {" out_ << "struct " << program_->Symbols().NameFor(str->impl()->name()) << " {"
<< std::endl; << std::endl;
auto add_padding = [&](uint32_t size) { auto add_padding = [&](uint32_t size) {