From c5b1b5c77ad375f0706f9db305618f69274e6cb6 Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 1 Dec 2022 14:52:33 +0000 Subject: [PATCH] Access struct member name through sem. This CL changes the uses of Declaration()->symbol for struct members in the sem to access the `Name` directly. Bug: tint:1718 Change-Id: I3050147b97bea66d6c283e176a7152f36eb2b25f Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/112444 Commit-Queue: Dan Sinclair Reviewed-by: Ben Clayton Kokoro: Kokoro --- src/tint/inspector/inspector.cc | 6 +++--- src/tint/resolver/resolver.cc | 2 +- src/tint/resolver/validator.cc | 2 +- src/tint/sem/struct.cc | 6 ++---- src/tint/transform/canonicalize_entry_point_io.cc | 12 ++++++------ src/tint/transform/decompose_memory_access.cc | 4 ++-- src/tint/transform/num_workgroups_from_uniform.cc | 2 +- src/tint/transform/packed_vec3.cc | 2 +- src/tint/transform/truncate_interstage_variables.cc | 3 +-- 9 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/tint/inspector/inspector.cc b/src/tint/inspector/inspector.cc index b641f53308..25cde92d05 100644 --- a/src/tint/inspector/inspector.cc +++ b/src/tint/inspector/inspector.cc @@ -648,9 +648,9 @@ void Inspector::AddEntryPointInOutVariables(std::string name, if (auto* struct_ty = unwrapped_type->As()) { // Recurse into members. for (auto* member : struct_ty->Members()) { - AddEntryPointInOutVariables( - name + "." + program_->Symbols().NameFor(member->Declaration()->symbol), - member->Type(), member->Declaration()->attributes, member->Location(), variables); + AddEntryPointInOutVariables(name + "." + program_->Symbols().NameFor(member->Name()), + member->Type(), member->Declaration()->attributes, + member->Location(), variables); } return; } diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index addd9895ce..5154cbe18c 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -3620,7 +3620,7 @@ bool Resolver::ApplyAddressSpaceUsageToType(ast::AddressSpace address_space, decl->type->source)) { std::stringstream err; err << "while analyzing structure member " << sem_.TypeNameOf(str) << "." - << builder_->Symbols().NameFor(decl->symbol); + << builder_->Symbols().NameFor(member->Name()); AddNote(err.str(), decl->source); return false; } diff --git a/src/tint/resolver/validator.cc b/src/tint/resolver/validator.cc index 9c3c591d23..29ac69f0f0 100644 --- a/src/tint/resolver/validator.cc +++ b/src/tint/resolver/validator.cc @@ -413,7 +413,7 @@ bool Validator::AddressSpaceLayout(const sem::Type* store_ty, }; auto member_name_of = [this](const sem::StructMember* sm) { - return symbols_.NameFor(sm->Declaration()->symbol); + return symbols_.NameFor(sm->Name()); }; // Only validate the [type + address space] once diff --git a/src/tint/sem/struct.cc b/src/tint/sem/struct.cc index d80a04af50..1634c39a63 100644 --- a/src/tint/sem/struct.cc +++ b/src/tint/sem/struct.cc @@ -80,7 +80,7 @@ bool Struct::Equals(const sem::Type& other) const { const StructMember* Struct::FindMember(Symbol name) const { for (auto* member : members_) { - if (member->Declaration()->symbol == name) { + if (member->Name() == name) { return member; } } @@ -102,9 +102,7 @@ std::string Struct::FriendlyName(const SymbolTable& symbols) const { std::string Struct::Layout(const tint::SymbolTable& symbols) const { std::stringstream ss; - auto member_name_of = [&](const sem::StructMember* sm) { - return symbols.NameFor(sm->Declaration()->symbol); - }; + auto member_name_of = [&](const sem::StructMember* sm) { return symbols.NameFor(sm->Name()); }; if (Members().empty()) { return {}; diff --git a/src/tint/transform/canonicalize_entry_point_io.cc b/src/tint/transform/canonicalize_entry_point_io.cc index 8a14fb73f6..b41529afe7 100644 --- a/src/tint/transform/canonicalize_entry_point_io.cc +++ b/src/tint/transform/canonicalize_entry_point_io.cc @@ -359,10 +359,10 @@ struct CanonicalizeEntryPointIO::State { continue; } - auto* member_ast = member->Declaration(); - auto name = ctx.src->Symbols().NameFor(member_ast->symbol); + auto name = ctx.src->Symbols().NameFor(member->Name()); - auto attributes = CloneShaderIOAttributes(member_ast->attributes, do_interpolate); + auto attributes = + CloneShaderIOAttributes(member->Declaration()->attributes, do_interpolate); auto* input_expr = AddInput(name, member->Type(), member->Location(), std::move(attributes)); inner_struct_values.Push(input_expr); @@ -388,9 +388,9 @@ struct CanonicalizeEntryPointIO::State { continue; } - auto* member_ast = member->Declaration(); - auto name = ctx.src->Symbols().NameFor(member_ast->symbol); - auto attributes = CloneShaderIOAttributes(member_ast->attributes, do_interpolate); + auto name = ctx.src->Symbols().NameFor(member->Name()); + auto attributes = + CloneShaderIOAttributes(member->Declaration()->attributes, do_interpolate); // Extract the original structure member. AddOutput(name, member->Type(), member->Location(), std::move(attributes), diff --git a/src/tint/transform/decompose_memory_access.cc b/src/tint/transform/decompose_memory_access.cc index 944797a8c0..671ebc4b4b 100644 --- a/src/tint/transform/decompose_memory_access.cc +++ b/src/tint/transform/decompose_memory_access.cc @@ -645,8 +645,8 @@ struct DecomposeMemoryAccess::State { utils::Vector stmts; for (auto* member : str->Members()) { auto* offset = b.Add("offset", u32(member->Offset())); - auto* element = b.MemberAccessor( - "value", ctx.Clone(member->Declaration()->symbol)); + auto* element = + b.MemberAccessor("value", ctx.Clone(member->Name())); Symbol store = StoreFunc(buf_ty, member->Type()->UnwrapRef(), var_user); auto* call = b.Call(store, "buffer", offset, element); diff --git a/src/tint/transform/num_workgroups_from_uniform.cc b/src/tint/transform/num_workgroups_from_uniform.cc index e6681ca006..b6c93b2c72 100644 --- a/src/tint/transform/num_workgroups_from_uniform.cc +++ b/src/tint/transform/num_workgroups_from_uniform.cc @@ -107,7 +107,7 @@ Transform::ApplyResult NumWorkgroupsFromUniform::Apply(const Program* src, // Capture the symbols that would be used to access this member, which // we will replace later. We currently have no way to get from the // parameter directly to the member accessor expressions that use it. - to_replace.insert({param->Declaration()->symbol, member->Declaration()->symbol}); + to_replace.insert({param->Declaration()->symbol, member->Name()}); // Remove the struct member. // The CanonicalizeEntryPointIO transform will have generated this diff --git a/src/tint/transform/packed_vec3.cc b/src/tint/transform/packed_vec3.cc index e947a538db..f4ceb761ee 100644 --- a/src/tint/transform/packed_vec3.cc +++ b/src/tint/transform/packed_vec3.cc @@ -57,7 +57,7 @@ struct PackedVec3::State { // Apply the PackedVec3::Attribute to the member auto* member_decl = member->Declaration(); - auto name = ctx.Clone(member_decl->symbol); + auto name = ctx.Clone(member->Name()); auto* type = ctx.Clone(member_decl->type); utils::Vector attrs{ b.ASTNodes().Create(b.ID(), b.AllocateNodeID()), diff --git a/src/tint/transform/truncate_interstage_variables.cc b/src/tint/transform/truncate_interstage_variables.cc index 30237bc85d..bbb27fdf92 100644 --- a/src/tint/transform/truncate_interstage_variables.cc +++ b/src/tint/transform/truncate_interstage_variables.cc @@ -131,8 +131,7 @@ Transform::ApplyResult TruncateInterstageVariables::Apply(const Program* src, } truncated_members.Push(ctx.Clone(member->Declaration())); - initializer_exprs.Push( - b.MemberAccessor("io", ctx.Clone(member->Declaration()->symbol))); + initializer_exprs.Push(b.MemberAccessor("io", ctx.Clone(member->Name()))); } // Create the new shader io struct.