tint/ast: Change TypeDecl::name to 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: I8b3e05d05886c6caa16513a5cfb45d30f7a8d720
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/119283
Reviewed-by: Dan Sinclair <dsinclair@chromium.org>
Kokoro: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton
2023-02-09 10:34:14 +00:00
parent 651d9e2558
commit b75252b7aa
31 changed files with 147 additions and 119 deletions

View File

@@ -72,7 +72,7 @@ Transform::ApplyResult AddBlockAttribute::Apply(const Program* src,
auto* block = b.ASTNodes().Create<BlockAttribute>(b.ID(), b.AllocateNodeID());
auto wrapper_name = src->Symbols().NameFor(global->name->symbol) + "_block";
auto* ret = b.create<ast::Struct>(
b.Symbols().New(wrapper_name),
b.Ident(b.Symbols().New(wrapper_name)),
utils::Vector{b.Member(kMemberName, CreateASTTypeFor(ctx, ty))},
utils::Vector{block});
ctx.InsertBefore(src->AST().GlobalDeclarations(), global, ret);

View File

@@ -455,7 +455,8 @@ struct CanonicalizeEntryPointIO::State {
// Create the new struct type.
auto struct_name = ctx.dst->Sym();
auto* in_struct = ctx.dst->create<ast::Struct>(struct_name, members, utils::Empty);
auto* in_struct = ctx.dst->create<ast::Struct>(ctx.dst->Ident(struct_name),
std::move(members), utils::Empty);
ctx.InsertBefore(ctx.src->AST().GlobalDeclarations(), func_ast, in_struct);
// Create a new function parameter using this struct type.
@@ -499,11 +500,12 @@ struct CanonicalizeEntryPointIO::State {
}
// Create the new struct type.
auto* out_struct = ctx.dst->create<ast::Struct>(ctx.dst->Sym(), members, utils::Empty);
auto* out_struct = ctx.dst->create<ast::Struct>(ctx.dst->Ident(ctx.dst->Sym()),
std::move(members), utils::Empty);
ctx.InsertBefore(ctx.src->AST().GlobalDeclarations(), func_ast, out_struct);
// Create the output struct object, assign its members, and return it.
auto* result_object = ctx.dst->Var(wrapper_result, ctx.dst->ty(out_struct->name));
auto* result_object = ctx.dst->Var(wrapper_result, ctx.dst->ty(out_struct->name->symbol));
wrapper_body.Push(ctx.dst->Decl(result_object));
for (auto* assignment : assignments) {
wrapper_body.Push(assignment);
@@ -634,7 +636,9 @@ struct CanonicalizeEntryPointIO::State {
CreateGlobalOutputVariables();
} else {
auto* output_struct = CreateOutputStruct();
wrapper_ret_type = [&, output_struct] { return ctx.dst->ty(output_struct->name); };
wrapper_ret_type = [&, output_struct] {
return ctx.dst->ty(output_struct->name->symbol);
};
}
}

View File

@@ -1270,7 +1270,7 @@ Transform::ApplyResult Renamer::Apply(const Program* src,
// Identifier *looks* like a builtin type, but check that the builtin type isn't being
// shadowed with a user declared type.
for (auto* decl : src->AST().TypeDecls()) {
if (decl->name == symbol) {
if (decl->name->symbol == symbol) {
return false;
}
}

View File

@@ -156,7 +156,8 @@ struct SpirvAtomic::State {
ForkedStruct& Fork(const ast::Struct* str) {
auto& forked = forked_structs[str];
if (!forked.name.IsValid()) {
forked.name = b.Symbols().New(ctx.src->Symbols().NameFor(str->name) + "_atomic");
forked.name =
b.Symbols().New(ctx.src->Symbols().NameFor(str->name->symbol) + "_atomic");
}
return forked;
}

View File

@@ -335,7 +335,7 @@ struct Std140::State {
// Create a new forked structure, and insert it just under the original
// structure.
auto name = b.Symbols().New(sym.NameFor(str->Name()) + "_std140");
auto* std140 = b.create<ast::Struct>(name, std::move(members),
auto* std140 = b.create<ast::Struct>(b.Ident(name), std::move(members),
ctx.Clone(str->Declaration()->attributes));
ctx.InsertAfter(src->AST().GlobalDeclarations(), global, std140);
std140_structs.Add(str, name);

View File

@@ -122,7 +122,7 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type
if (auto* alias = type_decl->As<ast::Alias>()) {
if (ty == ctx.src->Sem().Get(alias)) {
// Alias found. Use the alias name to ensure types compare equal.
return ctx.dst->ty(ctx.Clone(alias->name));
return ctx.dst->ty(ctx.Clone(alias->name->symbol));
}
}
}
@@ -138,7 +138,7 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type
return ctx.dst->ty.array(el, u32(count.value()), std::move(attrs));
}
if (auto* s = ty->As<sem::Struct>()) {
return ctx.dst->ty(ctx.Clone(s->Declaration()->name));
return ctx.dst->ty(ctx.Clone(s->Declaration()->name->symbol));
}
if (auto* s = ty->As<type::Reference>()) {
return CreateASTTypeFor(ctx, s->StoreType());

View File

@@ -122,8 +122,8 @@ TEST_F(CreateASTTypeForTest, AliasedArrayWithComplexOverrideLength) {
TEST_F(CreateASTTypeForTest, Struct) {
auto* str = create([](ProgramBuilder& b) {
auto* decl = b.Structure("S", {});
return b.create<sem::Struct>(decl, decl->source, decl->name, utils::Empty, 4u /* align */,
4u /* size */, 4u /* size_no_padding */);
return b.create<sem::Struct>(decl, decl->source, decl->name->symbol, utils::Empty,
4u /* align */, 4u /* size */, 4u /* size_no_padding */);
});
ASSERT_TRUE(str->Is<ast::TypeName>());
EXPECT_EQ(ast_type_builder.Symbols().NameFor(str->As<ast::TypeName>()->name->symbol), "S");