diff --git a/src/tint/ast/const.cc b/src/tint/ast/const.cc index 40f46a2f60..79466c0776 100644 --- a/src/tint/ast/const.cc +++ b/src/tint/ast/const.cc @@ -25,11 +25,11 @@ namespace tint::ast { Const::Const(ProgramID pid, NodeID nid, const Source& src, - const Symbol& sym, + const Identifier* n, const ast::Type* ty, const Expression* init, utils::VectorRef attrs) - : Base(pid, nid, src, sym, ty, init, std::move(attrs)) { + : Base(pid, nid, src, n, ty, init, std::move(attrs)) { TINT_ASSERT(AST, init != nullptr); } @@ -43,11 +43,11 @@ const char* Const::Kind() const { const Const* Const::Clone(CloneContext* ctx) const { auto src = ctx->Clone(source); - auto sym = ctx->Clone(symbol); + auto n = ctx->Clone(name); auto* ty = ctx->Clone(type); auto* init = ctx->Clone(initializer); auto attrs = ctx->Clone(attributes); - return ctx->dst->create(src, sym, ty, init, std::move(attrs)); + return ctx->dst->create(src, n, ty, init, std::move(attrs)); } } // namespace tint::ast diff --git a/src/tint/ast/const.h b/src/tint/ast/const.h index 4b955f0af6..aa73d4f4b8 100644 --- a/src/tint/ast/const.h +++ b/src/tint/ast/const.h @@ -36,14 +36,14 @@ class Const final : public Castable { /// @param pid the identifier of the program that owns this node /// @param nid the unique node identifier /// @param source the variable source - /// @param sym the variable symbol + /// @param name the variable name /// @param type the declared variable type /// @param initializer the initializer expression. Must not be nullptr. /// @param attributes the variable attributes Const(ProgramID pid, NodeID nid, const Source& source, - const Symbol& sym, + const Identifier* name, const ast::Type* type, const Expression* initializer, utils::VectorRef attributes); diff --git a/src/tint/ast/let.cc b/src/tint/ast/let.cc index 30ed851891..fd16d68fcd 100644 --- a/src/tint/ast/let.cc +++ b/src/tint/ast/let.cc @@ -25,11 +25,11 @@ namespace tint::ast { Let::Let(ProgramID pid, NodeID nid, const Source& src, - const Symbol& sym, + const Identifier* n, const ast::Type* ty, const Expression* init, utils::VectorRef attrs) - : Base(pid, nid, src, sym, ty, init, std::move(attrs)) { + : Base(pid, nid, src, n, ty, init, std::move(attrs)) { TINT_ASSERT(AST, init != nullptr); } @@ -43,11 +43,11 @@ const char* Let::Kind() const { const Let* Let::Clone(CloneContext* ctx) const { auto src = ctx->Clone(source); - auto sym = ctx->Clone(symbol); + auto* n = ctx->Clone(name); auto* ty = ctx->Clone(type); auto* init = ctx->Clone(initializer); auto attrs = ctx->Clone(attributes); - return ctx->dst->create(src, sym, ty, init, std::move(attrs)); + return ctx->dst->create(src, n, ty, init, std::move(attrs)); } } // namespace tint::ast diff --git a/src/tint/ast/let.h b/src/tint/ast/let.h index 8fd9cfa937..e0848aa36d 100644 --- a/src/tint/ast/let.h +++ b/src/tint/ast/let.h @@ -33,14 +33,14 @@ class Let final : public Castable { /// @param pid the identifier of the program that owns this node /// @param nid the unique node identifier /// @param source the variable source - /// @param sym the variable symbol + /// @param name the variable name /// @param type the declared variable type /// @param initializer the initializer expression /// @param attributes the variable attributes Let(ProgramID pid, NodeID nid, const Source& source, - const Symbol& sym, + const Identifier* name, const ast::Type* type, const Expression* initializer, utils::VectorRef attributes); diff --git a/src/tint/ast/override.cc b/src/tint/ast/override.cc index 5f2a600b6c..e7bee057a3 100644 --- a/src/tint/ast/override.cc +++ b/src/tint/ast/override.cc @@ -25,11 +25,11 @@ namespace tint::ast { Override::Override(ProgramID pid, NodeID nid, const Source& src, - const Symbol& sym, + const Identifier* n, const ast::Type* ty, const Expression* init, utils::VectorRef attrs) - : Base(pid, nid, src, sym, ty, init, std::move(attrs)) {} + : Base(pid, nid, src, n, ty, init, std::move(attrs)) {} Override::Override(Override&&) = default; @@ -41,11 +41,11 @@ const char* Override::Kind() const { const Override* Override::Clone(CloneContext* ctx) const { auto src = ctx->Clone(source); - auto sym = ctx->Clone(symbol); + auto* n = ctx->Clone(name); auto* ty = ctx->Clone(type); auto* init = ctx->Clone(initializer); auto attrs = ctx->Clone(attributes); - return ctx->dst->create(src, sym, ty, init, std::move(attrs)); + return ctx->dst->create(src, n, ty, init, std::move(attrs)); } } // namespace tint::ast diff --git a/src/tint/ast/override.h b/src/tint/ast/override.h index 2d586dfbce..c75035ee7a 100644 --- a/src/tint/ast/override.h +++ b/src/tint/ast/override.h @@ -36,14 +36,14 @@ class Override final : public Castable { /// @param pid the identifier of the program that owns this node /// @param nid the unique node identifier /// @param source the variable source - /// @param sym the variable symbol + /// @param name the variable name /// @param type the declared variable type /// @param initializer the initializer expression /// @param attributes the variable attributes Override(ProgramID pid, NodeID nid, const Source& source, - const Symbol& sym, + const Identifier* name, const ast::Type* type, const Expression* initializer, utils::VectorRef attributes); diff --git a/src/tint/ast/parameter.cc b/src/tint/ast/parameter.cc index 01ee3aa6f9..adbeb27e85 100644 --- a/src/tint/ast/parameter.cc +++ b/src/tint/ast/parameter.cc @@ -25,10 +25,10 @@ namespace tint::ast { Parameter::Parameter(ProgramID pid, NodeID nid, const Source& src, - const Symbol& sym, + const Identifier* n, const ast::Type* ty, utils::VectorRef attrs) - : Base(pid, nid, src, sym, ty, nullptr, std::move(attrs)) {} + : Base(pid, nid, src, n, ty, nullptr, std::move(attrs)) {} Parameter::Parameter(Parameter&&) = default; @@ -40,10 +40,10 @@ const char* Parameter::Kind() const { const Parameter* Parameter::Clone(CloneContext* ctx) const { auto src = ctx->Clone(source); - auto sym = ctx->Clone(symbol); + auto* n = ctx->Clone(name); auto* ty = ctx->Clone(type); auto attrs = ctx->Clone(attributes); - return ctx->dst->create(src, sym, ty, std::move(attrs)); + return ctx->dst->create(src, n, ty, std::move(attrs)); } } // namespace tint::ast diff --git a/src/tint/ast/parameter.h b/src/tint/ast/parameter.h index e9d9f62f23..79d1856e53 100644 --- a/src/tint/ast/parameter.h +++ b/src/tint/ast/parameter.h @@ -37,13 +37,13 @@ class Parameter final : public Castable { /// @param pid the identifier of the program that owns this node /// @param nid the unique node identifier /// @param source the variable source - /// @param sym the variable symbol + /// @param name the variable name /// @param type the declared variable type /// @param attributes the variable attributes Parameter(ProgramID pid, NodeID nid, const Source& source, - const Symbol& sym, + const Identifier* name, const ast::Type* type, utils::VectorRef attributes); diff --git a/src/tint/ast/var.cc b/src/tint/ast/var.cc index 3ed6677da8..87621ae441 100644 --- a/src/tint/ast/var.cc +++ b/src/tint/ast/var.cc @@ -23,13 +23,13 @@ namespace tint::ast { Var::Var(ProgramID pid, NodeID nid, const Source& src, - const Symbol& sym, + const Identifier* n, const ast::Type* ty, type::AddressSpace address_space, type::Access access, const Expression* init, utils::VectorRef attrs) - : Base(pid, nid, src, sym, ty, init, std::move(attrs)), + : Base(pid, nid, src, n, ty, init, std::move(attrs)), declared_address_space(address_space), declared_access(access) {} @@ -43,11 +43,11 @@ const char* Var::Kind() const { const Var* Var::Clone(CloneContext* ctx) const { auto src = ctx->Clone(source); - auto sym = ctx->Clone(symbol); + auto* n = ctx->Clone(name); auto* ty = ctx->Clone(type); auto* init = ctx->Clone(initializer); auto attrs = ctx->Clone(attributes); - return ctx->dst->create(src, sym, ty, declared_address_space, declared_access, init, + return ctx->dst->create(src, n, ty, declared_address_space, declared_access, init, std::move(attrs)); } diff --git a/src/tint/ast/var.h b/src/tint/ast/var.h index 3fdd7dbfa5..977b799adc 100644 --- a/src/tint/ast/var.h +++ b/src/tint/ast/var.h @@ -45,7 +45,7 @@ class Var final : public Castable { /// @param pid the identifier of the program that owns this node /// @param nid the unique node identifier /// @param source the variable source - /// @param sym the variable symbol + /// @param name the variable name /// @param type the declared variable type /// @param declared_address_space the declared address space /// @param declared_access the declared access control @@ -54,7 +54,7 @@ class Var final : public Castable { Var(ProgramID pid, NodeID nid, const Source& source, - const Symbol& sym, + const Identifier* name, const ast::Type* type, type::AddressSpace declared_address_space, type::Access declared_access, diff --git a/src/tint/ast/variable.cc b/src/tint/ast/variable.cc index 1617d450d9..1049eff4b6 100644 --- a/src/tint/ast/variable.cc +++ b/src/tint/ast/variable.cc @@ -15,6 +15,7 @@ #include "src/tint/ast/variable.h" #include "src/tint/ast/binding_attribute.h" #include "src/tint/ast/group_attribute.h" +#include "src/tint/ast/templated_identifier.h" TINT_INSTANTIATE_TYPEINFO(tint::ast::Variable); @@ -23,13 +24,15 @@ namespace tint::ast { Variable::Variable(ProgramID pid, NodeID nid, const Source& src, - const Symbol& sym, + const Identifier* n, const ast::Type* ty, const Expression* init, utils::VectorRef attrs) - : Base(pid, nid, src), symbol(sym), type(ty), initializer(init), attributes(std::move(attrs)) { - TINT_ASSERT(AST, symbol.IsValid()); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, symbol, program_id); + : Base(pid, nid, src), name(n), type(ty), initializer(init), attributes(std::move(attrs)) { + TINT_ASSERT(AST, name); + if (name) { + TINT_ASSERT(AST, !name->Is()); + } TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, initializer, program_id); } diff --git a/src/tint/ast/variable.h b/src/tint/ast/variable.h index 7a75c3f104..d1797feaa7 100644 --- a/src/tint/ast/variable.h +++ b/src/tint/ast/variable.h @@ -27,6 +27,7 @@ // Forward declarations namespace tint::ast { +class Identifier; class LocationAttribute; class Type; } // namespace tint::ast @@ -44,15 +45,15 @@ class Variable : public Castable { /// Constructor /// @param pid the identifier of the program that owns this node /// @param nid the unique node identifier - /// @param source the variable source - /// @param sym the variable symbol + /// @param src the variable source + /// @param name The struct member name /// @param type the declared variable type /// @param initializer the initializer expression /// @param attributes the variable attributes Variable(ProgramID pid, NodeID nid, - const Source& source, - const Symbol& sym, + const Source& src, + const Identifier* name, const ast::Type* type, const Expression* initializer, utils::VectorRef attributes); @@ -73,8 +74,8 @@ class Variable : public Castable { /// e.g. "var", "let", "const", etc virtual const char* Kind() const = 0; - /// The variable symbol - const Symbol symbol; + /// The variable name + const Identifier* const name; /// The declared variable type. This is null if the type is inferred, e.g.: /// let f = 1.0; diff --git a/src/tint/ast/variable_test.cc b/src/tint/ast/variable_test.cc index e797b0d964..05474c8f2b 100644 --- a/src/tint/ast/variable_test.cc +++ b/src/tint/ast/variable_test.cc @@ -27,7 +27,7 @@ using VariableTest = TestHelper; TEST_F(VariableTest, Creation) { auto* v = Var("my_var", ty.i32(), type::AddressSpace::kFunction); - EXPECT_EQ(v->symbol, Symbol(1, ID())); + EXPECT_EQ(v->name->symbol, Symbol(1, ID())); EXPECT_EQ(v->declared_address_space, type::AddressSpace::kFunction); EXPECT_TRUE(v->type->Is()); EXPECT_EQ(v->source.range.begin.line, 0u); @@ -40,7 +40,7 @@ TEST_F(VariableTest, CreationWithSource) { auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, "i", ty.f32(), type::AddressSpace::kPrivate, utils::Empty); - EXPECT_EQ(v->symbol, Symbol(1, ID())); + EXPECT_EQ(v->name->symbol, Symbol(1, ID())); EXPECT_EQ(v->declared_address_space, type::AddressSpace::kPrivate); EXPECT_TRUE(v->type->Is()); EXPECT_EQ(v->source.range.begin.line, 27u); @@ -53,7 +53,7 @@ TEST_F(VariableTest, CreationEmpty) { auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, "a_var", ty.i32(), type::AddressSpace::kWorkgroup, utils::Empty); - EXPECT_EQ(v->symbol, Symbol(1, ID())); + EXPECT_EQ(v->name->symbol, Symbol(1, ID())); EXPECT_EQ(v->declared_address_space, type::AddressSpace::kWorkgroup); EXPECT_TRUE(v->type->Is()); EXPECT_EQ(v->source.range.begin.line, 27u); @@ -62,11 +62,11 @@ TEST_F(VariableTest, CreationEmpty) { EXPECT_EQ(v->source.range.end.column, 7u); } -TEST_F(VariableTest, Assert_MissingSymbol) { +TEST_F(VariableTest, Assert_Null_Name) { EXPECT_FATAL_FAILURE( { ProgramBuilder b; - b.Var("", b.ty.i32()); + b.Var(static_cast(nullptr), b.ty.i32()); }, "internal compiler error"); } diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.cc index a4dad15348..565a4f4e22 100644 --- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.cc +++ b/src/tint/fuzzers/tint_ast_fuzzer/mutations/replace_identifier.cc @@ -80,8 +80,9 @@ void MutationReplaceIdentifier::Apply(const NodeIdMap& node_id_map, const auto* replacement_var = tint::As(node_id_map.GetNode(message_.replacement_id())); - auto* cloned_replacement = clone_context->dst->Expr( - clone_context->Clone(use_node->source), clone_context->Clone(replacement_var->symbol)); + auto* cloned_replacement = + clone_context->dst->Expr(clone_context->Clone(use_node->source), + clone_context->Clone(replacement_var->name->symbol)); clone_context->Replace(use_node, cloned_replacement); new_node_id_map->Add(cloned_replacement, message_.use_id()); } diff --git a/src/tint/inspector/inspector.cc b/src/tint/inspector/inspector.cc index ca3f33a4bf..26202e3b0e 100644 --- a/src/tint/inspector/inspector.cc +++ b/src/tint/inspector/inspector.cc @@ -211,7 +211,7 @@ EntryPoint Inspector::GetEntryPoint(const tint::ast::Function* func) { } for (auto* param : sem->Parameters()) { - AddEntryPointInOutVariables(program_->Symbols().NameFor(param->Declaration()->symbol), + AddEntryPointInOutVariables(program_->Symbols().NameFor(param->Declaration()->name->symbol), param->Type(), param->Declaration()->attributes, param->Location(), entry_point.input_variables); @@ -240,7 +240,7 @@ EntryPoint Inspector::GetEntryPoint(const tint::ast::Function* func) { for (auto* var : sem->TransitivelyReferencedGlobals()) { auto* decl = var->Declaration(); - auto name = program_->Symbols().NameFor(decl->symbol); + auto name = program_->Symbols().NameFor(decl->name->symbol); auto* global = var->As(); if (global && global->Declaration()->Is()) { @@ -335,7 +335,7 @@ std::map Inspector::GetNamedOverrideIds() { for (auto* var : program_->AST().GlobalVariables()) { auto* global = program_->Sem().Get(var); if (global && global->Declaration()->Is()) { - auto name = program_->Symbols().NameFor(var->symbol); + auto name = program_->Symbols().NameFor(var->name->symbol); result[name] = global->OverrideId(); } } diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index cbf532b6b5..d5516af455 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -1206,13 +1206,13 @@ class ProgramBuilder { /// @param variable the AST variable /// @return an ast::IdentifierExpression with the variable's symbol const ast::IdentifierExpression* Expr(const Source& source, const ast::Variable* variable) { - return create(source, Ident(source, variable->symbol)); + return create(source, Ident(source, variable->name->symbol)); } /// @param variable the AST variable /// @return an ast::IdentifierExpression with the variable's symbol const ast::IdentifierExpression* Expr(const ast::Variable* variable) { - return create(Ident(variable->symbol)); + return create(Ident(variable->name->symbol)); } /// @param ident the identifier @@ -1690,9 +1690,7 @@ class ProgramBuilder { /// options template > const ast::Var* Var(NAME&& name, OPTIONS&&... options) { - VarOptions opts(std::forward(options)...); - return create(Sym(std::forward(name)), opts.type, opts.address_space, - opts.access, opts.initializer, std::move(opts.attributes)); + return Var(source_, std::forward(name), std::forward(options)...); } /// @param source the variable source @@ -1709,7 +1707,7 @@ class ProgramBuilder { template const ast::Var* Var(const Source& source, NAME&& name, OPTIONS&&... options) { VarOptions opts(std::forward(options)...); - return create(source, Sym(std::forward(name)), opts.type, + return create(source, Ident(std::forward(name)), opts.type, opts.address_space, opts.access, opts.initializer, std::move(opts.attributes)); } @@ -1724,9 +1722,7 @@ class ProgramBuilder { /// @returns an `ast::Const` with the given name, type and additional options template > const ast::Const* Const(NAME&& name, OPTIONS&&... options) { - ConstOptions opts(std::forward(options)...); - return create(Sym(std::forward(name)), opts.type, opts.initializer, - std::move(opts.attributes)); + return Const(source_, std::forward(name), std::forward(options)...); } /// @param source the variable source @@ -1741,7 +1737,7 @@ class ProgramBuilder { template const ast::Const* Const(const Source& source, NAME&& name, OPTIONS&&... options) { ConstOptions opts(std::forward(options)...); - return create(source, Sym(std::forward(name)), opts.type, + return create(source, Ident(std::forward(name)), opts.type, opts.initializer, std::move(opts.attributes)); } @@ -1755,9 +1751,7 @@ class ProgramBuilder { /// @returns an `ast::Let` with the given name, type and additional options template > const ast::Let* Let(NAME&& name, OPTIONS&&... options) { - LetOptions opts(std::forward(options)...); - return create(Sym(std::forward(name)), opts.type, opts.initializer, - std::move(opts.attributes)); + return Let(source_, std::forward(name), std::forward(options)...); } /// @param source the variable source @@ -1772,8 +1766,8 @@ class ProgramBuilder { template const ast::Let* Let(const Source& source, NAME&& name, OPTIONS&&... options) { LetOptions opts(std::forward(options)...); - return create(source, Sym(std::forward(name)), opts.type, opts.initializer, - std::move(opts.attributes)); + return create(source, Ident(std::forward(name)), opts.type, + opts.initializer, std::move(opts.attributes)); } /// @param name the parameter name @@ -1784,7 +1778,7 @@ class ProgramBuilder { const ast::Parameter* Param(NAME&& name, const ast::Type* type, utils::VectorRef attributes = utils::Empty) { - return create(Sym(std::forward(name)), type, attributes); + return Param(source_, std::forward(name), type, std::move(attributes)); } /// @param source the parameter source @@ -1797,7 +1791,7 @@ class ProgramBuilder { NAME&& name, const ast::Type* type, utils::VectorRef attributes = utils::Empty) { - return create(source, Sym(std::forward(name)), type, attributes); + return create(source, Ident(std::forward(name)), type, attributes); } /// @param name the variable name @@ -1813,9 +1807,7 @@ class ProgramBuilder { /// ast::Module. template > const ast::Var* GlobalVar(NAME&& name, OPTIONS&&... options) { - auto* variable = Var(std::forward(name), std::forward(options)...); - AST().AddGlobalVariable(variable); - return variable; + return GlobalVar(source_, std::forward(name), std::forward(options)...); } /// @param source the variable source @@ -1848,9 +1840,7 @@ class ProgramBuilder { /// automatically registered as a global variable with the ast::Module. template > const ast::Const* GlobalConst(NAME&& name, OPTIONS&&... options) { - auto* variable = Const(std::forward(name), std::forward(options)...); - AST().AddGlobalVariable(variable); - return variable; + return GlobalConst(source_, std::forward(name), std::forward(options)...); } /// @param source the variable source @@ -1881,11 +1871,7 @@ class ProgramBuilder { /// automatically registered as a global variable with the ast::Module. template > const ast::Override* Override(NAME&& name, OPTIONS&&... options) { - OverrideOptions opts(std::forward(options)...); - auto* variable = create(Sym(std::forward(name)), opts.type, - opts.initializer, std::move(opts.attributes)); - AST().AddGlobalVariable(variable); - return variable; + return Override(source_, std::forward(name), std::forward(options)...); } /// @param source the variable source @@ -1901,7 +1887,7 @@ class ProgramBuilder { template const ast::Override* Override(const Source& source, NAME&& name, OPTIONS&&... options) { OverrideOptions opts(std::forward(options)...); - auto* variable = create(source, Sym(std::forward(name)), opts.type, + auto* variable = create(source, Ident(std::forward(name)), opts.type, opts.initializer, std::move(opts.attributes)); AST().AddGlobalVariable(variable); return variable; diff --git a/src/tint/reader/wgsl/parser_impl_function_decl_test.cc b/src/tint/reader/wgsl/parser_impl_function_decl_test.cc index 9d249f588b..415cfa10ca 100644 --- a/src/tint/reader/wgsl/parser_impl_function_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_function_decl_test.cc @@ -35,8 +35,8 @@ TEST_F(ParserImplTest, FunctionDecl) { EXPECT_EQ(f->return_type, nullptr); ASSERT_EQ(f->params.Length(), 2u); - EXPECT_EQ(f->params[0]->symbol, p->builder().Symbols().Get("a")); - EXPECT_EQ(f->params[1]->symbol, p->builder().Symbols().Get("b")); + EXPECT_EQ(f->params[0]->name->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(f->params[1]->name->symbol, p->builder().Symbols().Get("b")); EXPECT_EQ(f->return_type, nullptr); @@ -78,8 +78,8 @@ TEST_F(ParserImplTest, FunctionDecl_Unicode) { EXPECT_EQ(f->return_type, nullptr); ASSERT_EQ(f->params.Length(), 2u); - EXPECT_EQ(f->params[0]->symbol, p->builder().Symbols().Get(param_a_ident)); - EXPECT_EQ(f->params[1]->symbol, p->builder().Symbols().Get(param_b_ident)); + EXPECT_EQ(f->params[0]->name->symbol, p->builder().Symbols().Get(param_a_ident)); + EXPECT_EQ(f->params[1]->name->symbol, p->builder().Symbols().Get(param_b_ident)); EXPECT_EQ(f->return_type, nullptr); diff --git a/src/tint/reader/wgsl/parser_impl_function_header_test.cc b/src/tint/reader/wgsl/parser_impl_function_header_test.cc index 972ce0c839..6837e1f6bf 100644 --- a/src/tint/reader/wgsl/parser_impl_function_header_test.cc +++ b/src/tint/reader/wgsl/parser_impl_function_header_test.cc @@ -26,8 +26,8 @@ TEST_F(ParserImplTest, FunctionHeader) { EXPECT_EQ(f->name, "main"); ASSERT_EQ(f->params.Length(), 2u); - EXPECT_EQ(f->params[0]->symbol, p->builder().Symbols().Get("a")); - EXPECT_EQ(f->params[1]->symbol, p->builder().Symbols().Get("b")); + EXPECT_EQ(f->params[0]->name->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(f->params[1]->name->symbol, p->builder().Symbols().Get("b")); EXPECT_EQ(f->return_type, nullptr); } @@ -39,7 +39,7 @@ TEST_F(ParserImplTest, FunctionHeader_TrailingComma) { EXPECT_EQ(f->name, "main"); ASSERT_EQ(f->params.Length(), 1u); - EXPECT_EQ(f->params[0]->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(f->params[0]->name->symbol, p->builder().Symbols().Get("a")); EXPECT_EQ(f->return_type, nullptr); } diff --git a/src/tint/reader/wgsl/parser_impl_global_constant_decl_test.cc b/src/tint/reader/wgsl/parser_impl_global_constant_decl_test.cc index c465e4b4ec..a86ba691bd 100644 --- a/src/tint/reader/wgsl/parser_impl_global_constant_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_global_constant_decl_test.cc @@ -42,7 +42,7 @@ TEST_F(ParserImplTest, GlobalConstDecl) { auto* c = e.value->As(); ASSERT_NE(c, nullptr); - EXPECT_EQ(c->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(c->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(c->type, nullptr); EXPECT_TRUE(c->type->Is()); @@ -67,7 +67,7 @@ TEST_F(ParserImplTest, GlobalConstDecl_Inferred) { auto* c = e.value->As(); ASSERT_NE(c, nullptr); - EXPECT_EQ(c->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(c->name->symbol, p->builder().Symbols().Get("a")); EXPECT_EQ(c->type, nullptr); EXPECT_EQ(c->source.range.begin.line, 1u); @@ -118,7 +118,7 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithId) { auto* override = e.value->As(); ASSERT_NE(override, nullptr); - EXPECT_EQ(override->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(override->type, nullptr); EXPECT_TRUE(override->type->Is()); @@ -148,7 +148,7 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithId_TrailingComma) { auto* override = e.value->As(); ASSERT_NE(override, nullptr); - EXPECT_EQ(override->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(override->type, nullptr); EXPECT_TRUE(override->type->Is()); @@ -178,7 +178,7 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithoutId) { auto* override = e.value->As(); ASSERT_NE(override, nullptr); - EXPECT_EQ(override->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(override->type, nullptr); EXPECT_TRUE(override->type->Is()); diff --git a/src/tint/reader/wgsl/parser_impl_global_decl_test.cc b/src/tint/reader/wgsl/parser_impl_global_decl_test.cc index c77ba014c3..e27d614ba8 100644 --- a/src/tint/reader/wgsl/parser_impl_global_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_global_decl_test.cc @@ -32,7 +32,7 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalVariable) { ASSERT_EQ(program.AST().GlobalVariables().Length(), 1u); auto* v = program.AST().GlobalVariables()[0]; - EXPECT_EQ(v->symbol, program.Symbols().Get("a")); + EXPECT_EQ(v->name->symbol, program.Symbols().Get("a")); EXPECT_TRUE(Is(v->type)); } @@ -45,7 +45,7 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_Inferred) { ASSERT_EQ(program.AST().GlobalVariables().Length(), 1u); auto* v = program.AST().GlobalVariables()[0]; - EXPECT_EQ(v->symbol, program.Symbols().Get("a")); + EXPECT_EQ(v->name->symbol, program.Symbols().Get("a")); EXPECT_EQ(v->type, nullptr); } @@ -74,7 +74,7 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalConst) { ASSERT_EQ(program.AST().GlobalVariables().Length(), 1u); auto* v = program.AST().GlobalVariables()[0]; - EXPECT_EQ(v->symbol, program.Symbols().Get("a")); + EXPECT_EQ(v->name->symbol, program.Symbols().Get("a")); } TEST_F(ParserImplTest, GlobalDecl_GlobalConst_MissingInitializer) { diff --git a/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc b/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc index 0dcde16cfd..b00c9c56e5 100644 --- a/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc @@ -29,7 +29,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutInitializer) { auto* var = e.value->As(); ASSERT_NE(var, nullptr); - EXPECT_EQ(var->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a")); EXPECT_TRUE(var->type->Is()); EXPECT_EQ(var->declared_address_space, type::AddressSpace::kPrivate); @@ -53,7 +53,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithInitializer) { auto* var = e.value->As(); ASSERT_NE(var, nullptr); - EXPECT_EQ(var->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a")); EXPECT_TRUE(var->type->Is()); EXPECT_EQ(var->declared_address_space, type::AddressSpace::kPrivate); @@ -78,7 +78,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute) { auto* var = e.value->As(); ASSERT_NE(var, nullptr); - EXPECT_EQ(var->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(var->type, nullptr); EXPECT_TRUE(var->type->Is()); EXPECT_EQ(var->declared_address_space, type::AddressSpace::kUniform); @@ -109,7 +109,7 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute_MulitpleGroups) { auto* var = e.value->As(); ASSERT_NE(var, nullptr); - EXPECT_EQ(var->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(var->type, nullptr); EXPECT_TRUE(var->type->Is()); EXPECT_EQ(var->declared_address_space, type::AddressSpace::kUniform); diff --git a/src/tint/reader/wgsl/parser_impl_param_list_test.cc b/src/tint/reader/wgsl/parser_impl_param_list_test.cc index 26c1852cb8..7479935ba6 100644 --- a/src/tint/reader/wgsl/parser_impl_param_list_test.cc +++ b/src/tint/reader/wgsl/parser_impl_param_list_test.cc @@ -25,7 +25,7 @@ TEST_F(ParserImplTest, ParamList_Single) { ASSERT_FALSE(e.errored); EXPECT_EQ(e.value.Length(), 1u); - EXPECT_EQ(e.value[0]->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("a")); EXPECT_TRUE(e.value[0]->type->Is()); EXPECT_TRUE(e.value[0]->Is()); @@ -43,7 +43,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) { ASSERT_FALSE(e.errored); EXPECT_EQ(e.value.Length(), 3u); - EXPECT_EQ(e.value[0]->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("a")); EXPECT_TRUE(e.value[0]->type->Is()); EXPECT_TRUE(e.value[0]->Is()); @@ -52,7 +52,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) { ASSERT_EQ(e.value[0]->source.range.end.line, 1u); ASSERT_EQ(e.value[0]->source.range.end.column, 2u); - EXPECT_EQ(e.value[1]->symbol, p->builder().Symbols().Get("b")); + EXPECT_EQ(e.value[1]->name->symbol, p->builder().Symbols().Get("b")); EXPECT_TRUE(e.value[1]->type->Is()); EXPECT_TRUE(e.value[1]->Is()); @@ -61,7 +61,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) { ASSERT_EQ(e.value[1]->source.range.end.line, 1u); ASSERT_EQ(e.value[1]->source.range.end.column, 11u); - EXPECT_EQ(e.value[2]->symbol, p->builder().Symbols().Get("c")); + EXPECT_EQ(e.value[2]->name->symbol, p->builder().Symbols().Get("c")); ASSERT_TRUE(e.value[2]->type->Is()); ASSERT_TRUE(e.value[2]->type->As()->type->Is()); EXPECT_EQ(e.value[2]->type->As()->width, 2u); @@ -97,7 +97,7 @@ TEST_F(ParserImplTest, ParamList_Attributes) { ASSERT_FALSE(e.errored); ASSERT_EQ(e.value.Length(), 2u); - EXPECT_EQ(e.value[0]->symbol, p->builder().Symbols().Get("coord")); + EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("coord")); ASSERT_TRUE(e.value[0]->type->Is()); EXPECT_TRUE(e.value[0]->type->As()->type->Is()); EXPECT_EQ(e.value[0]->type->As()->width, 4u); @@ -112,7 +112,7 @@ TEST_F(ParserImplTest, ParamList_Attributes) { ASSERT_EQ(e.value[0]->source.range.end.line, 1u); ASSERT_EQ(e.value[0]->source.range.end.column, 25u); - EXPECT_EQ(e.value[1]->symbol, p->builder().Symbols().Get("loc1")); + EXPECT_EQ(e.value[1]->name->symbol, p->builder().Symbols().Get("loc1")); EXPECT_TRUE(e.value[1]->type->Is()); EXPECT_TRUE(e.value[1]->Is()); auto attrs_1 = e.value[1]->attributes; diff --git a/src/tint/reader/wgsl/parser_impl_variable_stmt_test.cc b/src/tint/reader/wgsl/parser_impl_variable_stmt_test.cc index 58d9a58eae..6233dc52ee 100644 --- a/src/tint/reader/wgsl/parser_impl_variable_stmt_test.cc +++ b/src/tint/reader/wgsl/parser_impl_variable_stmt_test.cc @@ -26,7 +26,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); ASSERT_NE(e->variable, nullptr); - EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(e->variable->name->symbol, p->builder().Symbols().Get("a")); EXPECT_EQ(e->source.range.begin.line, 1u); EXPECT_EQ(e->source.range.begin.column, 1u); @@ -45,7 +45,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_WithInit) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); ASSERT_NE(e->variable, nullptr); - EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(e->variable->name->symbol, p->builder().Symbols().Get("a")); EXPECT_EQ(e->source.range.begin.line, 1u); EXPECT_EQ(e->source.range.begin.column, 1u); @@ -75,7 +75,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); ASSERT_NE(e->variable, nullptr); - EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(e->variable->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(e->variable->initializer, nullptr); auto* call = e->variable->initializer->As(); @@ -93,7 +93,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit_NoSpace) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); ASSERT_NE(e->variable, nullptr); - EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(e->variable->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(e->variable->initializer, nullptr); auto* call = e->variable->initializer->As(); @@ -111,7 +111,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); ASSERT_NE(e->variable, nullptr); - EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(e->variable->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(e->variable->initializer, nullptr); auto* call = e->variable->initializer->As(); @@ -129,7 +129,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit_NoSpace) { ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); ASSERT_NE(e->variable, nullptr); - EXPECT_EQ(e->variable->symbol, p->builder().Symbols().Get("a")); + EXPECT_EQ(e->variable->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(e->variable->initializer, nullptr); auto* call = e->variable->initializer->As(); diff --git a/src/tint/resolver/dependency_graph.cc b/src/tint/resolver/dependency_graph.cc index c07eb0d6e4..24d5697c90 100644 --- a/src/tint/resolver/dependency_graph.cc +++ b/src/tint/resolver/dependency_graph.cc @@ -199,7 +199,7 @@ class DependencyScanner { TraverseFunction(func); }, [&](const ast::Variable* var) { - Declare(var->symbol, var); + Declare(var->name->symbol, var); TraverseType(var->type); TraverseAttributes(var->attributes); if (var->initializer) { @@ -237,10 +237,10 @@ class DependencyScanner { TINT_DEFER(scope_stack_.Pop()); for (auto* param : func->params) { - if (auto* shadows = scope_stack_.Get(param->symbol)) { + if (auto* shadows = scope_stack_.Get(param->name->symbol)) { graph_.shadows.Add(param, shadows); } - Declare(param->symbol, param); + Declare(param->name->symbol, param); } if (func->body) { TraverseStatements(func->body->statements); @@ -311,12 +311,12 @@ class DependencyScanner { } }, [&](const ast::VariableDeclStatement* v) { - if (auto* shadows = scope_stack_.Get(v->variable->symbol)) { + if (auto* shadows = scope_stack_.Get(v->variable->name->symbol)) { graph_.shadows.Add(v->variable, shadows); } TraverseType(v->variable->type); TraverseExpression(v->variable->initializer); - Declare(v->variable->symbol, v->variable); + Declare(v->variable->name->symbol, v->variable); }, [&](const ast::WhileStatement* w) { scope_stack_.Push(); @@ -560,7 +560,7 @@ struct DependencyAnalysis { node, // [&](const ast::TypeDecl* td) { return td->name; }, [&](const ast::Function* func) { return func->name->symbol; }, - [&](const ast::Variable* var) { return var->symbol; }, + [&](const ast::Variable* var) { return var->name->symbol; }, [&](const ast::DiagnosticDirective*) { return Symbol(); }, [&](const ast::Enable*) { return Symbol(); }, [&](const ast::ConstAssert*) { return Symbol(); }, diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index d305f68f7e..7648ae7383 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -344,7 +344,8 @@ type::Type* Resolver::Type(const ast::Type* ty) { resolved_node, // [&](type::Type* type) { return type; }, [&](sem::Variable* variable) { - auto name = builder_->Symbols().NameFor(variable->Declaration()->symbol); + auto name = + builder_->Symbols().NameFor(variable->Declaration()->name->symbol); AddError("cannot use variable '" + name + "' as type", ty->source); AddNote("'" + name + "' declared here", variable->Declaration()->source); return nullptr; @@ -381,6 +382,8 @@ type::Type* Resolver::Type(const ast::Type* ty) { } sem::Variable* Resolver::Variable(const ast::Variable* v, bool is_global) { + Mark(v->name); + return Switch( v, // [&](const ast::Var* var) { return Var(var, is_global); }, @@ -427,7 +430,8 @@ sem::Variable* Resolver::Let(const ast::Let* v, bool is_global) { if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, const_cast(ty), v->source)) { - AddNote("while instantiating 'let' " + builder_->Symbols().NameFor(v->symbol), v->source); + AddNote("while instantiating 'let' " + builder_->Symbols().NameFor(v->name->symbol), + v->source); return nullptr; } @@ -489,7 +493,7 @@ sem::Variable* Resolver::Override(const ast::Override* v) { if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, const_cast(ty), v->source)) { - AddNote("while instantiating 'override' " + builder_->Symbols().NameFor(v->symbol), + AddNote("while instantiating 'override' " + builder_->Symbols().NameFor(v->name->symbol), v->source); return nullptr; } @@ -582,7 +586,8 @@ sem::Variable* Resolver::Const(const ast::Const* c, bool is_global) { if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, const_cast(ty), c->source)) { - AddNote("while instantiating 'const' " + builder_->Symbols().NameFor(c->symbol), c->source); + AddNote("while instantiating 'const' " + builder_->Symbols().NameFor(c->name->symbol), + c->source); return nullptr; } @@ -669,7 +674,7 @@ sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) { if (!ApplyAddressSpaceUsageToType(address_space, var_ty, var->type ? var->type->source : var->source)) { - AddNote("while instantiating 'var' " + builder_->Symbols().NameFor(var->symbol), + AddNote("while instantiating 'var' " + builder_->Symbols().NameFor(var->name->symbol), var->source); return nullptr; } @@ -753,8 +758,10 @@ sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) { } sem::Parameter* Resolver::Parameter(const ast::Parameter* param, uint32_t index) { + Mark(param->name); + auto add_note = [&] { - AddNote("while instantiating parameter " + builder_->Symbols().NameFor(param->symbol), + AddNote("while instantiating parameter " + builder_->Symbols().NameFor(param->name->symbol), param->source); }; @@ -1018,8 +1025,8 @@ sem::Function* Resolver::Function(const ast::Function* decl) { Mark(param); { // Check the parameter name is unique for the function - if (auto added = parameter_names.Add(param->symbol, param->source); !added) { - auto name = builder_->Symbols().NameFor(param->symbol); + if (auto added = parameter_names.Add(param->name->symbol, param->source); !added) { + auto name = builder_->Symbols().NameFor(param->name->symbol); AddError("redefinition of parameter '" + name + "'", param->source); AddNote("previous definition is here", *added.value); return nullptr; @@ -2338,7 +2345,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) { }, [&](sem::Function* func) { return FunctionCall(expr, func, args, arg_behaviors); }, [&](sem::Variable* var) { - auto name = builder_->Symbols().NameFor(var->Declaration()->symbol); + auto name = builder_->Symbols().NameFor(var->Declaration()->name->symbol); AddError("cannot call variable '" + name + "'", ident->source); AddNote("'" + name + "' declared here", var->Declaration()->source); return nullptr; diff --git a/src/tint/resolver/uniformity.cc b/src/tint/resolver/uniformity.cc index bae85a4fff..403ac53ba6 100644 --- a/src/tint/resolver/uniformity.cc +++ b/src/tint/resolver/uniformity.cc @@ -189,7 +189,7 @@ struct FunctionInfo { parameters.Resize(func->params.Length()); for (size_t i = 0; i < func->params.Length(); i++) { auto* param = func->params[i]; - auto param_name = builder->Symbols().NameFor(param->symbol); + auto param_name = builder->Symbols().NameFor(param->name->symbol); auto* sem = builder->Sem().Get(param); parameters[i].sem = sem; @@ -621,7 +621,7 @@ class UniformityGraph { // Add an edge from the variable exit node to its value at this point. auto* exit_node = info.var_exit_nodes.GetOrCreate(var, [&]() { - auto name = NameFor(var->Declaration()); + auto name = NameFor(var->Declaration()->name); return CreateNode({name, "_value_", info.type, "_exit"}); }); exit_node->AddEdge(current_function_->variables.Get(var)); @@ -657,7 +657,7 @@ class UniformityGraph { // Add an edge from the variable exit node to its value at this point. auto* exit_node = info.var_exit_nodes.GetOrCreate(var, [&]() { - auto name = NameFor(var->Declaration()); + auto name = NameFor(var->Declaration()->name); return CreateNode({name, "_value_", info.type, "_exit"}); }); @@ -730,7 +730,8 @@ class UniformityGraph { // Create input nodes for any variables declared before this loop. for (auto* v : current_function_->local_var_decls) { - auto* in_node = CreateNode({NameFor(v->Declaration()), "_value_forloop_in"}); + auto* in_node = + CreateNode({NameFor(v->Declaration()->name), "_value_forloop_in"}); in_node->AddEdge(current_function_->variables.Get(v)); info.var_in_nodes.Replace(v, in_node); current_function_->variables.Set(v, in_node); @@ -747,7 +748,7 @@ class UniformityGraph { // Propagate assignments to the loop exit nodes. for (auto* var : current_function_->local_var_decls) { auto* exit_node = info.var_exit_nodes.GetOrCreate(var, [&]() { - auto name = NameFor(var->Declaration()); + auto name = NameFor(var->Declaration()->name); return CreateNode({name, "_value_", info.type, "_exit"}); }); exit_node->AddEdge(current_function_->variables.Get(var)); @@ -805,7 +806,8 @@ class UniformityGraph { // Create input nodes for any variables declared before this loop. for (auto* v : current_function_->local_var_decls) { - auto* in_node = CreateNode({NameFor(v->Declaration()), "_value_forloop_in"}); + auto* in_node = + CreateNode({NameFor(v->Declaration()->name), "_value_forloop_in"}); in_node->AddEdge(current_function_->variables.Get(v)); info.var_in_nodes.Replace(v, in_node); current_function_->variables.Set(v, in_node); @@ -823,7 +825,7 @@ class UniformityGraph { // Propagate assignments to the loop exit nodes. for (auto* var : current_function_->local_var_decls) { auto* exit_node = info.var_exit_nodes.GetOrCreate(var, [&]() { - auto name = NameFor(var->Declaration()); + auto name = NameFor(var->Declaration()->name); return CreateNode({name, "_value_", info.type, "_exit"}); }); exit_node->AddEdge(current_function_->variables.Get(var)); @@ -907,7 +909,8 @@ class UniformityGraph { } // Create an exit node for the variable. - auto* out_node = CreateNode({NameFor(var->Declaration()), "_value_if_exit"}); + auto* out_node = + CreateNode({NameFor(var->Declaration()->name), "_value_if_exit"}); // Add edges to the assigned value or the initial value. // Only add edges if the behavior for that block contains 'Next'. @@ -963,7 +966,7 @@ class UniformityGraph { // Create input nodes for any variables declared before this loop. for (auto* v : current_function_->local_var_decls) { - auto name = NameFor(v->Declaration()); + auto name = NameFor(v->Declaration()->name); auto* in_node = CreateNode({name, "_value_loop_in"}, v->Declaration()); in_node->AddEdge(current_function_->variables.Get(v)); info.var_in_nodes.Replace(v, in_node); @@ -1062,7 +1065,7 @@ class UniformityGraph { // Add an edge from the variable exit node to its new value. auto* exit_node = info.var_exit_nodes.GetOrCreate(var, [&]() { - auto name = NameFor(var->Declaration()); + auto name = NameFor(var->Declaration()->name); return CreateNode({name, "_value_", info.type, "_exit"}); }); exit_node->AddEdge(current_function_->variables.Get(var)); @@ -1401,7 +1404,7 @@ class UniformityGraph { // Cut the analysis short, since we only need to know the originating variable // that is being written to. auto* root_ident = sem_.Get(u)->RootIdentifier(); - auto* deref = CreateNode({NameFor(root_ident->Declaration()), "_deref"}); + auto* deref = CreateNode({NameFor(root_ident->Declaration()->name), "_deref"}); auto* old_value = current_function_->variables.Set(root_ident, deref); if (old_value) { @@ -1779,7 +1782,7 @@ class UniformityGraph { [&](const ast::Variable* v) { auto* var = sem_.Get(v); std::ostringstream ss; - ss << "reading from " << var_type(var) << "'" << NameFor(v) + ss << "reading from " << var_type(var) << "'" << NameFor(v->name) << "' may result in a non-uniform value"; diagnostics_.add_note(diag::System::Resolver, ss.str(), v->source); }, @@ -1796,7 +1799,8 @@ class UniformityGraph { auto* arg = c->args[non_uniform_source->arg_index]; auto* var = sem_.GetVal(arg)->RootIdentifier(); std::ostringstream ss; - ss << "reading from " << var_type(var) << "'" << NameFor(var->Declaration()) + ss << "reading from " << var_type(var) << "'" + << NameFor(var->Declaration()->name) << "' may result in a non-uniform value"; diagnostics_.add_note(diag::System::Resolver, ss.str(), var->Declaration()->source); diff --git a/src/tint/resolver/validator.cc b/src/tint/resolver/validator.cc index 29218af7a1..eb9133a37d 100644 --- a/src/tint/resolver/validator.cc +++ b/src/tint/resolver/validator.cc @@ -2354,7 +2354,7 @@ bool Validator::Assignment(const ast::Statement* a, const type::Type* rhs_ty) co [&](const ast::Override*) { return "cannot assign to 'override'"; }); if (err) { AddError(err, lhs->source); - AddNote("'" + symbols_.NameFor(v->symbol) + "' is declared here:", v->source); + AddNote("'" + symbols_.NameFor(v->name->symbol) + "' is declared here:", v->source); return false; } } @@ -2402,7 +2402,7 @@ bool Validator::IncrementDecrementStatement(const ast::IncrementDecrementStateme [&](const ast::Override*) { return "cannot modify 'override'"; }); if (err) { AddError(err, lhs->source); - AddNote("'" + symbols_.NameFor(v->symbol) + "' is declared here:", v->source); + AddNote("'" + symbols_.NameFor(v->name->symbol) + "' is declared here:", v->source); return false; } } diff --git a/src/tint/sem/array_count.cc b/src/tint/sem/array_count.cc index 4fa6c08271..d0f5145e40 100644 --- a/src/tint/sem/array_count.cc +++ b/src/tint/sem/array_count.cc @@ -14,6 +14,8 @@ #include "src/tint/sem/array_count.h" +#include "src/tint/ast/identifier.h" + TINT_INSTANTIATE_TYPEINFO(tint::sem::NamedOverrideArrayCount); TINT_INSTANTIATE_TYPEINFO(tint::sem::UnnamedOverrideArrayCount); @@ -32,7 +34,7 @@ bool NamedOverrideArrayCount::Equals(const UniqueNode& other) const { } std::string NamedOverrideArrayCount::FriendlyName(const SymbolTable& symbols) const { - return symbols.NameFor(variable->Declaration()->symbol); + return symbols.NameFor(variable->Declaration()->name->symbol); } type::ArrayCount* NamedOverrideArrayCount::Clone(type::CloneContext&) const { diff --git a/src/tint/sem/statement.cc b/src/tint/sem/statement.cc index 685f0d6d7b..bc1ba254d1 100644 --- a/src/tint/sem/statement.cc +++ b/src/tint/sem/statement.cc @@ -15,6 +15,7 @@ #include #include "src/tint/ast/block_statement.h" +#include "src/tint/ast/identifier.h" #include "src/tint/ast/loop_statement.h" #include "src/tint/ast/statement.h" #include "src/tint/ast/variable.h" @@ -46,7 +47,7 @@ CompoundStatement::CompoundStatement(const ast::Statement* declaration, CompoundStatement::~CompoundStatement() = default; void CompoundStatement::AddDecl(const sem::LocalVariable* var) { - decls_.Add(var->Declaration()->symbol, OrderedLocalVariable{decls_.Count(), var}); + decls_.Add(var->Declaration()->name->symbol, OrderedLocalVariable{decls_.Count(), var}); } } // namespace tint::sem diff --git a/src/tint/transform/add_block_attribute.cc b/src/tint/transform/add_block_attribute.cc index c2d674b9af..f79e120172 100644 --- a/src/tint/transform/add_block_attribute.cc +++ b/src/tint/transform/add_block_attribute.cc @@ -70,7 +70,7 @@ Transform::ApplyResult AddBlockAttribute::Apply(const Program* src, auto* wrapper = wrapper_structs.GetOrCreate(ty, [&] { auto* block = b.ASTNodes().Create(b.ID(), b.AllocateNodeID()); - auto wrapper_name = src->Symbols().NameFor(global->symbol) + "_block"; + auto wrapper_name = src->Symbols().NameFor(global->name->symbol) + "_block"; auto* ret = b.create( b.Symbols().New(wrapper_name), utils::Vector{b.Member(kMemberName, CreateASTTypeFor(ctx, ty))}, @@ -84,7 +84,7 @@ Transform::ApplyResult AddBlockAttribute::Apply(const Program* src, // any usage of the original variable. for (auto* user : var->Users()) { ctx.Replace(user->Declaration(), - b.MemberAccessor(ctx.Clone(global->symbol), kMemberName)); + b.MemberAccessor(ctx.Clone(global->name->symbol), kMemberName)); } } else { // Add a block attribute to this struct directly. diff --git a/src/tint/transform/array_length_from_uniform.cc b/src/tint/transform/array_length_from_uniform.cc index 1d2b584895..444a328efe 100644 --- a/src/tint/transform/array_length_from_uniform.cc +++ b/src/tint/transform/array_length_from_uniform.cc @@ -131,7 +131,7 @@ struct ArrayLengthFromUniform::State { // Load the total storage buffer size from the UBO. uint32_t array_index = size_index / 4; auto* vec_expr = b.IndexAccessor( - b.MemberAccessor(get_ubo()->symbol, kBufferSizeMemberName), u32(array_index)); + b.MemberAccessor(get_ubo()->name->symbol, kBufferSizeMemberName), u32(array_index)); uint32_t vec_index = size_index % 4; auto* total_storage_buffer_size = b.IndexAccessor(vec_expr, u32(vec_index)); diff --git a/src/tint/transform/binding_remapper.cc b/src/tint/transform/binding_remapper.cc index 5967d84e6a..470826d453 100644 --- a/src/tint/transform/binding_remapper.cc +++ b/src/tint/transform/binding_remapper.cc @@ -139,9 +139,9 @@ Transform::ApplyResult BindingRemapper::Apply(const Program* src, } auto* ty = sem->Type()->UnwrapRef(); const ast::Type* inner_ty = CreateASTTypeFor(ctx, ty); - auto* new_var = b.Var(ctx.Clone(var->source), ctx.Clone(var->symbol), inner_ty, - var->declared_address_space, ac, ctx.Clone(var->initializer), - ctx.Clone(var->attributes)); + auto* new_var = b.Var(ctx.Clone(var->source), ctx.Clone(var->name->symbol), + inner_ty, var->declared_address_space, ac, + ctx.Clone(var->initializer), ctx.Clone(var->attributes)); ctx.Replace(var, new_var); } diff --git a/src/tint/transform/calculate_array_length.cc b/src/tint/transform/calculate_array_length.cc index de363159a7..028f8c50ca 100644 --- a/src/tint/transform/calculate_array_length.cc +++ b/src/tint/transform/calculate_array_length.cc @@ -192,7 +192,7 @@ Transform::ApplyResult CalculateArrayLength::Apply(const Program* src, // translated to: // X.GetDimensions(ARGS..) by the writer buffer_size, b.AddressOf(ctx.Clone(storage_buffer_expr)), - b.AddressOf(b.Expr(buffer_size_result->variable->symbol)))); + b.AddressOf(b.Expr(buffer_size_result->variable->name->symbol)))); // Calculate actual array length // total_storage_buffer_size - array_offset diff --git a/src/tint/transform/canonicalize_entry_point_io.cc b/src/tint/transform/canonicalize_entry_point_io.cc index 9a9d91fc40..c19c9ad637 100644 --- a/src/tint/transform/canonicalize_entry_point_io.cc +++ b/src/tint/transform/canonicalize_entry_point_io.cc @@ -334,7 +334,7 @@ struct CanonicalizeEntryPointIO::State { } } - auto name = ctx.src->Symbols().NameFor(param->Declaration()->symbol); + auto name = ctx.src->Symbols().NameFor(param->Declaration()->name->symbol); auto* input_expr = AddInput(name, param->Type(), param->Location(), std::move(attributes)); inner_call_parameters.Push(input_expr); } @@ -615,7 +615,7 @@ struct CanonicalizeEntryPointIO::State { // Process the original return type to determine the outputs that the // outer function needs to produce. - ProcessReturnType(func_sem->ReturnType(), inner_result->symbol); + ProcessReturnType(func_sem->ReturnType(), inner_result->name->symbol); } // Add a fixed sample mask, if necessary. diff --git a/src/tint/transform/combine_samplers.cc b/src/tint/transform/combine_samplers.cc index 8703c90dce..284496ab21 100644 --- a/src/tint/transform/combine_samplers.cc +++ b/src/tint/transform/combine_samplers.cc @@ -185,10 +185,10 @@ struct CombineSamplers::State { const sem::Variable* texture_var = pair.first; const sem::Variable* sampler_var = pair.second; std::string name = - ctx.src->Symbols().NameFor(texture_var->Declaration()->symbol); + ctx.src->Symbols().NameFor(texture_var->Declaration()->name->symbol); if (sampler_var) { - name += - "_" + ctx.src->Symbols().NameFor(sampler_var->Declaration()->symbol); + name += "_" + ctx.src->Symbols().NameFor( + sampler_var->Declaration()->name->symbol); } if (IsGlobal(pair)) { // Both texture and sampler are global; add a new global variable @@ -263,7 +263,7 @@ struct CombineSamplers::State { ? global_combined_texture_samplers_[new_pair] : function_combined_texture_samplers_[call->Stmt()->Function()] [new_pair]; - args.Push(ctx.dst->Expr(var->symbol)); + args.Push(ctx.dst->Expr(var->name->symbol)); } else if (auto* sampler_type = type->As()) { type::SamplerKind kind = sampler_type->kind(); int index = (kind == type::SamplerKind::kSampler) ? 0 : 1; @@ -271,7 +271,7 @@ struct CombineSamplers::State { if (!p) { p = CreatePlaceholder(kind); } - args.Push(ctx.dst->Expr(p->symbol)); + args.Push(ctx.dst->Expr(p->name->symbol)); } else { args.Push(ctx.Clone(arg)); } @@ -317,7 +317,7 @@ struct CombineSamplers::State { ? global_combined_texture_samplers_[new_pair] : function_combined_texture_samplers_[call->Stmt()->Function()] [new_pair]; - auto* arg = ctx.dst->Expr(var->symbol); + auto* arg = ctx.dst->Expr(var->name->symbol); args.Push(arg); } // Append all of the remaining non-texture and non-sampler diff --git a/src/tint/transform/direct_variable_access.cc b/src/tint/transform/direct_variable_access.cc index 3522086df6..3e89ca3a52 100644 --- a/src/tint/transform/direct_variable_access.cc +++ b/src/tint/transform/direct_variable_access.cc @@ -711,13 +711,13 @@ struct DirectVariableAccess::State { PtrParamSymbols symbols; if (requires_base_ptr_param && requires_indices_param) { - auto original_name = param->Declaration()->symbol; + auto original_name = param->Declaration()->name->symbol; symbols.base_ptr = UniqueSymbolWithSuffix(original_name, "_base"); symbols.indices = UniqueSymbolWithSuffix(original_name, "_indices"); } else if (requires_base_ptr_param) { - symbols.base_ptr = ctx.Clone(param->Declaration()->symbol); + symbols.base_ptr = ctx.Clone(param->Declaration()->name->symbol); } else if (requires_indices_param) { - symbols.indices = ctx.Clone(param->Declaration()->symbol); + symbols.indices = ctx.Clone(param->Declaration()->name->symbol); } // Remember this base pointer name. @@ -1085,7 +1085,7 @@ struct DirectVariableAccess::State { if (IsPrivateOrFunction(shape.root.address_space)) { ss << "F"; } else { - ss << ctx.src->Symbols().NameFor(shape.root.variable->Declaration()->symbol); + ss << ctx.src->Symbols().NameFor(shape.root.variable->Declaration()->name->symbol); } for (auto& op : shape.ops) { @@ -1122,7 +1122,7 @@ struct DirectVariableAccess::State { } } - const ast::Expression* expr = b.Expr(ctx.Clone(root.variable->Declaration()->symbol)); + const ast::Expression* expr = b.Expr(ctx.Clone(root.variable->Declaration()->name->symbol)); if (deref) { if (root.variable->Type()->Is()) { expr = b.Deref(expr); diff --git a/src/tint/transform/module_scope_var_to_entry_point_param.cc b/src/tint/transform/module_scope_var_to_entry_point_param.cc index 71d9561999..285b95cc51 100644 --- a/src/tint/transform/module_scope_var_to_entry_point_param.cc +++ b/src/tint/transform/module_scope_var_to_entry_point_param.cc @@ -174,7 +174,7 @@ struct ModuleScopeVarToEntryPointParam::State { // TODO(jrprice): Do this for all other workgroup variables too. // Create a member in the workgroup parameter struct. - auto member = ctx.Clone(var->Declaration()->symbol); + auto member = ctx.Clone(var->Declaration()->name->symbol); workgroup_parameter_members.Push(ctx.dst->Member(member, store_type())); CloneStructTypes(var->Type()->UnwrapRef()); diff --git a/src/tint/transform/multiplanar_external_texture.cc b/src/tint/transform/multiplanar_external_texture.cc index 97d907c1da..1bbbe223d5 100644 --- a/src/tint/transform/multiplanar_external_texture.cc +++ b/src/tint/transform/multiplanar_external_texture.cc @@ -139,7 +139,7 @@ struct MultiplanarExternalTexture::State { // with the texture_external binding that corresponds with the new destination bindings. // NewBindingSymbols new_binding_syms; auto& syms = new_binding_symbols[sem_var]; - syms.plane_0 = ctx.Clone(global->symbol); + syms.plane_0 = ctx.Clone(global->name->symbol); syms.plane_1 = b.Symbols().New("ext_tex_plane_1"); b.GlobalVar(syms.plane_1, b.ty.sampled_texture(type::TextureDimension::k2d, b.ty.f32()), b.Group(AInt(bps.plane_1.group)), b.Binding(AInt(bps.plane_1.binding))); @@ -174,7 +174,7 @@ struct MultiplanarExternalTexture::State { // into the transform state so they can be used when transforming function // calls. auto& syms = new_binding_symbols[sem_var]; - syms.plane_0 = ctx.Clone(param->symbol); + syms.plane_0 = ctx.Clone(param->name->symbol); syms.plane_1 = b.Symbols().New("ext_tex_plane_1"); syms.params = b.Symbols().New("ext_tex_params"); auto tex2d_f32 = [&] { diff --git a/src/tint/transform/num_workgroups_from_uniform.cc b/src/tint/transform/num_workgroups_from_uniform.cc index 57e305dbf3..72b32dfd8b 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->Name()}); + to_replace.insert({param->Declaration()->name->symbol, member->Name()}); // Remove the struct member. // The CanonicalizeEntryPointIO transform will have generated this @@ -178,7 +178,8 @@ Transform::ApplyResult NumWorkgroupsFromUniform::Apply(const Program* src, } if (to_replace.count({ident->identifier->symbol, accessor->member->symbol})) { - ctx.Replace(accessor, b.MemberAccessor(get_ubo()->symbol, kNumWorkgroupsMemberName)); + ctx.Replace(accessor, + b.MemberAccessor(get_ubo()->name->symbol, kNumWorkgroupsMemberName)); } } diff --git a/src/tint/transform/simplify_pointers.cc b/src/tint/transform/simplify_pointers.cc index f08e171ec1..e9c719e371 100644 --- a/src/tint/transform/simplify_pointers.cc +++ b/src/tint/transform/simplify_pointers.cc @@ -158,7 +158,8 @@ struct SimplifyPointers::State { // We have a sub-expression that needs to be saved. // Create a new variable auto saved_name = ctx.dst->Symbols().New( - ctx.src->Symbols().NameFor(var->Declaration()->symbol) + "_save"); + ctx.src->Symbols().NameFor(var->Declaration()->name->symbol) + + "_save"); auto* decl = ctx.dst->Decl(ctx.dst->Let(saved_name, ctx.Clone(idx_expr))); saved.Push(decl); diff --git a/src/tint/transform/std140.cc b/src/tint/transform/std140.cc index 2fd8dde777..151a437193 100644 --- a/src/tint/transform/std140.cc +++ b/src/tint/transform/std140.cc @@ -529,7 +529,7 @@ struct Std140::State { } TINT_ICE(Transform, b.Diagnostics()) << "unexpected variable found walking access chain: " - << sym.NameFor(user->Variable()->Declaration()->symbol); + << sym.NameFor(user->Variable()->Declaration()->name->symbol); return Action::kError; }, [&](const sem::StructMemberAccess* a) { @@ -879,7 +879,9 @@ struct Std140::State { }); // Method for generating dynamic index expressions. // These are passed in as arguments to the function. - auto dynamic_index = [&](size_t idx) { return b.Expr(dynamic_index_params[idx]->symbol); }; + auto dynamic_index = [&](size_t idx) { + return b.Expr(dynamic_index_params[idx]->name->symbol); + }; // Fetch the access chain indices of the matrix access and the parameter index that // holds the matrix column index. @@ -987,7 +989,9 @@ struct Std140::State { }); // Method for generating dynamic index expressions. // These are passed in as arguments to the function. - auto dynamic_index = [&](size_t idx) { return b.Expr(dynamic_index_params[idx]->symbol); }; + auto dynamic_index = [&](size_t idx) { + return b.Expr(dynamic_index_params[idx]->name->symbol); + }; const ast::Expression* expr = nullptr; const type::Type* ty = nullptr; @@ -1073,8 +1077,9 @@ struct Std140::State { auto& access = chain.indices[index]; if (std::get_if(&access)) { - const auto* expr = b.Expr(ctx.Clone(chain.var->Declaration()->symbol)); - const auto name = src->Symbols().NameFor(chain.var->Declaration()->symbol); + const auto symbol = chain.var->Declaration()->name->symbol; + const auto* expr = b.Expr(ctx.Clone(symbol)); + const auto name = src->Symbols().NameFor(symbol); ty = chain.var->Type()->UnwrapRef(); return {expr, ty, name}; } diff --git a/src/tint/transform/substitute_override.cc b/src/tint/transform/substitute_override.cc index 9031f44b61..f5a859bb8a 100644 --- a/src/tint/transform/substitute_override.cc +++ b/src/tint/transform/substitute_override.cc @@ -63,7 +63,7 @@ Transform::ApplyResult SubstituteOverride::Apply(const Program* src, auto* sem = ctx.src->Sem().Get(w); auto source = ctx.Clone(w->source); - auto sym = ctx.Clone(w->symbol); + auto sym = ctx.Clone(w->name->symbol); auto* ty = ctx.Clone(w->type); // No replacement provided, just clone the override node as a const. diff --git a/src/tint/transform/texture_1d_to_2d.cc b/src/tint/transform/texture_1d_to_2d.cc index 4de61880c3..4561814350 100644 --- a/src/tint/transform/texture_1d_to_2d.cc +++ b/src/tint/transform/texture_1d_to_2d.cc @@ -85,9 +85,9 @@ struct Texture1DTo2D::State { auto create_var = [&](const ast::Variable* v, ast::Type* type) -> const ast::Variable* { if (v->As()) { - return ctx.dst->Param(ctx.Clone(v->symbol), type, ctx.Clone(v->attributes)); + return ctx.dst->Param(ctx.Clone(v->name->symbol), type, ctx.Clone(v->attributes)); } else { - return ctx.dst->Var(ctx.Clone(v->symbol), type, ctx.Clone(v->attributes)); + return ctx.dst->Var(ctx.Clone(v->name->symbol), type, ctx.Clone(v->attributes)); } }; diff --git a/src/tint/transform/unshadow.cc b/src/tint/transform/unshadow.cc index bbb3a27845..ac00a39693 100644 --- a/src/tint/transform/unshadow.cc +++ b/src/tint/transform/unshadow.cc @@ -51,7 +51,7 @@ struct Unshadow::State { auto rename = [&](const sem::Variable* v) -> const ast::Variable* { auto* decl = v->Declaration(); - auto name = src->Symbols().NameFor(decl->symbol); + auto name = src->Symbols().NameFor(decl->name->symbol); auto symbol = b.Symbols().New(name); renamed_to.Add(v, symbol); diff --git a/src/tint/transform/vertex_pulling.cc b/src/tint/transform/vertex_pulling.cc index 687ea79e46..438ede8b14 100644 --- a/src/tint/transform/vertex_pulling.cc +++ b/src/tint/transform/vertex_pulling.cc @@ -756,7 +756,7 @@ struct VertexPulling::State { void ProcessNonStructParameter(const ast::Function* func, const ast::Parameter* param) { if (ast::HasAttribute(param->attributes)) { // Create a function-scope variable to replace the parameter. - auto func_var_sym = ctx.Clone(param->symbol); + auto func_var_sym = ctx.Clone(param->name->symbol); auto* func_var_type = ctx.Clone(param->type); auto* func_var = b.Var(func_var_sym, func_var_type); ctx.InsertFront(func->body->statements, b.Decl(func_var)); @@ -780,9 +780,13 @@ struct VertexPulling::State { } // Check for existing vertex_index and instance_index builtins. if (builtin->builtin == ast::BuiltinValue::kVertexIndex) { - vertex_index_expr = [this, param]() { return b.Expr(ctx.Clone(param->symbol)); }; + vertex_index_expr = [this, param]() { + return b.Expr(ctx.Clone(param->name->symbol)); + }; } else if (builtin->builtin == ast::BuiltinValue::kInstanceIndex) { - instance_index_expr = [this, param]() { return b.Expr(ctx.Clone(param->symbol)); }; + instance_index_expr = [this, param]() { + return b.Expr(ctx.Clone(param->name->symbol)); + }; } new_function_parameters.Push(ctx.Clone(param)); } @@ -799,7 +803,7 @@ struct VertexPulling::State { void ProcessStructParameter(const ast::Function* func, const ast::Parameter* param, const ast::Struct* struct_ty) { - auto param_sym = ctx.Clone(param->symbol); + auto param_sym = ctx.Clone(param->name->symbol); // Process the struct members. bool has_locations = false; diff --git a/src/tint/transform/zero_init_workgroup_memory.cc b/src/tint/transform/zero_init_workgroup_memory.cc index 68490b224c..e4943a7fb1 100644 --- a/src/tint/transform/zero_init_workgroup_memory.cc +++ b/src/tint/transform/zero_init_workgroup_memory.cc @@ -141,7 +141,7 @@ struct ZeroInitWorkgroupMemory::State { for (auto* var : func->TransitivelyReferencedGlobals()) { if (var->AddressSpace() == type::AddressSpace::kWorkgroup) { auto get_expr = [&](uint32_t num_values) { - auto var_name = ctx.Clone(var->Declaration()->symbol); + auto var_name = ctx.Clone(var->Declaration()->name->symbol); return Expression{b.Expr(var_name), num_values, ArrayIndices{}}; }; if (!BuildZeroingStatements(var->Type()->UnwrapRef(), get_expr)) { @@ -160,7 +160,7 @@ struct ZeroInitWorkgroupMemory::State { for (auto* param : fn->params) { if (auto* builtin = ast::GetAttribute(param->attributes)) { if (builtin->builtin == ast::BuiltinValue::kLocalInvocationIndex) { - local_index = [=] { return b.Expr(ctx.Clone(param->symbol)); }; + local_index = [=] { return b.Expr(ctx.Clone(param->name->symbol)); }; break; } } @@ -171,7 +171,7 @@ struct ZeroInitWorkgroupMemory::State { member->Declaration()->attributes)) { if (builtin->builtin == ast::BuiltinValue::kLocalInvocationIndex) { local_index = [=] { - auto* param_expr = b.Expr(ctx.Clone(param->symbol)); + auto* param_expr = b.Expr(ctx.Clone(param->name->symbol)); auto* member_name = ctx.Clone(member->Declaration()->name); return b.MemberAccessor(param_expr, member_name); }; @@ -188,7 +188,7 @@ struct ZeroInitWorkgroupMemory::State { b.Builtin(ast::BuiltinValue::kLocalInvocationIndex), }); ctx.InsertBack(fn->params, param); - local_index = [=] { return b.Expr(param->symbol); }; + local_index = [=] { return b.Expr(param->name->symbol); }; } // Take the zeroing statements and bin them by the number of iterations diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 597ac0270f..cb1850a523 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -1916,7 +1916,7 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { // correctly translate the parameter to a [RW]ByteAddressBuffer for // storage buffers and a uint4[N] for uniform buffers. if (!EmitTypeAndName(out, type, v->AddressSpace(), v->Access(), - builder_.Symbols().NameFor(v->Declaration()->symbol))) { + builder_.Symbols().NameFor(v->Declaration()->name->symbol))) { return false; } } @@ -1996,7 +1996,7 @@ bool GeneratorImpl::EmitUniformVariable(const ast::Var* var, const sem::Variable out << ") uniform " << UniqueIdentifier(StructName(str) + "_ubo") << " {"; } EmitStructMembers(current_buffer_, str); - auto name = builder_.Symbols().NameFor(var->symbol); + auto name = builder_.Symbols().NameFor(var->name->symbol); line() << "} " << name << ";"; line(); @@ -2014,7 +2014,7 @@ bool GeneratorImpl::EmitStorageVariable(const ast::Var* var, const sem::Variable line() << "layout(binding = " << bp.binding << ", std430) buffer " << UniqueIdentifier(StructName(str) + "_ssbo") << " {"; EmitStructMembers(current_buffer_, str); - auto name = builder_.Symbols().NameFor(var->symbol); + auto name = builder_.Symbols().NameFor(var->name->symbol); line() << "} " << name << ";"; line(); @@ -2024,7 +2024,7 @@ bool GeneratorImpl::EmitStorageVariable(const ast::Var* var, const sem::Variable bool GeneratorImpl::EmitHandleVariable(const ast::Var* var, const sem::Variable* sem) { auto out = line(); - auto name = builder_.Symbols().NameFor(var->symbol); + auto name = builder_.Symbols().NameFor(var->name->symbol); auto* type = sem->Type()->UnwrapRef(); if (type->Is()) { // GLSL ignores Sampler variables. @@ -2103,7 +2103,7 @@ bool GeneratorImpl::EmitPrivateVariable(const sem::Variable* var) { auto* decl = var->Declaration(); auto out = line(); - auto name = builder_.Symbols().NameFor(decl->symbol); + auto name = builder_.Symbols().NameFor(decl->name->symbol); auto* type = var->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, var->AddressSpace(), var->Access(), name)) { return false; @@ -2130,7 +2130,7 @@ bool GeneratorImpl::EmitWorkgroupVariable(const sem::Variable* var) { out << "shared "; - auto name = builder_.Symbols().NameFor(decl->symbol); + auto name = builder_.Symbols().NameFor(decl->name->symbol); auto* type = var->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, var->AddressSpace(), var->Access(), name)) { return false; @@ -2163,7 +2163,7 @@ bool GeneratorImpl::EmitIOVariable(const sem::GlobalVariable* var) { EmitAttributes(out, var, decl->attributes); EmitInterpolationQualifiers(out, decl->attributes); - auto name = builder_.Symbols().NameFor(decl->symbol); + auto name = builder_.Symbols().NameFor(decl->name->symbol); auto* type = var->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, var->AddressSpace(), var->Access(), name)) { return false; @@ -2285,7 +2285,7 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { first = false; if (!EmitTypeAndName(out, type, sem->AddressSpace(), sem->Access(), - builder_.Symbols().NameFor(var->symbol))) { + builder_.Symbols().NameFor(var->name->symbol))) { return false; } } @@ -3096,7 +3096,7 @@ bool GeneratorImpl::EmitVar(const ast::Var* var) { auto out = line(); if (!EmitTypeAndName(out, type, sem->AddressSpace(), sem->Access(), - builder_.Symbols().NameFor(var->symbol))) { + builder_.Symbols().NameFor(var->name->symbol))) { return false; } @@ -3123,7 +3123,7 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) { auto out = line(); // TODO(senorblanco): handle const if (!EmitTypeAndName(out, type, type::AddressSpace::kNone, type::Access::kUndefined, - builder_.Symbols().NameFor(let->symbol))) { + builder_.Symbols().NameFor(let->name->symbol))) { return false; } @@ -3145,7 +3145,7 @@ bool GeneratorImpl::EmitProgramConstVariable(const ast::Variable* var) { auto out = line(); out << "const "; if (!EmitTypeAndName(out, type, type::AddressSpace::kNone, type::Access::kUndefined, - builder_.Symbols().NameFor(var->symbol))) { + builder_.Symbols().NameFor(var->name->symbol))) { return false; } out << " = "; diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc index 21266c3ce3..0f8fdb1665 100644 --- a/src/tint/writer/hlsl/generator_impl.cc +++ b/src/tint/writer/hlsl/generator_impl.cc @@ -2934,7 +2934,7 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { // correctly translate the parameter to a [RW]ByteAddressBuffer for // storage buffers and a uint4[N] for uniform buffers. if (!EmitTypeAndName(out, type, address_space, access, - builder_.Symbols().NameFor(v->Declaration()->symbol))) { + builder_.Symbols().NameFor(v->Declaration()->name->symbol))) { return false; } } @@ -3040,7 +3040,7 @@ bool GeneratorImpl::EmitGlobalVariable(const ast::Variable* global) { bool GeneratorImpl::EmitUniformVariable(const ast::Var* var, const sem::Variable* sem) { auto binding_point = sem->As()->BindingPoint(); auto* type = sem->Type()->UnwrapRef(); - auto name = builder_.Symbols().NameFor(var->symbol); + auto name = builder_.Symbols().NameFor(var->name->symbol); line() << "cbuffer cbuffer_" << name << RegisterAndSpace('b', binding_point) << " {"; { @@ -3061,7 +3061,7 @@ bool GeneratorImpl::EmitStorageVariable(const ast::Var* var, const sem::Variable auto* type = sem->Type()->UnwrapRef(); auto out = line(); if (!EmitTypeAndName(out, type, type::AddressSpace::kStorage, sem->Access(), - builder_.Symbols().NameFor(var->symbol))) { + builder_.Symbols().NameFor(var->name->symbol))) { return false; } @@ -3077,7 +3077,7 @@ bool GeneratorImpl::EmitHandleVariable(const ast::Var* var, const sem::Variable* auto* unwrapped_type = sem->Type()->UnwrapRef(); auto out = line(); - auto name = builder_.Symbols().NameFor(var->symbol); + auto name = builder_.Symbols().NameFor(var->name->symbol); auto* type = sem->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, sem->AddressSpace(), sem->Access(), name)) { return false; @@ -3109,7 +3109,7 @@ bool GeneratorImpl::EmitPrivateVariable(const sem::Variable* var) { out << "static "; - auto name = builder_.Symbols().NameFor(decl->symbol); + auto name = builder_.Symbols().NameFor(decl->name->symbol); auto* type = var->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, var->AddressSpace(), var->Access(), name)) { return false; @@ -3136,7 +3136,7 @@ bool GeneratorImpl::EmitWorkgroupVariable(const sem::Variable* var) { out << "groupshared "; - auto name = builder_.Symbols().NameFor(decl->symbol); + auto name = builder_.Symbols().NameFor(decl->name->symbol); auto* type = var->Type()->UnwrapRef(); if (!EmitTypeAndName(out, type, var->AddressSpace(), var->Access(), name)) { return false; @@ -3263,7 +3263,7 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { first = false; if (!EmitTypeAndName(out, type, sem->AddressSpace(), sem->Access(), - builder_.Symbols().NameFor(var->symbol))) { + builder_.Symbols().NameFor(var->name->symbol))) { return false; } } @@ -4275,7 +4275,7 @@ bool GeneratorImpl::EmitVar(const ast::Var* var) { auto out = line(); if (!EmitTypeAndName(out, type, sem->AddressSpace(), sem->Access(), - builder_.Symbols().NameFor(var->symbol))) { + builder_.Symbols().NameFor(var->name->symbol))) { return false; } @@ -4302,7 +4302,7 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) { auto out = line(); out << "const "; if (!EmitTypeAndName(out, type, type::AddressSpace::kNone, type::Access::kUndefined, - builder_.Symbols().NameFor(let->symbol))) { + builder_.Symbols().NameFor(let->name->symbol))) { return false; } out << " = "; diff --git a/src/tint/writer/msl/generator_impl.cc b/src/tint/writer/msl/generator_impl.cc index 091c3dce1b..b09c554ce9 100644 --- a/src/tint/writer/msl/generator_impl.cc +++ b/src/tint/writer/msl/generator_impl.cc @@ -1884,13 +1884,13 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { auto* type = program_->Sem().Get(v)->Type(); - std::string param_name = "const " + program_->Symbols().NameFor(v->symbol); + std::string param_name = "const " + program_->Symbols().NameFor(v->name->symbol); if (!EmitType(out, type, param_name)) { return false; } // Parameter name is output as part of the type for pointers. if (!type->Is()) { - out << " " << program_->Symbols().NameFor(v->symbol); + out << " " << program_->Symbols().NameFor(v->name->symbol); } } @@ -2016,7 +2016,7 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { auto* type = program_->Sem().Get(param)->Type()->UnwrapRef(); - auto param_name = program_->Symbols().NameFor(param->symbol); + auto param_name = program_->Symbols().NameFor(param->name->symbol); if (!EmitType(out, type, param_name)) { return false; } @@ -3021,7 +3021,7 @@ bool GeneratorImpl::EmitVar(const ast::Var* var) { return false; } - std::string name = program_->Symbols().NameFor(var->symbol); + std::string name = program_->Symbols().NameFor(var->name->symbol); if (!EmitType(out, type, name)) { return false; } @@ -3070,7 +3070,7 @@ bool GeneratorImpl::EmitLet(const ast::Let* let) { return false; } - std::string name = "const " + program_->Symbols().NameFor(let->symbol); + std::string name = "const " + program_->Symbols().NameFor(let->name->symbol); if (!EmitType(out, type, name)) { return false; } diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc index 805314716c..590004cdca 100644 --- a/src/tint/writer/spirv/builder.cc +++ b/src/tint/writer/spirv/builder.cc @@ -311,7 +311,7 @@ uint32_t Builder::LookupVariableID(const sem::Variable* var) { auto it = var_to_id_.find(var); if (it == var_to_id_.end()) { error_ = "unable to find ID for variable: " + - builder_.Symbols().NameFor(var->Declaration()->symbol); + builder_.Symbols().NameFor(var->Declaration()->name->symbol); return 0; } return it->second; @@ -514,7 +514,7 @@ bool Builder::GenerateEntryPoint(const ast::Function* func, uint32_t id) { uint32_t var_id = LookupVariableID(var); if (var_id == 0) { error_ = "unable to find ID for global variable: " + - builder_.Symbols().NameFor(var->Declaration()->symbol); + builder_.Symbols().NameFor(var->Declaration()->name->symbol); return false; } @@ -626,9 +626,9 @@ bool Builder::GenerateFunction(const ast::Function* func_ast) { return false; } - push_debug( - spv::Op::OpName, - {Operand(param_id), Operand(builder_.Symbols().NameFor(param->Declaration()->symbol))}); + push_debug(spv::Op::OpName, + {Operand(param_id), + Operand(builder_.Symbols().NameFor(param->Declaration()->name->symbol))}); params.push_back( Instruction{spv::Op::OpFunctionParameter, {Operand(param_type_id), param_op}}); @@ -725,7 +725,8 @@ bool Builder::GenerateFunctionVariable(const ast::Variable* v) { return false; } - push_debug(spv::Op::OpName, {Operand(var_id), Operand(builder_.Symbols().NameFor(v->symbol))}); + push_debug(spv::Op::OpName, + {Operand(var_id), Operand(builder_.Symbols().NameFor(v->name->symbol))}); // TODO(dsinclair) We could detect if the initializer is fully const and emit // an initializer value for the variable instead of doing the OpLoad. @@ -785,7 +786,8 @@ bool Builder::GenerateGlobalVariable(const ast::Variable* v) { return false; } - push_debug(spv::Op::OpName, {Operand(var_id), Operand(builder_.Symbols().NameFor(v->symbol))}); + push_debug(spv::Op::OpName, + {Operand(var_id), Operand(builder_.Symbols().NameFor(v->name->symbol))}); OperandList ops = {Operand(type_id), result, U32Operand(ConvertAddressSpace(sc))}; diff --git a/src/tint/writer/wgsl/generator_impl.cc b/src/tint/writer/wgsl/generator_impl.cc index f5113983ba..f0d3980027 100644 --- a/src/tint/writer/wgsl/generator_impl.cc +++ b/src/tint/writer/wgsl/generator_impl.cc @@ -324,7 +324,7 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { out << " "; } - out << program_->Symbols().NameFor(v->symbol) << " : "; + out << program_->Symbols().NameFor(v->name->symbol) << " : "; if (!EmitType(out, v->type)) { return false; @@ -713,7 +713,7 @@ bool GeneratorImpl::EmitVariable(std::ostream& out, const ast::Variable* v) { return false; } - out << " " << program_->Symbols().NameFor(v->symbol); + out << " " << program_->Symbols().NameFor(v->name->symbol); if (auto* ty = v->type) { out << " : ";