From 2ae29830db8d1ec4cc0d7fa3e2c8d0bfe8f593fa Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 15 Jun 2022 10:14:27 +0000 Subject: [PATCH] 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 Commit-Queue: Ben Clayton --- src/tint/ast/function.cc | 2 +- src/tint/ast/function.h | 7 +++++-- src/tint/ast/function_test.cc | 8 ++++---- src/tint/ast/module_test.cc | 2 +- src/tint/program_builder.h | 4 ++-- src/tint/reader/spirv/function.cc | 4 ++-- src/tint/reader/spirv/function.h | 4 ++-- src/tint/reader/wgsl/parser_impl.cc | 6 +++--- src/tint/reader/wgsl/parser_impl.h | 6 +++--- src/tint/resolver/call_test.cc | 2 +- src/tint/resolver/dependency_graph_test.cc | 12 +++++++----- src/tint/resolver/function_validation_test.cc | 4 ++-- src/tint/resolver/uniformity_test.cc | 2 +- src/tint/transform/calculate_array_length.cc | 2 +- src/tint/transform/canonicalize_entry_point_io.cc | 2 +- src/tint/transform/combine_samplers.cc | 2 +- src/tint/transform/decompose_memory_access.cc | 6 +++--- src/tint/transform/remove_phonies.cc | 2 +- src/tint/transform/vertex_pulling.cc | 2 +- 19 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/tint/ast/function.cc b/src/tint/ast/function.cc index d8485d6cc9..2fb64f1b95 100644 --- a/src/tint/ast/function.cc +++ b/src/tint/ast/function.cc @@ -25,7 +25,7 @@ namespace tint::ast { Function::Function(ProgramID pid, const Source& src, Symbol sym, - VariableList parameters, + ParameterList parameters, const Type* return_ty, const BlockStatement* b, AttributeList attrs, diff --git a/src/tint/ast/function.h b/src/tint/ast/function.h index 843877efde..585f1c80f1 100644 --- a/src/tint/ast/function.h +++ b/src/tint/ast/function.h @@ -31,6 +31,9 @@ namespace tint::ast { +/// ParameterList is a list of function parameters +using ParameterList = std::vector; + /// A Function statement. class Function final : public Castable { public: @@ -46,7 +49,7 @@ class Function final : public Castable { Function(ProgramID program_id, const Source& source, Symbol symbol, - VariableList params, + ParameterList params, const Type* return_type, const BlockStatement* body, AttributeList attributes, @@ -72,7 +75,7 @@ class Function final : public Castable { const Symbol symbol; /// The function params - const VariableList params; + const ParameterList params; /// The function return type const Type* const return_type; diff --git a/src/tint/ast/function_test.cc b/src/tint/ast/function_test.cc index 6b79af9c3d..4fb6b9121e 100644 --- a/src/tint/ast/function_test.cc +++ b/src/tint/ast/function_test.cc @@ -26,7 +26,7 @@ namespace { using FunctionTest = TestHelper; TEST_F(FunctionTest, Creation) { - VariableList params{Param("var", ty.i32())}; + ParameterList params{Param("var", ty.i32())}; auto* var = params[0]; auto* f = Func("func", params, ty.void_(), {}); @@ -37,7 +37,7 @@ TEST_F(FunctionTest, Creation) { } 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 src = f->source; @@ -67,7 +67,7 @@ TEST_F(FunctionTest, Assert_Null_Param) { EXPECT_FATAL_FAILURE( { ProgramBuilder b; - VariableList params; + ParameterList params; params.push_back(b.Param("var", b.ty.i32())); params.push_back(nullptr); @@ -126,7 +126,7 @@ TEST_F(FunctionTest, Assert_NonConstParam) { EXPECT_FATAL_FAILURE( { ProgramBuilder b; - VariableList params; + ParameterList params; params.push_back(b.Var("var", b.ty.i32(), ast::StorageClass::kNone)); b.Func("f", params, b.ty.void_(), {}); diff --git a/src/tint/ast/module_test.cc b/src/tint/ast/module_test.cc index 5944f2a20d..4a2884bd50 100644 --- a/src/tint/ast/module_test.cc +++ b/src/tint/ast/module_test.cc @@ -61,7 +61,7 @@ TEST_F(ModuleTest, Assert_DifferentProgramID_Function) { ProgramBuilder b1; ProgramBuilder b2; b1.AST().AddFunction(b2.create(b2.Symbols().Register("func"), - VariableList{}, b2.ty.f32(), b2.Block(), + ParameterList{}, b2.ty.f32(), b2.Block(), AttributeList{}, AttributeList{})); }, "internal compiler error"); diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index 5f47efb016..960f3d7e19 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -1941,7 +1941,7 @@ class ProgramBuilder { template const ast::Function* Func(const Source& source, NAME&& name, - ast::VariableList params, + ast::ParameterList params, const ast::Type* type, ast::StatementList body, ast::AttributeList attributes = {}, @@ -1964,7 +1964,7 @@ class ProgramBuilder { /// @returns the function pointer template const ast::Function* Func(NAME&& name, - ast::VariableList params, + ast::ParameterList params, const ast::Type* type, ast::StatementList body, ast::AttributeList attributes = {}, diff --git a/src/tint/reader/spirv/function.cc b/src/tint/reader/spirv/function.cc index db1b0338ae..72cc93b219 100644 --- a/src/tint/reader/spirv/function.cc +++ b/src/tint/reader/spirv/function.cc @@ -949,7 +949,7 @@ bool FunctionEmitter::EmitPipelineInput(std::string var_name, std::vector index_prefix, const Type* tip_type, const Type* forced_param_type, - ast::VariableList* params, + ast::ParameterList* params, ast::StatementList* statements) { // TODO(dneto): Handle structs where the locations are annotated on members. tip_type = tip_type->UnwrapAlias(); @@ -1399,7 +1399,7 @@ bool FunctionEmitter::ParseFunctionDeclaration(FunctionDeclaration* decl) { << function_.result_id(); } - ast::VariableList ast_params; + ast::ParameterList ast_params; function_.ForEachParam([this, &ast_params](const spvtools::opt::Instruction* param) { auto* type = parser_impl_.ConvertType(param->type_id()); if (type != nullptr) { diff --git a/src/tint/reader/spirv/function.h b/src/tint/reader/spirv/function.h index dbfd327175..5c50e211fc 100644 --- a/src/tint/reader/spirv/function.h +++ b/src/tint/reader/spirv/function.h @@ -459,7 +459,7 @@ class FunctionEmitter { std::vector index_prefix, const Type* tip_type, const Type* forced_param_type, - ast::VariableList* params, + ast::ParameterList* params, ast::StatementList* statements); /// Creates one or more struct members from an output variable, and the @@ -951,7 +951,7 @@ class FunctionEmitter { /// Function name std::string name; /// Function parameters - ast::VariableList params; + ast::ParameterList params; /// Function return type const Type* return_type; /// Function attributes diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index ddd9e96f05..13194780fc 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -210,7 +210,7 @@ ParserImpl::FunctionHeader::FunctionHeader(const FunctionHeader&) = default; ParserImpl::FunctionHeader::FunctionHeader(Source src, std::string n, - ast::VariableList p, + ast::ParameterList p, const ast::Type* ret_ty, ast::AttributeList ret_attrs) : source(src), name(n), params(p), return_type(ret_ty), return_type_attributes(ret_attrs) {} @@ -1443,8 +1443,8 @@ Maybe ParserImpl::function_header() { // param_list // : // | (param COMMA)* param COMMA? -Expect ParserImpl::expect_param_list() { - ast::VariableList ret; +Expect ParserImpl::expect_param_list() { + ast::ParameterList ret; while (continue_parsing()) { // Check for the end of the list. auto t = peek(); diff --git a/src/tint/reader/wgsl/parser_impl.h b/src/tint/reader/wgsl/parser_impl.h index 67d000437e..0c9515905d 100644 --- a/src/tint/reader/wgsl/parser_impl.h +++ b/src/tint/reader/wgsl/parser_impl.h @@ -232,7 +232,7 @@ class ParserImpl { /// @param ret_attrs return type attributes FunctionHeader(Source src, std::string n, - ast::VariableList p, + ast::ParameterList p, const ast::Type* ret_ty, ast::AttributeList ret_attrs); /// Destructor @@ -247,7 +247,7 @@ class ParserImpl { /// Function name std::string name; /// Function parameters - ast::VariableList params; + ast::ParameterList params; /// Function return type const ast::Type* return_type = nullptr; /// Function return type attributes @@ -459,7 +459,7 @@ class ParserImpl { Maybe function_header(); /// Parses a `param_list` grammar element, erroring on parse failure. /// @returns the parsed variables - Expect expect_param_list(); + Expect expect_param_list(); /// Parses a `param` grammar element, erroring on parse failure. /// @returns the parsed variable Expect expect_param(); diff --git a/src/tint/resolver/call_test.cc b/src/tint/resolver/call_test.cc index 39a6eb490c..535162315e 100644 --- a/src/tint/resolver/call_test.cc +++ b/src/tint/resolver/call_test.cc @@ -81,7 +81,7 @@ static constexpr Params all_param_types[] = { }; TEST_F(ResolverCallTest, Valid) { - ast::VariableList params; + ast::ParameterList params; ast::ExpressionList args; for (auto& p : all_param_types) { params.push_back(Param(Sym(), p.create_type(*this))); diff --git a/src/tint/resolver/dependency_graph_test.cc b/src/tint/resolver/dependency_graph_test.cc index 82b0a69b68..f562afbdad 100644 --- a/src/tint/resolver/dependency_graph_test.cc +++ b/src/tint/resolver/dependency_graph_test.cc @@ -384,11 +384,11 @@ struct SymbolTestHelper { /// The program builder ProgramBuilder* const builder; /// Parameters to a function that may need to be built - std::vector parameters; + ast::ParameterList parameters; /// Shallow function var / let declaration statements - std::vector statements; + ast::StatementList statements; /// Nested function local var / let declaration statements - std::vector nested_statements; + ast::StatementList nested_statements; /// Function attributes ast::AttributeList func_attrs; @@ -717,8 +717,10 @@ TEST_F(ResolverDependencyGraphUsedBeforeDeclTest, VarUsed) { // } // var G: f32 = 2.1; - Func("F", ast::VariableList{}, ty.void_(), - {Block(Assign(Expr(Source{{12, 34}}, "G"), 3.14_f))}); + Func("F", {}, ty.void_(), + { + Block(Assign(Expr(Source{{12, 34}}, "G"), 3.14_f)), + }); Global(Source{{56, 78}}, "G", ty.f32(), ast::StorageClass::kPrivate, Expr(2.1_f)); diff --git a/src/tint/resolver/function_validation_test.cc b/src/tint/resolver/function_validation_test.cc index ac4e01f03f..06817aae89 100644 --- a/src/tint/resolver/function_validation_test.cc +++ b/src/tint/resolver/function_validation_test.cc @@ -733,7 +733,7 @@ TEST_F(ResolverFunctionValidationTest, ParameterSotreType_AtomicFree) { } TEST_F(ResolverFunctionValidationTest, ParametersAtLimit) { - ast::VariableList params; + ast::ParameterList params; for (int i = 0; i < 255; i++) { params.emplace_back(Param("param_" + std::to_string(i), ty.i32())); } @@ -743,7 +743,7 @@ TEST_F(ResolverFunctionValidationTest, ParametersAtLimit) { } TEST_F(ResolverFunctionValidationTest, ParametersOverLimit) { - ast::VariableList params; + ast::ParameterList params; for (int i = 0; i < 256; i++) { params.emplace_back(Param("param_" + std::to_string(i), ty.i32())); } diff --git a/src/tint/resolver/uniformity_test.cc b/src/tint/resolver/uniformity_test.cc index d661099d71..7c07357afa 100644 --- a/src/tint/resolver/uniformity_test.cc +++ b/src/tint/resolver/uniformity_test.cc @@ -5001,7 +5001,7 @@ TEST_F(UniformityAnalysisTest, MaximumNumberOfPointerParameters) { // ... // *p254 = rhs; // } - ast::VariableList params; + ast::ParameterList params; ast::StatementList foo_body; const ast::Expression* rhs_init = b.Deref("p0"); for (int i = 1; i < 255; i++) { diff --git a/src/tint/transform/calculate_array_length.cc b/src/tint/transform/calculate_array_length.cc index bdda1cd43b..9cf1175970 100644 --- a/src/tint/transform/calculate_array_length.cc +++ b/src/tint/transform/calculate_array_length.cc @@ -98,7 +98,7 @@ void CalculateArrayLength::Run(CloneContext& ctx, const DataMap&, DataMap&) cons ctx.dst->Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter); ctx.dst->AST().AddFunction(ctx.dst->create( name, - ast::VariableList{ + ast::ParameterList{ // Note: The buffer parameter requires the kStorage StorageClass // in order for HLSL to emit this as a ByteAddressBuffer. ctx.dst->create(ctx.dst->Sym("buffer"), diff --git a/src/tint/transform/canonicalize_entry_point_io.cc b/src/tint/transform/canonicalize_entry_point_io.cc index 44d577bb52..104429b3bd 100644 --- a/src/tint/transform/canonicalize_entry_point_io.cc +++ b/src/tint/transform/canonicalize_entry_point_io.cc @@ -100,7 +100,7 @@ struct CanonicalizeEntryPointIO::State { const sem::Function* func_sem; /// 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. ast::StructMemberList wrapper_struct_param_members; /// The name of the wrapper function's struct parameter. diff --git a/src/tint/transform/combine_samplers.cc b/src/tint/transform/combine_samplers.cc index c9d4913b99..8cd3a6d49a 100644 --- a/src/tint/transform/combine_samplers.cc +++ b/src/tint/transform/combine_samplers.cc @@ -169,7 +169,7 @@ struct CombineSamplers::State { if (pairs.empty()) { return nullptr; } - ast::VariableList params; + ast::ParameterList params; for (auto pair : func->TextureSamplerPairs()) { const sem::Variable* texture_var = pair.first; const sem::Variable* sampler_var = pair.second; diff --git a/src/tint/transform/decompose_memory_access.cc b/src/tint/transform/decompose_memory_access.cc index a90a6e2711..f89d9abbdc 100644 --- a/src/tint/transform/decompose_memory_access.cc +++ b/src/tint/transform/decompose_memory_access.cc @@ -437,7 +437,7 @@ struct DecomposeMemoryAccess::State { auto* disable_validation = b.Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter); - ast::VariableList params = { + ast::ParameterList params = { // Note: The buffer parameter requires the StorageClass in // order for HLSL to emit this as a ByteAddressBuffer or cbuffer // array. @@ -528,7 +528,7 @@ struct DecomposeMemoryAccess::State { auto* el_ast_ty = CreateASTTypeFor(ctx, el_ty); auto* disable_validation = b.Disable(ast::DisabledValidation::kIgnoreConstructibleFunctionParameter); - ast::VariableList params{ + ast::ParameterList params{ // Note: The buffer parameter requires the StorageClass in // 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 // 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 // order for HLSL to emit this as a ByteAddressBuffer. b.create(b.Sym("buffer"), ast::StorageClass::kStorage, diff --git a/src/tint/transform/remove_phonies.cc b/src/tint/transform/remove_phonies.cc index 7ca1194487..1cac0b7690 100644 --- a/src/tint/transform/remove_phonies.cc +++ b/src/tint/transform/remove_phonies.cc @@ -132,7 +132,7 @@ void RemovePhonies::Run(CloneContext& ctx, const DataMap&, DataMap&) const { } auto sink = utils::GetOrCreate(sinks, sig, [&] { auto name = ctx.dst->Symbols().New("phony_sink"); - ast::VariableList params; + ast::ParameterList params; for (auto* ty : sig.types) { auto* ast_ty = CreateASTTypeFor(ctx, ty); params.push_back( diff --git a/src/tint/transform/vertex_pulling.cc b/src/tint/transform/vertex_pulling.cc index e297c90449..31e4e7c9ce 100644 --- a/src/tint/transform/vertex_pulling.cc +++ b/src/tint/transform/vertex_pulling.cc @@ -228,7 +228,7 @@ struct State { Symbol pulling_position_name; Symbol struct_buffer_name; std::unordered_map vertex_buffer_names; - ast::VariableList new_function_parameters; + ast::ParameterList new_function_parameters; /// Generate the vertex buffer binding name /// @param index index to append to buffer name