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>
This commit is contained in:
Ben Clayton
2023-02-09 10:34:14 +00:00
parent 057a733758
commit ce31d187ef
32 changed files with 157 additions and 120 deletions

View File

@@ -107,7 +107,7 @@ Transform::ApplyResult CalculateArrayLength::Apply(const Program* src,
auto* type = CreateASTTypeFor(ctx, buffer_type);
auto* disable_validation = b.Disable(ast::DisabledValidation::kFunctionParameter);
b.AST().AddFunction(b.create<ast::Function>(
name,
b.Ident(name),
utils::Vector{
b.Param("buffer",
b.ty.pointer(type, buffer_type->AddressSpace(), buffer_type->Access()),

View File

@@ -542,24 +542,25 @@ struct CanonicalizeEntryPointIO::State {
if (cfg.shader_style == ShaderStyle::kGlsl) {
// In GLSL, clone the original entry point name, as the wrapper will be
// called "main".
inner_name = ctx.Clone(func_ast->symbol);
inner_name = ctx.Clone(func_ast->name->symbol);
} else {
// Add a suffix to the function name, as the wrapper function will take
// the original entry point name.
auto ep_name = ctx.src->Symbols().NameFor(func_ast->symbol);
auto ep_name = ctx.src->Symbols().NameFor(func_ast->name->symbol);
inner_name = ctx.dst->Symbols().New(ep_name + "_inner");
}
// Clone everything, dropping the function and return type attributes.
// The parameter attributes will have already been stripped during
// processing.
auto* inner_function = ctx.dst->create<ast::Function>(
inner_name, ctx.Clone(func_ast->params), ctx.Clone(func_ast->return_type),
ctx.Clone(func_ast->body), utils::Empty, utils::Empty);
auto* inner_function =
ctx.dst->create<ast::Function>(ctx.dst->Ident(inner_name), ctx.Clone(func_ast->params),
ctx.Clone(func_ast->return_type),
ctx.Clone(func_ast->body), utils::Empty, utils::Empty);
ctx.Replace(func_ast, inner_function);
// Call the function.
return ctx.dst->Call(inner_function->symbol, inner_call_parameters);
return ctx.dst->Call(inner_function->name->symbol, inner_call_parameters);
}
/// Process the entry point function.
@@ -656,12 +657,12 @@ struct CanonicalizeEntryPointIO::State {
if (cfg.shader_style == ShaderStyle::kGlsl) {
name = ctx.dst->Symbols().New("main");
} else {
name = ctx.Clone(func_ast->symbol);
name = ctx.Clone(func_ast->name->symbol);
}
auto* wrapper_func = ctx.dst->create<ast::Function>(
name, wrapper_ep_parameters, wrapper_ret_type(), ctx.dst->Block(wrapper_body),
ctx.Clone(func_ast->attributes), utils::Empty);
ctx.dst->Ident(name), wrapper_ep_parameters, wrapper_ret_type(),
ctx.dst->Block(wrapper_body), ctx.Clone(func_ast->attributes), utils::Empty);
ctx.InsertAfter(ctx.src->AST().GlobalDeclarations(), func_ast, wrapper_func);
}

View File

@@ -214,12 +214,12 @@ struct CombineSamplers::State {
}
// Create a new function signature that differs only in the parameter
// list.
auto symbol = ctx.Clone(ast_fn->symbol);
auto name = ctx.Clone(ast_fn->name);
auto* return_type = ctx.Clone(ast_fn->return_type);
auto* body = ctx.Clone(ast_fn->body);
auto attributes = ctx.Clone(ast_fn->attributes);
auto return_type_attributes = ctx.Clone(ast_fn->return_type_attributes);
return ctx.dst->create<ast::Function>(symbol, params, return_type, body,
return ctx.dst->create<ast::Function>(name, params, return_type, body,
std::move(attributes),
std::move(return_type_attributes));
}

View File

@@ -483,7 +483,7 @@ struct DecomposeMemoryAccess::State {
if (auto* intrinsic = IntrinsicLoadFor(ctx.dst, address_space, el_ty)) {
auto* el_ast_ty = CreateASTTypeFor(ctx, el_ty);
auto* func = b.create<ast::Function>(
name, params, el_ast_ty, nullptr,
b.Ident(name), params, el_ast_ty, nullptr,
utils::Vector{
intrinsic,
b.Disable(ast::DisabledValidation::kFunctionHasNoBody),
@@ -582,7 +582,7 @@ struct DecomposeMemoryAccess::State {
if (auto* intrinsic = IntrinsicStoreFor(ctx.dst, address_space, el_ty)) {
auto* func = b.create<ast::Function>(
name, params, b.ty.void_(), nullptr,
b.Ident(name), params, b.ty.void_(), nullptr,
utils::Vector{
intrinsic,
b.Disable(ast::DisabledValidation::kFunctionHasNoBody),
@@ -728,7 +728,8 @@ struct DecomposeMemoryAccess::State {
}
auto* func = b.create<ast::Function>(
b.Symbols().New(std::string{"tint_"} + intrinsic->str()), params, ret_ty, nullptr,
b.Ident(b.Symbols().New(std::string{"tint_"} + intrinsic->str())), params, ret_ty,
nullptr,
utils::Vector{
atomic,
b.Disable(ast::DisabledValidation::kFunctionHasNoBody),
@@ -736,7 +737,7 @@ struct DecomposeMemoryAccess::State {
utils::Empty);
b.AST().AddFunction(func);
return func->symbol;
return func->name->symbol;
});
}
};

View File

@@ -600,7 +600,7 @@ struct DirectVariableAccess::State {
// Function was not called. Create a single variant with an empty signature.
FnVariant variant;
variant.name = ctx.Clone(fn->Declaration()->symbol);
variant.name = ctx.Clone(fn->Declaration()->name->symbol);
variant.order = 0; // Unaltered comes first.
fn_info->variants.Add(FnVariant::Signature{}, std::move(variant));
}
@@ -679,7 +679,7 @@ struct DirectVariableAccess::State {
if (target_signature.IsEmpty()) {
// Call target does not require any argument changes.
FnVariant variant;
variant.name = ctx.Clone(target->Declaration()->symbol);
variant.name = ctx.Clone(target->Declaration()->name->symbol);
variant.order = 0; // Unaltered comes first.
return variant;
}
@@ -688,7 +688,7 @@ struct DirectVariableAccess::State {
// This is derived from the original function name and the pointer parameter
// chains.
std::stringstream ss;
ss << ctx.src->Symbols().NameFor(target->Declaration()->symbol);
ss << ctx.src->Symbols().NameFor(target->Declaration()->name->symbol);
for (auto* param : target->Parameters()) {
if (auto indices = target_signature.Find(param)) {
ss << "_" << AccessShapeName(*indices);
@@ -855,7 +855,7 @@ struct DirectVariableAccess::State {
auto attrs = ctx.Clone(fn->Declaration()->attributes);
auto ret_attrs = ctx.Clone(fn->Declaration()->return_type_attributes);
pending_variant =
b.create<ast::Function>(variant.name, std::move(params), ret_ty, body,
b.create<ast::Function>(b.Ident(variant.name), std::move(params), ret_ty, body,
std::move(attrs), std::move(ret_attrs));
}

View File

@@ -49,7 +49,7 @@ Transform::ApplyResult SingleEntryPoint::Apply(const Program* src,
if (!f->IsEntryPoint()) {
continue;
}
if (src->Symbols().NameFor(f->symbol) == cfg->entry_point_name) {
if (src->Symbols().NameFor(f->name->symbol) == cfg->entry_point_name) {
entry_point = f;
break;
}
@@ -109,7 +109,7 @@ Transform::ApplyResult SingleEntryPoint::Apply(const Program* src,
b.AST().AddGlobalVariable(ctx.Clone(c));
},
[&](const ast::Function* func) {
if (sem.Get(func)->HasAncestorEntryPoint(entry_point->symbol)) {
if (sem.Get(func)->HasAncestorEntryPoint(entry_point->name->symbol)) {
b.AST().AddFunction(ctx.Clone(func));
}
},

View File

@@ -921,14 +921,14 @@ struct VertexPulling::State {
}
// Rewrite the function header with the new parameters.
auto func_sym = ctx.Clone(func->symbol);
auto func_sym = ctx.Clone(func->name->symbol);
auto* ret_type = ctx.Clone(func->return_type);
auto* body = ctx.Clone(func->body);
auto attrs = ctx.Clone(func->attributes);
auto ret_attrs = ctx.Clone(func->return_type_attributes);
auto* new_func =
b.create<ast::Function>(func->source, func_sym, new_function_parameters, ret_type, body,
std::move(attrs), std::move(ret_attrs));
b.create<ast::Function>(func->source, b.Ident(func_sym), new_function_parameters,
ret_type, body, std::move(attrs), std::move(ret_attrs));
ctx.Replace(func, new_func);
}
};