tint: Add ast::ParameterList, use it

This is currently identical to ast::VariableList, but once we break
ast::Variable up, this will become a different vector type.

Bug: tint:1580
Change-Id: Ib2db5772996a63cd1989e36f1034dc1fbd3b371a
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/93601
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
Ben Clayton 2022-06-15 10:14:27 +00:00 committed by Dawn LUCI CQ
parent 7164b97272
commit 2ae29830db
19 changed files with 42 additions and 37 deletions

View File

@ -25,7 +25,7 @@ namespace tint::ast {
Function::Function(ProgramID pid, Function::Function(ProgramID pid,
const Source& src, const Source& src,
Symbol sym, Symbol sym,
VariableList parameters, ParameterList parameters,
const Type* return_ty, const Type* return_ty,
const BlockStatement* b, const BlockStatement* b,
AttributeList attrs, AttributeList attrs,

View File

@ -31,6 +31,9 @@
namespace tint::ast { namespace tint::ast {
/// ParameterList is a list of function parameters
using ParameterList = std::vector<const Variable*>;
/// A Function statement. /// A Function statement.
class Function final : public Castable<Function, Node> { class Function final : public Castable<Function, Node> {
public: public:
@ -46,7 +49,7 @@ class Function final : public Castable<Function, Node> {
Function(ProgramID program_id, Function(ProgramID program_id,
const Source& source, const Source& source,
Symbol symbol, Symbol symbol,
VariableList params, ParameterList params,
const Type* return_type, const Type* return_type,
const BlockStatement* body, const BlockStatement* body,
AttributeList attributes, AttributeList attributes,
@ -72,7 +75,7 @@ class Function final : public Castable<Function, Node> {
const Symbol symbol; const Symbol symbol;
/// The function params /// The function params
const VariableList params; const ParameterList params;
/// The function return type /// The function return type
const Type* const return_type; const Type* const return_type;

View File

@ -26,7 +26,7 @@ namespace {
using FunctionTest = TestHelper; using FunctionTest = TestHelper;
TEST_F(FunctionTest, Creation) { TEST_F(FunctionTest, Creation) {
VariableList params{Param("var", ty.i32())}; ParameterList params{Param("var", ty.i32())};
auto* var = params[0]; auto* var = params[0];
auto* f = Func("func", params, ty.void_(), {}); auto* f = Func("func", params, ty.void_(), {});
@ -37,7 +37,7 @@ TEST_F(FunctionTest, Creation) {
} }
TEST_F(FunctionTest, Creation_WithSource) { TEST_F(FunctionTest, Creation_WithSource) {
VariableList params{Param("var", ty.i32())}; ParameterList params{Param("var", ty.i32())};
auto* f = Func(Source{Source::Location{20, 2}}, "func", params, ty.void_(), {}); auto* f = Func(Source{Source::Location{20, 2}}, "func", params, ty.void_(), {});
auto src = f->source; auto src = f->source;
@ -67,7 +67,7 @@ TEST_F(FunctionTest, Assert_Null_Param) {
EXPECT_FATAL_FAILURE( EXPECT_FATAL_FAILURE(
{ {
ProgramBuilder b; ProgramBuilder b;
VariableList params; ParameterList params;
params.push_back(b.Param("var", b.ty.i32())); params.push_back(b.Param("var", b.ty.i32()));
params.push_back(nullptr); params.push_back(nullptr);
@ -126,7 +126,7 @@ TEST_F(FunctionTest, Assert_NonConstParam) {
EXPECT_FATAL_FAILURE( EXPECT_FATAL_FAILURE(
{ {
ProgramBuilder b; ProgramBuilder b;
VariableList params; ParameterList params;
params.push_back(b.Var("var", b.ty.i32(), ast::StorageClass::kNone)); params.push_back(b.Var("var", b.ty.i32(), ast::StorageClass::kNone));
b.Func("f", params, b.ty.void_(), {}); b.Func("f", params, b.ty.void_(), {});

View File

@ -61,7 +61,7 @@ TEST_F(ModuleTest, Assert_DifferentProgramID_Function) {
ProgramBuilder b1; ProgramBuilder b1;
ProgramBuilder b2; ProgramBuilder b2;
b1.AST().AddFunction(b2.create<ast::Function>(b2.Symbols().Register("func"), b1.AST().AddFunction(b2.create<ast::Function>(b2.Symbols().Register("func"),
VariableList{}, b2.ty.f32(), b2.Block(), ParameterList{}, b2.ty.f32(), b2.Block(),
AttributeList{}, AttributeList{})); AttributeList{}, AttributeList{}));
}, },
"internal compiler error"); "internal compiler error");

View File

@ -1941,7 +1941,7 @@ class ProgramBuilder {
template <typename NAME> template <typename NAME>
const ast::Function* Func(const Source& source, const ast::Function* Func(const Source& source,
NAME&& name, NAME&& name,
ast::VariableList params, ast::ParameterList params,
const ast::Type* type, const ast::Type* type,
ast::StatementList body, ast::StatementList body,
ast::AttributeList attributes = {}, ast::AttributeList attributes = {},
@ -1964,7 +1964,7 @@ class ProgramBuilder {
/// @returns the function pointer /// @returns the function pointer
template <typename NAME> template <typename NAME>
const ast::Function* Func(NAME&& name, const ast::Function* Func(NAME&& name,
ast::VariableList params, ast::ParameterList params,
const ast::Type* type, const ast::Type* type,
ast::StatementList body, ast::StatementList body,
ast::AttributeList attributes = {}, ast::AttributeList attributes = {},

View File

@ -949,7 +949,7 @@ bool FunctionEmitter::EmitPipelineInput(std::string var_name,
std::vector<int> index_prefix, std::vector<int> index_prefix,
const Type* tip_type, const Type* tip_type,
const Type* forced_param_type, const Type* forced_param_type,
ast::VariableList* params, ast::ParameterList* params,
ast::StatementList* statements) { ast::StatementList* statements) {
// TODO(dneto): Handle structs where the locations are annotated on members. // TODO(dneto): Handle structs where the locations are annotated on members.
tip_type = tip_type->UnwrapAlias(); tip_type = tip_type->UnwrapAlias();
@ -1399,7 +1399,7 @@ bool FunctionEmitter::ParseFunctionDeclaration(FunctionDeclaration* decl) {
<< function_.result_id(); << function_.result_id();
} }
ast::VariableList ast_params; ast::ParameterList ast_params;
function_.ForEachParam([this, &ast_params](const spvtools::opt::Instruction* param) { function_.ForEachParam([this, &ast_params](const spvtools::opt::Instruction* param) {
auto* type = parser_impl_.ConvertType(param->type_id()); auto* type = parser_impl_.ConvertType(param->type_id());
if (type != nullptr) { if (type != nullptr) {

View File

@ -459,7 +459,7 @@ class FunctionEmitter {
std::vector<int> index_prefix, std::vector<int> index_prefix,
const Type* tip_type, const Type* tip_type,
const Type* forced_param_type, const Type* forced_param_type,
ast::VariableList* params, ast::ParameterList* params,
ast::StatementList* statements); ast::StatementList* statements);
/// Creates one or more struct members from an output variable, and the /// Creates one or more struct members from an output variable, and the
@ -951,7 +951,7 @@ class FunctionEmitter {
/// Function name /// Function name
std::string name; std::string name;
/// Function parameters /// Function parameters
ast::VariableList params; ast::ParameterList params;
/// Function return type /// Function return type
const Type* return_type; const Type* return_type;
/// Function attributes /// Function attributes

View File

@ -210,7 +210,7 @@ ParserImpl::FunctionHeader::FunctionHeader(const FunctionHeader&) = default;
ParserImpl::FunctionHeader::FunctionHeader(Source src, ParserImpl::FunctionHeader::FunctionHeader(Source src,
std::string n, std::string n,
ast::VariableList p, ast::ParameterList p,
const ast::Type* ret_ty, const ast::Type* ret_ty,
ast::AttributeList ret_attrs) ast::AttributeList ret_attrs)
: source(src), name(n), params(p), return_type(ret_ty), return_type_attributes(ret_attrs) {} : source(src), name(n), params(p), return_type(ret_ty), return_type_attributes(ret_attrs) {}
@ -1443,8 +1443,8 @@ Maybe<ParserImpl::FunctionHeader> ParserImpl::function_header() {
// param_list // param_list
// : // :
// | (param COMMA)* param COMMA? // | (param COMMA)* param COMMA?
Expect<ast::VariableList> ParserImpl::expect_param_list() { Expect<ast::ParameterList> ParserImpl::expect_param_list() {
ast::VariableList ret; ast::ParameterList ret;
while (continue_parsing()) { while (continue_parsing()) {
// Check for the end of the list. // Check for the end of the list.
auto t = peek(); auto t = peek();

View File

@ -232,7 +232,7 @@ class ParserImpl {
/// @param ret_attrs return type attributes /// @param ret_attrs return type attributes
FunctionHeader(Source src, FunctionHeader(Source src,
std::string n, std::string n,
ast::VariableList p, ast::ParameterList p,
const ast::Type* ret_ty, const ast::Type* ret_ty,
ast::AttributeList ret_attrs); ast::AttributeList ret_attrs);
/// Destructor /// Destructor
@ -247,7 +247,7 @@ class ParserImpl {
/// Function name /// Function name
std::string name; std::string name;
/// Function parameters /// Function parameters
ast::VariableList params; ast::ParameterList params;
/// Function return type /// Function return type
const ast::Type* return_type = nullptr; const ast::Type* return_type = nullptr;
/// Function return type attributes /// Function return type attributes
@ -459,7 +459,7 @@ class ParserImpl {
Maybe<FunctionHeader> function_header(); Maybe<FunctionHeader> function_header();
/// Parses a `param_list` grammar element, erroring on parse failure. /// Parses a `param_list` grammar element, erroring on parse failure.
/// @returns the parsed variables /// @returns the parsed variables
Expect<ast::VariableList> expect_param_list(); Expect<ast::ParameterList> expect_param_list();
/// Parses a `param` grammar element, erroring on parse failure. /// Parses a `param` grammar element, erroring on parse failure.
/// @returns the parsed variable /// @returns the parsed variable
Expect<ast::Variable*> expect_param(); Expect<ast::Variable*> expect_param();

View File

@ -81,7 +81,7 @@ static constexpr Params all_param_types[] = {
}; };
TEST_F(ResolverCallTest, Valid) { TEST_F(ResolverCallTest, Valid) {
ast::VariableList params; ast::ParameterList params;
ast::ExpressionList args; ast::ExpressionList args;
for (auto& p : all_param_types) { for (auto& p : all_param_types) {
params.push_back(Param(Sym(), p.create_type(*this))); params.push_back(Param(Sym(), p.create_type(*this)));

View File

@ -384,11 +384,11 @@ struct SymbolTestHelper {
/// The program builder /// The program builder
ProgramBuilder* const builder; ProgramBuilder* const builder;
/// Parameters to a function that may need to be built /// Parameters to a function that may need to be built
std::vector<const ast::Variable*> parameters; ast::ParameterList parameters;
/// Shallow function var / let declaration statements /// Shallow function var / let declaration statements
std::vector<const ast::Statement*> statements; ast::StatementList statements;
/// Nested function local var / let declaration statements /// Nested function local var / let declaration statements
std::vector<const ast::Statement*> nested_statements; ast::StatementList nested_statements;
/// Function attributes /// Function attributes
ast::AttributeList func_attrs; ast::AttributeList func_attrs;
@ -717,8 +717,10 @@ TEST_F(ResolverDependencyGraphUsedBeforeDeclTest, VarUsed) {
// } // }
// var G: f32 = 2.1; // var G: f32 = 2.1;
Func("F", ast::VariableList{}, ty.void_(), Func("F", {}, ty.void_(),
{Block(Assign(Expr(Source{{12, 34}}, "G"), 3.14_f))}); {
Block(Assign(Expr(Source{{12, 34}}, "G"), 3.14_f)),
});
Global(Source{{56, 78}}, "G", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1_f)); Global(Source{{56, 78}}, "G", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1_f));

View File

@ -733,7 +733,7 @@ TEST_F(ResolverFunctionValidationTest, ParameterSotreType_AtomicFree) {
} }
TEST_F(ResolverFunctionValidationTest, ParametersAtLimit) { TEST_F(ResolverFunctionValidationTest, ParametersAtLimit) {
ast::VariableList params; ast::ParameterList params;
for (int i = 0; i < 255; i++) { for (int i = 0; i < 255; i++) {
params.emplace_back(Param("param_" + std::to_string(i), ty.i32())); params.emplace_back(Param("param_" + std::to_string(i), ty.i32()));
} }
@ -743,7 +743,7 @@ TEST_F(ResolverFunctionValidationTest, ParametersAtLimit) {
} }
TEST_F(ResolverFunctionValidationTest, ParametersOverLimit) { TEST_F(ResolverFunctionValidationTest, ParametersOverLimit) {
ast::VariableList params; ast::ParameterList params;
for (int i = 0; i < 256; i++) { for (int i = 0; i < 256; i++) {
params.emplace_back(Param("param_" + std::to_string(i), ty.i32())); params.emplace_back(Param("param_" + std::to_string(i), ty.i32()));
} }

View File

@ -5001,7 +5001,7 @@ TEST_F(UniformityAnalysisTest, MaximumNumberOfPointerParameters) {
// ... // ...
// *p254 = rhs; // *p254 = rhs;
// } // }
ast::VariableList params; ast::ParameterList params;
ast::StatementList foo_body; ast::StatementList foo_body;
const ast::Expression* rhs_init = b.Deref("p0"); const ast::Expression* rhs_init = b.Deref("p0");
for (int i = 1; i < 255; i++) { for (int i = 1; i < 255; i++) {

View File

@ -98,7 +98,7 @@ void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) cons
ctx.dst->Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter); ctx.dst->Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
ctx.dst->AST().AddFunction(ctx.dst->create<ast::Function>( ctx.dst->AST().AddFunction(ctx.dst->create<ast::Function>(
name, name,
ast::VariableList{ ast::ParameterList{
// Note: The buffer parameter requires the kStorage StorageClass // Note: The buffer parameter requires the kStorage StorageClass
// in order for HLSL to emit this as a ByteAddressBuffer. // in order for HLSL to emit this as a ByteAddressBuffer.
ctx.dst->create<ast::Variable>(ctx.dst->Sym("buffer"), ctx.dst->create<ast::Variable>(ctx.dst->Sym("buffer"),

View File

@ -100,7 +100,7 @@ struct CanonicalizeEntryPointIO::State {
const sem::Function* func_sem; const sem::Function* func_sem;
/// The new entry point wrapper function's parameters. /// The new entry point wrapper function's parameters.
ast::VariableList wrapper_ep_parameters; ast::ParameterList wrapper_ep_parameters;
/// The members of the wrapper function's struct parameter. /// The members of the wrapper function's struct parameter.
ast::StructMemberList wrapper_struct_param_members; ast::StructMemberList wrapper_struct_param_members;
/// The name of the wrapper function's struct parameter. /// The name of the wrapper function's struct parameter.

View File

@ -169,7 +169,7 @@ struct CombineSamplers::State {
if (pairs.empty()) { if (pairs.empty()) {
return nullptr; return nullptr;
} }
ast::VariableList params; ast::ParameterList params;
for (auto pair : func->TextureSamplerPairs()) { for (auto pair : func->TextureSamplerPairs()) {
const sem::Variable* texture_var = pair.first; const sem::Variable* texture_var = pair.first;
const sem::Variable* sampler_var = pair.second; const sem::Variable* sampler_var = pair.second;

View File

@ -437,7 +437,7 @@ struct DecomposeMemoryAccess::State {
auto* disable_validation = auto* disable_validation =
b.Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter); b.Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
ast::VariableList params = { ast::ParameterList params = {
// Note: The buffer parameter requires the StorageClass in // Note: The buffer parameter requires the StorageClass in
// order for HLSL to emit this as a ByteAddressBuffer or cbuffer // order for HLSL to emit this as a ByteAddressBuffer or cbuffer
// array. // array.
@ -528,7 +528,7 @@ struct DecomposeMemoryAccess::State {
auto* el_ast_ty = CreateASTTypeFor(ctx, el_ty); auto* el_ast_ty = CreateASTTypeFor(ctx, el_ty);
auto* disable_validation = auto* disable_validation =
b.Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter); b.Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter);
ast::VariableList params{ ast::ParameterList params{
// Note: The buffer parameter requires the StorageClass in // Note: The buffer parameter requires the StorageClass in
// order for HLSL to emit this as a ByteAddressBuffer. // order for HLSL to emit this as a ByteAddressBuffer.
@ -621,7 +621,7 @@ struct DecomposeMemoryAccess::State {
// The first parameter to all WGSL atomics is the expression to the // The first parameter to all WGSL atomics is the expression to the
// atomic. This is replaced with two parameters: the buffer and offset. // atomic. This is replaced with two parameters: the buffer and offset.
ast::VariableList params = { ast::ParameterList params = {
// Note: The buffer parameter requires the kStorage StorageClass in // Note: The buffer parameter requires the kStorage StorageClass in
// order for HLSL to emit this as a ByteAddressBuffer. // order for HLSL to emit this as a ByteAddressBuffer.
b.create<ast::Variable>(b.Sym("buffer"), ast::StorageClass::kStorage, b.create<ast::Variable>(b.Sym("buffer"), ast::StorageClass::kStorage,

View File

@ -132,7 +132,7 @@ void RemovePhonies::Run(CloneContext& ctx, const DataMap&, DataMap&) const {
} }
auto sink = utils::GetOrCreate(sinks, sig, [&] { auto sink = utils::GetOrCreate(sinks, sig, [&] {
auto name = ctx.dst->Symbols().New("phony_sink"); auto name = ctx.dst->Symbols().New("phony_sink");
ast::VariableList params; ast::ParameterList params;
for (auto* ty : sig.types) { for (auto* ty : sig.types) {
auto* ast_ty = CreateASTTypeFor(ctx, ty); auto* ast_ty = CreateASTTypeFor(ctx, ty);
params.push_back( params.push_back(

View File

@ -228,7 +228,7 @@ struct State {
Symbol pulling_position_name; Symbol pulling_position_name;
Symbol struct_buffer_name; Symbol struct_buffer_name;
std::unordered_map<uint32_t, Symbol> vertex_buffer_names; std::unordered_map<uint32_t, Symbol> vertex_buffer_names;
ast::VariableList new_function_parameters; ast::ParameterList new_function_parameters;
/// Generate the vertex buffer binding name /// Generate the vertex buffer binding name
/// @param index index to append to buffer name /// @param index index to append to buffer name