tint/ast: Change Function::symbol to Function::name
Function::name is an ast::Identifier.
The goal here is to have all AST nodes use an identifier instead of
symbols directly. This will greatly simplify the renamer transform,
and gives the symbol a Source location, which is helpful for
diagnostics and tooling.
Change-Id: I723a9a104668758db2cb32051efa1f6d3c105913
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119280
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Ben Clayton <bclayton@google.com>
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
diff --git a/src/tint/resolver/dependency_graph.cc b/src/tint/resolver/dependency_graph.cc
index 7326f81..c07eb0d 100644
--- a/src/tint/resolver/dependency_graph.cc
+++ b/src/tint/resolver/dependency_graph.cc
@@ -195,7 +195,7 @@
TraverseType(alias->type);
},
[&](const ast::Function* func) {
- Declare(func->symbol, func);
+ Declare(func->name->symbol, func);
TraverseFunction(func);
},
[&](const ast::Variable* var) {
@@ -559,7 +559,7 @@
return Switch(
node, //
[&](const ast::TypeDecl* td) { return td->name; },
- [&](const ast::Function* func) { return func->symbol; },
+ [&](const ast::Function* func) { return func->name->symbol; },
[&](const ast::Variable* var) { return var->symbol; },
[&](const ast::DiagnosticDirective*) { return Symbol(); },
[&](const ast::Enable*) { return Symbol(); },
diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc
index 947499b..e268107f 100644
--- a/src/tint/resolver/resolver.cc
+++ b/src/tint/resolver/resolver.cc
@@ -350,7 +350,7 @@
return nullptr;
},
[&](sem::Function* func) {
- auto name = builder_->Symbols().NameFor(func->Declaration()->symbol);
+ auto name = builder_->Symbols().NameFor(func->Declaration()->name->symbol);
AddError("cannot use function '" + name + "' as type", ty->source);
AddNote("'" + name + "' declared here", func->Declaration()->source);
return nullptr;
@@ -993,6 +993,8 @@
}
sem::Function* Resolver::Function(const ast::Function* decl) {
+ Mark(decl->name);
+
uint32_t parameter_index = 0;
utils::Hashmap<Symbol, Source, 8> parameter_names;
utils::Vector<sem::Parameter*, 8> parameters;
@@ -1080,9 +1082,9 @@
if (auto* str = return_type->As<sem::Struct>()) {
if (!ApplyAddressSpaceUsageToType(type::AddressSpace::kNone, str, decl->source)) {
- AddNote(
- "while instantiating return type for " + builder_->Symbols().NameFor(decl->symbol),
- decl->source);
+ AddNote("while instantiating return type for " +
+ builder_->Symbols().NameFor(decl->name->symbol),
+ decl->source);
return nullptr;
}
@@ -1669,7 +1671,7 @@
break;
case Alias::ModuleScope: {
auto* func = var.expr->Stmt()->Function();
- auto func_name = builder_->Symbols().NameFor(func->Declaration()->symbol);
+ auto func_name = builder_->Symbols().NameFor(func->Declaration()->name->symbol);
AddNote(
"aliases with module-scope variable " + var.access + " in '" + func_name + "'",
var.expr->Declaration()->source);
diff --git a/src/tint/resolver/resolver_test.cc b/src/tint/resolver/resolver_test.cc
index 21425da..1433a6e 100644
--- a/src/tint/resolver/resolver_test.cc
+++ b/src/tint/resolver/resolver_test.cc
@@ -2000,17 +2000,17 @@
const auto& b_eps = func_b_sem->AncestorEntryPoints();
ASSERT_EQ(2u, b_eps.size());
- EXPECT_EQ(Symbols().Register("ep_1"), b_eps[0]->Declaration()->symbol);
- EXPECT_EQ(Symbols().Register("ep_2"), b_eps[1]->Declaration()->symbol);
+ EXPECT_EQ(Symbols().Register("ep_1"), b_eps[0]->Declaration()->name->symbol);
+ EXPECT_EQ(Symbols().Register("ep_2"), b_eps[1]->Declaration()->name->symbol);
const auto& a_eps = func_a_sem->AncestorEntryPoints();
ASSERT_EQ(1u, a_eps.size());
- EXPECT_EQ(Symbols().Register("ep_1"), a_eps[0]->Declaration()->symbol);
+ EXPECT_EQ(Symbols().Register("ep_1"), a_eps[0]->Declaration()->name->symbol);
const auto& c_eps = func_c_sem->AncestorEntryPoints();
ASSERT_EQ(2u, c_eps.size());
- EXPECT_EQ(Symbols().Register("ep_1"), c_eps[0]->Declaration()->symbol);
- EXPECT_EQ(Symbols().Register("ep_2"), c_eps[1]->Declaration()->symbol);
+ EXPECT_EQ(Symbols().Register("ep_1"), c_eps[0]->Declaration()->name->symbol);
+ EXPECT_EQ(Symbols().Register("ep_2"), c_eps[1]->Declaration()->name->symbol);
EXPECT_TRUE(ep_1_sem->AncestorEntryPoints().empty());
EXPECT_TRUE(ep_2_sem->AncestorEntryPoints().empty());
diff --git a/src/tint/resolver/uniformity.cc b/src/tint/resolver/uniformity.cc
index 8fa6d64..bae85a4 100644
--- a/src/tint/resolver/uniformity.cc
+++ b/src/tint/resolver/uniformity.cc
@@ -171,7 +171,7 @@
/// @param func the AST function
/// @param builder the program builder
FunctionInfo(const ast::Function* func, const ProgramBuilder* builder) {
- name = builder->Symbols().NameFor(func->symbol);
+ name = builder->Symbols().NameFor(func->name->symbol);
callsite_tag = {CallSiteTag::CallSiteNoRestriction};
function_tag = NoRestriction;
@@ -1769,7 +1769,7 @@
if (auto* param = var->As<sem::Parameter>()) {
auto* func = param->Owner()->As<sem::Function>();
ss << param_type(param) << "'" << NameFor(ident->identifier) << "' of '"
- << NameFor(func->Declaration()) << "' may be non-uniform";
+ << NameFor(func->Declaration()->name) << "' may be non-uniform";
} else {
ss << "reading from " << var_type(var) << "'" << NameFor(ident->identifier)
<< "' may result in a non-uniform value";
diff --git a/src/tint/resolver/validator.cc b/src/tint/resolver/validator.cc
index 02b8f39..29218af 100644
--- a/src/tint/resolver/validator.cc
+++ b/src/tint/resolver/validator.cc
@@ -1037,7 +1037,7 @@
} else if (TINT_UNLIKELY(IsValidationEnabled(
decl->attributes, ast::DisabledValidation::kFunctionHasNoBody))) {
TINT_ICE(Resolver, diagnostics_)
- << "Function " << symbols_.NameFor(decl->symbol) << " has no body";
+ << "Function " << symbols_.NameFor(decl->name->symbol) << " has no body";
}
for (auto* attr : decl->return_type_attributes) {
@@ -1069,7 +1069,7 @@
// a function behavior is always one of {}, or {Next}.
if (TINT_UNLIKELY(func->Behaviors() != sem::Behaviors{} &&
func->Behaviors() != sem::Behavior::kNext)) {
- auto name = symbols_.NameFor(decl->symbol);
+ auto name = symbols_.NameFor(decl->name->symbol);
TINT_ICE(Resolver, diagnostics_)
<< "function '" << name << "' behaviors are: " << func->Behaviors();
}
@@ -1236,30 +1236,30 @@
};
// Outer lambda for validating the entry point attributes for a type.
- auto validate_entry_point_attributes = [&](utils::VectorRef<const ast::Attribute*> attrs,
- const type::Type* ty, Source source,
- ParamOrRetType param_or_ret,
- std::optional<uint32_t> location) {
- if (!validate_entry_point_attributes_inner(attrs, ty, source, param_or_ret,
- /*is_struct_member*/ false, location)) {
- return false;
- }
+ auto validate_entry_point_attributes =
+ [&](utils::VectorRef<const ast::Attribute*> attrs, const type::Type* ty, Source source,
+ ParamOrRetType param_or_ret, std::optional<uint32_t> location) {
+ if (!validate_entry_point_attributes_inner(attrs, ty, source, param_or_ret,
+ /*is_struct_member*/ false, location)) {
+ return false;
+ }
- if (auto* str = ty->As<sem::Struct>()) {
- for (auto* member : str->Members()) {
- if (!validate_entry_point_attributes_inner(
- member->Declaration()->attributes, member->Type(), member->Source(),
- param_or_ret,
- /*is_struct_member*/ true, member->Location())) {
- AddNote("while analyzing entry point '" + symbols_.NameFor(decl->symbol) + "'",
- decl->source);
- return false;
+ if (auto* str = ty->As<sem::Struct>()) {
+ for (auto* member : str->Members()) {
+ if (!validate_entry_point_attributes_inner(
+ member->Declaration()->attributes, member->Type(), member->Source(),
+ param_or_ret,
+ /*is_struct_member*/ true, member->Location())) {
+ AddNote("while analyzing entry point '" +
+ symbols_.NameFor(decl->name->symbol) + "'",
+ decl->source);
+ return false;
+ }
}
}
- }
- return true;
- };
+ return true;
+ };
for (auto* param : func->Parameters()) {
auto* param_decl = param->Declaration();
@@ -1329,7 +1329,7 @@
// Bindings must not alias within a shader stage: two different variables in the
// resource interface of a given shader must not have the same group and binding values,
// when considered as a pair of values.
- auto func_name = symbols_.NameFor(decl->symbol);
+ auto func_name = symbols_.NameFor(decl->name->symbol);
AddError(
"entry point '" + func_name +
"' references multiple variables that use the same resource binding @group(" +
@@ -1875,11 +1875,12 @@
auto backtrace = [&](const sem::Function* func, const sem::Function* entry_point) {
if (func != entry_point) {
TraverseCallChain(diagnostics_, entry_point, func, [&](const sem::Function* f) {
- AddNote("called by function '" + symbols_.NameFor(f->Declaration()->symbol) + "'",
- f->Declaration()->source);
+ AddNote(
+ "called by function '" + symbols_.NameFor(f->Declaration()->name->symbol) + "'",
+ f->Declaration()->source);
});
AddNote("called by entry point '" +
- symbols_.NameFor(entry_point->Declaration()->symbol) + "'",
+ symbols_.NameFor(entry_point->Declaration()->name->symbol) + "'",
entry_point->Declaration()->source);
}
};
@@ -1986,7 +1987,7 @@
continue;
}
- AddError("entry point '" + symbols_.NameFor(ep->Declaration()->symbol) +
+ AddError("entry point '" + symbols_.NameFor(ep->Declaration()->name->symbol) +
"' uses two different 'push_constant' variables.",
ep->Declaration()->source);
AddNote("first 'push_constant' variable declaration is here",
@@ -1994,11 +1995,11 @@
if (func != ep) {
TraverseCallChain(diagnostics_, ep, func, [&](const sem::Function* f) {
AddNote("called by function '" +
- symbols_.NameFor(f->Declaration()->symbol) + "'",
+ symbols_.NameFor(f->Declaration()->name->symbol) + "'",
f->Declaration()->source);
});
AddNote("called by entry point '" +
- symbols_.NameFor(ep->Declaration()->symbol) + "'",
+ symbols_.NameFor(ep->Declaration()->name->symbol) + "'",
ep->Declaration()->source);
}
AddNote("second 'push_constant' variable declaration is here",
@@ -2007,11 +2008,11 @@
TraverseCallChain(
diagnostics_, ep, push_constant_func, [&](const sem::Function* f) {
AddNote("called by function '" +
- symbols_.NameFor(f->Declaration()->symbol) + "'",
+ symbols_.NameFor(f->Declaration()->name->symbol) + "'",
f->Declaration()->source);
});
AddNote("called by entry point '" +
- symbols_.NameFor(ep->Declaration()->symbol) + "'",
+ symbols_.NameFor(ep->Declaration()->name->symbol) + "'",
ep->Declaration()->source);
}
return false;