From 971318f7a2e7270b81b786da1fa8420a1bc3e02a Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Tue, 14 Feb 2023 13:52:43 +0000 Subject: [PATCH] tint: Replace all remaining AST types with ast::Type This CL removes the following AST nodes: * ast::Array * ast::Atomic * ast::Matrix * ast::MultisampledTexture * ast::Pointer * ast::SampledTexture * ast::Texture * ast::TypeName * ast::Vector ast::Type, which used to be the base class for all AST types, is now a thin wrapper around ast::IdentifierExpression. All types are now referred to using their type name. The resolver now handles type resolution and validation of the types listed above based on the TemplateIdentifier arguments. Other changes: * ProgramBuilder has undergone substantial refactoring. * ProgramBuilder helpers for type inferencing is now more explicit. Instead of passing 'nullptr', a new 'Infer' template argument is passed. * ast::CheckIdentifier() is used for more tests that check identifiers, including types. Bug: tint:1810 Change-Id: I8e739ef49435dc1c20a462f3ec5ba265661a7edb Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118723 Reviewed-by: Dan Sinclair Kokoro: Kokoro Commit-Queue: Ben Clayton Reviewed-by: James Price --- src/tint/BUILD.gn | 39 +- src/tint/CMakeLists.txt | 31 +- src/tint/ast/alias.cc | 4 +- src/tint/ast/alias.h | 14 +- src/tint/ast/alias_test.cc | 12 +- src/tint/ast/array.cc | 80 - src/tint/ast/array.h | 77 - src/tint/ast/array_test.cc | 84 - src/tint/ast/atomic.cc | 43 - src/tint/ast/atomic.h | 53 - src/tint/ast/atomic_test.cc | 38 - src/tint/ast/bitcast_expression.cc | 4 +- src/tint/ast/bitcast_expression.h | 10 +- src/tint/ast/bitcast_expression_test.cc | 16 +- src/tint/ast/builtin_texture_helper_test.cc | 4 +- src/tint/ast/builtin_texture_helper_test.h | 2 +- src/tint/ast/call_expression.cc | 40 +- src/tint/ast/call_expression.h | 33 +- src/tint/ast/call_expression_test.cc | 31 +- src/tint/ast/const.cc | 4 +- src/tint/ast/const.h | 2 +- src/tint/ast/function.cc | 4 +- src/tint/ast/function.h | 5 +- src/tint/ast/function_test.cc | 13 +- src/tint/ast/identifier_expression_test.cc | 5 - src/tint/ast/let.cc | 4 +- src/tint/ast/let.h | 2 +- src/tint/ast/matrix.cc | 57 - src/tint/ast/matrix.h | 70 - src/tint/ast/matrix_test.cc | 49 - src/tint/ast/module.h | 1 - src/tint/ast/multisampled_texture.cc | 49 - src/tint/ast/multisampled_texture.h | 59 - src/tint/ast/multisampled_texture_test.cc | 56 - src/tint/ast/override.cc | 4 +- src/tint/ast/override.h | 2 +- src/tint/ast/parameter.cc | 4 +- src/tint/ast/parameter.h | 2 +- src/tint/ast/pointer.cc | 56 - src/tint/ast/pointer.h | 68 - src/tint/ast/pointer_test.cc | 43 - src/tint/ast/sampled_texture.cc | 49 - src/tint/ast/sampled_texture.h | 59 - src/tint/ast/sampled_texture_test.cc | 46 - src/tint/ast/struct_member.cc | 4 +- src/tint/ast/struct_member.h | 6 +- src/tint/ast/struct_member_test.cc | 12 +- src/tint/ast/struct_test.cc | 5 - src/tint/ast/templated_identifier.cc | 14 +- src/tint/ast/templated_identifier.h | 8 +- src/tint/ast/test_helper.h | 39 +- src/tint/ast/texture.cc | 60 - src/tint/ast/texture.h | 60 - src/tint/ast/texture_test.cc | 51 - src/tint/ast/traverse_expressions.h | 3 +- src/tint/ast/type.cc | 24 +- src/tint/ast/type.h | 50 +- src/tint/ast/type_name.cc | 40 - src/tint/ast/type_name.h | 59 - src/tint/ast/type_name_test.cc | 72 - src/tint/ast/var.cc | 4 +- src/tint/ast/var.h | 2 +- src/tint/ast/variable.cc | 2 +- src/tint/ast/variable.h | 6 +- src/tint/ast/variable_test.cc | 15 +- src/tint/ast/vector.cc | 50 - src/tint/ast/vector.h | 61 - src/tint/ast/vector_test.cc | 37 - src/tint/clone_context.cc | 4 + src/tint/clone_context.h | 6 + src/tint/inspector/inspector_test.cc | 48 +- src/tint/inspector/test_inspector_builder.cc | 84 +- src/tint/inspector/test_inspector_builder.h | 50 +- src/tint/intrinsics.def | 27 + src/tint/ir/builder_impl.h | 2 +- src/tint/program.cc | 16 +- src/tint/program.h | 18 +- src/tint/program_builder.cc | 19 +- src/tint/program_builder.h | 1521 ++++++++++------- src/tint/program_builder_test.cc | 4 +- src/tint/reader/spirv/function.cc | 60 +- src/tint/reader/spirv/parser_impl.cc | 1 - .../spirv/parser_impl_convert_type_test.cc | 6 +- .../reader/spirv/parser_impl_test_helper.cc | 7 - src/tint/reader/spirv/parser_type.cc | 40 +- src/tint/reader/spirv/parser_type.h | 42 +- src/tint/reader/wgsl/parser_impl.cc | 66 +- src/tint/reader/wgsl/parser_impl.h | 41 +- .../reader/wgsl/parser_impl_call_stmt_test.cc | 7 +- .../reader/wgsl/parser_impl_callable_test.cc | 58 +- .../wgsl/parser_impl_depth_texture_test.cc | 26 +- .../parser_impl_diagnostic_attribute_test.cc | 3 +- .../parser_impl_diagnostic_control_test.cc | 5 +- .../parser_impl_diagnostic_directive_test.cc | 3 +- .../parser_impl_function_attribute_test.cc | 5 +- .../wgsl/parser_impl_function_decl_test.cc | 5 +- .../wgsl/parser_impl_function_header_test.cc | 9 +- .../parser_impl_global_constant_decl_test.cc | 16 +- .../wgsl/parser_impl_global_decl_test.cc | 25 +- .../parser_impl_global_variable_decl_test.cc | 23 +- .../wgsl/parser_impl_param_list_test.cc | 31 +- .../parser_impl_primary_expression_test.cc | 22 +- .../reader/wgsl/parser_impl_sampler_test.cc | 7 +- .../parser_impl_singular_expression_test.cc | 5 +- .../wgsl/parser_impl_struct_body_decl_test.cc | 7 +- .../wgsl/parser_impl_struct_member_test.cc | 29 +- .../wgsl/parser_impl_texture_sampler_test.cc | 133 +- .../wgsl/parser_impl_type_alias_test.cc | 15 +- .../reader/wgsl/parser_impl_type_decl_test.cc | 192 +-- ...arser_impl_type_decl_without_ident_test.cc | 189 +- .../wgsl/parser_impl_variable_decl_test.cc | 13 +- .../parser_impl_variable_ident_decl_test.cc | 7 +- .../wgsl/parser_impl_variable_stmt_test.cc | 18 +- .../resolver/address_space_validation_test.cc | 6 +- src/tint/resolver/alias_analysis_test.cc | 2 +- .../resolver/assignment_validation_test.cc | 4 +- src/tint/resolver/atomics_validation_test.cc | 12 +- .../resolver/attribute_validation_test.cc | 22 +- src/tint/resolver/builtin_test.cc | 33 +- src/tint/resolver/builtin_validation_test.cc | 7 +- .../resolver/const_eval_binary_op_test.cc | 14 +- src/tint/resolver/const_eval_bitcast_test.cc | 2 +- .../resolver/const_eval_construction_test.cc | 42 +- .../resolver/const_eval_conversion_test.cc | 2 +- .../resolver/const_eval_member_access_test.cc | 22 +- src/tint/resolver/dependency_graph.cc | 181 +- src/tint/resolver/dependency_graph.h | 1 + src/tint/resolver/dependency_graph_test.cc | 108 +- src/tint/resolver/evaluation_stage_test.cc | 4 +- src/tint/resolver/expression_kind_test.cc | 193 ++- src/tint/resolver/f16_extension_test.cc | 7 +- src/tint/resolver/function_validation_test.cc | 74 +- src/tint/resolver/inferred_type_test.cc | 2 +- src/tint/resolver/load_test.cc | 4 +- src/tint/resolver/materialize_test.cc | 14 +- src/tint/resolver/override_test.cc | 11 +- src/tint/resolver/ptr_ref_test.cc | 2 +- src/tint/resolver/resolver.cc | 860 +++++----- src/tint/resolver/resolver.h | 49 +- src/tint/resolver/resolver_behavior_test.cc | 2 +- src/tint/resolver/resolver_test.cc | 24 +- src/tint/resolver/resolver_test_helper.h | 53 +- src/tint/resolver/sem_helper.cc | 62 +- src/tint/resolver/sem_helper.h | 72 +- .../resolver/struct_address_space_use_test.cc | 4 +- src/tint/resolver/struct_layout_test.cc | 8 +- .../type_initializer_validation_test.cc | 296 ++-- src/tint/resolver/type_validation_test.cc | 106 +- src/tint/resolver/uniformity.cc | 76 +- src/tint/resolver/uniformity_test.cc | 2 +- src/tint/resolver/validation_test.cc | 4 +- src/tint/resolver/validator.cc | 34 +- src/tint/resolver/validator.h | 12 +- src/tint/resolver/variable_test.cc | 24 +- src/tint/resolver/variable_validation_test.cc | 31 +- src/tint/sem/type_mappings.h | 4 - src/tint/traits.h | 5 - src/tint/transform/add_block_attribute.cc | 2 +- src/tint/transform/binding_remapper.cc | 2 +- src/tint/transform/builtin_polyfill.cc | 28 +- src/tint/transform/calculate_array_length.cc | 9 +- .../transform/canonicalize_entry_point_io.cc | 12 +- src/tint/transform/clamp_frag_depth.cc | 6 +- src/tint/transform/combine_samplers.cc | 22 +- src/tint/transform/decompose_memory_access.cc | 51 +- .../transform/decompose_memory_access_test.cc | 32 +- src/tint/transform/decompose_strided_array.cc | 74 +- .../transform/decompose_strided_matrix.cc | 5 +- src/tint/transform/demote_to_helper.cc | 2 +- src/tint/transform/direct_variable_access.cc | 12 +- .../module_scope_var_to_entry_point_param.cc | 10 +- .../transform/multiplanar_external_texture.cc | 7 +- src/tint/transform/pad_structs.cc | 2 +- src/tint/transform/remove_phonies.cc | 2 +- src/tint/transform/renamer.cc | 33 +- src/tint/transform/renamer_test.cc | 48 +- src/tint/transform/robustness.cc | 4 +- src/tint/transform/spirv_atomic.cc | 10 +- src/tint/transform/std140.cc | 35 +- src/tint/transform/substitute_override.cc | 2 +- src/tint/transform/texture_1d_to_2d.cc | 20 +- src/tint/transform/transform.cc | 25 +- src/tint/transform/transform.h | 8 +- src/tint/transform/transform_test.cc | 77 +- .../truncate_interstage_variables.cc | 5 +- src/tint/transform/unshadow.cc | 2 +- src/tint/transform/vertex_pulling.cc | 15 +- src/tint/type/builtin.cc | 110 ++ src/tint/type/builtin.h | 44 + src/tint/type/builtin_bench.cc | 764 +++++---- src/tint/type/builtin_test.cc | 356 ++-- src/tint/type/storage_texture_test.cc | 6 +- src/tint/type/texture.cc | 32 + src/tint/type/texture.h | 18 + src/tint/writer/append_vector.cc | 6 +- src/tint/writer/append_vector_test.cc | 23 +- src/tint/writer/glsl/generator_impl.cc | 14 +- src/tint/writer/glsl/generator_impl.h | 3 +- .../generator_impl_member_accessor_test.cc | 37 +- .../generator_impl_module_constant_test.cc | 6 +- .../writer/glsl/generator_impl_type_test.cc | 34 +- ...rator_impl_variable_decl_statement_test.cc | 6 +- .../generator_impl_member_accessor_test.cc | 39 +- .../generator_impl_module_constant_test.cc | 6 +- .../writer/hlsl/generator_impl_type_test.cc | 34 +- ...rator_impl_variable_decl_statement_test.cc | 6 +- src/tint/writer/msl/generator_impl.cc | 6 +- .../writer/msl/generator_impl_binary_test.cc | 16 +- .../generator_impl_builtin_texture_test.cc | 2 +- .../msl/generator_impl_function_test.cc | 5 +- .../generator_impl_module_constant_test.cc | 6 +- .../msl/generator_impl_sanitizer_test.cc | 16 +- .../writer/msl/generator_impl_type_test.cc | 92 +- ...rator_impl_variable_decl_statement_test.cc | 8 +- src/tint/writer/spirv/builder.cc | 4 +- .../spirv/builder_accessor_expression_test.cc | 4 +- src/tint/writer/spirv/builder_builtin_test.cc | 4 +- .../writer/spirv/builder_entry_point_test.cc | 2 +- .../spirv/builder_function_attribute_test.cc | 4 +- .../spirv/builder_global_variable_test.cc | 12 +- src/tint/writer/spirv/builder_type_test.cc | 98 +- src/tint/writer/text_generator.h | 4 - src/tint/writer/wgsl/generator_impl.cc | 186 +- src/tint/writer/wgsl/generator_impl.h | 35 +- .../writer/wgsl/generator_impl_binary_test.cc | 2 +- .../wgsl/generator_impl_function_test.cc | 2 +- .../wgsl/generator_impl_global_decl_test.cc | 2 +- .../wgsl/generator_impl_initializer_test.cc | 4 +- .../writer/wgsl/generator_impl_type_test.cc | 142 +- ...rator_impl_variable_decl_statement_test.cc | 8 +- ...sign_to_storage_var.wgsl.expected.dxc.hlsl | 16 +- ...sign_to_storage_var.wgsl.expected.fxc.hlsl | 16 +- .../array/strides.spvasm.expected.dxc.hlsl | 12 +- .../array/strides.spvasm.expected.fxc.hlsl | 12 +- .../write.wgsl.expected.dxc.hlsl | 4 +- .../write.wgsl.expected.fxc.hlsl | 4 +- .../write_f16.wgsl.expected.dxc.hlsl | 8 +- .../static_index/write.wgsl.expected.dxc.hlsl | 8 +- .../static_index/write.wgsl.expected.fxc.hlsl | 8 +- .../write_f16.wgsl.expected.dxc.hlsl | 12 +- .../types/array4_f16.wgsl.expected.dxc.hlsl | 4 +- .../types/array4_f32.wgsl.expected.dxc.hlsl | 4 +- .../types/array4_f32.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.dxc.hlsl | 4 +- .../to_storage.wgsl.expected.fxc.hlsl | 4 +- .../mat2x2/stride/16.spvasm.expected.dxc.hlsl | 4 +- .../mat2x2/stride/16.spvasm.expected.fxc.hlsl | 4 +- .../array_in_struct.wgsl.expected.dxc.hlsl | 4 +- .../array_in_struct.wgsl.expected.fxc.hlsl | 4 +- 295 files changed, 4613 insertions(+), 5901 deletions(-) delete mode 100644 src/tint/ast/array.cc delete mode 100644 src/tint/ast/array.h delete mode 100644 src/tint/ast/array_test.cc delete mode 100644 src/tint/ast/atomic.cc delete mode 100644 src/tint/ast/atomic.h delete mode 100644 src/tint/ast/atomic_test.cc delete mode 100644 src/tint/ast/matrix.cc delete mode 100644 src/tint/ast/matrix.h delete mode 100644 src/tint/ast/matrix_test.cc delete mode 100644 src/tint/ast/multisampled_texture.cc delete mode 100644 src/tint/ast/multisampled_texture.h delete mode 100644 src/tint/ast/multisampled_texture_test.cc delete mode 100644 src/tint/ast/pointer.cc delete mode 100644 src/tint/ast/pointer.h delete mode 100644 src/tint/ast/pointer_test.cc delete mode 100644 src/tint/ast/sampled_texture.cc delete mode 100644 src/tint/ast/sampled_texture.h delete mode 100644 src/tint/ast/sampled_texture_test.cc delete mode 100644 src/tint/ast/texture.cc delete mode 100644 src/tint/ast/texture.h delete mode 100644 src/tint/ast/texture_test.cc delete mode 100644 src/tint/ast/type_name.cc delete mode 100644 src/tint/ast/type_name.h delete mode 100644 src/tint/ast/type_name_test.cc delete mode 100644 src/tint/ast/vector.cc delete mode 100644 src/tint/ast/vector.h delete mode 100644 src/tint/ast/vector_test.cc diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index 59f367c3fd..58d6e955d7 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -239,9 +239,7 @@ libtint_source_set("libtint_syntax_tree_src") { sources = [ "ast/accessor_expression.h", "ast/alias.h", - "ast/array.h", "ast/assignment_statement.h", - "ast/atomic.h", "ast/attribute.h", "ast/binary_expression.h", "ast/binding_attribute.h", @@ -286,19 +284,15 @@ libtint_source_set("libtint_syntax_tree_src") { "ast/literal_expression.h", "ast/location_attribute.h", "ast/loop_statement.h", - "ast/matrix.h", "ast/member_accessor_expression.h", "ast/module.h", - "ast/multisampled_texture.h", "ast/node.h", "ast/node_id.h", "ast/override.h", "ast/parameter.h", "ast/phony_expression.h", "ast/pipeline_stage.h", - "ast/pointer.h", "ast/return_statement.h", - "ast/sampled_texture.h", "ast/stage_attribute.h", "ast/statement.h", "ast/stride_attribute.h", @@ -309,17 +303,14 @@ libtint_source_set("libtint_syntax_tree_src") { "ast/struct_member_size_attribute.h", "ast/switch_statement.h", "ast/templated_identifier.h", - "ast/texture.h", "ast/traverse_expressions.h", "ast/type.h", "ast/type_decl.h", - "ast/type_name.h", "ast/unary_op.h", "ast/unary_op_expression.h", "ast/var.h", "ast/variable.h", "ast/variable_decl_statement.h", - "ast/vector.h", "ast/while_statement.h", "ast/workgroup_attribute.h", "clone_context.cc", @@ -542,12 +533,8 @@ libtint_source_set("libtint_ast_src") { "ast/accessor_expression.h", "ast/alias.cc", "ast/alias.h", - "ast/array.cc", - "ast/array.h", "ast/assignment_statement.cc", "ast/assignment_statement.h", - "ast/atomic.cc", - "ast/atomic.h", "ast/attribute.cc", "ast/attribute.h", "ast/binary_expression.cc", @@ -636,14 +623,10 @@ libtint_source_set("libtint_ast_src") { "ast/location_attribute.h", "ast/loop_statement.cc", "ast/loop_statement.h", - "ast/matrix.cc", - "ast/matrix.h", "ast/member_accessor_expression.cc", "ast/member_accessor_expression.h", "ast/module.cc", "ast/module.h", - "ast/multisampled_texture.cc", - "ast/multisampled_texture.h", "ast/node.cc", "ast/node.h", "ast/node_id.h", @@ -655,12 +638,8 @@ libtint_source_set("libtint_ast_src") { "ast/phony_expression.h", "ast/pipeline_stage.cc", "ast/pipeline_stage.h", - "ast/pointer.cc", - "ast/pointer.h", "ast/return_statement.cc", "ast/return_statement.h", - "ast/sampled_texture.cc", - "ast/sampled_texture.h", "ast/stage_attribute.cc", "ast/stage_attribute.h", "ast/statement.cc", @@ -681,15 +660,11 @@ libtint_source_set("libtint_ast_src") { "ast/switch_statement.h", "ast/templated_identifier.cc", "ast/templated_identifier.h", - "ast/texture.cc", - "ast/texture.h", "ast/traverse_expressions.h", "ast/type.cc", "ast/type.h", "ast/type_decl.cc", "ast/type_decl.h", - "ast/type_name.cc", - "ast/type_name.h", "ast/unary_op.cc", "ast/unary_op.h", "ast/unary_op_expression.cc", @@ -700,8 +675,6 @@ libtint_source_set("libtint_ast_src") { "ast/variable.h", "ast/variable_decl_statement.cc", "ast/variable_decl_statement.h", - "ast/vector.cc", - "ast/vector.h", "ast/while_statement.cc", "ast/while_statement.h", "ast/workgroup_attribute.cc", @@ -1294,9 +1267,7 @@ if (tint_build_unittests) { tint_unittests_source_set("tint_unittests_ast_src") { sources = [ "ast/alias_test.cc", - "ast/array_test.cc", "ast/assignment_statement_test.cc", - "ast/atomic_test.cc", "ast/binary_expression_test.cc", "ast/binding_attribute_test.cc", "ast/bitcast_expression_test.cc", @@ -1336,14 +1307,10 @@ if (tint_build_unittests) { "ast/invariant_attribute_test.cc", "ast/location_attribute_test.cc", "ast/loop_statement_test.cc", - "ast/matrix_test.cc", "ast/member_accessor_expression_test.cc", "ast/module_test.cc", - "ast/multisampled_texture_test.cc", "ast/phony_expression_test.cc", - "ast/pointer_test.cc", "ast/return_statement_test.cc", - "ast/sampled_texture_test.cc", "ast/stage_attribute_test.cc", "ast/stride_attribute_test.cc", "ast/struct_member_align_attribute_test.cc", @@ -1353,13 +1320,10 @@ if (tint_build_unittests) { "ast/struct_test.cc", "ast/switch_statement_test.cc", "ast/templated_identifier_test.cc", - "ast/texture_test.cc", "ast/traverse_expressions_test.cc", - "ast/type_name_test.cc", "ast/unary_op_expression_test.cc", "ast/variable_decl_statement_test.cc", "ast/variable_test.cc", - "ast/vector_test.cc", "ast/while_statement_test.cc", "ast/workgroup_attribute_test.cc", ] @@ -1489,7 +1453,6 @@ if (tint_build_unittests) { sources = [ "type/access_test.cc", "type/address_space_test.cc", - "type/array_test.cc", "type/atomic_test.cc", "type/bool_test.cc", "type/builtin_test.cc", @@ -1583,6 +1546,7 @@ if (tint_build_unittests) { deps = [ ":libtint_base_src", ":libtint_transform_src", + ":libtint_unittests_ast_helper", ":libtint_wgsl_reader_src", ":libtint_wgsl_writer_src", ] @@ -1626,6 +1590,7 @@ if (tint_build_unittests) { ] deps = [ ":libtint_base_src", + ":libtint_unittests_ast_helper", ":libtint_writer_src", ] } diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 92c3bb64fe..868bce5adf 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -84,12 +84,8 @@ list(APPEND TINT_LIB_SRCS ast/accessor_expression.h ast/alias.cc ast/alias.h - ast/array.cc - ast/array.h ast/assignment_statement.cc ast/assignment_statement.h - ast/atomic.cc - ast/atomic.h ast/attribute.cc ast/attribute.h ast/binary_expression.cc @@ -172,14 +168,10 @@ list(APPEND TINT_LIB_SRCS ast/location_attribute.h ast/loop_statement.cc ast/loop_statement.h - ast/matrix.cc - ast/matrix.h ast/member_accessor_expression.cc ast/member_accessor_expression.h ast/module.cc ast/module.h - ast/multisampled_texture.cc - ast/multisampled_texture.h ast/node_id.h ast/node.cc ast/node.h @@ -191,12 +183,8 @@ list(APPEND TINT_LIB_SRCS ast/phony_expression.h ast/pipeline_stage.cc ast/pipeline_stage.h - ast/pointer.cc - ast/pointer.h ast/return_statement.cc ast/return_statement.h - ast/sampled_texture.cc - ast/sampled_texture.h ast/stage_attribute.cc ast/stage_attribute.h ast/statement.cc @@ -217,15 +205,11 @@ list(APPEND TINT_LIB_SRCS ast/switch_statement.h ast/templated_identifier.cc ast/templated_identifier.h - ast/texture.cc - ast/texture.h ast/traverse_expressions.h - ast/type_decl.cc - ast/type_decl.h - ast/type_name.cc - ast/type_name.h ast/type.cc ast/type.h + ast/type_decl.cc + ast/type_decl.h ast/unary_op_expression.cc ast/unary_op_expression.h ast/unary_op.cc @@ -236,8 +220,6 @@ list(APPEND TINT_LIB_SRCS ast/variable_decl_statement.h ast/variable.cc ast/variable.h - ast/vector.cc - ast/vector.h ast/while_statement.cc ast/while_statement.h ast/workgroup_attribute.cc @@ -808,9 +790,7 @@ endif() if(TINT_BUILD_TESTS) list(APPEND TINT_TEST_SRCS ast/alias_test.cc - ast/array_test.cc ast/assignment_statement_test.cc - ast/atomic_test.cc ast/binary_expression_test.cc ast/binding_attribute_test.cc ast/bitcast_expression_test.cc @@ -847,14 +827,10 @@ if(TINT_BUILD_TESTS) ast/invariant_attribute_test.cc ast/location_attribute_test.cc ast/loop_statement_test.cc - ast/matrix_test.cc ast/member_accessor_expression_test.cc ast/module_test.cc - ast/multisampled_texture_test.cc ast/phony_expression_test.cc - ast/pointer_test.cc ast/return_statement_test.cc - ast/sampled_texture_test.cc ast/stage_attribute_test.cc ast/stride_attribute_test.cc ast/struct_member_align_attribute_test.cc @@ -866,13 +842,10 @@ if(TINT_BUILD_TESTS) ast/templated_identifier_test.cc ast/test_helper.h ast/test_helper_test.cc - ast/texture_test.cc ast/traverse_expressions_test.cc - ast/type_name_test.cc ast/unary_op_expression_test.cc ast/variable_decl_statement_test.cc ast/variable_test.cc - ast/vector_test.cc ast/while_statement_test.cc ast/workgroup_attribute_test.cc castable_test.cc diff --git a/src/tint/ast/alias.cc b/src/tint/ast/alias.cc index 2672667bb1..ec5cf43156 100644 --- a/src/tint/ast/alias.cc +++ b/src/tint/ast/alias.cc @@ -20,7 +20,7 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::Alias); namespace tint::ast { -Alias::Alias(ProgramID pid, NodeID nid, const Source& src, const Identifier* n, const Type* subtype) +Alias::Alias(ProgramID pid, NodeID nid, const Source& src, const Identifier* n, Type subtype) : Base(pid, nid, src, n), type(subtype) { TINT_ASSERT(AST, type); } @@ -33,7 +33,7 @@ const Alias* Alias::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering auto src = ctx->Clone(source); auto sym = ctx->Clone(name); - auto* ty = ctx->Clone(type); + auto ty = ctx->Clone(type); return ctx->dst->create(src, sym, ty); } diff --git a/src/tint/ast/alias.h b/src/tint/ast/alias.h index 971d46b951..267a313c33 100644 --- a/src/tint/ast/alias.h +++ b/src/tint/ast/alias.h @@ -17,13 +17,9 @@ #include +#include "src/tint/ast/type.h" #include "src/tint/ast/type_decl.h" -// Forward declarations -namespace tint::ast { -class Type; -} // namespace tint::ast - namespace tint::ast { /// A type alias type. Holds a name and pointer to another type. @@ -35,11 +31,7 @@ class Alias final : public Castable { /// @param src the source of this node /// @param name the symbol for the alias /// @param subtype the alias'd type - Alias(ProgramID pid, - NodeID nid, - const Source& src, - const Identifier* name, - const Type* subtype); + Alias(ProgramID pid, NodeID nid, const Source& src, const Identifier* name, Type subtype); /// Move constructor Alias(Alias&&); /// Destructor @@ -51,7 +43,7 @@ class Alias final : public Castable { const Alias* Clone(CloneContext* ctx) const override; /// the alias type - const Type* const type; + const Type type; }; } // namespace tint::ast diff --git a/src/tint/ast/alias_test.cc b/src/tint/ast/alias_test.cc index b35fb1a4d2..6e5d6473b1 100644 --- a/src/tint/ast/alias_test.cc +++ b/src/tint/ast/alias_test.cc @@ -13,13 +13,7 @@ // limitations under the License. #include "src/tint/ast/alias.h" -#include "src/tint/ast/array.h" -#include "src/tint/ast/matrix.h" -#include "src/tint/ast/pointer.h" -#include "src/tint/ast/struct.h" #include "src/tint/ast/test_helper.h" -#include "src/tint/ast/texture.h" -#include "src/tint/ast/vector.h" #include "src/tint/type/access.h" namespace tint::ast { @@ -28,10 +22,10 @@ namespace { using AstAliasTest = TestHelper; TEST_F(AstAliasTest, Create) { - auto* u32 = ty.u32(); + auto u32 = ty.u32(); auto* a = Alias("a_type", u32); - EXPECT_EQ(Symbols().NameFor(a->name->symbol), "a_type"); - EXPECT_EQ(a->type, u32); + CheckIdentifier(Symbols(), a->name, "a_type"); + CheckIdentifier(Symbols(), a->type, "u32"); } } // namespace diff --git a/src/tint/ast/array.cc b/src/tint/ast/array.cc deleted file mode 100644 index 6233381150..0000000000 --- a/src/tint/ast/array.cc +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/array.h" - -#include -#include - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::Array); - -namespace tint::ast { - -namespace { -// Returns the string representation of an array size expression. -std::string SizeExprToString(const Expression* size, const SymbolTable& symbols) { - if (auto* ident = size->As()) { - return symbols.NameFor(ident->identifier->symbol); - } - if (auto* literal = size->As()) { - return std::to_string(literal->value); - } - // This will never be exposed to the user as the Resolver will reject this - // expression for array size. - return ""; -} -} // namespace - -Array::Array(ProgramID pid, - NodeID nid, - const Source& src, - const Type* subtype, - const Expression* cnt, - utils::VectorRef attrs) - : Base(pid, nid, src), type(subtype), count(cnt), attributes(std::move(attrs)) {} - -Array::Array(Array&&) = default; - -Array::~Array() = default; - -std::string Array::FriendlyName(const SymbolTable& symbols) const { - std::ostringstream out; - for (auto* attr : attributes) { - if (auto* stride = attr->As()) { - out << "@stride(" << stride->stride << ") "; - } - } - out << "array"; - if (type) { - out << "<" << type->FriendlyName(symbols); - if (count) { - out << ", " << SizeExprToString(count, symbols); - } - out << ">"; - } - return out.str(); -} - -const Array* Array::Clone(CloneContext* ctx) const { - // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source); - auto* ty = ctx->Clone(type); - auto* cnt = ctx->Clone(count); - auto attrs = ctx->Clone(attributes); - return ctx->dst->create(src, ty, cnt, std::move(attrs)); -} - -} // namespace tint::ast diff --git a/src/tint/ast/array.h b/src/tint/ast/array.h deleted file mode 100644 index 19e806ee82..0000000000 --- a/src/tint/ast/array.h +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_TINT_AST_ARRAY_H_ -#define SRC_TINT_AST_ARRAY_H_ - -#include - -#include "src/tint/ast/attribute.h" -#include "src/tint/ast/type.h" - -// Forward declarations -namespace tint::ast { -class Expression; -} // namespace tint::ast - -namespace tint::ast { - -/// An array type. If size is zero then it is a runtime array. -class Array final : public Castable { - public: - /// Constructor - /// @param pid the identifier of the program that owns this node - /// @param nid the unique node identifier - /// @param src the source of this node - /// @param subtype the type of the array elements - /// @param count the number of elements in the array - /// @param attributes the array attributes - /// @note a runtime-sized array is represented by a null count and a non-null type - Array(ProgramID pid, - NodeID nid, - const Source& src, - const Type* subtype, - const Expression* count, - utils::VectorRef attributes); - /// Move constructor - Array(Array&&); - ~Array() override; - - /// @returns true if this is a runtime array. - /// i.e. the size is determined at runtime - bool IsRuntimeArray() const { return type != nullptr && count == nullptr; } - - /// @param symbols the program's symbol table - /// @returns the name for this type that closely resembles how it would be - /// declared in WGSL. - std::string FriendlyName(const SymbolTable& symbols) const override; - - /// Clones this type and all transitive types using the `CloneContext` `ctx`. - /// @param ctx the clone context - /// @return the newly cloned type - const Array* Clone(CloneContext* ctx) const override; - - /// the array element type - const Type* const type; - - /// the array size in elements, or nullptr for a runtime array - const Expression* const count; - - /// the array attributes - const utils::Vector attributes; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_ARRAY_H_ diff --git a/src/tint/ast/array_test.cc b/src/tint/ast/array_test.cc deleted file mode 100644 index eb5eddc5b1..0000000000 --- a/src/tint/ast/array_test.cc +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/array.h" - -#include "src/tint/ast/test_helper.h" - -using namespace tint::number_suffixes; // NOLINT - -namespace tint::ast { -namespace { - -using AstArrayTest = TestHelper; - -TEST_F(AstArrayTest, CreateSizedArray) { - auto* count = Expr(3_u); - auto* arr = create(ty.u32(), count, utils::Empty); - ASSERT_TRUE(arr->type->Is()); - EXPECT_EQ(Symbols().NameFor(arr->type->As()->name->symbol), "u32"); - EXPECT_EQ(arr->count, count); - EXPECT_TRUE(arr->Is()); - EXPECT_FALSE(arr->IsRuntimeArray()); -} - -TEST_F(AstArrayTest, CreateRuntimeArray) { - auto* arr = create(ty.u32(), nullptr, utils::Empty); - ASSERT_TRUE(arr->type->Is()); - EXPECT_EQ(Symbols().NameFor(arr->type->As()->name->symbol), "u32"); - EXPECT_EQ(arr->count, nullptr); - EXPECT_TRUE(arr->Is()); - EXPECT_TRUE(arr->IsRuntimeArray()); -} - -TEST_F(AstArrayTest, CreateInferredTypeArray) { - auto* arr = create(nullptr, nullptr, utils::Empty); - EXPECT_EQ(arr->type, nullptr); - EXPECT_EQ(arr->count, nullptr); - EXPECT_TRUE(arr->Is()); - EXPECT_FALSE(arr->IsRuntimeArray()); -} - -TEST_F(AstArrayTest, FriendlyName_RuntimeSized) { - auto* arr = create(ty.i32(), nullptr, utils::Empty); - EXPECT_EQ(arr->FriendlyName(Symbols()), "array"); -} - -TEST_F(AstArrayTest, FriendlyName_LiteralSized) { - auto* arr = create(ty.i32(), Expr(5_u), utils::Empty); - EXPECT_EQ(arr->FriendlyName(Symbols()), "array"); -} - -TEST_F(AstArrayTest, FriendlyName_ConstantSized) { - auto* arr = create(ty.i32(), Expr("size"), utils::Empty); - EXPECT_EQ(arr->FriendlyName(Symbols()), "array"); -} - -TEST_F(AstArrayTest, FriendlyName_WithStride) { - auto* arr = create(ty.i32(), Expr(5_u), utils::Vector{create(32u)}); - EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(32) array"); -} - -TEST_F(AstArrayTest, FriendlyName_InferredTypeAndCount) { - auto* arr = create(nullptr, nullptr, utils::Empty); - EXPECT_EQ(arr->FriendlyName(Symbols()), "array"); -} - -TEST_F(AstArrayTest, FriendlyName_InferredTypeAndCount_WithStrize) { - auto* arr = create(nullptr, nullptr, utils::Vector{create(32u)}); - EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(32) array"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/atomic.cc b/src/tint/ast/atomic.cc deleted file mode 100644 index 9914c6a8bc..0000000000 --- a/src/tint/ast/atomic.cc +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2021 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/atomic.h" - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::Atomic); - -namespace tint::ast { - -Atomic::Atomic(ProgramID pid, NodeID nid, const Source& src, const Type* const subtype) - : Base(pid, nid, src), type(subtype) {} - -std::string Atomic::FriendlyName(const SymbolTable& symbols) const { - std::ostringstream out; - out << "atomic<" << type->FriendlyName(symbols) << ">"; - return out.str(); -} - -Atomic::Atomic(Atomic&&) = default; - -Atomic::~Atomic() = default; - -const Atomic* Atomic::Clone(CloneContext* ctx) const { - // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source); - auto* ty = ctx->Clone(type); - return ctx->dst->create(src, ty); -} - -} // namespace tint::ast diff --git a/src/tint/ast/atomic.h b/src/tint/ast/atomic.h deleted file mode 100644 index 689871e1cf..0000000000 --- a/src/tint/ast/atomic.h +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright 2021 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_TINT_AST_ATOMIC_H_ -#define SRC_TINT_AST_ATOMIC_H_ - -#include - -#include "src/tint/ast/type.h" - -namespace tint::ast { - -/// An atomic type. -class Atomic final : public Castable { - public: - /// Constructor - /// @param pid the identifier of the program that owns this node - /// @param nid the unique node identifier - /// @param src the source of this node - /// @param subtype the pointee type - Atomic(ProgramID pid, NodeID nid, const Source& src, const Type* const subtype); - /// Move constructor - Atomic(Atomic&&); - ~Atomic() override; - - /// @param symbols the program's symbol table - /// @returns the name for this type that closely resembles how it would be - /// declared in WGSL. - std::string FriendlyName(const SymbolTable& symbols) const override; - - /// Clones this type and all transitive types using the `CloneContext` `ctx`. - /// @param ctx the clone context - /// @return the newly cloned type - const Atomic* Clone(CloneContext* ctx) const override; - - /// the pointee type - const Type* const type; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_ATOMIC_H_ diff --git a/src/tint/ast/atomic_test.cc b/src/tint/ast/atomic_test.cc deleted file mode 100644 index abb906e87e..0000000000 --- a/src/tint/ast/atomic_test.cc +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2021 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/atomic.h" - -#include "src/tint/ast/test_helper.h" - -namespace tint::ast { -namespace { - -using AstAtomicTest = TestHelper; - -TEST_F(AstAtomicTest, Creation) { - auto* i32 = ty.i32(); - auto* p = create(i32); - ASSERT_TRUE(p->type->Is()); - EXPECT_EQ(Symbols().NameFor(p->type->As()->name->symbol), "i32"); -} - -TEST_F(AstAtomicTest, FriendlyName) { - auto* i32 = ty.i32(); - auto* p = create(i32); - EXPECT_EQ(p->FriendlyName(Symbols()), "atomic"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/bitcast_expression.cc b/src/tint/ast/bitcast_expression.cc index 5cabf67e02..4091d7351a 100644 --- a/src/tint/ast/bitcast_expression.cc +++ b/src/tint/ast/bitcast_expression.cc @@ -23,7 +23,7 @@ namespace tint::ast { BitcastExpression::BitcastExpression(ProgramID pid, NodeID nid, const Source& src, - const Type* t, + Type t, const Expression* e) : Base(pid, nid, src), type(t), expr(e) { TINT_ASSERT(AST, type); @@ -37,7 +37,7 @@ BitcastExpression::~BitcastExpression() = default; const BitcastExpression* BitcastExpression::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering auto src = ctx->Clone(source); - auto* t = ctx->Clone(type); + auto t = ctx->Clone(type); auto* e = ctx->Clone(expr); return ctx->dst->create(src, t, e); } diff --git a/src/tint/ast/bitcast_expression.h b/src/tint/ast/bitcast_expression.h index 66952b7247..82d3bd2395 100644 --- a/src/tint/ast/bitcast_expression.h +++ b/src/tint/ast/bitcast_expression.h @@ -16,11 +16,7 @@ #define SRC_TINT_AST_BITCAST_EXPRESSION_H_ #include "src/tint/ast/expression.h" - -// Forward declarations -namespace tint::ast { -class Type; -} // namespace tint::ast +#include "src/tint/ast/type.h" namespace tint::ast { @@ -36,7 +32,7 @@ class BitcastExpression final : public Castable { BitcastExpression(ProgramID pid, NodeID nid, const Source& source, - const Type* type, + Type type, const Expression* expr); /// Move constructor BitcastExpression(BitcastExpression&&); @@ -49,7 +45,7 @@ class BitcastExpression final : public Castable { const BitcastExpression* Clone(CloneContext* ctx) const override; /// the target cast type - const Type* const type; + const Type type; /// the expression const Expression* const expr; }; diff --git a/src/tint/ast/bitcast_expression_test.cc b/src/tint/ast/bitcast_expression_test.cc index 1a446f3856..d288a77490 100644 --- a/src/tint/ast/bitcast_expression_test.cc +++ b/src/tint/ast/bitcast_expression_test.cc @@ -24,17 +24,15 @@ using BitcastExpressionTest = TestHelper; TEST_F(BitcastExpressionTest, Create) { auto* expr = Expr("expr"); - - auto* exp = create(ty.f32(), expr); - ASSERT_TRUE(exp->type->Is()); - EXPECT_EQ(Symbols().NameFor(exp->type->As()->name->symbol), "f32"); + auto* exp = Bitcast(ty.f32(), expr); + CheckIdentifier(Symbols(), exp->type, "f32"); ASSERT_EQ(exp->expr, expr); } TEST_F(BitcastExpressionTest, CreateWithSource) { auto* expr = Expr("expr"); - auto* exp = create(Source{Source::Location{20, 2}}, ty.f32(), expr); + auto* exp = Bitcast(Source{Source::Location{20, 2}}, ty.f32(), expr); auto src = exp->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); @@ -43,7 +41,7 @@ TEST_F(BitcastExpressionTest, CreateWithSource) { TEST_F(BitcastExpressionTest, IsBitcast) { auto* expr = Expr("expr"); - auto* exp = create(ty.f32(), expr); + auto* exp = Bitcast(ty.f32(), expr); EXPECT_TRUE(exp->Is()); } @@ -51,7 +49,7 @@ TEST_F(BitcastExpressionTest, Assert_Null_Type) { EXPECT_FATAL_FAILURE( { ProgramBuilder b; - b.create(nullptr, b.Expr("idx")); + b.Bitcast(ast::Type(), "idx"); }, "internal compiler error"); } @@ -60,7 +58,7 @@ TEST_F(BitcastExpressionTest, Assert_Null_Expr) { EXPECT_FATAL_FAILURE( { ProgramBuilder b; - b.create(b.ty.f32(), nullptr); + b.Bitcast(b.ty.f32(), nullptr); }, "internal compiler error"); } @@ -70,7 +68,7 @@ TEST_F(BitcastExpressionTest, Assert_DifferentProgramID_Expr) { { ProgramBuilder b1; ProgramBuilder b2; - b1.create(b1.ty.f32(), b2.Expr("idx")); + b1.Bitcast(b1.ty.f32(), b2.Expr("idx")); }, "internal compiler error"); } diff --git a/src/tint/ast/builtin_texture_helper_test.cc b/src/tint/ast/builtin_texture_helper_test.cc index df09f1180d..4aefbc67ca 100644 --- a/src/tint/ast/builtin_texture_helper_test.cc +++ b/src/tint/ast/builtin_texture_helper_test.cc @@ -127,7 +127,7 @@ std::ostream& operator<<(std::ostream& out, const TextureOverloadCase& data) { return out; } -const ast::Type* TextureOverloadCase::BuildResultVectorComponentType(ProgramBuilder* b) const { +ast::Type TextureOverloadCase::BuildResultVectorComponentType(ProgramBuilder* b) const { switch (texture_data_type) { case ast::builtin::test::TextureDataType::kF32: return b->ty.f32(); @@ -166,7 +166,7 @@ const ast::Variable* TextureOverloadCase::BuildTextureVariable(ProgramBuilder* b attrs); case ast::builtin::test::TextureKind::kStorage: { - auto* st = b->ty.storage_texture(texture_dimension, texel_format, access); + auto st = b->ty.storage_texture(texture_dimension, texel_format, access); return b->GlobalVar(kTextureName, st, attrs); } } diff --git a/src/tint/ast/builtin_texture_helper_test.h b/src/tint/ast/builtin_texture_helper_test.h index 7130b9a019..6fe0193770 100644 --- a/src/tint/ast/builtin_texture_helper_test.h +++ b/src/tint/ast/builtin_texture_helper_test.h @@ -224,7 +224,7 @@ struct TextureOverloadCase { /// @param builder the AST builder used for the test /// @returns the vector component type of the texture function return value - const ast::Type* BuildResultVectorComponentType(ProgramBuilder* builder) const; + ast::Type BuildResultVectorComponentType(ProgramBuilder* builder) const; /// @param builder the AST builder used for the test /// @returns a variable holding the test texture, automatically registered as /// a global variable. diff --git a/src/tint/ast/call_expression.cc b/src/tint/ast/call_expression.cc index 145092f5d2..9da71066f6 100644 --- a/src/tint/ast/call_expression.cc +++ b/src/tint/ast/call_expression.cc @@ -22,41 +22,14 @@ TINT_INSTANTIATE_TYPEINFO(tint::ast::CallExpression); namespace tint::ast { -namespace { -CallExpression::Target ToTarget(const Identifier* name) { - CallExpression::Target target; - target.name = name; - return target; -} -CallExpression::Target ToTarget(const Type* type) { - CallExpression::Target target; - target.type = type; - return target; -} -} // namespace - CallExpression::CallExpression(ProgramID pid, NodeID nid, const Source& src, - const Identifier* name, + const IdentifierExpression* t, utils::VectorRef a) - : Base(pid, nid, src), target(ToTarget(name)), args(std::move(a)) { - TINT_ASSERT(AST, name); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, name, program_id); - for (auto* arg : args) { - TINT_ASSERT(AST, arg); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, arg, program_id); - } -} - -CallExpression::CallExpression(ProgramID pid, - NodeID nid, - const Source& src, - const Type* type, - utils::VectorRef a) - : Base(pid, nid, src), target(ToTarget(type)), args(std::move(a)) { - TINT_ASSERT(AST, type); - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, type, program_id); + : Base(pid, nid, src), target(t), args(std::move(a)) { + TINT_ASSERT(AST, target); + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, target, program_id); for (auto* arg : args) { TINT_ASSERT(AST, arg); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, arg, program_id); @@ -71,9 +44,8 @@ const CallExpression* CallExpression::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering auto src = ctx->Clone(source); auto p = ctx->Clone(args); - return target.name - ? ctx->dst->create(src, ctx->Clone(target.name), std::move(p)) - : ctx->dst->create(src, ctx->Clone(target.type), std::move(p)); + auto t = ctx->Clone(target); + return ctx->dst->create(src, t, std::move(p)); } } // namespace tint::ast diff --git a/src/tint/ast/call_expression.h b/src/tint/ast/call_expression.h index a3b6edcf6c..b22ec11f92 100644 --- a/src/tint/ast/call_expression.h +++ b/src/tint/ast/call_expression.h @@ -19,8 +19,7 @@ // Forward declarations namespace tint::ast { -class Type; -class Identifier; +class IdentifierExpression; } // namespace tint::ast namespace tint::ast { @@ -36,24 +35,12 @@ class CallExpression final : public Castable { /// @param pid the identifier of the program that owns this node /// @param nid the unique node identifier /// @param source the call expression source - /// @param name the function or type name + /// @param target the target of the call /// @param args the arguments CallExpression(ProgramID pid, NodeID nid, const Source& source, - const Identifier* name, - utils::VectorRef args); - - /// Constructor - /// @param pid the identifier of the program that owns this node - /// @param nid the unique node identifier - /// @param source the call expression source - /// @param type the type - /// @param args the arguments - CallExpression(ProgramID pid, - NodeID nid, - const Source& source, - const Type* type, + const IdentifierExpression* target, utils::VectorRef args); /// Move constructor @@ -66,18 +53,8 @@ class CallExpression final : public Castable { /// @return the newly cloned node const CallExpression* Clone(CloneContext* ctx) const override; - /// Target is either an identifier, or a Type. - /// One of these must be nullptr and the other a non-nullptr. - struct Target { - /// name is a function or builtin to call, or type name to construct or - /// cast-to - const Identifier* name = nullptr; - /// type to construct or cast-to - const Type* type = nullptr; - }; - - /// The target function - const Target target; + /// The target function or type + const IdentifierExpression* target; /// The arguments const utils::Vector args; diff --git a/src/tint/ast/call_expression_test.cc b/src/tint/ast/call_expression_test.cc index 12b446a798..6a6ee29b07 100644 --- a/src/tint/ast/call_expression_test.cc +++ b/src/tint/ast/call_expression_test.cc @@ -21,15 +21,14 @@ namespace { using CallExpressionTest = TestHelper; TEST_F(CallExpressionTest, CreationIdentifier) { - auto* func = Ident("func"); + auto* func = Expr("func"); utils::Vector params{ Expr("param1"), Expr("param2"), }; auto* stmt = Call(func, params); - EXPECT_EQ(stmt->target.name, func); - EXPECT_EQ(stmt->target.type, nullptr); + EXPECT_EQ(stmt->target, func); const auto& vec = stmt->args; ASSERT_EQ(vec.Length(), 2u); @@ -38,10 +37,9 @@ TEST_F(CallExpressionTest, CreationIdentifier) { } TEST_F(CallExpressionTest, CreationIdentifier_WithSource) { - auto* func = Ident("func"); + auto* func = Expr("func"); auto* stmt = Call(Source{{20, 2}}, func); - EXPECT_EQ(stmt->target.name, func); - EXPECT_EQ(stmt->target.type, nullptr); + EXPECT_EQ(stmt->target, func); auto src = stmt->source; EXPECT_EQ(src.range.begin.line, 20u); @@ -49,15 +47,14 @@ TEST_F(CallExpressionTest, CreationIdentifier_WithSource) { } TEST_F(CallExpressionTest, CreationType) { - auto* type = ty.f32(); + auto* type = Expr(ty.f32()); utils::Vector params{ Expr("param1"), Expr("param2"), }; auto* stmt = Call(type, params); - EXPECT_EQ(stmt->target.name, nullptr); - EXPECT_EQ(stmt->target.type, type); + EXPECT_EQ(stmt->target, type); const auto& vec = stmt->args; ASSERT_EQ(vec.Length(), 2u); @@ -66,10 +63,9 @@ TEST_F(CallExpressionTest, CreationType) { } TEST_F(CallExpressionTest, CreationType_WithSource) { - auto* type = ty.f32(); + auto* type = Expr(ty.f32()); auto* stmt = Call(Source{{20, 2}}, type); - EXPECT_EQ(stmt->target.name, nullptr); - EXPECT_EQ(stmt->target.type, type); + EXPECT_EQ(stmt->target, type); auto src = stmt->source; EXPECT_EQ(src.range.begin.line, 20u); @@ -77,7 +73,7 @@ TEST_F(CallExpressionTest, CreationType_WithSource) { } TEST_F(CallExpressionTest, IsCall) { - auto* func = Ident("func"); + auto* func = Expr("func"); auto* stmt = Call(func); EXPECT_TRUE(stmt->Is()); } @@ -91,15 +87,6 @@ TEST_F(CallExpressionTest, Assert_Null_Identifier) { "internal compiler error"); } -TEST_F(CallExpressionTest, Assert_Null_Type) { - EXPECT_FATAL_FAILURE( - { - ProgramBuilder b; - b.Call(static_cast(nullptr)); - }, - "internal compiler error"); -} - TEST_F(CallExpressionTest, Assert_Null_Param) { EXPECT_FATAL_FAILURE( { diff --git a/src/tint/ast/const.cc b/src/tint/ast/const.cc index 79466c0776..60f9bef53a 100644 --- a/src/tint/ast/const.cc +++ b/src/tint/ast/const.cc @@ -26,7 +26,7 @@ Const::Const(ProgramID pid, NodeID nid, const Source& src, const Identifier* n, - const ast::Type* ty, + Type ty, const Expression* init, utils::VectorRef attrs) : Base(pid, nid, src, n, ty, init, std::move(attrs)) { @@ -44,7 +44,7 @@ const char* Const::Kind() const { const Const* Const::Clone(CloneContext* ctx) const { auto src = ctx->Clone(source); auto n = ctx->Clone(name); - auto* ty = ctx->Clone(type); + auto ty = ctx->Clone(type); auto* init = ctx->Clone(initializer); auto attrs = ctx->Clone(attributes); return ctx->dst->create(src, n, ty, init, std::move(attrs)); diff --git a/src/tint/ast/const.h b/src/tint/ast/const.h index aa73d4f4b8..75dc7675a0 100644 --- a/src/tint/ast/const.h +++ b/src/tint/ast/const.h @@ -44,7 +44,7 @@ class Const final : public Castable { NodeID nid, const Source& source, const Identifier* name, - const ast::Type* type, + Type type, const Expression* initializer, utils::VectorRef attributes); diff --git a/src/tint/ast/function.cc b/src/tint/ast/function.cc index 5c0597a1a7..3c5446c066 100644 --- a/src/tint/ast/function.cc +++ b/src/tint/ast/function.cc @@ -27,7 +27,7 @@ Function::Function(ProgramID pid, const Source& src, const Identifier* n, utils::VectorRef parameters, - const Type* return_ty, + Type return_ty, const BlockStatement* b, utils::VectorRef attrs, utils::VectorRef return_type_attrs) @@ -73,7 +73,7 @@ const Function* Function::Clone(CloneContext* ctx) const { auto src = ctx->Clone(source); auto n = ctx->Clone(name); auto p = ctx->Clone(params); - auto* ret = ctx->Clone(return_type); + auto ret = ctx->Clone(return_type); auto* b = ctx->Clone(body); auto attrs = ctx->Clone(attributes); auto ret_attrs = ctx->Clone(return_type_attributes); diff --git a/src/tint/ast/function.h b/src/tint/ast/function.h index fd39ba3974..802f46dbbc 100644 --- a/src/tint/ast/function.h +++ b/src/tint/ast/function.h @@ -32,6 +32,7 @@ // Forward declarations namespace tint::ast { class Identifier; +class IdentifierExpression; } // namespace tint::ast namespace tint::ast { @@ -54,7 +55,7 @@ class Function final : public Castable { const Source& source, const Identifier* name, utils::VectorRef params, - const Type* return_type, + Type return_type, const BlockStatement* body, utils::VectorRef attributes, utils::VectorRef return_type_attributes); @@ -82,7 +83,7 @@ class Function final : public Castable { const utils::Vector params; /// The function return type - const Type* const return_type; + const Type return_type; /// The function body const BlockStatement* const body; diff --git a/src/tint/ast/function_test.cc b/src/tint/ast/function_test.cc index 90afda1512..a9b327e666 100644 --- a/src/tint/ast/function_test.cc +++ b/src/tint/ast/function_test.cc @@ -27,13 +27,13 @@ using FunctionTest = TestHelper; TEST_F(FunctionTest, Creation_i32ReturnType) { utils::Vector params{Param("var", ty.i32())}; - auto* i32 = ty.i32(); + auto i32 = ty.i32(); auto* var = params[0]; auto* f = Func("func", params, i32, utils::Empty); EXPECT_EQ(f->name->symbol, Symbols().Get("func")); ASSERT_EQ(f->params.Length(), 1u); - EXPECT_EQ(f->return_type, i32); + CheckIdentifier(Symbols(), f->return_type, "i32"); EXPECT_EQ(f->params[0], var); } @@ -116,15 +116,6 @@ TEST_F(FunctionTest, Assert_TemplatedName) { "internal compiler error"); } -TEST_F(FunctionTest, Assert_InvalidName) { - EXPECT_FATAL_FAILURE( - { - ProgramBuilder b; - b.Func("", utils::Empty, b.ty.void_(), utils::Empty); - }, - "internal compiler error"); -} - TEST_F(FunctionTest, Assert_NullParam) { using ParamList = utils::Vector; EXPECT_FATAL_FAILURE( diff --git a/src/tint/ast/identifier_expression_test.cc b/src/tint/ast/identifier_expression_test.cc index 6eb951c1eb..e31b654ab5 100644 --- a/src/tint/ast/identifier_expression_test.cc +++ b/src/tint/ast/identifier_expression_test.cc @@ -44,11 +44,6 @@ TEST_F(IdentifierExpressionTest, Creation_WithSource) { EXPECT_EQ(i->identifier->source.range, (Source::Range{{20, 2}})); } -TEST_F(IdentifierExpressionTest, IsIdentifier) { - auto* i = Expr("ident"); - EXPECT_TRUE(i->Is()); -} - TEST_F(IdentifierExpressionTest, Assert_InvalidSymbol) { EXPECT_FATAL_FAILURE( { diff --git a/src/tint/ast/let.cc b/src/tint/ast/let.cc index fd16d68fcd..e899f56069 100644 --- a/src/tint/ast/let.cc +++ b/src/tint/ast/let.cc @@ -26,7 +26,7 @@ Let::Let(ProgramID pid, NodeID nid, const Source& src, const Identifier* n, - const ast::Type* ty, + Type ty, const Expression* init, utils::VectorRef attrs) : Base(pid, nid, src, n, ty, init, std::move(attrs)) { @@ -44,7 +44,7 @@ const char* Let::Kind() const { const Let* Let::Clone(CloneContext* ctx) const { auto src = ctx->Clone(source); auto* n = ctx->Clone(name); - auto* ty = ctx->Clone(type); + auto ty = ctx->Clone(type); auto* init = ctx->Clone(initializer); auto attrs = ctx->Clone(attributes); return ctx->dst->create(src, n, ty, init, std::move(attrs)); diff --git a/src/tint/ast/let.h b/src/tint/ast/let.h index e0848aa36d..7ff84b2b7f 100644 --- a/src/tint/ast/let.h +++ b/src/tint/ast/let.h @@ -41,7 +41,7 @@ class Let final : public Castable { NodeID nid, const Source& source, const Identifier* name, - const ast::Type* type, + Type type, const Expression* initializer, utils::VectorRef attributes); diff --git a/src/tint/ast/matrix.cc b/src/tint/ast/matrix.cc deleted file mode 100644 index 69371274f9..0000000000 --- a/src/tint/ast/matrix.cc +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/matrix.h" - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::Matrix); - -namespace tint::ast { - -Matrix::Matrix(ProgramID pid, - NodeID nid, - const Source& src, - const Type* subtype, - uint32_t r, - uint32_t c) - : Base(pid, nid, src), type(subtype), rows(r), columns(c) { - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, subtype, program_id); - TINT_ASSERT(AST, rows > 1); - TINT_ASSERT(AST, rows < 5); - TINT_ASSERT(AST, columns > 1); - TINT_ASSERT(AST, columns < 5); -} - -Matrix::Matrix(Matrix&&) = default; - -Matrix::~Matrix() = default; - -std::string Matrix::FriendlyName(const SymbolTable& symbols) const { - std::ostringstream out; - out << "mat" << columns << "x" << rows; - if (type) { - out << "<" << type->FriendlyName(symbols) << ">"; - } - return out.str(); -} - -const Matrix* Matrix::Clone(CloneContext* ctx) const { - // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source); - auto* ty = ctx->Clone(type); - return ctx->dst->create(src, ty, rows, columns); -} - -} // namespace tint::ast diff --git a/src/tint/ast/matrix.h b/src/tint/ast/matrix.h deleted file mode 100644 index 00bf658595..0000000000 --- a/src/tint/ast/matrix.h +++ /dev/null @@ -1,70 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_TINT_AST_MATRIX_H_ -#define SRC_TINT_AST_MATRIX_H_ - -#include - -#include "src/tint/ast/type.h" - -namespace tint::ast { - -/// A matrix type -class Matrix final : public Castable { - public: - /// Constructor - /// @param pid the identifier of the program that owns this node - /// @param nid the unique node identifier - /// @param src the source of this node - /// @param subtype the declared type of the matrix components. May be null for - /// matrix initializers, where the element type will be inferred from - /// the initializer arguments - /// @param rows the number of rows in the matrix - /// @param columns the number of columns in the matrix - Matrix(ProgramID pid, - NodeID nid, - const Source& src, - const Type* subtype, - uint32_t rows, - uint32_t columns); - /// Move constructor - Matrix(Matrix&&); - ~Matrix() override; - - /// @param symbols the program's symbol table - /// @returns the name for this type that closely resembles how it would be - /// declared in WGSL. - std::string FriendlyName(const SymbolTable& symbols) const override; - - /// Clones this type and all transitive types using the `CloneContext` `ctx`. - /// @param ctx the clone context - /// @return the newly cloned type - const Matrix* Clone(CloneContext* ctx) const override; - - /// The declared type of the matrix components. May be null for matrix - /// initializers, where the element type will be inferred from the initializer - /// arguments - const Type* const type; - - /// The number of rows in the matrix - const uint32_t rows; - - /// The number of columns in the matrix - const uint32_t columns; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_MATRIX_H_ diff --git a/src/tint/ast/matrix_test.cc b/src/tint/ast/matrix_test.cc deleted file mode 100644 index 2199f782d3..0000000000 --- a/src/tint/ast/matrix_test.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/matrix.h" -#include "src/tint/ast/alias.h" -#include "src/tint/ast/array.h" -#include "src/tint/ast/pointer.h" -#include "src/tint/ast/struct.h" -#include "src/tint/ast/test_helper.h" -#include "src/tint/ast/texture.h" -#include "src/tint/ast/vector.h" -#include "src/tint/type/access.h" - -namespace tint::ast { -namespace { - -using AstMatrixTest = TestHelper; - -TEST_F(AstMatrixTest, Creation) { - auto* m = create(ty.i32(), 2u, 4u); - ASSERT_TRUE(m->type->Is()); - EXPECT_EQ(Symbols().NameFor(m->type->As()->name->symbol), "i32"); - EXPECT_EQ(m->rows, 2u); - EXPECT_EQ(m->columns, 4u); -} - -TEST_F(AstMatrixTest, FriendlyName) { - auto* m = create(ty.i32(), 3u, 2u); - EXPECT_EQ(m->FriendlyName(Symbols()), "mat2x3"); -} - -TEST_F(AstMatrixTest, FriendlyName_WithoutType) { - auto* m = create(nullptr, 3u, 2u); - EXPECT_EQ(m->FriendlyName(Symbols()), "mat2x3"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/module.h b/src/tint/ast/module.h index 6ccfaca6b8..a19f2bd626 100644 --- a/src/tint/ast/module.h +++ b/src/tint/ast/module.h @@ -21,7 +21,6 @@ #include "src/tint/ast/diagnostic_directive.h" #include "src/tint/ast/enable.h" #include "src/tint/ast/function.h" -#include "src/tint/ast/type.h" #include "src/tint/utils/vector.h" namespace tint::ast { diff --git a/src/tint/ast/multisampled_texture.cc b/src/tint/ast/multisampled_texture.cc deleted file mode 100644 index 05aea9dcd8..0000000000 --- a/src/tint/ast/multisampled_texture.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/multisampled_texture.h" - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::MultisampledTexture); - -namespace tint::ast { - -MultisampledTexture::MultisampledTexture(ProgramID pid, - NodeID nid, - const Source& src, - type::TextureDimension d, - const Type* ty) - : Base(pid, nid, src, d), type(ty) { - TINT_ASSERT(AST, type); -} - -MultisampledTexture::MultisampledTexture(MultisampledTexture&&) = default; - -MultisampledTexture::~MultisampledTexture() = default; - -std::string MultisampledTexture::FriendlyName(const SymbolTable& symbols) const { - std::ostringstream out; - out << "texture_multisampled_" << dim << "<" << type->FriendlyName(symbols) << ">"; - return out.str(); -} - -const MultisampledTexture* MultisampledTexture::Clone(CloneContext* ctx) const { - // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source); - auto* ty = ctx->Clone(type); - return ctx->dst->create(src, dim, ty); -} - -} // namespace tint::ast diff --git a/src/tint/ast/multisampled_texture.h b/src/tint/ast/multisampled_texture.h deleted file mode 100644 index dfa192ebe4..0000000000 --- a/src/tint/ast/multisampled_texture.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_TINT_AST_MULTISAMPLED_TEXTURE_H_ -#define SRC_TINT_AST_MULTISAMPLED_TEXTURE_H_ - -#include - -#include "src/tint/ast/texture.h" -#include "src/tint/type/texture_dimension.h" - -namespace tint::ast { - -/// A multisampled texture type. -class MultisampledTexture final : public Castable { - public: - /// Constructor - /// @param pid the identifier of the program that owns this node - /// @param nid the unique node identifier - /// @param src the source of this node - /// @param dim the dimensionality of the texture - /// @param type the data type of the multisampled texture - MultisampledTexture(ProgramID pid, - NodeID nid, - const Source& src, - type::TextureDimension dim, - const Type* type); - /// Move constructor - MultisampledTexture(MultisampledTexture&&); - ~MultisampledTexture() override; - - /// @param symbols the program's symbol table - /// @returns the name for this type that closely resembles how it would be - /// declared in WGSL. - std::string FriendlyName(const SymbolTable& symbols) const override; - - /// Clones this type and all transitive types using the `CloneContext` `ctx`. - /// @param ctx the clone context - /// @return the newly cloned type - const MultisampledTexture* Clone(CloneContext* ctx) const override; - - /// The subtype of the multisampled texture - const Type* const type; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_MULTISAMPLED_TEXTURE_H_ diff --git a/src/tint/ast/multisampled_texture_test.cc b/src/tint/ast/multisampled_texture_test.cc deleted file mode 100644 index 6b8125c903..0000000000 --- a/src/tint/ast/multisampled_texture_test.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/multisampled_texture.h" - -#include "src/tint/ast/alias.h" -#include "src/tint/ast/array.h" -#include "src/tint/ast/matrix.h" -#include "src/tint/ast/pointer.h" -#include "src/tint/ast/sampled_texture.h" -#include "src/tint/ast/struct.h" -#include "src/tint/ast/test_helper.h" -#include "src/tint/ast/texture.h" -#include "src/tint/ast/vector.h" -#include "src/tint/type/access.h" - -namespace tint::ast { -namespace { - -using AstMultisampledTextureTest = TestHelper; - -TEST_F(AstMultisampledTextureTest, IsTexture) { - Texture* t = create(type::TextureDimension::kCube, ty.f32()); - EXPECT_TRUE(t->Is()); - EXPECT_FALSE(t->Is()); -} - -TEST_F(AstMultisampledTextureTest, Dim) { - auto* s = create(type::TextureDimension::k3d, ty.f32()); - EXPECT_EQ(s->dim, type::TextureDimension::k3d); -} - -TEST_F(AstMultisampledTextureTest, Type) { - auto* s = create(type::TextureDimension::k3d, ty.f32()); - ASSERT_TRUE(s->type->Is()); - EXPECT_EQ(Symbols().NameFor(s->type->As()->name->symbol), "f32"); -} - -TEST_F(AstMultisampledTextureTest, FriendlyName) { - auto* s = create(type::TextureDimension::k3d, ty.f32()); - EXPECT_EQ(s->FriendlyName(Symbols()), "texture_multisampled_3d"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/override.cc b/src/tint/ast/override.cc index e7bee057a3..79f0772098 100644 --- a/src/tint/ast/override.cc +++ b/src/tint/ast/override.cc @@ -26,7 +26,7 @@ Override::Override(ProgramID pid, NodeID nid, const Source& src, const Identifier* n, - const ast::Type* ty, + Type ty, const Expression* init, utils::VectorRef attrs) : Base(pid, nid, src, n, ty, init, std::move(attrs)) {} @@ -42,7 +42,7 @@ const char* Override::Kind() const { const Override* Override::Clone(CloneContext* ctx) const { auto src = ctx->Clone(source); auto* n = ctx->Clone(name); - auto* ty = ctx->Clone(type); + auto ty = ctx->Clone(type); auto* init = ctx->Clone(initializer); auto attrs = ctx->Clone(attributes); return ctx->dst->create(src, n, ty, init, std::move(attrs)); diff --git a/src/tint/ast/override.h b/src/tint/ast/override.h index c75035ee7a..531d147248 100644 --- a/src/tint/ast/override.h +++ b/src/tint/ast/override.h @@ -44,7 +44,7 @@ class Override final : public Castable { NodeID nid, const Source& source, const Identifier* name, - const ast::Type* type, + Type type, const Expression* initializer, utils::VectorRef attributes); diff --git a/src/tint/ast/parameter.cc b/src/tint/ast/parameter.cc index adbeb27e85..a2c6e5b474 100644 --- a/src/tint/ast/parameter.cc +++ b/src/tint/ast/parameter.cc @@ -26,7 +26,7 @@ Parameter::Parameter(ProgramID pid, NodeID nid, const Source& src, const Identifier* n, - const ast::Type* ty, + Type ty, utils::VectorRef attrs) : Base(pid, nid, src, n, ty, nullptr, std::move(attrs)) {} @@ -41,7 +41,7 @@ const char* Parameter::Kind() const { const Parameter* Parameter::Clone(CloneContext* ctx) const { auto src = ctx->Clone(source); auto* n = ctx->Clone(name); - auto* ty = ctx->Clone(type); + auto ty = ctx->Clone(type); auto attrs = ctx->Clone(attributes); return ctx->dst->create(src, n, ty, std::move(attrs)); } diff --git a/src/tint/ast/parameter.h b/src/tint/ast/parameter.h index 79d1856e53..7ea49ae466 100644 --- a/src/tint/ast/parameter.h +++ b/src/tint/ast/parameter.h @@ -44,7 +44,7 @@ class Parameter final : public Castable { NodeID nid, const Source& source, const Identifier* name, - const ast::Type* type, + Type type, utils::VectorRef attributes); /// Move constructor diff --git a/src/tint/ast/pointer.cc b/src/tint/ast/pointer.cc deleted file mode 100644 index 2216872bbd..0000000000 --- a/src/tint/ast/pointer.cc +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/pointer.h" - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::Pointer); - -namespace tint::ast { - -Pointer::Pointer(ProgramID pid, - NodeID nid, - const Source& src, - const Type* const subtype, - type::AddressSpace addr_space, - type::Access ac) - : Base(pid, nid, src), type(subtype), address_space(addr_space), access(ac) {} - -std::string Pointer::FriendlyName(const SymbolTable& symbols) const { - std::ostringstream out; - out << "ptr<"; - if (address_space != type::AddressSpace::kNone) { - out << address_space << ", "; - } - out << type->FriendlyName(symbols); - if (access != type::Access::kUndefined) { - out << ", " << access; - } - out << ">"; - return out.str(); -} - -Pointer::Pointer(Pointer&&) = default; - -Pointer::~Pointer() = default; - -const Pointer* Pointer::Clone(CloneContext* ctx) const { - // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source); - auto* ty = ctx->Clone(type); - return ctx->dst->create(src, ty, address_space, access); -} - -} // namespace tint::ast diff --git a/src/tint/ast/pointer.h b/src/tint/ast/pointer.h deleted file mode 100644 index dda146accc..0000000000 --- a/src/tint/ast/pointer.h +++ /dev/null @@ -1,68 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_TINT_AST_POINTER_H_ -#define SRC_TINT_AST_POINTER_H_ - -#include - -#include "src/tint/ast/type.h" -#include "src/tint/type/access.h" -#include "src/tint/type/address_space.h" - -namespace tint::ast { - -/// A pointer type. -class Pointer final : public Castable { - public: - /// Constructor - /// @param pid the identifier of the program that owns this node - /// @param nid the unique node identifier - /// @param src the source of this node - /// @param subtype the pointee type - /// @param address_space the address space of the pointer - /// @param access the access control of the pointer - Pointer(ProgramID pid, - NodeID nid, - const Source& src, - const Type* const subtype, - type::AddressSpace address_space, - type::Access access); - /// Move constructor - Pointer(Pointer&&); - ~Pointer() override; - - /// @param symbols the program's symbol table - /// @returns the name for this type that closely resembles how it would be - /// declared in WGSL. - std::string FriendlyName(const SymbolTable& symbols) const override; - - /// Clones this type and all transitive types using the `CloneContext` `ctx`. - /// @param ctx the clone context - /// @return the newly cloned type - const Pointer* Clone(CloneContext* ctx) const override; - - /// The pointee type - const Type* const type; - - /// The address space of the pointer - type::AddressSpace const address_space; - - /// The access control of the pointer - type::Access const access; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_POINTER_H_ diff --git a/src/tint/ast/pointer_test.cc b/src/tint/ast/pointer_test.cc deleted file mode 100644 index ad2ff157d2..0000000000 --- a/src/tint/ast/pointer_test.cc +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/pointer.h" - -#include "src/tint/ast/test_helper.h" - -namespace tint::ast { -namespace { - -using AstPointerTest = TestHelper; - -TEST_F(AstPointerTest, Creation) { - auto* p = create(ty.i32(), type::AddressSpace::kStorage, type::Access::kRead); - ASSERT_TRUE(p->type->Is()); - EXPECT_EQ(Symbols().NameFor(p->type->As()->name->symbol), "i32"); - EXPECT_EQ(p->address_space, type::AddressSpace::kStorage); - EXPECT_EQ(p->access, type::Access::kRead); -} - -TEST_F(AstPointerTest, FriendlyName) { - auto* p = create(ty.i32(), type::AddressSpace::kWorkgroup, type::Access::kUndefined); - EXPECT_EQ(p->FriendlyName(Symbols()), "ptr"); -} - -TEST_F(AstPointerTest, FriendlyNameWithAccess) { - auto* p = create(ty.i32(), type::AddressSpace::kStorage, type::Access::kReadWrite); - EXPECT_EQ(p->FriendlyName(Symbols()), "ptr"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/sampled_texture.cc b/src/tint/ast/sampled_texture.cc deleted file mode 100644 index cc33962c6a..0000000000 --- a/src/tint/ast/sampled_texture.cc +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/sampled_texture.h" - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::SampledTexture); - -namespace tint::ast { - -SampledTexture::SampledTexture(ProgramID pid, - NodeID nid, - const Source& src, - type::TextureDimension d, - const Type* ty) - : Base(pid, nid, src, d), type(ty) { - TINT_ASSERT(AST, type); -} - -SampledTexture::SampledTexture(SampledTexture&&) = default; - -SampledTexture::~SampledTexture() = default; - -std::string SampledTexture::FriendlyName(const SymbolTable& symbols) const { - std::ostringstream out; - out << "texture_" << dim << "<" << type->FriendlyName(symbols) << ">"; - return out.str(); -} - -const SampledTexture* SampledTexture::Clone(CloneContext* ctx) const { - // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source); - auto* ty = ctx->Clone(type); - return ctx->dst->create(src, dim, ty); -} - -} // namespace tint::ast diff --git a/src/tint/ast/sampled_texture.h b/src/tint/ast/sampled_texture.h deleted file mode 100644 index 4ad7aa7e6b..0000000000 --- a/src/tint/ast/sampled_texture.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_TINT_AST_SAMPLED_TEXTURE_H_ -#define SRC_TINT_AST_SAMPLED_TEXTURE_H_ - -#include - -#include "src/tint/ast/texture.h" -#include "src/tint/type/texture_dimension.h" - -namespace tint::ast { - -/// A sampled texture type. -class SampledTexture final : public Castable { - public: - /// Constructor - /// @param pid the identifier of the program that owns this node - /// @param nid the unique node identifier - /// @param src the source of this node - /// @param dim the dimensionality of the texture - /// @param type the data type of the sampled texture - SampledTexture(ProgramID pid, - NodeID nid, - const Source& src, - type::TextureDimension dim, - const Type* type); - /// Move constructor - SampledTexture(SampledTexture&&); - ~SampledTexture() override; - - /// @param symbols the program's symbol table - /// @returns the name for this type that closely resembles how it would be - /// declared in WGSL. - std::string FriendlyName(const SymbolTable& symbols) const override; - - /// Clones this type and all transitive types using the `CloneContext` `ctx`. - /// @param ctx the clone context - /// @return the newly cloned type - const SampledTexture* Clone(CloneContext* ctx) const override; - - /// The subtype of the sampled texture - const Type* const type; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_SAMPLED_TEXTURE_H_ diff --git a/src/tint/ast/sampled_texture_test.cc b/src/tint/ast/sampled_texture_test.cc deleted file mode 100644 index 01d7b656a9..0000000000 --- a/src/tint/ast/sampled_texture_test.cc +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/sampled_texture.h" - -#include "src/tint/ast/test_helper.h" - -namespace tint::ast { -namespace { - -using AstSampledTextureTest = TestHelper; - -TEST_F(AstSampledTextureTest, IsTexture) { - Texture* t = create(type::TextureDimension::kCube, ty.f32()); - EXPECT_TRUE(t->Is()); -} - -TEST_F(AstSampledTextureTest, Dim) { - auto* s = create(type::TextureDimension::k3d, ty.f32()); - EXPECT_EQ(s->dim, type::TextureDimension::k3d); -} - -TEST_F(AstSampledTextureTest, Type) { - auto* s = create(type::TextureDimension::k3d, ty.f32()); - ASSERT_TRUE(s->type->Is()); - EXPECT_EQ(Symbols().NameFor(s->type->As()->name->symbol), "f32"); -} - -TEST_F(AstSampledTextureTest, FriendlyName) { - auto* s = create(type::TextureDimension::k3d, ty.f32()); - EXPECT_EQ(s->FriendlyName(Symbols()), "texture_3d"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/struct_member.cc b/src/tint/ast/struct_member.cc index 8a3d27a2b8..10f278d99b 100644 --- a/src/tint/ast/struct_member.cc +++ b/src/tint/ast/struct_member.cc @@ -24,7 +24,7 @@ StructMember::StructMember(ProgramID pid, NodeID nid, const Source& src, const Identifier* n, - const ast::Type* ty, + Type ty, utils::VectorRef attrs) : Base(pid, nid, src), name(n), type(ty), attributes(std::move(attrs)) { @@ -47,7 +47,7 @@ const StructMember* StructMember::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering auto src = ctx->Clone(source); auto n = ctx->Clone(name); - auto* ty = ctx->Clone(type); + auto ty = ctx->Clone(type); auto attrs = ctx->Clone(attributes); return ctx->dst->create(src, n, ty, std::move(attrs)); } diff --git a/src/tint/ast/struct_member.h b/src/tint/ast/struct_member.h index 388d404352..fba504ac9f 100644 --- a/src/tint/ast/struct_member.h +++ b/src/tint/ast/struct_member.h @@ -18,11 +18,11 @@ #include #include "src/tint/ast/attribute.h" +#include "src/tint/ast/type.h" // Forward declarations namespace tint::ast { class Identifier; -class Type; } // namespace tint::ast namespace tint::ast { @@ -41,7 +41,7 @@ class StructMember final : public Castable { NodeID nid, const Source& src, const Identifier* name, - const ast::Type* type, + Type type, utils::VectorRef attributes); /// Move constructor StructMember(StructMember&&); @@ -58,7 +58,7 @@ class StructMember final : public Castable { const Identifier* const name; /// The type - const ast::Type* const type; + const Type type; /// The attributes const utils::Vector attributes; diff --git a/src/tint/ast/struct_member_test.cc b/src/tint/ast/struct_member_test.cc index d67b379b4c..94a072ff47 100644 --- a/src/tint/ast/struct_member_test.cc +++ b/src/tint/ast/struct_member_test.cc @@ -23,9 +23,8 @@ using StructMemberTest = TestHelper; TEST_F(StructMemberTest, Creation) { auto* st = Member("a", ty.i32(), utils::Vector{MemberSize(4_a)}); - EXPECT_EQ(Symbols().NameFor(st->name->symbol), "a"); - ASSERT_TRUE(st->type->Is()); - EXPECT_EQ(Symbols().NameFor(st->type->As()->name->symbol), "i32"); + ast::CheckIdentifier(Symbols(), st->name, "a"); + ast::CheckIdentifier(Symbols(), st->type, "i32"); EXPECT_EQ(st->attributes.Length(), 1u); EXPECT_TRUE(st->attributes[0]->Is()); EXPECT_EQ(st->source.range.begin.line, 0u); @@ -37,9 +36,8 @@ TEST_F(StructMemberTest, Creation) { TEST_F(StructMemberTest, CreationWithSource) { auto* st = Member(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 8}}}, "a", ty.i32()); - EXPECT_EQ(Symbols().NameFor(st->name->symbol), "a"); - ASSERT_TRUE(st->type->Is()); - EXPECT_EQ(Symbols().NameFor(st->type->As()->name->symbol), "i32"); + ast::CheckIdentifier(Symbols(), st->name, "a"); + ast::CheckIdentifier(Symbols(), st->type, "i32"); EXPECT_EQ(st->attributes.Length(), 0u); EXPECT_EQ(st->source.range.begin.line, 27u); EXPECT_EQ(st->source.range.begin.column, 4u); @@ -60,7 +58,7 @@ TEST_F(StructMemberTest, Assert_Null_Type) { EXPECT_FATAL_FAILURE( { ProgramBuilder b; - b.Member("a", nullptr); + b.Member("a", ast::Type{}); }, "internal compiler error"); } diff --git a/src/tint/ast/struct_test.cc b/src/tint/ast/struct_test.cc index 072a197ff0..cfb41819e9 100644 --- a/src/tint/ast/struct_test.cc +++ b/src/tint/ast/struct_test.cc @@ -15,12 +15,7 @@ #include "src/tint/ast/struct.h" #include "gtest/gtest-spi.h" #include "src/tint/ast/alias.h" -#include "src/tint/ast/array.h" -#include "src/tint/ast/matrix.h" -#include "src/tint/ast/pointer.h" #include "src/tint/ast/test_helper.h" -#include "src/tint/ast/texture.h" -#include "src/tint/ast/vector.h" #include "src/tint/transform/add_block_attribute.h" namespace tint::ast { diff --git a/src/tint/ast/templated_identifier.cc b/src/tint/ast/templated_identifier.cc index 756b183db6..3a8b545df2 100644 --- a/src/tint/ast/templated_identifier.cc +++ b/src/tint/ast/templated_identifier.cc @@ -26,10 +26,15 @@ TemplatedIdentifier::TemplatedIdentifier(ProgramID pid, NodeID nid, const Source& src, const Symbol& sym, - utils::VectorRef args) - : Base(pid, nid, src, sym), arguments(std::move(args)) { + utils::VectorRef args, + utils::VectorRef attrs) + : Base(pid, nid, src, sym), arguments(std::move(args)), attributes(std::move(attrs)) { + TINT_ASSERT(AST, !arguments.IsEmpty()); // Should have been an Identifier if this fires. for (auto* arg : arguments) { - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, arg, program_id); + TINT_ASSERT_PROGRAM_IDS_EQUAL(AST, arg, program_id); + } + for (auto* attr : attributes) { + TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, attr, program_id); } } @@ -42,7 +47,8 @@ const TemplatedIdentifier* TemplatedIdentifier::Clone(CloneContext* ctx) const { auto src = ctx->Clone(source); auto sym = ctx->Clone(symbol); auto args = ctx->Clone(arguments); - return ctx->dst->create(src, sym, args); + auto attrs = ctx->Clone(attributes); + return ctx->dst->create(src, sym, std::move(args), std::move(attrs)); } } // namespace tint::ast diff --git a/src/tint/ast/templated_identifier.h b/src/tint/ast/templated_identifier.h index 7a49c051a7..9f4b17bc29 100644 --- a/src/tint/ast/templated_identifier.h +++ b/src/tint/ast/templated_identifier.h @@ -19,6 +19,7 @@ // Forward declarations namespace tint::ast { +class Attribute; class Expression; } // namespace tint::ast @@ -33,11 +34,13 @@ class TemplatedIdentifier final : public Castable args); + utils::VectorRef args, + utils::VectorRef attrs); /// Move constructor TemplatedIdentifier(TemplatedIdentifier&&); ~TemplatedIdentifier() override; @@ -49,6 +52,9 @@ class TemplatedIdentifier final : public Castable arguments; + + /// Attributes on the identifier + const utils::Vector attributes; }; } // namespace tint::ast diff --git a/src/tint/ast/test_helper.h b/src/tint/ast/test_helper.h index 03ecda8c8c..9d7b68901b 100644 --- a/src/tint/ast/test_helper.h +++ b/src/tint/ast/test_helper.h @@ -71,14 +71,13 @@ struct IsTemplatedIdentifierMatcher> { static constexpr bool value = true; }; -/// A testing utility for checking that an Identifier and any optional templated arguments match the -/// expected values. +/// A testing utility for checking that an Identifier matches the expected values. /// @param symbols the symbol table /// @param got the identifier /// @param expected the expected identifier name template void CheckIdentifier(const SymbolTable& symbols, const Identifier* got, std::string_view expected) { - EXPECT_FALSE(got->Is()); + EXPECT_FALSE(got->Is()); EXPECT_EQ(symbols.NameFor(got->symbol), expected); } @@ -92,8 +91,8 @@ void CheckIdentifier(const SymbolTable& symbols, const Identifier* ident, const TemplatedIdentifierMatcher& expected) { EXPECT_EQ(symbols.NameFor(ident->symbol), expected.name); - ASSERT_TRUE(ident->Is()); - auto* got = ident->As(); + ASSERT_TRUE(ident->Is()); + auto* got = ident->As(); ASSERT_EQ(got->arguments.Length(), std::tuple_size_v); size_t arg_idx = 0; @@ -103,8 +102,7 @@ void CheckIdentifier(const SymbolTable& symbols, using T = std::decay_t; if constexpr (traits::IsStringLike) { ASSERT_TRUE(got_arg->Is()); - ast::CheckIdentifier(symbols, got_arg->As()->identifier, - expected_arg); + CheckIdentifier(symbols, got_arg->As()->identifier, expected_arg); } else if constexpr (IsTemplatedIdentifierMatcher::value) { ASSERT_TRUE(got_arg->Is()); auto* got_ident = got_arg->As()->identifier; @@ -150,6 +148,33 @@ void CheckIdentifier(const SymbolTable& symbols, std::apply([&](auto&&... args) { ((check_arg(args)), ...); }, expected.args); } +/// A testing utility for checking that an IdentifierExpression matches the expected values. +/// @param symbols the symbol table +/// @param expr the IdentifierExpression +/// @param expected the expected identifier name +template +void CheckIdentifier(const SymbolTable& symbols, + const Expression* expr, + std::string_view expected) { + auto* expr_ident = expr->As(); + ASSERT_NE(expr_ident, nullptr) << "expression is not a IdentifierExpression"; + CheckIdentifier(symbols, expr_ident->identifier, expected); +} + +/// A testing utility for checking that an IdentifierExpression matches the expected name and +/// template arguments. +/// @param symbols the symbol table +/// @param expr the IdentifierExpression +/// @param expected the expected identifier name and arguments +template +void CheckIdentifier(const SymbolTable& symbols, + const Expression* expr, + const TemplatedIdentifierMatcher& expected) { + auto* expr_ident = expr->As(); + ASSERT_NE(expr_ident, nullptr) << "expression is not a IdentifierExpression"; + CheckIdentifier(symbols, expr_ident->identifier, expected); +} + } // namespace tint::ast #endif // SRC_TINT_AST_TEST_HELPER_H_ diff --git a/src/tint/ast/texture.cc b/src/tint/ast/texture.cc deleted file mode 100644 index bcfbcb5381..0000000000 --- a/src/tint/ast/texture.cc +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/texture.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::Texture); - -namespace tint::ast { - -bool IsTextureArray(type::TextureDimension dim) { - switch (dim) { - case type::TextureDimension::k2dArray: - case type::TextureDimension::kCubeArray: - return true; - case type::TextureDimension::k2d: - case type::TextureDimension::kNone: - case type::TextureDimension::k1d: - case type::TextureDimension::k3d: - case type::TextureDimension::kCube: - return false; - } - return false; -} - -int NumCoordinateAxes(type::TextureDimension dim) { - switch (dim) { - case type::TextureDimension::kNone: - return 0; - case type::TextureDimension::k1d: - return 1; - case type::TextureDimension::k2d: - case type::TextureDimension::k2dArray: - return 2; - case type::TextureDimension::k3d: - case type::TextureDimension::kCube: - case type::TextureDimension::kCubeArray: - return 3; - } - return 0; -} - -Texture::Texture(ProgramID pid, NodeID nid, const Source& src, type::TextureDimension d) - : Base(pid, nid, src), dim(d) {} - -Texture::Texture(Texture&&) = default; - -Texture::~Texture() = default; - -} // namespace tint::ast diff --git a/src/tint/ast/texture.h b/src/tint/ast/texture.h deleted file mode 100644 index be78ba906c..0000000000 --- a/src/tint/ast/texture.h +++ /dev/null @@ -1,60 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_TINT_AST_TEXTURE_H_ -#define SRC_TINT_AST_TEXTURE_H_ - -#include "src/tint/ast/type.h" -#include "src/tint/type/texture_dimension.h" - -namespace tint::ast { - -/// @param dim the type::TextureDimension to query -/// @return true if the given type::TextureDimension is an array texture -bool IsTextureArray(type::TextureDimension dim); - -/// Returns the number of axes in the coordinate used for accessing -/// the texture, where an access is one of: sampling, fetching, load, -/// or store. -/// None -> 0 -/// 1D -> 1 -/// 2D, 2DArray -> 2 -/// 3D, Cube, CubeArray -> 3 -/// Note: To sample a cube texture, the coordinate has 3 dimensions, -/// but textureDimensions on a cube or cube array returns a 2-element -/// size, representing the (x,y) size of each cube face, in texels. -/// @param dim the type::TextureDimension to query -/// @return number of dimensions in a coordinate for the dimensionality -int NumCoordinateAxes(type::TextureDimension dim); - -/// A texture type. -class Texture : public Castable { - public: - /// Constructor - /// @param pid the identifier of the program that owns this node - /// @param nid the unique node identifier - /// @param src the source of this node - /// @param dim the dimensionality of the texture - Texture(ProgramID pid, NodeID nid, const Source& src, type::TextureDimension dim); - /// Move constructor - Texture(Texture&&); - ~Texture() override; - - /// The texture dimension - const type::TextureDimension dim; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_TEXTURE_H_ diff --git a/src/tint/ast/texture_test.cc b/src/tint/ast/texture_test.cc deleted file mode 100644 index e1cd4f6812..0000000000 --- a/src/tint/ast/texture_test.cc +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2021 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/texture.h" - -#include "src/tint/ast/alias.h" -#include "src/tint/ast/array.h" -#include "src/tint/ast/matrix.h" -#include "src/tint/ast/pointer.h" -#include "src/tint/ast/struct.h" -#include "src/tint/ast/test_helper.h" -#include "src/tint/ast/vector.h" - -namespace tint::ast { -namespace { - -using AstTextureTypeTest = TestHelper; - -TEST_F(AstTextureTypeTest, IsTextureArray) { - EXPECT_EQ(false, IsTextureArray(type::TextureDimension::kNone)); - EXPECT_EQ(false, IsTextureArray(type::TextureDimension::k1d)); - EXPECT_EQ(false, IsTextureArray(type::TextureDimension::k2d)); - EXPECT_EQ(true, IsTextureArray(type::TextureDimension::k2dArray)); - EXPECT_EQ(false, IsTextureArray(type::TextureDimension::k3d)); - EXPECT_EQ(false, IsTextureArray(type::TextureDimension::kCube)); - EXPECT_EQ(true, IsTextureArray(type::TextureDimension::kCubeArray)); -} - -TEST_F(AstTextureTypeTest, NumCoordinateAxes) { - EXPECT_EQ(0, NumCoordinateAxes(type::TextureDimension::kNone)); - EXPECT_EQ(1, NumCoordinateAxes(type::TextureDimension::k1d)); - EXPECT_EQ(2, NumCoordinateAxes(type::TextureDimension::k2d)); - EXPECT_EQ(2, NumCoordinateAxes(type::TextureDimension::k2dArray)); - EXPECT_EQ(3, NumCoordinateAxes(type::TextureDimension::k3d)); - EXPECT_EQ(3, NumCoordinateAxes(type::TextureDimension::kCube)); - EXPECT_EQ(3, NumCoordinateAxes(type::TextureDimension::kCubeArray)); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/traverse_expressions.h b/src/tint/ast/traverse_expressions.h index ce7ea52e28..629e010756 100644 --- a/src/tint/ast/traverse_expressions.h +++ b/src/tint/ast/traverse_expressions.h @@ -148,7 +148,8 @@ bool TraverseExpressions(const ast::Expression* root, diag::List& diags, CALLBAC PhonyExpression>()))) { return true; // Leaf expression } - TINT_ICE(AST, diags) << "unhandled expression type: " << expr->TypeInfo().name; + TINT_ICE(AST, diags) + << "unhandled expression type: " << (expr ? expr->TypeInfo().name : ""); return false; }); if (!ok) { diff --git a/src/tint/ast/type.cc b/src/tint/ast/type.cc index 6408596c1f..7267c80c1e 100644 --- a/src/tint/ast/type.cc +++ b/src/tint/ast/type.cc @@ -1,4 +1,4 @@ -// Copyright 2020 The Tint Authors. +// Copyright 2023 The Tint Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -13,22 +13,12 @@ // limitations under the License. #include "src/tint/ast/type.h" +#include "src/tint/ast/identifier_expression.h" -#include "src/tint/ast/alias.h" -#include "src/tint/ast/matrix.h" -#include "src/tint/ast/pointer.h" -#include "src/tint/ast/texture.h" -#include "src/tint/ast/vector.h" -#include "src/tint/symbol_table.h" +namespace tint { -TINT_INSTANTIATE_TYPEINFO(tint::ast::Type); +ProgramID ProgramIDOf(ast::Type type) { + return ProgramIDOf(type.expr); +} -namespace tint::ast { - -Type::Type(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} - -Type::Type(Type&&) = default; - -Type::~Type() = default; - -} // namespace tint::ast +} // namespace tint diff --git a/src/tint/ast/type.h b/src/tint/ast/type.h index 4f1f276974..e5d626c67e 100644 --- a/src/tint/ast/type.h +++ b/src/tint/ast/type.h @@ -1,4 +1,4 @@ -// Copyright 2020 The Tint Authors. +// Copyright 2023 The Tint Authors. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -15,38 +15,38 @@ #ifndef SRC_TINT_AST_TYPE_H_ #define SRC_TINT_AST_TYPE_H_ -#include - -#include "src/tint/ast/node.h" -#include "src/tint/clone_context.h" +#include "src/tint/program_id.h" // Forward declarations -namespace tint { -class ProgramBuilder; -class SymbolTable; -} // namespace tint +namespace tint::ast { +class IdentifierExpression; +} // namespace tint::ast namespace tint::ast { -/// Base class for a type in the system -class Type : public Castable { - public: - /// Move constructor - Type(Type&&); - ~Type() override; - /// @param symbols the program's symbol table - /// @returns the name for this type that closely resembles how it would be - /// declared in WGSL. - virtual std::string FriendlyName(const SymbolTable& symbols) const = 0; +/// Type is a thin wrapper around an IdentifierExpression, to help statically disambiguate known +/// type expressions from other expressions. +struct Type { + /// The type expression + const IdentifierExpression* expr = nullptr; - protected: - /// Constructor - /// @param pid the identifier of the program that owns this node - /// @param nid the unique node identifier - /// @param src the source of this node - Type(ProgramID pid, NodeID nid, const Source& src); + /// Indirection operator for accessing the type's expression + /// @return #expr + const IdentifierExpression* operator->() const { return expr; } + + /// Implicit conversion operator to the type's expression + /// @return #expr + operator const IdentifierExpression*() const { return expr; } }; } // namespace tint::ast +namespace tint { + +/// @param type an AST type +/// @returns the ProgramID of the given AST type. +ProgramID ProgramIDOf(ast::Type type); + +} // namespace tint + #endif // SRC_TINT_AST_TYPE_H_ diff --git a/src/tint/ast/type_name.cc b/src/tint/ast/type_name.cc deleted file mode 100644 index 5a02dd98ea..0000000000 --- a/src/tint/ast/type_name.cc +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright 2021 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/type_name.h" - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::TypeName); - -namespace tint::ast { - -TypeName::TypeName(ProgramID pid, NodeID nid, const Source& src, const Identifier* n) - : Base(pid, nid, src), name(n) {} - -TypeName::~TypeName() = default; - -TypeName::TypeName(TypeName&&) = default; - -std::string TypeName::FriendlyName(const SymbolTable& symbols) const { - return symbols.NameFor(name->symbol); -} - -const TypeName* TypeName::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source); - auto n = ctx->Clone(name); - return ctx->dst->create(src, n); -} - -} // namespace tint::ast diff --git a/src/tint/ast/type_name.h b/src/tint/ast/type_name.h deleted file mode 100644 index 2c4025c830..0000000000 --- a/src/tint/ast/type_name.h +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2021 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_TINT_AST_TYPE_NAME_H_ -#define SRC_TINT_AST_TYPE_NAME_H_ - -#include - -#include "src/tint/ast/type.h" - -// Forward declarations -namespace tint::ast { -class Identifier; -} // namespace tint::ast - -namespace tint::ast { - -/// A named type (i.e. struct or alias) -class TypeName final : public Castable { - public: - /// Constructor - /// @param pid the identifier of the program that owns this node - /// @param nid the unique node identifier - /// @param src the source of this node - /// @param name the type name - TypeName(ProgramID pid, NodeID nid, const Source& src, const Identifier* name); - /// Move constructor - TypeName(TypeName&&); - /// Destructor - ~TypeName() override; - - /// @param symbols the program's symbol table - /// @returns the name for this type that closely resembles how it would be - /// declared in WGSL. - std::string FriendlyName(const SymbolTable& symbols) const override; - - /// Clones this type and all transitive types using the `CloneContext` `ctx`. - /// @param ctx the clone context - /// @return the newly cloned type - const TypeName* Clone(CloneContext* ctx) const override; - - /// The type name - Identifier const* const name; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_TYPE_NAME_H_ diff --git a/src/tint/ast/type_name_test.cc b/src/tint/ast/type_name_test.cc deleted file mode 100644 index f5fe496b48..0000000000 --- a/src/tint/ast/type_name_test.cc +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2023 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "gtest/gtest-spi.h" - -#include "src/tint/ast/test_helper.h" - -namespace tint::ast { -namespace { - -using namespace tint::number_suffixes; // NOLINT -using TypeNameTest = TestHelper; - -TEST_F(TypeNameTest, Creation_NonTemplated) { - auto* t = ty("ty"); - ASSERT_NE(t->name, nullptr); - EXPECT_EQ(t->name->symbol, Symbols().Get("ty")); -} - -TEST_F(TypeNameTest, Creation_Templated) { - auto* t = ty("ty", 1_a, 2._a, false); - auto* name = As(t->name); - ASSERT_NE(name, nullptr); - EXPECT_EQ(name->symbol, Symbols().Get("ty")); - ASSERT_EQ(name->arguments.Length(), 3u); - EXPECT_TRUE(name->arguments[0]->Is()); - EXPECT_TRUE(name->arguments[1]->Is()); - EXPECT_TRUE(name->arguments[2]->Is()); -} - -TEST_F(TypeNameTest, Creation_WithSource) { - auto* t = ty(Source{{20, 2}}, "ty"); - ASSERT_NE(t->name, nullptr); - EXPECT_EQ(t->name->symbol, Symbols().Get("ty")); - - auto src = t->source; - EXPECT_EQ(src.range.begin.line, 20u); - EXPECT_EQ(src.range.begin.column, 2u); -} - -TEST_F(TypeNameTest, Assert_InvalidSymbol) { - EXPECT_FATAL_FAILURE( - { - ProgramBuilder b; - b.ty(""); - }, - "internal compiler error"); -} - -TEST_F(TypeNameTest, Assert_DifferentProgramID_Symbol) { - EXPECT_FATAL_FAILURE( - { - ProgramBuilder b1; - ProgramBuilder b2; - b1.ty(b2.Sym("b2")); - }, - "internal compiler error"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/var.cc b/src/tint/ast/var.cc index 87621ae441..b748381470 100644 --- a/src/tint/ast/var.cc +++ b/src/tint/ast/var.cc @@ -24,7 +24,7 @@ Var::Var(ProgramID pid, NodeID nid, const Source& src, const Identifier* n, - const ast::Type* ty, + Type ty, type::AddressSpace address_space, type::Access access, const Expression* init, @@ -44,7 +44,7 @@ const char* Var::Kind() const { const Var* Var::Clone(CloneContext* ctx) const { auto src = ctx->Clone(source); auto* n = ctx->Clone(name); - auto* ty = ctx->Clone(type); + auto ty = ctx->Clone(type); auto* init = ctx->Clone(initializer); auto attrs = ctx->Clone(attributes); return ctx->dst->create(src, n, ty, declared_address_space, declared_access, init, diff --git a/src/tint/ast/var.h b/src/tint/ast/var.h index 977b799adc..e3537d1e32 100644 --- a/src/tint/ast/var.h +++ b/src/tint/ast/var.h @@ -55,7 +55,7 @@ class Var final : public Castable { NodeID nid, const Source& source, const Identifier* name, - const ast::Type* type, + Type type, type::AddressSpace declared_address_space, type::Access declared_access, const Expression* initializer, diff --git a/src/tint/ast/variable.cc b/src/tint/ast/variable.cc index 1049eff4b6..2aa60bfb92 100644 --- a/src/tint/ast/variable.cc +++ b/src/tint/ast/variable.cc @@ -25,7 +25,7 @@ Variable::Variable(ProgramID pid, NodeID nid, const Source& src, const Identifier* n, - const ast::Type* ty, + Type ty, const Expression* init, utils::VectorRef attrs) : Base(pid, nid, src), name(n), type(ty), initializer(init), attributes(std::move(attrs)) { diff --git a/src/tint/ast/variable.h b/src/tint/ast/variable.h index d1797feaa7..7663e4fdce 100644 --- a/src/tint/ast/variable.h +++ b/src/tint/ast/variable.h @@ -22,6 +22,7 @@ #include "src/tint/ast/binding_attribute.h" #include "src/tint/ast/expression.h" #include "src/tint/ast/group_attribute.h" +#include "src/tint/ast/type.h" #include "src/tint/type/access.h" #include "src/tint/type/address_space.h" @@ -29,7 +30,6 @@ namespace tint::ast { class Identifier; class LocationAttribute; -class Type; } // namespace tint::ast namespace tint::ast { @@ -54,7 +54,7 @@ class Variable : public Castable { NodeID nid, const Source& src, const Identifier* name, - const ast::Type* type, + Type type, const Expression* initializer, utils::VectorRef attributes); @@ -80,7 +80,7 @@ class Variable : public Castable { /// The declared variable type. This is null if the type is inferred, e.g.: /// let f = 1.0; /// var i = 1; - const ast::Type* const type; + const Type type; /// The initializer expression or nullptr if none set const Expression* const initializer; diff --git a/src/tint/ast/variable_test.cc b/src/tint/ast/variable_test.cc index 29dc75452f..ff97b2f558 100644 --- a/src/tint/ast/variable_test.cc +++ b/src/tint/ast/variable_test.cc @@ -27,10 +27,9 @@ using VariableTest = TestHelper; TEST_F(VariableTest, Creation) { auto* v = Var("my_var", ty.i32(), type::AddressSpace::kFunction); - EXPECT_EQ(Symbols().NameFor(v->name->symbol), "my_var"); + CheckIdentifier(Symbols(), v->name, "my_var"); EXPECT_EQ(v->declared_address_space, type::AddressSpace::kFunction); - ASSERT_TRUE(v->type->Is()); - EXPECT_EQ(Symbols().NameFor(v->type->As()->name->symbol), "i32"); + CheckIdentifier(Symbols(), v->type, "i32"); EXPECT_EQ(v->source.range.begin.line, 0u); EXPECT_EQ(v->source.range.begin.column, 0u); EXPECT_EQ(v->source.range.end.line, 0u); @@ -41,10 +40,9 @@ TEST_F(VariableTest, CreationWithSource) { auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 5}}}, "i", ty.f32(), type::AddressSpace::kPrivate, utils::Empty); - EXPECT_EQ(Symbols().NameFor(v->name->symbol), "i"); + CheckIdentifier(Symbols(), v->name, "i"); EXPECT_EQ(v->declared_address_space, type::AddressSpace::kPrivate); - ASSERT_TRUE(v->type->Is()); - EXPECT_EQ(Symbols().NameFor(v->type->As()->name->symbol), "f32"); + CheckIdentifier(Symbols(), v->type, "f32"); EXPECT_EQ(v->source.range.begin.line, 27u); EXPECT_EQ(v->source.range.begin.column, 4u); EXPECT_EQ(v->source.range.end.line, 27u); @@ -55,10 +53,9 @@ TEST_F(VariableTest, CreationEmpty) { auto* v = Var(Source{Source::Range{Source::Location{27, 4}, Source::Location{27, 7}}}, "a_var", ty.i32(), type::AddressSpace::kWorkgroup, utils::Empty); - EXPECT_EQ(Symbols().NameFor(v->name->symbol), "a_var"); + CheckIdentifier(Symbols(), v->name, "a_var"); EXPECT_EQ(v->declared_address_space, type::AddressSpace::kWorkgroup); - ASSERT_TRUE(v->type->Is()); - EXPECT_EQ(Symbols().NameFor(v->type->As()->name->symbol), "i32"); + CheckIdentifier(Symbols(), v->type, "i32"); EXPECT_EQ(v->source.range.begin.line, 27u); EXPECT_EQ(v->source.range.begin.column, 4u); EXPECT_EQ(v->source.range.end.line, 27u); diff --git a/src/tint/ast/vector.cc b/src/tint/ast/vector.cc deleted file mode 100644 index d49da33126..0000000000 --- a/src/tint/ast/vector.cc +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/vector.h" - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::Vector); - -namespace tint::ast { - -Vector::Vector(ProgramID pid, NodeID nid, Source const& src, const Type* subtype, uint32_t w) - : Base(pid, nid, src), type(subtype), width(w) { - TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, subtype, program_id); - TINT_ASSERT(AST, width > 1); - TINT_ASSERT(AST, width < 5); -} - -Vector::Vector(Vector&&) = default; - -Vector::~Vector() = default; - -std::string Vector::FriendlyName(const SymbolTable& symbols) const { - std::ostringstream out; - out << "vec" << width; - if (type) { - out << "<" << type->FriendlyName(symbols) << ">"; - } - return out.str(); -} - -const Vector* Vector::Clone(CloneContext* ctx) const { - // Clone arguments outside of create() call to have deterministic ordering - auto src = ctx->Clone(source); - auto* ty = ctx->Clone(type); - return ctx->dst->create(src, ty, width); -} - -} // namespace tint::ast diff --git a/src/tint/ast/vector.h b/src/tint/ast/vector.h deleted file mode 100644 index 0f2478266a..0000000000 --- a/src/tint/ast/vector.h +++ /dev/null @@ -1,61 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#ifndef SRC_TINT_AST_VECTOR_H_ -#define SRC_TINT_AST_VECTOR_H_ - -#include - -#include "src/tint/ast/type.h" - -namespace tint::ast { - -/// A vector type. -class Vector final : public Castable { - public: - /// Constructor - /// @param pid the identifier of the program that owns this node - /// @param nid the unique node identifier - /// @param src the source of this node - /// @param subtype the declared type of the vector components. May be null - /// for vector initializers, where the element type will be inferred - /// from the initializer arguments - /// @param width the number of elements in the vector - Vector(ProgramID pid, NodeID nid, Source const& src, const Type* subtype, uint32_t width); - /// Move constructor - Vector(Vector&&); - ~Vector() override; - - /// @param symbols the program's symbol table - /// @returns the name for this type that closely resembles how it would be - /// declared in WGSL. - std::string FriendlyName(const SymbolTable& symbols) const override; - - /// Clones this type and all transitive types using the `CloneContext` `ctx`. - /// @param ctx the clone context - /// @return the newly cloned type - const Vector* Clone(CloneContext* ctx) const override; - - /// The declared type of the vector components. May be null for vector - /// initializers, where the element type will be inferred from the initializer - /// arguments - const Type* const type; - - /// The number of elements in the vector - const uint32_t width; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_VECTOR_H_ diff --git a/src/tint/ast/vector_test.cc b/src/tint/ast/vector_test.cc deleted file mode 100644 index 81a00757dc..0000000000 --- a/src/tint/ast/vector_test.cc +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright 2020 The Tint Authors. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -#include "src/tint/ast/vector.h" - -#include "src/tint/ast/test_helper.h" - -namespace tint::ast { -namespace { - -using AstVectorTest = TestHelper; - -TEST_F(AstVectorTest, Creation) { - auto* v = create(ty.i32(), 2u); - ASSERT_TRUE(v->type->Is()); - EXPECT_EQ(Symbols().NameFor(v->type->As()->name->symbol), "i32"); - EXPECT_EQ(v->width, 2u); -} - -TEST_F(AstVectorTest, FriendlyName) { - auto* v = create(ty.f32(), 3u); - EXPECT_EQ(v->FriendlyName(Symbols()), "vec3"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/clone_context.cc b/src/tint/clone_context.cc index fe94a14488..83e6d6c72e 100644 --- a/src/tint/clone_context.cc +++ b/src/tint/clone_context.cc @@ -66,6 +66,10 @@ ast::FunctionList CloneContext::Clone(const ast::FunctionList& v) { return out; } +ast::Type CloneContext::Clone(const ast::Type& ty) { + return {Clone(ty.expr)}; +} + const tint::Cloneable* CloneContext::CloneCloneable(const Cloneable* object) { // If the input is nullptr, there's nothing to clone - just return nullptr. if (object == nullptr) { diff --git a/src/tint/clone_context.h b/src/tint/clone_context.h index 1ec34224e7..188ee253ac 100644 --- a/src/tint/clone_context.h +++ b/src/tint/clone_context.h @@ -40,6 +40,7 @@ class ProgramBuilder; namespace tint::ast { class FunctionList; class Node; +struct Type; } // namespace tint::ast namespace tint { @@ -142,6 +143,11 @@ class CloneContext { return CheckedCast(c); } + /// Clones the ast::Type `ty` into the ProgramBuilder #dst + /// @param ty the AST type. + /// @return the cloned node + ast::Type Clone(const ast::Type& ty); + /// Clones the Source `s` into #dst /// TODO(bclayton) - Currently this 'clone' is a shallow copy. If/when /// `Source.File`s are owned by the Program this should make a copy of the diff --git a/src/tint/inspector/inspector_test.cc b/src/tint/inspector/inspector_test.cc index a0263f3712..fe4cba133b 100644 --- a/src/tint/inspector/inspector_test.cc +++ b/src/tint/inspector/inspector_test.cc @@ -286,7 +286,7 @@ TEST_P(InspectorGetEntryPointComponentAndCompositionTest, Test) { ComponentType component; CompositionType composition; std::tie(component, composition) = GetParam(); - std::function tint_type = GetTypeFunction(component, composition); + std::function tint_type = GetTypeFunction(component, composition); if (component == ComponentType::kF16) { Enable(ast::Extension::kF16); @@ -1785,14 +1785,14 @@ TEST_F(InspectorGetResourceBindingsTest, Simple) { MemberInfo{0, ty.i32()}, }); - auto* s_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); + auto s_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); AddResource("s_texture", s_texture_type, 2, 0); AddSampler("s_var", 3, 0); AddGlobalVariable("s_coords", ty.f32()); MakeSamplerReferenceBodyFunction("s_func", "s_texture", "s_var", "s_coords", ty.f32(), utils::Empty); - auto* cs_depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); + auto cs_depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); AddResource("cs_texture", cs_depth_texture_type, 3, 1); AddComparisonSampler("cs_var", 3, 2); AddGlobalVariable("cs_coords", ty.vec2()); @@ -1800,14 +1800,14 @@ TEST_F(InspectorGetResourceBindingsTest, Simple) { MakeComparisonSamplerReferenceBodyFunction("cs_func", "cs_texture", "cs_var", "cs_coords", "cs_depth", ty.f32(), utils::Empty); - auto* depth_ms_texture_type = ty.depth_multisampled_texture(type::TextureDimension::k2d); + auto depth_ms_texture_type = ty.depth_multisampled_texture(type::TextureDimension::k2d); AddResource("depth_ms_texture", depth_ms_texture_type, 3, 3); Func("depth_ms_func", utils::Empty, ty.void_(), utils::Vector{ Ignore("depth_ms_texture"), }); - auto* st_type = + auto st_type = MakeStorageTextureTypes(type::TextureDimension::k2d, type::TexelFormat::kR32Uint); AddStorageTexture("st_var", st_type, 4, 0); MakeStorageTextureBodyFunction("st_func", "st_var", ty.vec2(), utils::Empty); @@ -2586,7 +2586,7 @@ TEST_F(InspectorGetReadOnlyStorageBufferResourceBindingsTest, SkipNonReadOnly) { } TEST_F(InspectorGetSamplerResourceBindingsTest, Simple) { - auto* sampled_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); + auto sampled_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); AddResource("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32()); @@ -2621,7 +2621,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, NoSampler) { } TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) { - auto* sampled_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); + auto sampled_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); AddResource("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32()); @@ -2646,7 +2646,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, InFunction) { } TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) { - auto* sampled_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); + auto sampled_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); AddResource("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32()); @@ -2663,7 +2663,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, UnknownEntryPoint) { } TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) { - auto* depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); + auto depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); AddResource("foo_texture", depth_texture_type, 0, 0); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.vec2()); @@ -2684,7 +2684,7 @@ TEST_F(InspectorGetSamplerResourceBindingsTest, SkipsComparisonSamplers) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, Simple) { - auto* depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); + auto depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); AddResource("foo_texture", depth_texture_type, 0, 0); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.vec2()); @@ -2721,7 +2721,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, NoSampler) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) { - auto* depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); + auto depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); AddResource("foo_texture", depth_texture_type, 0, 0); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.vec2()); @@ -2747,7 +2747,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, InFunction) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) { - auto* depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); + auto depth_texture_type = ty.depth_texture(type::TextureDimension::k2d); AddResource("foo_texture", depth_texture_type, 0, 0); AddComparisonSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.vec2()); @@ -2766,7 +2766,7 @@ TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, UnknownEntryPoint) { } TEST_F(InspectorGetComparisonSamplerResourceBindingsTest, SkipsSamplers) { - auto* sampled_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); + auto sampled_texture_type = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); AddResource("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); AddGlobalVariable("foo_coords", ty.f32()); @@ -2798,11 +2798,11 @@ TEST_F(InspectorGetSampledTextureResourceBindingsTest, Empty) { } TEST_P(InspectorGetSampledTextureResourceBindingsTestWithParam, textureSample) { - auto* sampled_texture_type = + ast::Type sampled_texture_type = ty.sampled_texture(GetParam().type_dim, GetBaseType(GetParam().sampled_kind)); AddResource("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); - auto* coord_type = GetCoordsType(GetParam().type_dim, ty.f32()); + ast::Type coord_type = GetCoordsType(GetParam().type_dim, ty.f32()); AddGlobalVariable("foo_coords", coord_type); MakeSamplerReferenceBodyFunction("ep", "foo_texture", "foo_sampler", "foo_coords", @@ -2847,11 +2847,11 @@ INSTANTIATE_TEST_SUITE_P( inspector::ResourceBinding::SampledKind::kFloat})); TEST_P(InspectorGetSampledArrayTextureResourceBindingsTestWithParam, textureSample) { - auto* sampled_texture_type = + ast::Type sampled_texture_type = ty.sampled_texture(GetParam().type_dim, GetBaseType(GetParam().sampled_kind)); AddResource("foo_texture", sampled_texture_type, 0, 0); AddSampler("foo_sampler", 0, 1); - auto* coord_type = GetCoordsType(GetParam().type_dim, ty.f32()); + ast::Type coord_type = GetCoordsType(GetParam().type_dim, ty.f32()); AddGlobalVariable("foo_coords", coord_type); AddGlobalVariable("foo_array_index", ty.i32()); @@ -2886,10 +2886,10 @@ INSTANTIATE_TEST_SUITE_P( inspector::ResourceBinding::SampledKind::kFloat})); TEST_P(InspectorGetMultisampledTextureResourceBindingsTestWithParam, textureLoad) { - auto* multisampled_texture_type = + ast::Type multisampled_texture_type = ty.multisampled_texture(GetParam().type_dim, GetBaseType(GetParam().sampled_kind)); AddResource("foo_texture", multisampled_texture_type, 0, 0); - auto* coord_type = GetCoordsType(GetParam().type_dim, ty.i32()); + ast::Type coord_type = GetCoordsType(GetParam().type_dim, ty.i32()); AddGlobalVariable("foo_coords", coord_type); AddGlobalVariable("foo_sample_index", ty.i32()); @@ -2973,10 +2973,10 @@ TEST_P(InspectorGetStorageTextureResourceBindingsTestWithParam, Simple) { ResourceBinding::SampledKind expected_kind; std::tie(format, expected_format, expected_kind) = format_params; - auto* st_type = MakeStorageTextureTypes(dim, format); + ast::Type st_type = MakeStorageTextureTypes(dim, format); AddStorageTexture("st_var", st_type, 0, 0); - const ast::Type* dim_type = nullptr; + ast::Type dim_type; switch (dim) { case type::TextureDimension::k1d: dim_type = ty.u32(); @@ -3074,7 +3074,7 @@ INSTANTIATE_TEST_SUITE_P( ResourceBinding::SampledKind::kFloat)))); TEST_P(InspectorGetDepthTextureResourceBindingsTestWithParam, textureDimensions) { - auto* depth_texture_type = ty.depth_texture(GetParam().type_dim); + auto depth_texture_type = ty.depth_texture(GetParam().type_dim); AddResource("dt", depth_texture_type, 0, 0); Func("ep", utils::Empty, ty.void_(), @@ -3111,7 +3111,7 @@ INSTANTIATE_TEST_SUITE_P( inspector::ResourceBinding::TextureDimension::kCubeArray})); TEST_F(InspectorGetDepthMultisampledTextureResourceBindingsTest, textureDimensions) { - auto* depth_ms_texture_type = ty.depth_multisampled_texture(type::TextureDimension::k2d); + auto depth_ms_texture_type = ty.depth_multisampled_texture(type::TextureDimension::k2d); AddResource("tex", depth_ms_texture_type, 0, 0); Func("ep", utils::Empty, ty.void_(), @@ -3135,7 +3135,7 @@ TEST_F(InspectorGetDepthMultisampledTextureResourceBindingsTest, textureDimensio } TEST_F(InspectorGetExternalTextureResourceBindingsTest, Simple) { - auto* external_texture_type = ty.external_texture(); + auto external_texture_type = ty.external_texture(); AddResource("et", external_texture_type, 0, 0); Func("ep", utils::Empty, ty.void_(), diff --git a/src/tint/inspector/test_inspector_builder.cc b/src/tint/inspector/test_inspector_builder.cc index 677f9c1b5f..e73c6f5324 100644 --- a/src/tint/inspector/test_inspector_builder.cc +++ b/src/tint/inspector/test_inspector_builder.cc @@ -64,7 +64,7 @@ const ast::Struct* InspectorBuilder::MakeInOutStruct(std::string name, const ast::Function* InspectorBuilder::MakePlainGlobalReferenceBodyFunction( std::string func, std::string var, - const ast::Type* type, + ast::Type type, utils::VectorRef attributes) { utils::Vector stmts; stmts.Push(Decl(Var("local_" + var, type))); @@ -82,15 +82,14 @@ bool InspectorBuilder::ContainsName(utils::VectorRef vec, const s return false; } -std::string InspectorBuilder::StructMemberName(size_t idx, const ast::Type* type) { - return std::to_string(idx) + type->FriendlyName(Symbols()); +std::string InspectorBuilder::StructMemberName(size_t idx, ast::Type type) { + return std::to_string(idx) + Symbols().NameFor(type->identifier->symbol); } -const ast::Struct* InspectorBuilder::MakeStructType( - const std::string& name, - utils::VectorRef member_types) { +const ast::Struct* InspectorBuilder::MakeStructType(const std::string& name, + utils::VectorRef member_types) { utils::Vector members; - for (auto* type : member_types) { + for (auto type : member_types) { members.Push(MakeStructMember(members.Length(), type, {})); } return MakeStructTypeFromMembers(name, std::move(members)); @@ -104,37 +103,37 @@ const ast::Struct* InspectorBuilder::MakeStructTypeFromMembers( const ast::StructMember* InspectorBuilder::MakeStructMember( size_t index, - const ast::Type* type, + ast::Type type, utils::VectorRef attributes) { return Member(StructMemberName(index, type), type, std::move(attributes)); } const ast::Struct* InspectorBuilder::MakeUniformBufferType( const std::string& name, - utils::VectorRef member_types) { + utils::VectorRef member_types) { return MakeStructType(name, member_types); } -std::function InspectorBuilder::MakeStorageBufferTypes( +std::function InspectorBuilder::MakeStorageBufferTypes( const std::string& name, - utils::VectorRef member_types) { + utils::VectorRef member_types) { MakeStructType(name, member_types); return [this, name] { return ty(name); }; } void InspectorBuilder::AddUniformBuffer(const std::string& name, - const ast::Type* type, + ast::Type type, uint32_t group, uint32_t binding) { GlobalVar(name, type, type::AddressSpace::kUniform, Binding(AInt(binding)), Group(AInt(group))); } -void InspectorBuilder::AddWorkgroupStorage(const std::string& name, const ast::Type* type) { +void InspectorBuilder::AddWorkgroupStorage(const std::string& name, ast::Type type) { GlobalVar(name, type, type::AddressSpace::kWorkgroup); } void InspectorBuilder::AddStorageBuffer(const std::string& name, - const ast::Type* type, + ast::Type type, type::Access access, uint32_t group, uint32_t binding) { @@ -145,11 +144,11 @@ void InspectorBuilder::AddStorageBuffer(const std::string& name, void InspectorBuilder::MakeStructVariableReferenceBodyFunction( std::string func_name, std::string struct_name, - utils::VectorRef> members) { + utils::VectorRef> members) { utils::Vector stmts; for (auto member : members) { size_t member_idx; - const ast::Type* member_type; + ast::Type member_type; std::tie(member_idx, member_type) = member; std::string member_name = StructMemberName(member_idx, member_type); @@ -158,7 +157,7 @@ void InspectorBuilder::MakeStructVariableReferenceBodyFunction( for (auto member : members) { size_t member_idx; - const ast::Type* member_type; + ast::Type member_type; std::tie(member_idx, member_type) = member; std::string member_name = StructMemberName(member_idx, member_type); @@ -183,13 +182,13 @@ void InspectorBuilder::AddComparisonSampler(const std::string& name, } void InspectorBuilder::AddResource(const std::string& name, - const ast::Type* type, + ast::Type type, uint32_t group, uint32_t binding) { GlobalVar(name, type, Binding(AInt(binding)), Group(AInt(group))); } -void InspectorBuilder::AddGlobalVariable(const std::string& name, const ast::Type* type) { +void InspectorBuilder::AddGlobalVariable(const std::string& name, ast::Type type) { GlobalVar(name, type, type::AddressSpace::kPrivate); } @@ -198,7 +197,7 @@ const ast::Function* InspectorBuilder::MakeSamplerReferenceBodyFunction( const std::string& texture_name, const std::string& sampler_name, const std::string& coords_name, - const ast::Type* base_type, + ast::Type base_type, utils::VectorRef attributes) { std::string result_name = "sampler_result"; @@ -216,7 +215,7 @@ const ast::Function* InspectorBuilder::MakeSamplerReferenceBodyFunction( const std::string& sampler_name, const std::string& coords_name, const std::string& array_index, - const ast::Type* base_type, + ast::Type base_type, utils::VectorRef attributes) { std::string result_name = "sampler_result"; @@ -235,7 +234,7 @@ const ast::Function* InspectorBuilder::MakeComparisonSamplerReferenceBodyFunctio const std::string& sampler_name, const std::string& coords_name, const std::string& depth_name, - const ast::Type* base_type, + ast::Type base_type, utils::VectorRef attributes) { std::string result_name = "sampler_result"; @@ -248,7 +247,7 @@ const ast::Function* InspectorBuilder::MakeComparisonSamplerReferenceBodyFunctio return Func(func_name, utils::Empty, ty.void_(), std::move(stmts), std::move(attributes)); } -const ast::Type* InspectorBuilder::GetBaseType(ResourceBinding::SampledKind sampled_kind) { +ast::Type InspectorBuilder::GetBaseType(ResourceBinding::SampledKind sampled_kind) { switch (sampled_kind) { case ResourceBinding::SampledKind::kFloat: return ty.f32(); @@ -257,35 +256,34 @@ const ast::Type* InspectorBuilder::GetBaseType(ResourceBinding::SampledKind samp case ResourceBinding::SampledKind::kUInt: return ty.u32(); default: - return nullptr; + return ast::Type{}; } } -const ast::Type* InspectorBuilder::GetCoordsType(type::TextureDimension dim, - const ast::Type* scalar) { +ast::Type InspectorBuilder::GetCoordsType(type::TextureDimension dim, ast::Type scalar) { switch (dim) { case type::TextureDimension::k1d: return scalar; case type::TextureDimension::k2d: case type::TextureDimension::k2dArray: - return create(scalar, 2u); + return ty.vec2(scalar); case type::TextureDimension::k3d: case type::TextureDimension::kCube: case type::TextureDimension::kCubeArray: - return create(scalar, 3u); + return ty.vec3(scalar); default: [=]() { FAIL() << "Unsupported texture dimension: " << dim; }(); } - return nullptr; + return ast::Type{}; } -const ast::Type* InspectorBuilder::MakeStorageTextureTypes(type::TextureDimension dim, - type::TexelFormat format) { +ast::Type InspectorBuilder::MakeStorageTextureTypes(type::TextureDimension dim, + type::TexelFormat format) { return ty.storage_texture(dim, format, type::Access::kWrite); } void InspectorBuilder::AddStorageTexture(const std::string& name, - const ast::Type* type, + ast::Type type, uint32_t group, uint32_t binding) { GlobalVar(name, type, Binding(AInt(binding)), Group(AInt(group))); @@ -294,7 +292,7 @@ void InspectorBuilder::AddStorageTexture(const std::string& name, const ast::Function* InspectorBuilder::MakeStorageTextureBodyFunction( const std::string& func_name, const std::string& st_name, - const ast::Type* dim_type, + ast::Type dim_type, utils::VectorRef attributes) { utils::Vector stmts{ Decl(Var("dim", dim_type)), @@ -305,24 +303,24 @@ const ast::Function* InspectorBuilder::MakeStorageTextureBodyFunction( return Func(func_name, utils::Empty, ty.void_(), std::move(stmts), std::move(attributes)); } -std::function InspectorBuilder::GetTypeFunction(ComponentType component, - CompositionType composition) { - std::function func; +std::function InspectorBuilder::GetTypeFunction(ComponentType component, + CompositionType composition) { + std::function func; switch (component) { case ComponentType::kF32: - func = [this]() -> const ast::Type* { return ty.f32(); }; + func = [this]() { return ty.f32(); }; break; case ComponentType::kI32: - func = [this]() -> const ast::Type* { return ty.i32(); }; + func = [this]() { return ty.i32(); }; break; case ComponentType::kU32: - func = [this]() -> const ast::Type* { return ty.u32(); }; + func = [this]() { return ty.u32(); }; break; case ComponentType::kF16: - func = [this]() -> const ast::Type* { return ty.f16(); }; + func = [this]() { return ty.f16(); }; break; case ComponentType::kUnknown: - return []() -> const ast::Type* { return nullptr; }; + return []() { return ast::Type{}; }; } uint32_t n; @@ -339,10 +337,10 @@ std::function InspectorBuilder::GetTypeFunction(ComponentTyp n = 4; break; default: - return []() -> ast::Type* { return nullptr; }; + return []() { return ast::Type{}; }; } - return [this, func, n]() -> const ast::Type* { return ty.vec(func(), n); }; + return [this, func, n]() { return ty.vec(func(), n); }; } Inspector& InspectorBuilder::Build() { diff --git a/src/tint/inspector/test_inspector_builder.h b/src/tint/inspector/test_inspector_builder.h index 8b32529b9c..1d99863851 100644 --- a/src/tint/inspector/test_inspector_builder.h +++ b/src/tint/inspector/test_inspector_builder.h @@ -107,7 +107,7 @@ class InspectorBuilder : public ProgramBuilder { const ast::Function* MakePlainGlobalReferenceBodyFunction( std::string func, std::string var, - const ast::Type* type, + ast::Type type, utils::VectorRef attributes); /// @param vec Vector of StageVariable to be searched @@ -119,14 +119,14 @@ class InspectorBuilder : public ProgramBuilder { /// @param idx index of member /// @param type type of member /// @returns a string for the member - std::string StructMemberName(size_t idx, const ast::Type* type); + std::string StructMemberName(size_t idx, ast::Type type); /// Generates a struct type /// @param name name for the type /// @param member_types a vector of member types /// @returns a struct type const ast::Struct* MakeStructType(const std::string& name, - utils::VectorRef member_types); + utils::VectorRef member_types); /// Generates a struct type from a list of member nodes. /// @param name name for the struct type @@ -142,7 +142,7 @@ class InspectorBuilder : public ProgramBuilder { /// @param attributes a list of attributes to apply to the member field /// @returns a struct member const ast::StructMember* MakeStructMember(size_t index, - const ast::Type* type, + ast::Type type, utils::VectorRef attributes); /// Generates types appropriate for using in an uniform buffer @@ -150,15 +150,14 @@ class InspectorBuilder : public ProgramBuilder { /// @param member_types a vector of member types /// @returns a struct type that has the layout for an uniform buffer. const ast::Struct* MakeUniformBufferType(const std::string& name, - utils::VectorRef member_types); + utils::VectorRef member_types); /// Generates types appropriate for using in a storage buffer /// @param name name for the type /// @param member_types a vector of member types /// @returns a function that returns the created structure. - std::function MakeStorageBufferTypes( - const std::string& name, - utils::VectorRef member_types); + std::function MakeStorageBufferTypes(const std::string& name, + utils::VectorRef member_types); /// Adds an uniform buffer variable to the program /// @param name the name of the variable @@ -166,14 +165,14 @@ class InspectorBuilder : public ProgramBuilder { /// @param group the binding/group/ to use for the uniform buffer /// @param binding the binding number to use for the uniform buffer void AddUniformBuffer(const std::string& name, - const ast::Type* type, + ast::Type type, uint32_t group, uint32_t binding); /// Adds a workgroup storage variable to the program /// @param name the name of the variable /// @param type the type of the variable - void AddWorkgroupStorage(const std::string& name, const ast::Type* type); + void AddWorkgroupStorage(const std::string& name, ast::Type type); /// Adds a storage buffer variable to the program /// @param name the name of the variable @@ -182,13 +181,13 @@ class InspectorBuilder : public ProgramBuilder { /// @param group the binding/group to use for the storage buffer /// @param binding the binding number to use for the storage buffer void AddStorageBuffer(const std::string& name, - const ast::Type* type, + ast::Type type, type::Access access, uint32_t group, uint32_t binding); /// MemberInfo is a tuple of member index and type. - using MemberInfo = std::tuple; + using MemberInfo = std::tuple; /// Generates a function that references a specific struct variable /// @param func_name name of the function created @@ -215,15 +214,12 @@ class InspectorBuilder : public ProgramBuilder { /// @param type the type to use /// @param group the binding/group to use for the resource /// @param binding the binding number to use for the resource - void AddResource(const std::string& name, - const ast::Type* type, - uint32_t group, - uint32_t binding); + void AddResource(const std::string& name, ast::Type type, uint32_t group, uint32_t binding); /// Add a module scope private variable to the progames /// @param name the name of the variable /// @param type the type to use - void AddGlobalVariable(const std::string& name, const ast::Type* type); + void AddGlobalVariable(const std::string& name, ast::Type type); /// Generates a function that references a specific sampler variable /// @param func_name name of the function created @@ -238,7 +234,7 @@ class InspectorBuilder : public ProgramBuilder { const std::string& texture_name, const std::string& sampler_name, const std::string& coords_name, - const ast::Type* base_type, + ast::Type base_type, utils::VectorRef attributes); /// Generates a function that references a specific sampler variable @@ -256,7 +252,7 @@ class InspectorBuilder : public ProgramBuilder { const std::string& sampler_name, const std::string& coords_name, const std::string& array_index, - const ast::Type* base_type, + ast::Type base_type, utils::VectorRef attributes); /// Generates a function that references a specific comparison sampler @@ -275,26 +271,26 @@ class InspectorBuilder : public ProgramBuilder { const std::string& sampler_name, const std::string& coords_name, const std::string& depth_name, - const ast::Type* base_type, + ast::Type base_type, utils::VectorRef attributes); /// Gets an appropriate type for the data in a given texture type. /// @param sampled_kind type of in the texture /// @returns a pointer to a type appropriate for the coord param - const ast::Type* GetBaseType(ResourceBinding::SampledKind sampled_kind); + ast::Type GetBaseType(ResourceBinding::SampledKind sampled_kind); /// Gets an appropriate type for the coords parameter depending the the /// dimensionality of the texture being sampled. /// @param dim dimensionality of the texture being sampled /// @param scalar the scalar type /// @returns a pointer to a type appropriate for the coord param - const ast::Type* GetCoordsType(type::TextureDimension dim, const ast::Type* scalar); + ast::Type GetCoordsType(type::TextureDimension dim, ast::Type scalar); /// Generates appropriate types for a Read-Only StorageTexture /// @param dim the texture dimension of the storage texture /// @param format the texel format of the storage texture /// @returns the storage texture type - const ast::Type* MakeStorageTextureTypes(type::TextureDimension dim, type::TexelFormat format); + ast::Type MakeStorageTextureTypes(type::TextureDimension dim, type::TexelFormat format); /// Adds a storage texture variable to the program /// @param name the name of the variable @@ -302,7 +298,7 @@ class InspectorBuilder : public ProgramBuilder { /// @param group the binding/group to use for the sampled texture /// @param binding the binding57 number to use for the sampled texture void AddStorageTexture(const std::string& name, - const ast::Type* type, + ast::Type type, uint32_t group, uint32_t binding); @@ -315,7 +311,7 @@ class InspectorBuilder : public ProgramBuilder { const ast::Function* MakeStorageTextureBodyFunction( const std::string& func_name, const std::string& st_name, - const ast::Type* dim_type, + ast::Type dim_type, utils::VectorRef attributes); /// Get a generator function that returns a type appropriate for a stage @@ -323,8 +319,8 @@ class InspectorBuilder : public ProgramBuilder { /// @param component component type of the stage variable /// @param composition composition type of the stage variable /// @returns a generator function for the stage variable's type. - std::function GetTypeFunction(ComponentType component, - CompositionType composition); + std::function GetTypeFunction(ComponentType component, + CompositionType composition); /// Build the Program given all of the previous methods called and return an /// Inspector for it. diff --git a/src/tint/intrinsics.def b/src/tint/intrinsics.def index c49048263b..5985921229 100644 --- a/src/tint/intrinsics.def +++ b/src/tint/intrinsics.def @@ -136,6 +136,15 @@ enum builtin_type { i32 u32 // https://www.w3.org/TR/WGSL/#matrix-types + mat2x2 + mat2x3 + mat2x4 + mat3x2 + mat3x3 + mat3x4 + mat4x2 + mat4x3 + mat4x4 mat2x2f mat2x2h mat2x3f @@ -155,6 +164,9 @@ enum builtin_type { mat4x4f mat4x4h // https://www.w3.org/TR/WGSL/#vector-types + vec2 + vec3 + vec4 vec2f vec2h vec2i @@ -167,6 +179,12 @@ enum builtin_type { vec4h vec4i vec4u + // https://www.w3.org/TR/WGSL/#array-types + array + // https://www.w3.org/TR/WGSL/#atomic-types + atomic + // https://www.w3.org/TR/WGSL/#ref-ptr-types + ptr // https://www.w3.org/TR/WGSL/#sampler-type sampler sampler_comparison @@ -176,6 +194,15 @@ enum builtin_type { texture_depth_cube texture_depth_cube_array texture_depth_multisampled_2d + // https://www.w3.org/TR/WGSL/#sampled-texture-type + texture_1d + texture_2d + texture_2d_array + texture_3d + texture_cube + texture_cube_array + // https://www.w3.org/TR/WGSL/#multisampled-texture-type + texture_multisampled_2d // https://www.w3.org/TR/WGSL/#texture-storage texture_storage_1d texture_storage_2d diff --git a/src/tint/ir/builder_impl.h b/src/tint/ir/builder_impl.h index c086677532..034ab65c4d 100644 --- a/src/tint/ir/builder_impl.h +++ b/src/tint/ir/builder_impl.h @@ -19,6 +19,7 @@ #include #include +#include "src/tint/ast/type.h" #include "src/tint/constant/clone_context.h" #include "src/tint/diagnostic/diagnostic.h" #include "src/tint/ir/builder.h" @@ -49,7 +50,6 @@ class Node; class ReturnStatement; class Statement; class SwitchStatement; -class Type; class WhileStatement; class Variable; } // namespace tint::ast diff --git a/src/tint/program.cc b/src/tint/program.cc index a5d8c4563a..378a1ceede 100644 --- a/src/tint/program.cc +++ b/src/tint/program.cc @@ -18,6 +18,7 @@ #include "src/tint/demangler.h" #include "src/tint/resolver/resolver.h" +#include "src/tint/sem/type_expression.h" #include "src/tint/sem/value_expression.h" namespace tint { @@ -118,21 +119,24 @@ bool Program::IsValid() const { } const type::Type* Program::TypeOf(const ast::Expression* expr) const { - auto* sem = Sem().GetVal(expr); - return sem ? sem->Type() : nullptr; + return tint::Switch( + Sem().Get(expr), // + [](const sem::ValueExpression* ty_expr) { return ty_expr->Type(); }, + [](const sem::TypeExpression* ty_expr) { return ty_expr->Type(); }); } -const type::Type* Program::TypeOf(const ast::Type* type) const { - return Sem().Get(type); +const type::Type* Program::TypeOf(const ast::Variable* var) const { + auto* sem = Sem().Get(var); + return sem ? sem->Type() : nullptr; } const type::Type* Program::TypeOf(const ast::TypeDecl* type_decl) const { return Sem().Get(type_decl); } -std::string Program::FriendlyName(const ast::Type* type) const { +std::string Program::FriendlyName(ast::Type type) const { TINT_ASSERT_PROGRAM_IDS_EQUAL(Program, type, ID()); - return type ? type->FriendlyName(Symbols()) : ""; + return type ? Symbols().NameFor(type->identifier->symbol) : ""; } std::string Program::FriendlyName(const type::Type* type) const { diff --git a/src/tint/program.h b/src/tint/program.h index 873a0c4a63..1c57fe07e8 100644 --- a/src/tint/program.h +++ b/src/tint/program.h @@ -138,11 +138,11 @@ class Program { /// expression has no resolved type. const type::Type* TypeOf(const ast::Expression* expr) const; - /// Helper for returning the resolved semantic type of the AST type `type`. - /// @param type the AST type - /// @return the resolved semantic type for the type, or nullptr if the type - /// has no resolved type. - const type::Type* TypeOf(const ast::Type* type) const; + /// Helper for returning the resolved semantic type of the variable `var`. + /// @param var the AST variable + /// @return the resolved semantic type for the variable, or nullptr if the + /// variable has no resolved type. + const type::Type* TypeOf(const ast::Variable* var) const; /// Helper for returning the resolved semantic type of the AST type /// declaration `type_decl`. @@ -152,13 +152,11 @@ class Program { const type::Type* TypeOf(const ast::TypeDecl* type_decl) const; /// @param type a type - /// @returns the name for `type` that closely resembles how it would be - /// declared in WGSL. - std::string FriendlyName(const ast::Type* type) const; + /// @returns the name for `type` that closely resembles how it would be declared in WGSL. + std::string FriendlyName(ast::Type type) const; /// @param type a type - /// @returns the name for `type` that closely resembles how it would be - /// declared in WGSL. + /// @returns the name for `type` that closely resembles how it would be declared in WGSL. std::string FriendlyName(const type::Type* type) const; /// Overload of FriendlyName, which removes an ambiguity when passing nullptr. diff --git a/src/tint/program_builder.cc b/src/tint/program_builder.cc index a847e00a48..aaaa279cc1 100644 --- a/src/tint/program_builder.cc +++ b/src/tint/program_builder.cc @@ -19,6 +19,7 @@ #include "src/tint/ast/variable_decl_statement.h" #include "src/tint/debug.h" #include "src/tint/demangler.h" +#include "src/tint/sem/type_expression.h" #include "src/tint/sem/value_expression.h" #include "src/tint/sem/variable.h" #include "src/tint/utils/compiler_macros.h" @@ -97,8 +98,10 @@ void ProgramBuilder::AssertNotMoved() const { } const type::Type* ProgramBuilder::TypeOf(const ast::Expression* expr) const { - auto* sem = Sem().GetVal(expr); - return sem ? sem->Type() : nullptr; + return tint::Switch( + Sem().Get(expr), // + [](const sem::ValueExpression* e) { return e->Type(); }, + [](const sem::TypeExpression* e) { return e->Type(); }); } const type::Type* ProgramBuilder::TypeOf(const ast::Variable* var) const { @@ -106,17 +109,13 @@ const type::Type* ProgramBuilder::TypeOf(const ast::Variable* var) const { return sem ? sem->Type() : nullptr; } -const type::Type* ProgramBuilder::TypeOf(const ast::Type* type) const { - return Sem().Get(type); -} - const type::Type* ProgramBuilder::TypeOf(const ast::TypeDecl* type_decl) const { return Sem().Get(type_decl); } -std::string ProgramBuilder::FriendlyName(const ast::Type* type) const { +std::string ProgramBuilder::FriendlyName(ast::Type type) const { TINT_ASSERT_PROGRAM_IDS_EQUAL(ProgramBuilder, type, ID()); - return type ? type->FriendlyName(Symbols()) : ""; + return type.expr ? Symbols().NameFor(type->identifier->symbol) : ""; } std::string ProgramBuilder::FriendlyName(const type::Type* type) const { @@ -127,10 +126,6 @@ std::string ProgramBuilder::FriendlyName(std::nullptr_t) const { return ""; } -const ast::TypeName* ProgramBuilder::TypesBuilder::Of(const ast::TypeDecl* decl) const { - return (*this)(decl->name->symbol); -} - ProgramBuilder::TypesBuilder::TypesBuilder(ProgramBuilder* pb) : builder(pb) {} const ast::Statement* ProgramBuilder::WrapInStatement(const ast::Expression* expr) { diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index 0541511e15..265219d389 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -22,9 +22,7 @@ #include "tint/override_id.h" #include "src/tint/ast/alias.h" -#include "src/tint/ast/array.h" #include "src/tint/ast/assignment_statement.h" -#include "src/tint/ast/atomic.h" #include "src/tint/ast/binary_expression.h" #include "src/tint/ast/binding_attribute.h" #include "src/tint/ast/bitcast_expression.h" @@ -57,16 +55,12 @@ #include "src/tint/ast/invariant_attribute.h" #include "src/tint/ast/let.h" #include "src/tint/ast/loop_statement.h" -#include "src/tint/ast/matrix.h" #include "src/tint/ast/member_accessor_expression.h" #include "src/tint/ast/module.h" -#include "src/tint/ast/multisampled_texture.h" #include "src/tint/ast/override.h" #include "src/tint/ast/parameter.h" #include "src/tint/ast/phony_expression.h" -#include "src/tint/ast/pointer.h" #include "src/tint/ast/return_statement.h" -#include "src/tint/ast/sampled_texture.h" #include "src/tint/ast/stage_attribute.h" #include "src/tint/ast/stride_attribute.h" #include "src/tint/ast/struct_member_align_attribute.h" @@ -74,11 +68,10 @@ #include "src/tint/ast/struct_member_size_attribute.h" #include "src/tint/ast/switch_statement.h" #include "src/tint/ast/templated_identifier.h" -#include "src/tint/ast/type_name.h" +#include "src/tint/ast/type.h" #include "src/tint/ast/unary_op_expression.h" #include "src/tint/ast/var.h" #include "src/tint/ast/variable_decl_statement.h" -#include "src/tint/ast/vector.h" #include "src/tint/ast/while_statement.h" #include "src/tint/ast/workgroup_attribute.h" #include "src/tint/constant/composite.h" @@ -106,6 +99,7 @@ #include "src/tint/type/u32.h" #include "src/tint/type/vector.h" #include "src/tint/type/void.h" +#include "src/tint/utils/string.h" #ifdef CURRENTLY_IN_TINT_PUBLIC_HEADER #error "internal tint header being #included from tint.h" @@ -145,6 +139,14 @@ struct IsVectorLike> { }; } // namespace detail +// A sentinel type used by some template arguments to signal that the a type should be inferred. +struct Infer {}; + +/// Evaluates to true if T is a Infer, AInt or AFloat. +template +static constexpr const bool IsInferOrAbstract = + std::is_same_v, Infer> || IsAbstract>; + // Forward declare metafunction that evaluates to true iff T can be wrapped in a statement. template struct CanWrapInStatement; @@ -163,6 +165,12 @@ class ProgramBuilder { std::is_integral_v> || std::is_floating_point_v> || std::is_same_v; + /// Evaluates to true if T can be converted to an identifier. + template + static constexpr const bool IsIdentifierLike = std::is_same_v || // Symbol + std::is_enum_v || // Enum + traits::IsStringLike; // String + /// A helper used to disable overloads if the first type in `TYPES` is a Source. Used to avoid /// ambiguities in overloads that take a Source as the first parameter and those that /// perfectly-forward the first argument. @@ -177,12 +185,36 @@ class ProgramBuilder { using DisableIfScalar = traits::EnableIf>>>; + /// A helper used to enable overloads if the first type in `TYPES` is a scalar type. Used to + /// avoid ambiguities in overloads that take a scalar as the first parameter and those that + /// perfectly-forward the first argument. + template + using EnableIfScalar = + traits::EnableIf>>>; + /// A helper used to disable overloads if the first type in `TYPES` is a utils::Vector, /// utils::VectorRef or utils::VectorRef. template using DisableIfVectorLike = traits::EnableIf< !detail::IsVectorLike>>::value>; + /// A helper used to enable overloads if the first type in `TYPES` is identifier-like. + template + using EnableIfIdentifierLike = + traits::EnableIf>>>; + + /// A helper used to disable overloads if the first type in `TYPES` is Infer or an abstract + /// numeric. + template + using DisableIfInferOrAbstract = + traits::EnableIf>>>; + + /// A helper used to enable overloads if the first type in `TYPES` is Infer or an abstract + /// numeric. + template + using EnableIfInferOrAbstract = + traits::EnableIf>>>; + /// VarOptions is a helper for accepting an arbitrary number of order independent options for /// constructing an ast::Var. struct VarOptions { @@ -192,14 +224,14 @@ class ProgramBuilder { } ~VarOptions(); - const ast::Type* type = nullptr; + ast::Type type; type::AddressSpace address_space = type::AddressSpace::kNone; type::Access access = type::Access::kUndefined; const ast::Expression* initializer = nullptr; utils::Vector attributes; private: - void Set(const ast::Type* t) { type = t; } + void Set(ast::Type t) { type = t; } void Set(type::AddressSpace addr_space) { address_space = addr_space; } void Set(type::Access ac) { access = ac; } void Set(const ast::Expression* c) { initializer = c; } @@ -219,12 +251,12 @@ class ProgramBuilder { } ~LetOptions(); - const ast::Type* type = nullptr; + ast::Type type; const ast::Expression* initializer = nullptr; utils::Vector attributes; private: - void Set(const ast::Type* t) { type = t; } + void Set(ast::Type t) { type = t; } void Set(const ast::Expression* c) { initializer = c; } void Set(utils::VectorRef l) { attributes = std::move(l); } void Set(const ast::Attribute* a) { attributes.Push(a); } @@ -242,12 +274,12 @@ class ProgramBuilder { } ~ConstOptions(); - const ast::Type* type = nullptr; + ast::Type type; const ast::Expression* initializer = nullptr; utils::Vector attributes; private: - void Set(const ast::Type* t) { type = t; } + void Set(ast::Type t) { type = t; } void Set(const ast::Expression* c) { initializer = c; } void Set(utils::VectorRef l) { attributes = std::move(l); } void Set(const ast::Attribute* a) { attributes.Push(a); } @@ -262,12 +294,12 @@ class ProgramBuilder { } ~OverrideOptions(); - const ast::Type* type = nullptr; + ast::Type type; const ast::Expression* initializer = nullptr; utils::Vector attributes; private: - void Set(const ast::Type* t) { type = t; } + void Set(ast::Type t) { type = t; } void Set(const ast::Expression* c) { initializer = c; } void Set(utils::VectorRef l) { attributes = std::move(l); } void Set(const ast::Attribute* a) { attributes.Push(a); } @@ -551,328 +583,587 @@ class ProgramBuilder { /// @param builder the program builder explicit TypesBuilder(ProgramBuilder* builder); - /// @return the tint AST type for the C type `T`. + /// @return the C type `T`. template - const ast::Type* Of() const { + ast::Type Of() const { return CToAST::get(this); } - /// @returns nullptr ast::Type - const ast::Type* void_() const { return nullptr; } + /// @param type the type to return + /// @return type (passthrough) + ast::Type operator()(const ast::Type& type) const { return type; } - /// @returns a 'bool' typename - const ast::TypeName* bool_() const { return (*this)("bool"); } + /// Creates a type + /// @param name the name + /// @param args the optional template arguments + /// @returns the type + template , + typename = std::enable_if_t, ast::Type>>> + ast::Type operator()(NAME&& name, ARGS&&... args) const { + if constexpr (traits::IsTypeOrDerived, ast::Expression>) { + static_assert(sizeof...(ARGS) == 0); + return {name}; + } else { + return {builder->Expr( + builder->Ident(std::forward(name), std::forward(args)...))}; + } + } + + /// Creates a type + /// @param source the Source of the node + /// @param name the name + /// @param args the optional template arguments + /// @returns the type + template , ast::Type>>> + ast::Type operator()(const Source& source, NAME&& name, ARGS&&... args) const { + return {builder->Expr( + builder->Ident(source, std::forward(name), std::forward(args)...))}; + } + + /// @returns a a nullptr expression wrapped in an ast::Type + ast::Type void_() const { return ast::Type{}; } + + /// @returns a 'bool' type + ast::Type bool_() const { return (*this)("bool"); } /// @param source the Source of the node - /// @returns a 'bool' typename - const ast::TypeName* bool_(const Source& source) const { return (*this)(source, "bool"); } + /// @returns a 'bool' type + ast::Type bool_(const Source& source) const { return (*this)(source, "bool"); } - /// @returns a 'f16' typename - const ast::TypeName* f16() const { return (*this)("f16"); } + /// @returns a 'f16' type + ast::Type f16() const { return (*this)("f16"); } /// @param source the Source of the node - /// @returns a 'f16' typename - const ast::TypeName* f16(const Source& source) const { return (*this)(source, "f16"); } + /// @returns a 'f16' type + ast::Type f16(const Source& source) const { return (*this)(source, "f16"); } - /// @returns a 'f32' typename - const ast::TypeName* f32() const { return (*this)("f32"); } + /// @returns a 'f32' type + ast::Type f32() const { return (*this)("f32"); } /// @param source the Source of the node - /// @returns a 'f32' typename - const ast::TypeName* f32(const Source& source) const { return (*this)(source, "f32"); } + /// @returns a 'f32' type + ast::Type f32(const Source& source) const { return (*this)(source, "f32"); } - /// @returns a 'i32' typename - const ast::TypeName* i32() const { return (*this)("i32"); } + /// @returns a 'i32' type + ast::Type i32() const { return (*this)("i32"); } /// @param source the Source of the node - /// @returns a 'i32' typename - const ast::TypeName* i32(const Source& source) const { return (*this)(source, "i32"); } + /// @returns a 'i32' type + ast::Type i32(const Source& source) const { return (*this)(source, "i32"); } - /// @returns a 'u32' typename - const ast::TypeName* u32() const { return (*this)("u32"); } + /// @returns a 'u32' type + ast::Type u32() const { return (*this)("u32"); } /// @param source the Source of the node - /// @returns a 'u32' typename - const ast::TypeName* u32(const Source& source) const { return (*this)(source, "u32"); } + /// @returns a 'u32' type + ast::Type u32(const Source& source) const { return (*this)(source, "u32"); } /// @param type vector subtype /// @param n vector width in elements - /// @return the tint AST type for a `n`-element vector of `type`. - const ast::Vector* vec(const ast::Type* type, uint32_t n) const { - return builder->create(type, n); - } + /// @return a @p n element vector of @p type + ast::Type vec(ast::Type type, uint32_t n) const { return vec(builder->source_, type, n); } /// @param source the Source of the node /// @param type vector subtype /// @param n vector width in elements - /// @return the tint AST type for a `n`-element vector of `type`. - const ast::Vector* vec(const Source& source, const ast::Type* type, uint32_t n) const { - return builder->create(source, type, n); + /// @return a @p n element vector of @p type + ast::Type vec(const Source& source, ast::Type type, uint32_t n) const { + switch (n) { + case 2: + return vec2(source, type); + case 3: + return vec3(source, type); + case 4: + return vec4(source, type); + } + TINT_ICE(ProgramBuilder, builder->Diagnostics()) << "invalid vector width " << n; + return ast::Type{}; } /// @param type vector subtype - /// @return the tint AST type for a 2-element vector of `type`. - const ast::Vector* vec2(const ast::Type* type) const { return vec(type, 2u); } + /// @return a 2-element vector of @p type + ast::Type vec2(ast::Type type) const { return vec2(builder->source_, type); } /// @param source the vector source /// @param type vector subtype - /// @return the tint AST type for a 2-element vector of `type`. - const ast::Vector* vec2(const Source& source, const ast::Type* type) const { - return vec(source, type, 2u); + /// @return a 2-element vector of @p type + ast::Type vec2(const Source& source, ast::Type type) const { + return (*this)(source, "vec2", type); } /// @param type vector subtype - /// @return the tint AST type for a 3-element vector of `type`. - const ast::Vector* vec3(const ast::Type* type) const { return vec(type, 3u); } + /// @return a 3-element vector of @p type + ast::Type vec3(ast::Type type) const { return vec3(builder->source_, type); } /// @param source the vector source /// @param type vector subtype - /// @return the tint AST type for a 3-element vector of `type`. - const ast::Vector* vec3(const Source& source, const ast::Type* type) const { - return vec(source, type, 3u); + /// @return a 3-element vector of @p type + ast::Type vec3(const Source& source, ast::Type type) const { + return (*this)(source, "vec3", type); } /// @param type vector subtype - /// @return the tint AST type for a 4-element vector of `type`. - const ast::Vector* vec4(const ast::Type* type) const { return vec(type, 4u); } + /// @return a 4-element vector of @p type + ast::Type vec4(ast::Type type) const { return vec4(builder->source_, type); } /// @param source the vector source /// @param type vector subtype - /// @return the tint AST type for a 4-element vector of `type`. - const ast::Vector* vec4(const Source& source, const ast::Type* type) const { - return vec(source, type, 4u); + /// @return a 4-element vector of @p type + ast::Type vec4(const Source& source, ast::Type type) const { + return (*this)(source, "vec4", type); + } + + /// @param source the Source of the node + /// @return a 2-element vector of the type `T` + template + ast::Type vec2(const Source& source) const { + if constexpr (IsInferOrAbstract) { + return (*this)(source, "vec2"); + } else { + return (*this)(source, "vec2", Of()); + } + } + + /// @param source the Source of the node + /// @return a 3-element vector of the type `T` + template + ast::Type vec3(const Source& source) const { + if constexpr (IsInferOrAbstract) { + return (*this)(source, "vec3"); + } else { + return (*this)(source, "vec3", Of()); + } + } + + /// @param source the Source of the node + /// @return a 4-element vector of the type `T` + template + ast::Type vec4(const Source& source) const { + if constexpr (IsInferOrAbstract) { + return (*this)(source, "vec4"); + } else { + return (*this)(source, "vec4", Of()); + } + } + + /// @return a 2-element vector of the type `T` + template + ast::Type vec2() const { + return vec2(builder->source_); + } + + /// @return a 3-element vector of the type `T` + template + ast::Type vec3() const { + return vec3(builder->source_); + } + + /// @return a 4-element vector of the type `T` + template + ast::Type vec4() const { + return vec4(builder->source_); + } + + /// @param source the Source of the node + /// @param n vector width in elements + /// @return a @p n element vector of @p type + template + ast::Type vec(const Source& source, uint32_t n) const { + switch (n) { + case 2: + return vec2(source); + case 3: + return vec3(source); + case 4: + return vec4(source); + } + TINT_ICE(ProgramBuilder, builder->Diagnostics()) << "invalid vector width " << n; + return ast::Type{}; + } + + /// @return a @p N element vector of @p type + template + ast::Type vec() const { + return vec(builder->source_, N); } /// @param n vector width in elements - /// @return the tint AST type for a `n`-element vector of `type`. + /// @return a @p n element vector of @p type template - const ast::Vector* vec(uint32_t n) const { - return vec(Of(), n); - } - - /// @return the tint AST type for a 2-element vector of the C type `T`. - template - const ast::Vector* vec2() const { - return vec2(Of()); - } - - /// @param source the Source of the node - /// @return the tint AST type for a 2-element vector of the C type `T`. - template - const ast::Vector* vec2(const Source& source) const { - return vec2(source, Of()); - } - - /// @return the tint AST type for a 3-element vector of the C type `T`. - template - const ast::Vector* vec3() const { - return vec3(Of()); - } - - /// @param source the Source of the node - /// @return the tint AST type for a 3-element vector of the C type `T`. - template - const ast::Vector* vec3(const Source& source) const { - return vec3(source, Of()); - } - - /// @return the tint AST type for a 4-element vector of the C type `T`. - template - const ast::Vector* vec4() const { - return vec4(Of()); - } - - /// @param source the Source of the node - /// @return the tint AST type for a 4-element vector of the C type `T`. - template - const ast::Vector* vec4(const Source& source) const { - return vec4(source, Of()); + ast::Type vec(uint32_t n) const { + return vec(builder->source_, n); } /// @param type matrix subtype /// @param columns number of columns for the matrix /// @param rows number of rows for the matrix - /// @return the tint AST type for a matrix of `type` - const ast::Matrix* mat(const ast::Type* type, uint32_t columns, uint32_t rows) const { - return builder->create(type, rows, columns); + /// @return a matrix of @p type + ast::Type mat(ast::Type type, uint32_t columns, uint32_t rows) const { + return mat(builder->source_, type, columns, rows); } /// @param source the Source of the node /// @param type matrix subtype /// @param columns number of columns for the matrix /// @param rows number of rows for the matrix - /// @return the tint AST type for a matrix of `type` - const ast::Matrix* mat(const Source& source, - const ast::Type* type, - uint32_t columns, - uint32_t rows) const { - return builder->create(source, type, rows, columns); + /// @return a matrix of @p type + ast::Type mat(const Source& source, ast::Type type, uint32_t columns, uint32_t rows) const { + if (TINT_LIKELY(columns >= 2 && columns <= 4 && rows >= 2 && rows <= 4)) { + static constexpr const char* names[] = { + "mat2x2", "mat2x3", "mat2x4", // + "mat3x2", "mat3x3", "mat3x4", // + "mat4x2", "mat4x3", "mat4x4", // + }; + auto i = (columns - 2) * 3 + (rows - 2); + return (*this)(source, names[i], type); + } + TINT_ICE(ProgramBuilder, builder->Diagnostics()) + << "invalid matrix dimensions " << columns << "x" << rows; + return ast::Type{}; } /// @param type matrix subtype - /// @return the tint AST type for a 2x3 matrix of `type`. - const ast::Matrix* mat2x2(const ast::Type* type) const { return mat(type, 2u, 2u); } + /// @return a 2x3 matrix of @p type. + ast::Type mat2x2(ast::Type type) const { return (*this)("mat2x2", type); } /// @param type matrix subtype - /// @return the tint AST type for a 2x3 matrix of `type`. - const ast::Matrix* mat2x3(const ast::Type* type) const { return mat(type, 2u, 3u); } + /// @return a 2x3 matrix of @p type. + ast::Type mat2x3(ast::Type type) const { return (*this)("mat2x3", type); } /// @param type matrix subtype - /// @return the tint AST type for a 2x4 matrix of `type`. - const ast::Matrix* mat2x4(const ast::Type* type) const { return mat(type, 2u, 4u); } + /// @return a 2x4 matrix of @p type. + ast::Type mat2x4(ast::Type type) const { return (*this)("mat2x4", type); } /// @param type matrix subtype - /// @return the tint AST type for a 3x2 matrix of `type`. - const ast::Matrix* mat3x2(const ast::Type* type) const { return mat(type, 3u, 2u); } + /// @return a 3x2 matrix of @p type. + ast::Type mat3x2(ast::Type type) const { return (*this)("mat3x2", type); } /// @param type matrix subtype - /// @return the tint AST type for a 3x3 matrix of `type`. - const ast::Matrix* mat3x3(const ast::Type* type) const { return mat(type, 3u, 3u); } + /// @return a 3x3 matrix of @p type. + ast::Type mat3x3(ast::Type type) const { return (*this)("mat3x3", type); } /// @param type matrix subtype - /// @return the tint AST type for a 3x4 matrix of `type`. - const ast::Matrix* mat3x4(const ast::Type* type) const { return mat(type, 3u, 4u); } + /// @return a 3x4 matrix of @p type. + ast::Type mat3x4(ast::Type type) const { return (*this)("mat3x4", type); } /// @param type matrix subtype - /// @return the tint AST type for a 4x2 matrix of `type`. - const ast::Matrix* mat4x2(const ast::Type* type) const { return mat(type, 4u, 2u); } + /// @return a 4x2 matrix of @p type. + ast::Type mat4x2(ast::Type type) const { return (*this)("mat4x2", type); } /// @param type matrix subtype - /// @return the tint AST type for a 4x3 matrix of `type`. - const ast::Matrix* mat4x3(const ast::Type* type) const { return mat(type, 4u, 3u); } + /// @return a 4x3 matrix of @p type. + ast::Type mat4x3(ast::Type type) const { return (*this)("mat4x3", type); } /// @param type matrix subtype - /// @return the tint AST type for a 4x4 matrix of `type`. - const ast::Matrix* mat4x4(const ast::Type* type) const { return mat(type, 4u, 4u); } + /// @return a 4x4 matrix of @p type. + ast::Type mat4x4(ast::Type type) const { return (*this)("mat4x4", type); } + + /// @param source the source of the type + /// @return a 2x2 matrix of the type `T` + template + ast::Type mat2x2(const Source& source) const { + if constexpr (IsInferOrAbstract) { + return (*this)(source, "mat2x2"); + } else { + return (*this)(source, "mat2x2", Of()); + } + } + + /// @param source the source of the type + /// @return a 2x3 matrix of the type `T` + template + ast::Type mat2x3(const Source& source) const { + if constexpr (IsInferOrAbstract) { + return (*this)(source, "mat2x3"); + } else { + return (*this)(source, "mat2x3", Of()); + } + } + + /// @param source the source of the type + /// @return a 2x4 matrix of the type `T` + template + ast::Type mat2x4(const Source& source) const { + if constexpr (IsInferOrAbstract) { + return (*this)(source, "mat2x4"); + } else { + return (*this)(source, "mat2x4", Of()); + } + } + + /// @param source the source of the type + /// @return a 3x2 matrix of the type `T` + template + ast::Type mat3x2(const Source& source) const { + if constexpr (IsInferOrAbstract) { + return (*this)(source, "mat3x2"); + } else { + return (*this)(source, "mat3x2", Of()); + } + } + + /// @param source the source of the type + /// @return a 3x3 matrix of the type `T` + template + ast::Type mat3x3(const Source& source) const { + if constexpr (IsInferOrAbstract) { + return (*this)(source, "mat3x3"); + } else { + return (*this)(source, "mat3x3", Of()); + } + } + + /// @param source the source of the type + /// @return a 3x4 matrix of the type `T` + template + ast::Type mat3x4(const Source& source) const { + if constexpr (IsInferOrAbstract) { + return (*this)(source, "mat3x4"); + } else { + return (*this)(source, "mat3x4", Of()); + } + } + + /// @param source the source of the type + /// @return a 4x2 matrix of the type `T` + template + ast::Type mat4x2(const Source& source) const { + if constexpr (IsInferOrAbstract) { + return (*this)(source, "mat4x2"); + } else { + return (*this)(source, "mat4x2", Of()); + } + } + + /// @param source the source of the type + /// @return a 4x3 matrix of the type `T` + template + ast::Type mat4x3(const Source& source) const { + if constexpr (IsInferOrAbstract) { + return (*this)(source, "mat4x3"); + } else { + return (*this)(source, "mat4x3", Of()); + } + } + + /// @param source the source of the type + /// @return a 4x4 matrix of the type `T` + template + ast::Type mat4x4(const Source& source) const { + if constexpr (IsInferOrAbstract) { + return (*this)(source, "mat4x4"); + } else { + return (*this)(source, "mat4x4", Of()); + } + } + + /// @return a 2x2 matrix of the type `T` + template + ast::Type mat2x2() const { + return mat2x2(builder->source_); + } + + /// @return a 2x3 matrix of the type `T` + template + ast::Type mat2x3() const { + return mat2x3(builder->source_); + } + + /// @return a 2x4 matrix of the type `T` + template + ast::Type mat2x4() const { + return mat2x4(builder->source_); + } + + /// @return a 3x2 matrix of the type `T` + template + ast::Type mat3x2() const { + return mat3x2(builder->source_); + } + + /// @return a 3x3 matrix of the type `T` + template + ast::Type mat3x3() const { + return mat3x3(builder->source_); + } + + /// @return a 3x4 matrix of the type `T` + template + ast::Type mat3x4() const { + return mat3x4(builder->source_); + } + + /// @return a 4x2 matrix of the type `T` + template + ast::Type mat4x2() const { + return mat4x2(builder->source_); + } + + /// @return a 4x3 matrix of the type `T` + template + ast::Type mat4x3() const { + return mat4x3(builder->source_); + } + + /// @return a 4x4 matrix of the type `T` + template + ast::Type mat4x4() const { + return mat4x4(builder->source_); + } + + /// @param source the Source of the node + /// @param columns number of columns for the matrix + /// @param rows number of rows for the matrix + /// @return a matrix of @p type + template + ast::Type mat(const Source& source, uint32_t columns, uint32_t rows) const { + switch ((columns - 2) * 3 + (rows - 2)) { + case 0: + return mat2x2(source); + case 1: + return mat2x3(source); + case 2: + return mat2x4(source); + case 3: + return mat3x2(source); + case 4: + return mat3x3(source); + case 5: + return mat3x4(source); + case 6: + return mat4x2(source); + case 7: + return mat4x3(source); + case 8: + return mat4x4(source); + default: + TINT_ICE(ProgramBuilder, builder->Diagnostics()) + << "invalid matrix dimensions " << columns << "x" << rows; + return ast::Type{}; + } + } /// @param columns number of columns for the matrix /// @param rows number of rows for the matrix - /// @return the tint AST type for a matrix of `type` + /// @return a matrix of @p type template - const ast::Matrix* mat(uint32_t columns, uint32_t rows) const { - return mat(Of(), columns, rows); + ast::Type mat(uint32_t columns, uint32_t rows) const { + return mat(builder->source_, columns, rows); } - /// @return the tint AST type for a 2x3 matrix of the C type `T`. - template - const ast::Matrix* mat2x2() const { - return mat2x2(Of()); + /// @return a matrix of @p type + template + ast::Type mat() const { + return mat(builder->source_, COLUMNS, ROWS); } - /// @return the tint AST type for a 2x3 matrix of the C type `T`. - template - const ast::Matrix* mat2x3() const { - return mat2x3(Of()); - } - - /// @return the tint AST type for a 2x4 matrix of the C type `T`. - template - const ast::Matrix* mat2x4() const { - return mat2x4(Of()); - } - - /// @return the tint AST type for a 3x2 matrix of the C type `T`. - template - const ast::Matrix* mat3x2() const { - return mat3x2(Of()); - } - - /// @return the tint AST type for a 3x3 matrix of the C type `T`. - template - const ast::Matrix* mat3x3() const { - return mat3x3(Of()); - } - - /// @return the tint AST type for a 3x4 matrix of the C type `T`. - template - const ast::Matrix* mat3x4() const { - return mat3x4(Of()); - } - - /// @return the tint AST type for a 4x2 matrix of the C type `T`. - template - const ast::Matrix* mat4x2() const { - return mat4x2(Of()); - } - - /// @return the tint AST type for a 4x3 matrix of the C type `T`. - template - const ast::Matrix* mat4x3() const { - return mat4x3(Of()); - } - - /// @return the tint AST type for a 4x4 matrix of the C type `T`. - template - const ast::Matrix* mat4x4() const { - return mat4x4(Of()); + /// @param subtype the array element type + /// @param attrs the optional attributes for the array + /// @return an array of type `T` + ast::Type array(ast::Type subtype, + utils::VectorRef attrs = utils::Empty) const { + return array(builder->source_, subtype, std::move(attrs)); } /// @param subtype the array element type /// @param n the array size. nullptr represents a runtime-array /// @param attrs the optional attributes for the array - /// @return the array of size `n` of type `T` - template - const ast::Array* array( - const ast::Type* subtype, - COUNT&& n = nullptr, - utils::VectorRef attrs = utils::Empty) const { + /// @return an array of size `n` of type `T` + template > + ast::Type array(ast::Type subtype, + COUNT&& n, + utils::VectorRef attrs = utils::Empty) const { return array(builder->source_, subtype, std::forward(n), std::move(attrs)); } + /// @param source the Source of the node + /// @param subtype the array element type + /// @param attrs the optional attributes for the array + /// @return an array of type `T` + ast::Type array(const Source& source, + ast::Type subtype, + utils::VectorRef attrs = utils::Empty) const { + return ast::Type{builder->Expr( + builder->create(source, builder->Sym("array"), + utils::Vector{ + subtype.expr, + }, + std::move(attrs)))}; + } + /// @param source the Source of the node /// @param subtype the array element type /// @param n the array size. nullptr represents a runtime-array /// @param attrs the optional attributes for the array - /// @return the array of size `n` of type `T` - template - const ast::Array* array( - const Source& source, - const ast::Type* subtype, - COUNT&& n = nullptr, - utils::VectorRef attrs = utils::Empty) const { - if constexpr (std::is_same_v, std::nullptr_t>) { - return builder->create(source, subtype, nullptr, std::move(attrs)); - } else { - return builder->create( - source, subtype, builder->Expr(std::forward(n)), std::move(attrs)); - } + /// @return an array of size `n` of type `T` + template > + ast::Type array(const Source& source, + ast::Type subtype, + COUNT&& n, + utils::VectorRef attrs = utils::Empty) const { + return ast::Type{builder->Expr( + builder->create(source, builder->Sym("array"), + utils::Vector{ + subtype.expr, + builder->Expr(std::forward(n)), + }, + std::move(attrs)))}; } - /// @param attrs the optional attributes for the array - /// @return the runtime-sized array of type `T` - template - const ast::Array* array( - utils::VectorRef attrs = utils::Empty) const { - return array(Of(), nullptr, std::move(attrs)); - } - - /// @param attrs the optional attributes for the array - /// @return the array of size `N` of type `T` - template - const ast::Array* array( - utils::VectorRef attrs = utils::Empty) const { - return array(Of(), tint::u32(N), std::move(attrs)); - } - - /// Creates a type name - /// @param name the name - /// @param args the optional template arguments - /// @returns the type name - template > - const ast::TypeName* operator()(NAME&& name, ARGS&&... args) const { - return (*this)(builder->source_, std::forward(name), std::forward(args)...); - } - - /// Creates a type name /// @param source the Source of the node - /// @param name the name - /// @param args the optional template arguments - /// @returns the type name - template - const ast::TypeName* operator()(const Source& source, NAME&& name, ARGS&&... args) const { - return builder->create( - source, - builder->Ident(source, std::forward(name), std::forward(args)...)); + /// @return a inferred-size or runtime-sized array of type `T` + template > + ast::Type array(const Source& source) const { + return (*this)(source, "array"); + } + + /// @return a inferred-size or runtime-sized array of type `T` + template > + ast::Type array() const { + return array(builder->source_); + } + + /// @param source the Source of the node + /// @param attrs the optional attributes for the array + /// @return a inferred-size or runtime-sized array of type `T` + template > + ast::Type array(const Source& source, + utils::VectorRef attrs = utils::Empty) const { + return ast::Type{builder->Expr( + builder->create(source, builder->Sym("array"), + utils::Vector{ + Of().expr, + }, + std::move(attrs)))}; + } + + /// @param attrs the optional attributes for the array + /// @return a inferred-size or runtime-sized array of type `T` + template > + ast::Type array(utils::VectorRef attrs = utils::Empty) const { + return array(builder->source_, std::move(attrs)); + } + + /// @param source the Source of the node + /// @param attrs the optional attributes for the array + /// @return an array of size `N` of type `T` + template + ast::Type array(const Source& source, + utils::VectorRef attrs = utils::Empty) const { + static_assert(!IsInferOrAbstract, "arrays with a count cannot be inferred"); + return array(source, Of(), tint::u32(N), std::move(attrs)); + } + + /// @param attrs the optional attributes for the array + /// @return an array of size `N` of type `T` + template + ast::Type array(utils::VectorRef attrs = utils::Empty) const { + static_assert(!IsInferOrAbstract, "arrays with a count cannot be inferred"); + return array(builder->source_, std::move(attrs)); } /// Creates an alias type @@ -880,7 +1171,7 @@ class ProgramBuilder { /// @param type the alias type /// @returns the alias pointer template - const ast::Alias* alias(NAME&& name, const ast::Type* type) const { + const ast::Alias* alias(NAME&& name, ast::Type type) const { return alias(builder->source_, std::forward(name), type); } @@ -890,7 +1181,7 @@ class ProgramBuilder { /// @param type the alias type /// @returns the alias pointer template - const ast::Alias* alias(const Source& source, NAME&& name, const ast::Type* type) const { + const ast::Alias* alias(const Source& source, NAME&& name, ast::Type type) const { return builder->create(source, builder->Ident(std::forward(name)), type); } @@ -899,10 +1190,10 @@ class ProgramBuilder { /// @param address_space the address space of the pointer /// @param access the optional access control of the pointer /// @return the pointer to `type` with the given type::AddressSpace - const ast::Pointer* pointer(const ast::Type* type, - type::AddressSpace address_space, - type::Access access = type::Access::kUndefined) const { - return builder->create(type, address_space, access); + ast::Type pointer(ast::Type type, + type::AddressSpace address_space, + type::Access access = type::Access::kUndefined) const { + return pointer(builder->source_, type, address_space, access); } /// @param source the Source of the node @@ -910,20 +1201,24 @@ class ProgramBuilder { /// @param address_space the address space of the pointer /// @param access the optional access control of the pointer /// @return the pointer to `type` with the given type::AddressSpace - const ast::Pointer* pointer(const Source& source, - const ast::Type* type, - type::AddressSpace address_space, - type::Access access = type::Access::kUndefined) const { - return builder->create(source, type, address_space, access); + ast::Type pointer(const Source& source, + ast::Type type, + type::AddressSpace address_space, + type::Access access = type::Access::kUndefined) const { + if (access != type::Access::kUndefined) { + return (*this)(source, "ptr", address_space, type, access); + } else { + return (*this)(source, "ptr", address_space, type); + } } /// @param address_space the address space of the pointer /// @param access the optional access control of the pointer /// @return the pointer to type `T` with the given type::AddressSpace. template - const ast::Pointer* pointer(type::AddressSpace address_space, - type::Access access = type::Access::kUndefined) const { - return pointer(Of(), address_space, access); + ast::Type pointer(type::AddressSpace address_space, + type::Access access = type::Access::kUndefined) const { + return pointer(builder->source_, address_space, access); } /// @param source the Source of the node @@ -931,41 +1226,41 @@ class ProgramBuilder { /// @param access the optional access control of the pointer /// @return the pointer to type `T` with the given type::AddressSpace. template - const ast::Pointer* pointer(const Source& source, - type::AddressSpace address_space, - type::Access access = type::Access::kUndefined) const { - return pointer(source, Of(), address_space, access); + ast::Type pointer(const Source& source, + type::AddressSpace address_space, + type::Access access = type::Access::kUndefined) const { + if (access != type::Access::kUndefined) { + return (*this)(source, "ptr", address_space, Of(), access); + } else { + return (*this)(source, "ptr", address_space, Of()); + } } /// @param source the Source of the node /// @param type the type of the atomic /// @return the atomic to `type` - const ast::Atomic* atomic(const Source& source, const ast::Type* type) const { - return builder->create(source, type); + ast::Type atomic(const Source& source, ast::Type type) const { + return (*this)(source, "atomic", type); } /// @param type the type of the atomic /// @return the atomic to `type` - const ast::Atomic* atomic(const ast::Type* type) const { - return builder->create(type); - } + ast::Type atomic(ast::Type type) const { return (*this)("atomic", type); } /// @return the atomic to type `T` template - const ast::Atomic* atomic() const { + ast::Type atomic() const { return atomic(Of()); } /// @param kind the kind of sampler - /// @returns the sampler typename - const ast::TypeName* sampler(type::SamplerKind kind) const { - return sampler(builder->source_, kind); - } + /// @returns the sampler + ast::Type sampler(type::SamplerKind kind) const { return sampler(builder->source_, kind); } /// @param source the Source of the node /// @param kind the kind of sampler - /// @returns the sampler typename - const ast::TypeName* sampler(const Source& source, type::SamplerKind kind) const { + /// @returns the sampler + ast::Type sampler(const Source& source, type::SamplerKind kind) const { switch (kind) { case type::SamplerKind::kSampler: return (*this)(source, "sampler"); @@ -973,20 +1268,19 @@ class ProgramBuilder { return (*this)(source, "sampler_comparison"); } TINT_ICE(ProgramBuilder, builder->Diagnostics()) << "invalid sampler kind " << kind; - return nullptr; + return ast::Type{}; } /// @param dims the dimensionality of the texture - /// @returns the depth texture typename - const ast::TypeName* depth_texture(type::TextureDimension dims) const { + /// @returns the depth texture + ast::Type depth_texture(type::TextureDimension dims) const { return depth_texture(builder->source_, dims); } /// @param source the Source of the node /// @param dims the dimensionality of the texture - /// @returns the depth texture typename - const ast::TypeName* depth_texture(const Source& source, - type::TextureDimension dims) const { + /// @returns the depth texture + ast::Type depth_texture(const Source& source, type::TextureDimension dims) const { switch (dims) { case type::TextureDimension::k2d: return (*this)(source, "texture_depth_2d"); @@ -1001,71 +1295,92 @@ class ProgramBuilder { } TINT_ICE(ProgramBuilder, builder->Diagnostics()) << "invalid depth_texture dimensions: " << dims; - return nullptr; + return ast::Type{}; } /// @param dims the dimensionality of the texture - /// @returns the multisampled depth texture typename - const ast::TypeName* depth_multisampled_texture(type::TextureDimension dims) const { + /// @returns the multisampled depth texture + ast::Type depth_multisampled_texture(type::TextureDimension dims) const { return depth_multisampled_texture(builder->source_, dims); } /// @param source the Source of the node /// @param dims the dimensionality of the texture - /// @returns the multisampled depth texture typename - const ast::TypeName* depth_multisampled_texture(const Source& source, - type::TextureDimension dims) const { + /// @returns the multisampled depth texture + ast::Type depth_multisampled_texture(const Source& source, + type::TextureDimension dims) const { if (dims == type::TextureDimension::k2d) { return (*this)(source, "texture_depth_multisampled_2d"); } TINT_ICE(ProgramBuilder, builder->Diagnostics()) << "invalid depth_multisampled_texture dimensions: " << dims; - return nullptr; + return ast::Type{}; } /// @param dims the dimensionality of the texture /// @param subtype the texture subtype. /// @returns the sampled texture - const ast::SampledTexture* sampled_texture(type::TextureDimension dims, - const ast::Type* subtype) const { - return builder->create(dims, subtype); + ast::Type sampled_texture(type::TextureDimension dims, ast::Type subtype) const { + return sampled_texture(builder->source_, dims, subtype); } /// @param source the Source of the node /// @param dims the dimensionality of the texture /// @param subtype the texture subtype. /// @returns the sampled texture - const ast::SampledTexture* sampled_texture(const Source& source, - type::TextureDimension dims, - const ast::Type* subtype) const { - return builder->create(source, dims, subtype); + ast::Type sampled_texture(const Source& source, + type::TextureDimension dims, + ast::Type subtype) const { + switch (dims) { + case type::TextureDimension::k1d: + return (*this)(source, "texture_1d", subtype); + case type::TextureDimension::k2d: + return (*this)(source, "texture_2d", subtype); + case type::TextureDimension::k3d: + return (*this)(source, "texture_3d", subtype); + case type::TextureDimension::k2dArray: + return (*this)(source, "texture_2d_array", subtype); + case type::TextureDimension::kCube: + return (*this)(source, "texture_cube", subtype); + case type::TextureDimension::kCubeArray: + return (*this)(source, "texture_cube_array", subtype); + default: + break; + } + TINT_ICE(ProgramBuilder, builder->Diagnostics()) + << "invalid sampled_texture dimensions: " << dims; + return ast::Type{}; } /// @param dims the dimensionality of the texture /// @param subtype the texture subtype. /// @returns the multisampled texture - const ast::MultisampledTexture* multisampled_texture(type::TextureDimension dims, - const ast::Type* subtype) const { - return builder->create(dims, subtype); + ast::Type multisampled_texture(type::TextureDimension dims, ast::Type subtype) const { + return multisampled_texture(builder->source_, dims, subtype); } /// @param source the Source of the node /// @param dims the dimensionality of the texture /// @param subtype the texture subtype. /// @returns the multisampled texture - const ast::MultisampledTexture* multisampled_texture(const Source& source, - type::TextureDimension dims, - const ast::Type* subtype) const { - return builder->create(source, dims, subtype); + ast::Type multisampled_texture(const Source& source, + type::TextureDimension dims, + ast::Type subtype) const { + if (dims == type::TextureDimension::k2d) { + return (*this)(source, "texture_multisampled_2d", subtype); + } + TINT_ICE(ProgramBuilder, builder->Diagnostics()) + << "invalid multisampled_texture dimensions: " << dims; + return ast::Type{}; } /// @param dims the dimensionality of the texture /// @param format the texel format of the texture /// @param access the access control of the texture - /// @returns the storage texture typename - const ast::TypeName* storage_texture(type::TextureDimension dims, - type::TexelFormat format, - type::Access access) const { + /// @returns the storage texture + ast::Type storage_texture(type::TextureDimension dims, + type::TexelFormat format, + type::Access access) const { return storage_texture(builder->source_, dims, format, access); } @@ -1073,45 +1388,40 @@ class ProgramBuilder { /// @param dims the dimensionality of the texture /// @param format the texel format of the texture /// @param access the access control of the texture - /// @returns the storage texture typename - const ast::TypeName* storage_texture(const Source& source, - type::TextureDimension dims, - type::TexelFormat format, - type::Access access) const { + /// @returns the storage texture + ast::Type storage_texture(const Source& source, + type::TextureDimension dims, + type::TexelFormat format, + type::Access access) const { switch (dims) { case type::TextureDimension::k1d: - return (*this)(source, "texture_storage_1d", utils::ToString(format), - utils::ToString(access)); + return (*this)(source, "texture_storage_1d", format, access); case type::TextureDimension::k2d: - return (*this)(source, "texture_storage_2d", utils::ToString(format), - utils::ToString(access)); + return (*this)(source, "texture_storage_2d", format, access); case type::TextureDimension::k2dArray: - return (*this)(source, "texture_storage_2d_array", utils::ToString(format), - utils::ToString(access)); + return (*this)(source, "texture_storage_2d_array", format, access); case type::TextureDimension::k3d: - return (*this)(source, "texture_storage_3d", utils::ToString(format), - utils::ToString(access)); + return (*this)(source, "texture_storage_3d", format, access); default: break; } TINT_ICE(ProgramBuilder, builder->Diagnostics()) - << "invalid sampled_texture dimensions: " << dims; - return nullptr; + << "invalid storage_texture dimensions: " << dims; + return ast::Type{}; } /// @returns the external texture - const ast::TypeName* external_texture() const { return external_texture(builder->source_); } + ast::Type external_texture() const { return (*this)("texture_external"); } /// @param source the Source of the node - /// @returns the external texture typename - const ast::TypeName* external_texture(const Source& source) const { + /// @returns the external texture + ast::Type external_texture(const Source& source) const { return (*this)(source, "texture_external"); } - /// Constructs a TypeName for the type declaration. /// @param type the type - /// @return either type or a pointer to a new ast::TypeName - const ast::TypeName* Of(const ast::TypeDecl* type) const; + /// @return an ast::Type of the type declaration. + ast::Type Of(const ast::TypeDecl* type) const { return (*this)(type->name->symbol); } /// The ProgramBuilder ProgramBuilder* const builder; @@ -1121,7 +1431,7 @@ class ProgramBuilder { /// contains a single static `get()` method for obtaining the corresponding /// AST type for the C type `T`. /// `get()` has the signature: - /// `static const ast::Type* get(Types* t)` + /// `static ast::Type get(Types* t)` template struct CToAST {}; }; @@ -1133,91 +1443,107 @@ class ProgramBuilder { /// @return a new unnamed symbol Symbol Sym() { return Symbols().New(); } - /// @param name the symbol string - /// @return a Symbol with the given name - Symbol Sym(const std::string& name) { return Symbols().Register(name); } - + /// Passthrough /// @param sym the symbol /// @return `sym` Symbol Sym(Symbol sym) { return sym; } - /// @param source the source information + /// @param name the symbol string + /// @return a Symbol with the given name + Symbol Sym(const std::string& name) { return Symbols().Register(name); } + + /// @param enumerator the enumerator + /// @return a Symbol with the given enum value + template >>> + Symbol Sym(ENUM&& enumerator) { + return Sym(utils::ToString(enumerator)); + } + + /// @return nullptr + const ast::Identifier* Ident(std::nullptr_t) { return nullptr; } + /// @param identifier the identifier symbol - /// @param args optional templated identifier arguments /// @return an ast::Identifier with the given symbol - template - const auto* Ident(const Source& source, IDENTIFIER&& identifier, ARGS&&... args) { - Symbol sym = Sym(std::forward(identifier)); - if constexpr (sizeof...(args) > 0) { - return create(source, sym, - ExprList(std::forward(args)...)); + template + const ast::Identifier* Ident(IDENTIFIER&& identifier) { + if constexpr (traits::IsTypeOrDerived, ast::Identifier>) { + return identifier; // Passthrough } else { - return create(source, sym); + return Ident(source_, std::forward(identifier)); } } + /// @param source the source information /// @param identifier the identifier symbol - /// @param args optional templated identifier arguments /// @return an ast::Identifier with the given symbol + template + const ast::Identifier* Ident(const Source& source, IDENTIFIER&& identifier) { + return create(source, Sym(std::forward(identifier))); + } + + /// @param identifier the identifier symbol + /// @param args the templated identifier arguments + /// @return an ast::TemplatedIdentifier with the given symbol and template arguments template > - const auto* Ident(IDENTIFIER&& identifier, ARGS&&... args) { - if constexpr (traits::IsTypeOrDerived, ast::Identifier>) { - static_assert(sizeof...(args) == 0); - return identifier; // Pass-through - } else { - return Ident(source_, std::forward(identifier), - std::forward(args)...); - } + const ast::TemplatedIdentifier* Ident(IDENTIFIER&& identifier, ARGS&&... args) { + return Ident(source_, std::forward(identifier), std::forward(args)...); + } + + /// @param source the source information + /// @param identifier the identifier symbol + /// @param args the templated identifier arguments + /// @return an ast::TemplatedIdentifier with the given symbol and template arguments + template + const ast::TemplatedIdentifier* Ident(const Source& source, + IDENTIFIER&& identifier, + ARGS&&... args) { + return create(source, Sym(std::forward(identifier)), + ExprList(std::forward(args)...), + utils::Empty); } /// @param expr the expression - /// @return expr - template - traits::EnableIfIsType* Expr(T* expr) { + /// @return expr (passthrough) + template > + const T* Expr(const T* expr) { return expr; } + /// @param type an ast::Type + /// @return type.expr + const ast::IdentifierExpression* Expr(ast::Type type) { return type.expr; } + + /// @param ident the identifier + /// @return an ast::IdentifierExpression with the given identifier + const ast::IdentifierExpression* Expr(const ast::Identifier* ident) { + return ident ? create(ident->source, ident) : nullptr; + } + /// Passthrough for nullptr /// @return nullptr const ast::IdentifierExpression* Expr(std::nullptr_t) { return nullptr; } - /// @param source the source information - /// @param symbol the identifier symbol - /// @return an ast::IdentifierExpression with the given symbol - const ast::IdentifierExpression* Expr(const Source& source, Symbol symbol) { - return create(source, Ident(source, symbol)); - } - - /// @param symbol the identifier symbol - /// @return an ast::IdentifierExpression with the given symbol - const ast::IdentifierExpression* Expr(Symbol symbol) { - return create(Ident(symbol)); + /// @param name the identifier name + /// @return an ast::IdentifierExpression with the given name + template > + const ast::IdentifierExpression* Expr(NAME&& name) { + auto* ident = Ident(source_, name); + return create(ident->source, ident); } /// @param source the source information /// @param name the identifier name /// @return an ast::IdentifierExpression with the given name - const ast::IdentifierExpression* Expr(const Source& source, const char* name) { + template > + const ast::IdentifierExpression* Expr(const Source& source, NAME&& name) { return create(source, Ident(source, name)); } - /// @param name the identifier name - /// @return an ast::IdentifierExpression with the given name - const ast::IdentifierExpression* Expr(const char* name) { - return create(Ident(name)); - } - - /// @param source the source information - /// @param name the identifier name - /// @return an ast::IdentifierExpression with the given name - const ast::IdentifierExpression* Expr(const Source& source, const std::string& name) { - return create(source, Ident(source, name)); - } - - /// @param name the identifier name - /// @return an ast::IdentifierExpression with the given name - const ast::IdentifierExpression* Expr(const std::string& name) { - return create(Ident(name)); + /// @param variable the AST variable + /// @return an ast::IdentifierExpression with the variable's symbol + const ast::IdentifierExpression* Expr(const ast::Variable* variable) { + auto* ident = Ident(variable->source, variable->name->symbol); + return create(ident->source, ident); } /// @param source the source information @@ -1227,19 +1553,6 @@ class ProgramBuilder { return create(source, Ident(source, variable->name->symbol)); } - /// @param variable the AST variable - /// @return an ast::IdentifierExpression with the variable's symbol - const ast::IdentifierExpression* Expr(const ast::Variable* variable) { - return create(Ident(variable->name->symbol)); - } - - /// @param ident the identifier - /// @return an ast::IdentifierExpression with the given identifier - template > - const ast::IdentifierExpression* Expr(const IDENTIFIER* ident) { - return create(ident); - } - /// @param source the source information /// @param value the boolean value /// @return a Scalar constructor for the given value @@ -1250,14 +1563,6 @@ class ProgramBuilder { return create(source, value); } - /// @param value the boolean value - /// @return a Scalar constructor for the given value - template - std::enable_if_t, const ast::BoolLiteralExpression*> Expr( - BOOL value) { - return create(value); - } - /// @param source the source information /// @param value the float value /// @return a 'f'-suffixed FloatLiteralExpression for the f32 value @@ -1266,13 +1571,6 @@ class ProgramBuilder { ast::FloatLiteralExpression::Suffix::kF); } - /// @param value the float value - /// @return a 'f'-suffixed FloatLiteralExpression for the f32 value - const ast::FloatLiteralExpression* Expr(f32 value) { - return create(static_cast(value.value), - ast::FloatLiteralExpression::Suffix::kF); - } - /// @param source the source information /// @param value the float value /// @return a 'h'-suffixed FloatLiteralExpression for the f16 value @@ -1281,13 +1579,6 @@ class ProgramBuilder { ast::FloatLiteralExpression::Suffix::kH); } - /// @param value the float value - /// @return a 'h'-suffixed FloatLiteralExpression for the f16 value - const ast::FloatLiteralExpression* Expr(f16 value) { - return create(static_cast(value.value), - ast::FloatLiteralExpression::Suffix::kH); - } - /// @param source the source information /// @param value the integer value /// @return an unsuffixed IntLiteralExpression for the AInt value @@ -1296,12 +1587,6 @@ class ProgramBuilder { ast::IntLiteralExpression::Suffix::kNone); } - /// @param value the integer value - /// @return an unsuffixed IntLiteralExpression for the AInt value - const ast::IntLiteralExpression* Expr(AInt value) { - return create(value, ast::IntLiteralExpression::Suffix::kNone); - } - /// @param source the source information /// @param value the integer value /// @return an unsuffixed FloatLiteralExpression for the AFloat value @@ -1310,13 +1595,6 @@ class ProgramBuilder { ast::FloatLiteralExpression::Suffix::kNone); } - /// @param value the integer value - /// @return an unsuffixed FloatLiteralExpression for the AFloat value - const ast::FloatLiteralExpression* Expr(AFloat value) { - return create(value.value, - ast::FloatLiteralExpression::Suffix::kNone); - } - /// @param source the source information /// @param value the integer value /// @return a signed 'i'-suffixed IntLiteralExpression for the i32 value @@ -1325,12 +1603,6 @@ class ProgramBuilder { ast::IntLiteralExpression::Suffix::kI); } - /// @param value the integer value - /// @return a signed 'i'-suffixed IntLiteralExpression for the i32 value - const ast::IntLiteralExpression* Expr(i32 value) { - return create(value, ast::IntLiteralExpression::Suffix::kI); - } - /// @param source the source information /// @param value the unsigned int value /// @return an unsigned 'u'-suffixed IntLiteralExpression for the u32 value @@ -1339,10 +1611,11 @@ class ProgramBuilder { ast::IntLiteralExpression::Suffix::kU); } - /// @param value the unsigned int value - /// @return an unsigned 'u'-suffixed IntLiteralExpression for the u32 value - const ast::IntLiteralExpression* Expr(u32 value) { - return create(value, ast::IntLiteralExpression::Suffix::kU); + /// @param value the scalar value + /// @return literal expression of the appropriate type + template > + const auto* Expr(SCALAR&& value) { + return Expr(source_, std::forward(value)); } /// Converts `arg` to an `ast::Expression` using `Expr()`, then appends it to @@ -1373,9 +1646,7 @@ class ProgramBuilder { /// `Expr()`, template > auto ExprList(ARGS&&... args) { - utils::Vector list; - Append(list, std::forward(args)...); - return list; + return utils::Vector{Expr(args)...}; } /// @param list the list of expressions @@ -1402,98 +1673,167 @@ class ProgramBuilder { /// @param type the type to cast to /// @param expr the expression for the bitcast - /// @return an `ast::BitcastExpression` of `type` constructed with the values + /// @return an `ast::BitcastExpression` of @p type constructed with the values /// `expr`. template - const ast::BitcastExpression* Bitcast(const ast::Type* type, EXPR&& expr) { - return create(type, Expr(std::forward(expr))); + const ast::BitcastExpression* Bitcast(ast::Type type, EXPR&& expr) { + return Bitcast(source_, type, Expr(std::forward(expr))); } /// @param source the source information /// @param type the type to cast to /// @param expr the expression for the bitcast - /// @return an `ast::BitcastExpression` of `type` constructed with the values + /// @return an `ast::BitcastExpression` of @p type constructed with the values /// `expr`. template - const ast::BitcastExpression* Bitcast(const Source& source, - const ast::Type* type, - EXPR&& expr) { + const ast::BitcastExpression* Bitcast(const Source& source, ast::Type type, EXPR&& expr) { return create(source, type, Expr(std::forward(expr))); } - /// @param args the arguments for the vector initializer /// @param type the vector type /// @param size the vector size + /// @param args the arguments for the vector initializer /// @return an `ast::CallExpression` of a `size`-element vector of - /// type `type`, constructed with the values `args`. + /// type `type`, constructed with the values @p args. template - const ast::CallExpression* vec(const ast::Type* type, uint32_t size, ARGS&&... args) { - return Call(ty.vec(type, size), std::forward(args)...); + const ast::CallExpression* vec(ast::Type type, uint32_t size, ARGS&&... args) { + return vec(source_, type, size, std::forward(args)...); + } + + /// @param source the source of the call + /// @param type the vector type + /// @param size the vector size + /// @param args the arguments for the vector initializer + /// @return an `ast::CallExpression` of a `size`-element vector of + /// type `type`, constructed with the values @p args. + template + const ast::CallExpression* vec(const Source& source, + ast::Type type, + uint32_t size, + ARGS&&... args) { + return Call(source, ty.vec(type, size), std::forward(args)...); } /// @param args the arguments for the vector initializer - /// @return an `ast::CallExpression` of a 2-element vector of type - /// `T`, constructed with the values `args`. - template > + /// @return an `ast::CallExpression` of a 2-element vector of type `T`, constructed with the + /// values @p args. + template > const ast::CallExpression* vec2(ARGS&&... args) { - return Call(ty.vec2(), std::forward(args)...); + return vec2(source_, std::forward(args)...); } /// @param source the vector source /// @param args the arguments for the vector initializer - /// @return an `ast::CallExpression` of a 2-element vector of type - /// `T`, constructed with the values `args`. + /// @return an `ast::CallExpression` of a 2-element vector of type `T`, constructed with the + /// values @p args. template const ast::CallExpression* vec2(const Source& source, ARGS&&... args) { return Call(source, ty.vec2(), std::forward(args)...); } + /// @param type the element type of the vector /// @param args the arguments for the vector initializer - /// @return an `ast::CallExpression` of a 3-element vector of type - /// `T`, constructed with the values `args`. - template > + /// @return an `ast::CallExpression` of a 2-element vector of type @p type, constructed with the + /// values @p args. + template + const ast::CallExpression* vec2(ast::Type type, ARGS&&... args) { + return vec2(source_, type, std::forward(args)...); + } + + /// @param source the vector source + /// @param type the element type of the vector + /// @param args the arguments for the vector initializer + /// @return an `ast::CallExpression` of a 2-element vector of type @p type, constructed with the + /// values @p args. + template + const ast::CallExpression* vec2(const Source& source, ast::Type type, ARGS&&... args) { + return Call(source, ty.vec2(type), std::forward(args)...); + } + + /// @param args the arguments for the vector initializer + /// @return an `ast::CallExpression` of a 3-element vector of type `T`, constructed with the + /// values @p args. + template > const ast::CallExpression* vec3(ARGS&&... args) { - return Call(ty.vec3(), std::forward(args)...); + return vec3(source_, std::forward(args)...); } /// @param source the vector source /// @param args the arguments for the vector initializer - /// @return an `ast::CallExpression` of a 3-element vector of type - /// `T`, constructed with the values `args`. + /// @return an `ast::CallExpression` of a 3-element vector of type `T`, constructed with the + /// values @p args. template const ast::CallExpression* vec3(const Source& source, ARGS&&... args) { return Call(source, ty.vec3(), std::forward(args)...); } + /// @param type the element type of the vector /// @param args the arguments for the vector initializer - /// @return an `ast::CallExpression` of a 4-element vector of type - /// `T`, constructed with the values `args`. - template > + /// @return an `ast::CallExpression` of a 3-element vector of type @p type, constructed with the + /// values @p args. + template + const ast::CallExpression* vec3(ast::Type type, ARGS&&... args) { + return vec3(source_, type, std::forward(args)...); + } + + /// @param source the vector source + /// @param type the element type of the vector + /// @param args the arguments for the vector initializer + /// @return an `ast::CallExpression` of a 3-element vector of type @p type, constructed with the + /// values @p args. + template + const ast::CallExpression* vec3(const Source& source, ast::Type type, ARGS&&... args) { + return Call(source, ty.vec3(type), std::forward(args)...); + } + + /// @param args the arguments for the vector initializer + /// @return an `ast::CallExpression` of a 4-element vector of type `T`, constructed with the + /// values @p args. + template > const ast::CallExpression* vec4(ARGS&&... args) { - return Call(ty.vec4(), std::forward(args)...); + return vec4(source_, std::forward(args)...); } /// @param source the vector source /// @param args the arguments for the vector initializer - /// @return an `ast::CallExpression` of a 4-element vector of type - /// `T`, constructed with the values `args`. + /// @return an `ast::CallExpression` of a 4-element vector of type `T`, constructed with the + /// values @p args. template const ast::CallExpression* vec4(const Source& source, ARGS&&... args) { return Call(source, ty.vec4(), std::forward(args)...); } + /// @param type the element type of the vector + /// @param args the arguments for the vector initializer + /// @return an `ast::CallExpression` of a 4-element vector of type @p type, constructed with the + /// values @p args. + template + const ast::CallExpression* vec4(ast::Type type, ARGS&&... args) { + return vec4(source_, type, std::forward(args)...); + } + + /// @param source the vector source + /// @param type the element type of the vector + /// @param args the arguments for the vector initializer + /// @return an `ast::CallExpression` of a 4-element vector of type @p type, constructed with the + /// values @p args. + template + const ast::CallExpression* vec4(const Source& source, ast::Type type, ARGS&&... args) { + return Call(source, ty.vec4(type), std::forward(args)...); + } + /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 2x2 matrix of type - /// `T`, constructed with the values `args`. - template > + /// `T`, constructed with the values @p args. + template > const ast::CallExpression* mat2x2(ARGS&&... args) { - return Call(ty.mat2x2(), std::forward(args)...); + return mat2x2(source_, std::forward(args)...); } /// @param source the matrix source /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 2x2 matrix of type - /// `T`, constructed with the values `args`. + /// `T`, constructed with the values @p args. template const ast::CallExpression* mat2x2(const Source& source, ARGS&&... args) { return Call(source, ty.mat2x2(), std::forward(args)...); @@ -1501,16 +1841,16 @@ class ProgramBuilder { /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 2x3 matrix of type - /// `T`, constructed with the values `args`. - template > + /// `T`, constructed with the values @p args. + template > const ast::CallExpression* mat2x3(ARGS&&... args) { - return Call(ty.mat2x3(), std::forward(args)...); + return mat2x3(source_, std::forward(args)...); } /// @param source the matrix source /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 2x3 matrix of type - /// `T`, constructed with the values `args`. + /// `T`, constructed with the values @p args. template const ast::CallExpression* mat2x3(const Source& source, ARGS&&... args) { return Call(source, ty.mat2x3(), std::forward(args)...); @@ -1518,16 +1858,16 @@ class ProgramBuilder { /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 2x4 matrix of type - /// `T`, constructed with the values `args`. - template > + /// `T`, constructed with the values @p args. + template > const ast::CallExpression* mat2x4(ARGS&&... args) { - return Call(ty.mat2x4(), std::forward(args)...); + return mat2x4(source_, std::forward(args)...); } /// @param source the matrix source /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 2x4 matrix of type - /// `T`, constructed with the values `args`. + /// `T`, constructed with the values @p args. template const ast::CallExpression* mat2x4(const Source& source, ARGS&&... args) { return Call(source, ty.mat2x4(), std::forward(args)...); @@ -1535,16 +1875,16 @@ class ProgramBuilder { /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 3x2 matrix of type - /// `T`, constructed with the values `args`. - template > + /// `T`, constructed with the values @p args. + template > const ast::CallExpression* mat3x2(ARGS&&... args) { - return Call(ty.mat3x2(), std::forward(args)...); + return mat3x2(source_, std::forward(args)...); } /// @param source the matrix source /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 3x2 matrix of type - /// `T`, constructed with the values `args`. + /// `T`, constructed with the values @p args. template const ast::CallExpression* mat3x2(const Source& source, ARGS&&... args) { return Call(source, ty.mat3x2(), std::forward(args)...); @@ -1552,16 +1892,16 @@ class ProgramBuilder { /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 3x3 matrix of type - /// `T`, constructed with the values `args`. - template > + /// `T`, constructed with the values @p args. + template > const ast::CallExpression* mat3x3(ARGS&&... args) { - return Call(ty.mat3x3(), std::forward(args)...); + return mat3x3(source_, std::forward(args)...); } /// @param source the matrix source /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 3x3 matrix of type - /// `T`, constructed with the values `args`. + /// `T`, constructed with the values @p args. template const ast::CallExpression* mat3x3(const Source& source, ARGS&&... args) { return Call(source, ty.mat3x3(), std::forward(args)...); @@ -1569,16 +1909,16 @@ class ProgramBuilder { /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 3x4 matrix of type - /// `T`, constructed with the values `args`. - template > + /// `T`, constructed with the values @p args. + template > const ast::CallExpression* mat3x4(ARGS&&... args) { - return Call(ty.mat3x4(), std::forward(args)...); + return mat3x4(source_, std::forward(args)...); } /// @param source the matrix source /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 3x4 matrix of type - /// `T`, constructed with the values `args`. + /// `T`, constructed with the values @p args. template const ast::CallExpression* mat3x4(const Source& source, ARGS&&... args) { return Call(source, ty.mat3x4(), std::forward(args)...); @@ -1586,16 +1926,16 @@ class ProgramBuilder { /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 4x2 matrix of type - /// `T`, constructed with the values `args`. - template > + /// `T`, constructed with the values @p args. + template > const ast::CallExpression* mat4x2(ARGS&&... args) { - return Call(ty.mat4x2(), std::forward(args)...); + return mat4x2(source_, std::forward(args)...); } /// @param source the matrix source /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 4x2 matrix of type - /// `T`, constructed with the values `args`. + /// `T`, constructed with the values @p args. template const ast::CallExpression* mat4x2(const Source& source, ARGS&&... args) { return Call(source, ty.mat4x2(), std::forward(args)...); @@ -1603,16 +1943,16 @@ class ProgramBuilder { /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 4x3 matrix of type - /// `T`, constructed with the values `args`. - template > + /// `T`, constructed with the values @p args. + template > const ast::CallExpression* mat4x3(ARGS&&... args) { - return Call(ty.mat4x3(), std::forward(args)...); + return mat4x3(source_, std::forward(args)...); } /// @param source the matrix source /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 4x3 matrix of type - /// `T`, constructed with the values `args`. + /// `T`, constructed with the values @p args. template const ast::CallExpression* mat4x3(const Source& source, ARGS&&... args) { return Call(source, ty.mat4x3(), std::forward(args)...); @@ -1620,33 +1960,50 @@ class ProgramBuilder { /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 4x4 matrix of type - /// `T`, constructed with the values `args`. - template > + /// `T`, constructed with the values @p args. + template > const ast::CallExpression* mat4x4(ARGS&&... args) { - return Call(ty.mat4x4(), std::forward(args)...); + return mat4x4(source_, std::forward(args)...); } /// @param source the matrix source /// @param args the arguments for the matrix initializer /// @return an `ast::CallExpression` of a 4x4 matrix of type - /// `T`, constructed with the values `args`. + /// `T`, constructed with the values @p args. template const ast::CallExpression* mat4x4(const Source& source, ARGS&&... args) { return Call(source, ty.mat4x4(), std::forward(args)...); } /// @param args the arguments for the array initializer - /// @return an `ast::CallExpression` of an array with element type - /// `T` and size `N`, constructed with the values `args`. - template + /// @return an `ast::CallExpression` of an array with element type `T`, constructed with the + /// values @p args. + template > + const ast::CallExpression* array(ARGS&&... args) { + return Call(ty.array(), std::forward(args)...); + } + + /// @param source the array source + /// @param args the arguments for the array initializer + /// @return an `ast::CallExpression` of an array with element type `T`, constructed with the + /// values @p args. + template + const ast::CallExpression* array(const Source& source, ARGS&&... args) { + return Call(source, ty.array(), std::forward(args)...); + } + + /// @param args the arguments for the array initializer + /// @return an `ast::CallExpression` of an array with element type `T` and size `N`, constructed + /// with the values @p args. + template > const ast::CallExpression* array(ARGS&&... args) { return Call(ty.array(), std::forward(args)...); } /// @param source the array source /// @param args the arguments for the array initializer - /// @return an `ast::CallExpression` of an array with element type - /// `T` and size `N`, constructed with the values `args`. + /// @return an `ast::CallExpression` of an array with element type `T` and size `N`, constructed + /// with the values @p args. template const ast::CallExpression* array(const Source& source, ARGS&&... args) { return Call(source, ty.array(), std::forward(args)...); @@ -1656,9 +2013,9 @@ class ProgramBuilder { /// @param n the array size. nullptr represents a runtime-array. /// @param args the arguments for the array initializer /// @return an `ast::CallExpression` of an array with element type - /// `subtype`, constructed with the values `args`. + /// `subtype`, constructed with the values @p args. template - const ast::CallExpression* array(const ast::Type* subtype, EXPR&& n, ARGS&&... args) { + const ast::CallExpression* array(ast::Type subtype, EXPR&& n, ARGS&&... args) { return Call(ty.array(subtype, std::forward(n)), std::forward(args)...); } @@ -1667,10 +2024,10 @@ class ProgramBuilder { /// @param n the array size. nullptr represents a runtime-array. /// @param args the arguments for the array initializer /// @return an `ast::CallExpression` of an array with element type - /// `subtype`, constructed with the values `args`. + /// `subtype`, constructed with the values @p args. template const ast::CallExpression* array(const Source& source, - const ast::Type* subtype, + ast::Type subtype, EXPR&& n, ARGS&&... args) { return Call(source, ty.array(subtype, std::forward(n)), std::forward(args)...); @@ -1734,6 +2091,7 @@ class ProgramBuilder { /// @param options the extra options passed to the ast::Var initializer /// Can be any of the following, in any order: /// * ast::Expression* - specifies the variable's initializer expression (required) + /// * ast::Identifier* - specifies the variable type /// * ast::Type* - specifies the variable type /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) /// Note that non-repeatable arguments of the same type will use the last argument's value. @@ -1748,6 +2106,7 @@ class ProgramBuilder { /// @param options the extra options passed to the ast::Var initializer /// Can be any of the following, in any order: /// * ast::Expression* - specifies the variable's initializer expression (required) + /// * ast::Identifier* - specifies the variable type /// * ast::Type* - specifies the variable type /// * ast::Attribute* - specifies the variable's attributes (repeatable, or vector) /// Note that non-repeatable arguments of the same type will use the last argument's value. @@ -1794,7 +2153,7 @@ class ProgramBuilder { /// @returns an `ast::Parameter` with the given name and type template const ast::Parameter* Param(NAME&& name, - const ast::Type* type, + ast::Type type, utils::VectorRef attributes = utils::Empty) { return Param(source_, std::forward(name), type, std::move(attributes)); } @@ -1807,9 +2166,10 @@ class ProgramBuilder { template const ast::Parameter* Param(const Source& source, NAME&& name, - const ast::Type* type, + ast::Type type, utils::VectorRef attributes = utils::Empty) { - return create(source, Ident(std::forward(name)), type, attributes); + return create(source, Ident(std::forward(name)), type, + std::move(attributes)); } /// @param name the variable name @@ -2017,41 +2377,44 @@ class ProgramBuilder { Expr(std::forward(expr))); } + /// @param args the arguments for the type constructor + /// @returns an ast::CallExpression to the type `T`, with the arguments of @p args converted to + /// `ast::Expression`s using Expr(). + template > + const ast::CallExpression* Call(ARGS&&... args) { + return Call(source_, ty.Of(), std::forward(args)...); + } + + /// @param source the source of the call + /// @param args the arguments for the type constructor + /// @returns an ast::CallExpression to the type `T` with the arguments of @p args converted to + /// `ast::Expression`s using Expr(). + template + const ast::CallExpression* Call(const Source& source, ARGS&&... args) { + return Call(source, ty.Of(), std::forward(args)...); + } + /// @param target the call target /// @param args the function call arguments - /// @returns a `ast::CallExpression` to the function `func`, with the - /// arguments of `args` converted to `ast::Expression`s using `Expr()`. + /// @returns an ast::CallExpression to the target @p target, with the arguments of @p args + /// converted to `ast::Expression`s using Expr(). template , typename = DisableIfScalar> const ast::CallExpression* Call(TARGET&& target, ARGS&&... args) { - return Call(source_, std::forward(target), std::forward(args)...); + return Call(source_, Expr(std::forward(target)), std::forward(args)...); } - /// @param source the source information - /// @param target the call target. Can be an ast::Type or ast::Identifier, or string-like. + /// @param source the source of the call + /// @param target the call target /// @param args the function call arguments - /// @returns a `ast::CallExpression` to the target @p target, with the arguments of @p args + /// @returns an ast::CallExpression to the target @p target, with the arguments of @p args /// converted to `ast::Expression`s using Expr(). template > const ast::CallExpression* Call(const Source& source, TARGET&& target, ARGS&&... args) { - if constexpr (traits::IsTypeOrDerived, ast::Type>) { - return create(source, target, - ExprList(std::forward(args)...)); - - } else { - return create(source, Ident(target), - ExprList(std::forward(args)...)); - } - } - - /// @param args the arguments for the type constructor - /// @return an `ast::CallExpression` of type `ty`, with the values - /// of `args` converted to `ast::Expression`s using `Expr()` - template > - const ast::CallExpression* Call(ARGS&&... args) { - return Call(ty.Of(), std::forward(args)...); + return create(source, Expr(std::forward(target)), + ExprList(std::forward(args)...)); } /// @param source the source information @@ -2470,13 +2833,12 @@ class ProgramBuilder { /// be automatically placed into a block, or nullptr for a stub function. /// @param attributes the optional function attributes /// @param return_type_attributes the optional function return type attributes - /// attributes /// @returns the function pointer template > const ast::Function* Func( NAME&& name, utils::VectorRef params, - const ast::Type* type, + ast::Type type, BODY&& body, utils::VectorRef attributes = utils::Empty, utils::VectorRef return_type_attributes = utils::Empty) { @@ -2494,14 +2856,13 @@ class ProgramBuilder { /// be automatically placed into a block, or nullptr for a stub function. /// @param attributes the optional function attributes /// @param return_type_attributes the optional function return type attributes - /// attributes /// @returns the function pointer template > const ast::Function* Func( const Source& source, NAME&& name, utils::VectorRef params, - const ast::Type* type, + ast::Type type, BODY&& body, utils::VectorRef attributes = utils::Empty, utils::VectorRef return_type_attributes = utils::Empty) { @@ -2603,7 +2964,7 @@ class ProgramBuilder { /// @param type the alias target type /// @returns the alias type template - const ast::Alias* Alias(NAME&& name, const ast::Type* type) { + const ast::Alias* Alias(NAME&& name, ast::Type type) { return Alias(source_, std::forward(name), type); } @@ -2613,8 +2974,8 @@ class ProgramBuilder { /// @param type the alias target type /// @returns the alias type template - const ast::Alias* Alias(const Source& source, NAME&& name, const ast::Type* type) { - auto* out = ty.alias(source, std::forward(name), type); + const ast::Alias* Alias(const Source& source, NAME&& name, ast::Type type) { + auto out = ty.alias(source, std::forward(name), type); AST().AddTypeDecl(out); return out; } @@ -2656,16 +3017,16 @@ class ProgramBuilder { /// @param type the struct member type /// @param attributes the optional struct member attributes /// @returns the struct member pointer - template + template > const ast::StructMember* Member( NAME&& name, - const ast::Type* type, + ast::Type type, utils::VectorRef attributes = utils::Empty) { return Member(source_, std::forward(name), type, std::move(attributes)); } /// Creates a ast::StructMember - /// @param source the source information + /// @param source the struct member source /// @param name the struct member name /// @param type the struct member type /// @param attributes the optional struct member attributes @@ -2674,7 +3035,7 @@ class ProgramBuilder { const ast::StructMember* Member( const Source& source, NAME&& name, - const ast::Type* type, + ast::Type type, utils::VectorRef attributes = utils::Empty) { return create(source, Ident(std::forward(name)), type, std::move(attributes)); @@ -2686,7 +3047,7 @@ class ProgramBuilder { /// @param type the struct member type /// @returns the struct member pointer template - const ast::StructMember* Member(uint32_t offset, NAME&& name, const ast::Type* type) { + const ast::StructMember* Member(uint32_t offset, NAME&& name, ast::Type type) { return create(source_, Ident(std::forward(name)), type, utils::Vector{ MemberOffset(AInt(offset)), @@ -2998,6 +3359,15 @@ class ProgramBuilder { std::forward(cases)...}); } + /// Creates a ast::CaseStatement with input list of selectors, and body + /// @param selectors list of selectors + /// @param body the case body + /// @returns the case statement pointer + const ast::CaseStatement* Case(utils::VectorRef selectors, + const ast::BlockStatement* body = nullptr) { + return Case(source_, std::move(selectors), body); + } + /// Creates a ast::CaseStatement with input list of selectors, and body /// @param source the source information /// @param selectors list of selectors @@ -3009,22 +3379,20 @@ class ProgramBuilder { return create(source, std::move(selectors), body ? body : Block()); } - /// Creates a ast::CaseStatement with input list of selectors, and body - /// @param selectors list of selectors - /// @param body the case body - /// @returns the case statement pointer - const ast::CaseStatement* Case(utils::VectorRef selectors, - const ast::BlockStatement* body = nullptr) { - return create(std::move(selectors), body ? body : Block()); - } - /// Convenient overload that takes a single selector /// @param selector a single case selector /// @param body the case body /// @returns the case statement pointer const ast::CaseStatement* Case(const ast::CaseSelector* selector, const ast::BlockStatement* body = nullptr) { - return Case(utils::Vector{selector}, body); + return Case(utils::Vector{selector}, body ? body : Block()); + } + + /// Convenience function that creates a 'default' ast::CaseStatement + /// @param body the case body + /// @returns the case statement pointer + const ast::CaseStatement* DefaultCase(const ast::BlockStatement* body = nullptr) { + return DefaultCase(source_, body); } /// Convenience function that creates a 'default' ast::CaseStatement @@ -3036,13 +3404,6 @@ class ProgramBuilder { return Case(source, utils::Vector{DefaultCaseSelector(source)}, body); } - /// Convenience function that creates a 'default' ast::CaseStatement - /// @param body the case body - /// @returns the case statement pointer - const ast::CaseStatement* DefaultCase(const ast::BlockStatement* body = nullptr) { - return Case(utils::Vector{DefaultCaseSelector()}, body); - } - /// Convenience function that creates a case selector /// @param source the source information /// @param expr the selector expression @@ -3350,14 +3711,6 @@ class ProgramBuilder { /// variable has no resolved type. const type::Type* TypeOf(const ast::Variable* var) const; - /// Helper for returning the resolved semantic type of the AST type `type`. - /// @note As the Resolver is run when the Program is built, this will only be - /// useful for the Resolver itself and tests that use their own Resolver. - /// @param type the AST type - /// @return the resolved semantic type for the type, or nullptr if the type - /// has no resolved type. - const type::Type* TypeOf(const ast::Type* type) const; - /// Helper for returning the resolved semantic type of the AST type /// declaration `type_decl`. /// @note As the Resolver is run when the Program is built, this will only be @@ -3368,13 +3721,11 @@ class ProgramBuilder { const type::Type* TypeOf(const ast::TypeDecl* type_decl) const; /// @param type a type - /// @returns the name for `type` that closely resembles how it would be - /// declared in WGSL. - std::string FriendlyName(const ast::Type* type) const; + /// @returns the name for `type` that closely resembles how it would be declared in WGSL. + std::string FriendlyName(ast::Type type) const; /// @param type a type - /// @returns the name for `type` that closely resembles how it would be - /// declared in WGSL. + /// @returns the name for `type` that closely resembles how it would be declared in WGSL. std::string FriendlyName(const type::Type* type) const; /// Overload of FriendlyName, which removes an ambiguity when passing nullptr. @@ -3455,35 +3806,31 @@ class ProgramBuilder { // Various template specializations for ProgramBuilder::TypesBuilder::CToAST. template <> struct ProgramBuilder::TypesBuilder::CToAST { - static const ast::Type* get(const ProgramBuilder::TypesBuilder*) { return nullptr; } + static ast::Type get(const ProgramBuilder::TypesBuilder*) { return ast::Type{}; } }; template <> struct ProgramBuilder::TypesBuilder::CToAST { - static const ast::Type* get(const ProgramBuilder::TypesBuilder*) { return nullptr; } + static ast::Type get(const ProgramBuilder::TypesBuilder*) { return ast::Type{}; } }; template <> struct ProgramBuilder::TypesBuilder::CToAST { - static const ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->i32(); } + static ast::Type get(const ProgramBuilder::TypesBuilder* t) { return t->i32(); } }; template <> struct ProgramBuilder::TypesBuilder::CToAST { - static const ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->u32(); } + static ast::Type get(const ProgramBuilder::TypesBuilder* t) { return t->u32(); } }; template <> struct ProgramBuilder::TypesBuilder::CToAST { - static const ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->f32(); } + static ast::Type get(const ProgramBuilder::TypesBuilder* t) { return t->f32(); } }; template <> struct ProgramBuilder::TypesBuilder::CToAST { - static const ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->f16(); } + static ast::Type get(const ProgramBuilder::TypesBuilder* t) { return t->f16(); } }; template <> struct ProgramBuilder::TypesBuilder::CToAST { - static const ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->bool_(); } -}; -template <> -struct ProgramBuilder::TypesBuilder::CToAST { - static const ast::Type* get(const ProgramBuilder::TypesBuilder* t) { return t->void_(); } + static ast::Type get(const ProgramBuilder::TypesBuilder* t) { return t->bool_(); } }; //! @endcond diff --git a/src/tint/program_builder_test.cc b/src/tint/program_builder_test.cc index 02e3ba29b6..27338164d5 100644 --- a/src/tint/program_builder_test.cc +++ b/src/tint/program_builder_test.cc @@ -33,7 +33,7 @@ TEST_F(ProgramBuilderTest, IDsAreUnique) { TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) { Program inner([] { ProgramBuilder builder; - auto* ty = builder.ty.f32(); + auto ty = builder.ty.f32(); builder.Func("a", {}, ty, {}, {}); return builder; }()); @@ -54,7 +54,7 @@ TEST_F(ProgramBuilderTest, WrapDoesntAffectInner) { EXPECT_FALSE(inner.Symbols().Get("b").IsValid()); EXPECT_FALSE(outer.Symbols().Get("b").IsValid()); - auto* ty = outer.ty.f32(); + auto ty = outer.ty.f32(); outer.Func("b", {}, ty, {}, {}); ASSERT_EQ(inner.AST().Functions().Length(), 1u); diff --git a/src/tint/reader/spirv/function.cc b/src/tint/reader/spirv/function.cc index c5eb5a4b33..a23ca20380 100644 --- a/src/tint/reader/spirv/function.cc +++ b/src/tint/reader/spirv/function.cc @@ -1259,7 +1259,7 @@ bool FunctionEmitter::EmitEntryPointAsWrapper() { FunctionDeclaration decl; decl.source = source; decl.name = ep_info_->name; - const ast::Type* return_type = nullptr; // Populated below. + ast::Type return_type; // Populated below. // Pipeline inputs become parameters to the wrapper function, and // their values are saved into the corresponding private variables that @@ -3825,7 +3825,7 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue( if (unary_builtin_name != nullptr) { ExpressionList params; params.Push(MakeOperand(inst, 0).expr); - return {ast_type, builder_.Call(Source{}, unary_builtin_name, std::move(params))}; + return {ast_type, builder_.Call(unary_builtin_name, std::move(params))}; } const auto builtin = GetBuiltin(op); @@ -3906,7 +3906,7 @@ TypedExpression FunctionEmitter::MaybeEmitCombinatorialValue( } operands.Push(operand.expr); } - return {ast_type, builder_.Call(Source{}, ast_type->Build(builder_), std::move(operands))}; + return {ast_type, builder_.Call(ast_type->Build(builder_), std::move(operands))}; } if (op == spv::Op::OpCompositeExtract) { @@ -3971,7 +3971,7 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(const spvtools::opt::Inst auto e1 = MakeOperand(inst, 2); auto e2 = ToSignedIfUnsigned(MakeOperand(inst, 3)); - return {e1.type, builder_.Call(Source{}, "ldexp", utils::Vector{e1.expr, e2.expr})}; + return {e1.type, builder_.Call("ldexp", utils::Vector{e1.expr, e2.expr})}; } auto* result_type = parser_impl_.ConvertType(inst.type_id()); @@ -3983,7 +3983,7 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(const spvtools::opt::Inst case GLSLstd450Determinant: { auto m = MakeOperand(inst, 2); TINT_ASSERT(Reader, m.type->Is()); - return {ty_.F32(), builder_.Call(Source{}, "determinant", m.expr)}; + return {ty_.F32(), builder_.Call("determinant", m.expr)}; } case GLSLstd450Normalize: @@ -4049,7 +4049,7 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(const spvtools::opt::Inst return { f32, builder_.MemberAccessor( - builder_.Call(Source{}, "refract", + builder_.Call("refract", utils::Vector{ builder_.vec2(incident.expr, 0_f), builder_.vec2(normal.expr, 0_f), @@ -4084,7 +4084,7 @@ TypedExpression FunctionEmitter::EmitGlslStd450ExtInst(const spvtools::opt::Inst } operands.Push(operand.expr); } - auto* call = builder_.Call(Source{}, name, std::move(operands)); + auto* call = builder_.Call(name, std::move(operands)); TypedExpression call_expr{result_type, call}; return parser_impl_.RectifyForcedResultType(call_expr, inst, first_operand_type); } @@ -5199,7 +5199,7 @@ bool FunctionEmitter::EmitFunctionCall(const spvtools::opt::Instruction& inst) { if (failed()) { return false; } - auto* call_expr = create(Source{}, function, std::move(args)); + auto* call_expr = builder_.Call(function, std::move(args)); auto* result_type = parser_impl_.ConvertType(inst.type_id()); if (!result_type) { return Fail() << "internal error: no mapped type result of call: " << inst.PrettyPrint(); @@ -5270,7 +5270,7 @@ TypedExpression FunctionEmitter::MakeBuiltinCall(const spvtools::opt::Instructio } params.Push(operand.expr); } - auto* call_expr = create(Source{}, ident, std::move(params)); + auto* call_expr = builder_.Call(ident, std::move(params)); auto* result_type = parser_impl_.ConvertType(inst.type_id()); if (!result_type) { Fail() << "internal error: no mapped type result of call: " << inst.PrettyPrint(); @@ -5298,10 +5298,7 @@ TypedExpression FunctionEmitter::MakeSimpleSelect(const spvtools::opt::Instructi params.Push(true_value.expr); // The condition goes last. params.Push(condition.expr); - return {op_ty, create( - Source{}, - create(Source{}, builder_.Symbols().Register("select")), - std::move(params))}; + return {op_ty, builder_.Call("select", std::move(params))}; } return {}; } @@ -5604,7 +5601,7 @@ bool FunctionEmitter::EmitImageAccess(const spvtools::opt::Instruction& inst) { return false; } - auto* call_expr = builder_.Call(Source{}, builtin_name, std::move(args)); + auto* call_expr = builder_.Call(builtin_name, std::move(args)); if (inst.type_id() != 0) { // It returns a value. @@ -5697,7 +5694,7 @@ bool FunctionEmitter::EmitImageQuery(const spvtools::opt::Instruction& inst) { dims_args.Push(MakeOperand(inst, 1).expr); } const ast::Expression* dims_call = - builder_.Call(Source{}, "textureDimensions", std::move(dims_args)); + builder_.Call("textureDimensions", std::move(dims_args)); auto dims = texture_type->dims; if ((dims == type::TextureDimension::kCube) || (dims == type::TextureDimension::kCubeArray)) { @@ -5706,9 +5703,8 @@ bool FunctionEmitter::EmitImageQuery(const spvtools::opt::Instruction& inst) { create(Source{}, dims_call, PrefixSwizzle(2)); } exprs.Push(dims_call); - if (ast::IsTextureArray(dims)) { - auto num_layers = - builder_.Call(Source{}, "textureNumLayers", GetImageExpression(inst)); + if (type::IsTextureArray(dims)) { + auto num_layers = builder_.Call("textureNumLayers", GetImageExpression(inst)); exprs.Push(num_layers); } auto* result_type = parser_impl_.ConvertType(inst.type_id()); @@ -5720,7 +5716,7 @@ bool FunctionEmitter::EmitImageQuery(const spvtools::opt::Instruction& inst) { // vector initializer - otherwise, just emit the single expression to omit an // unnecessary cast. (exprs.Length() > 1) - ? builder_.Call(Source{}, unsigned_type->Build(builder_), std::move(exprs)) + ? builder_.Call(unsigned_type->Build(builder_), std::move(exprs)) : exprs[0], }; @@ -5735,15 +5731,13 @@ bool FunctionEmitter::EmitImageQuery(const spvtools::opt::Instruction& inst) { case spv::Op::OpImageQuerySamples: { const auto* name = (op == spv::Op::OpImageQueryLevels) ? "textureNumLevels" : "textureNumSamples"; - const ast::Expression* ast_expr = - builder_.Call(Source{}, name, GetImageExpression(inst)); + const ast::Expression* ast_expr = builder_.Call(name, GetImageExpression(inst)); auto* result_type = parser_impl_.ConvertType(inst.type_id()); // The SPIR-V result type must be integer scalar. // The WGSL bulitin returns u32. // If they aren't the same then convert the result. if (!result_type->Is()) { - ast_expr = - builder_.Call(Source{}, result_type->Build(builder_), utils::Vector{ast_expr}); + ast_expr = builder_.Call(result_type->Build(builder_), utils::Vector{ast_expr}); } TypedExpression expr{result_type, ast_expr}; return EmitConstDefOrWriteToHoistedVar(inst, expr); @@ -5768,7 +5762,7 @@ bool FunctionEmitter::EmitAtomicOp(const spvtools::opt::Instruction& inst) { } // Function return type - const ast::Type* ret_type = nullptr; + ast::Type ret_type; if (inst.type_id() != 0) { ret_type = parser_impl_.ConvertType(inst.type_id())->Build(builder_); } else { @@ -5787,7 +5781,7 @@ bool FunctionEmitter::EmitAtomicOp(const spvtools::opt::Instruction& inst) { }); // Emit call to stub, will be replaced with call to atomic builtin by transform::SpirvAtomic - auto* call = builder_.Call(Source{}, stub->name->symbol, std::move(exprs)); + auto* call = builder_.Call(stub->name->symbol, std::move(exprs)); if (inst.type_id() != 0) { auto* result_type = parser_impl_.ConvertType(inst.type_id()); TypedExpression expr{result_type, call}; @@ -5897,8 +5891,8 @@ FunctionEmitter::ExpressionList FunctionEmitter::MakeCoordinateOperandsForImageA } type::TextureDimension dim = texture_type->dims; // Number of regular coordinates. - uint32_t num_axes = static_cast(ast::NumCoordinateAxes(dim)); - bool is_arrayed = ast::IsTextureArray(dim); + uint32_t num_axes = static_cast(type::NumCoordinateAxes(dim)); + bool is_arrayed = type::IsTextureArray(dim); if ((num_axes == 0) || (num_axes > 3)) { Fail() << "unsupported image dimensionality for " << texture_type->TypeInfo().name << " prompted by " << inst.PrettyPrint(); @@ -6052,7 +6046,7 @@ const ast::Expression* FunctionEmitter::ConvertTexelForStorage( for (auto i = src_count; i < dest_count; i++) { exprs.Push(parser_impl_.MakeNullExpression(component_type).expr); } - texel.expr = builder_.Call(Source{}, src_type->Build(builder_), std::move(exprs)); + texel.expr = builder_.Call(src_type->Build(builder_), std::move(exprs)); } return texel.expr; @@ -6062,7 +6056,7 @@ TypedExpression FunctionEmitter::ToI32(TypedExpression value) { if (!value || value.type->Is()) { return value; } - return {ty_.I32(), builder_.Call(Source{}, builder_.ty.i32(), utils::Vector{value.expr})}; + return {ty_.I32(), builder_.Call(builder_.ty.i32(), utils::Vector{value.expr})}; } TypedExpression FunctionEmitter::ToSignedIfUnsigned(TypedExpression value) { @@ -6103,7 +6097,7 @@ TypedExpression FunctionEmitter::MakeArrayLength(const spvtools::opt::Instructio auto* member_access = builder_.MemberAccessor(Source{}, member_expr.expr, field_name); // Generate the builtin function call. - auto* call_expr = builder_.Call(Source{}, "arrayLength", builder_.AddressOf(member_access)); + auto* call_expr = builder_.Call("arrayLength", builder_.AddressOf(member_access)); return {parser_impl_.ConvertType(inst.type_id()), call_expr}; } @@ -6142,11 +6136,9 @@ TypedExpression FunctionEmitter::MakeOuterProduct(const spvtools::opt::Instructi row_factor, column_factor); result_row.Push(elem); } - result_columns.Push( - builder_.Call(Source{}, col_ty->Build(builder_), std::move(result_row))); + result_columns.Push(builder_.Call(col_ty->Build(builder_), std::move(result_row))); } - return {result_ty, - builder_.Call(Source{}, result_ty->Build(builder_), std::move(result_columns))}; + return {result_ty, builder_.Call(result_ty->Build(builder_), std::move(result_columns))}; } bool FunctionEmitter::MakeVectorInsertDynamic(const spvtools::opt::Instruction& inst) { diff --git a/src/tint/reader/spirv/parser_impl.cc b/src/tint/reader/spirv/parser_impl.cc index 0b7d30ed60..2589d8e91c 100644 --- a/src/tint/reader/spirv/parser_impl.cc +++ b/src/tint/reader/spirv/parser_impl.cc @@ -24,7 +24,6 @@ #include "src/tint/ast/disable_validation_attribute.h" #include "src/tint/ast/id_attribute.h" #include "src/tint/ast/interpolate_attribute.h" -#include "src/tint/ast/type_name.h" #include "src/tint/ast/unary_op_expression.h" #include "src/tint/reader/spirv/function.h" #include "src/tint/type/depth_texture.h" diff --git a/src/tint/reader/spirv/parser_impl_convert_type_test.cc b/src/tint/reader/spirv/parser_impl_convert_type_test.cc index a4716320a5..0dc8ddc3fb 100644 --- a/src/tint/reader/spirv/parser_impl_convert_type_test.cc +++ b/src/tint/reader/spirv/parser_impl_convert_type_test.cc @@ -546,7 +546,7 @@ TEST_F(SpvParserTest, ConvertType_StructTwoMembers) { ASSERT_NE(type, nullptr); EXPECT_TRUE(type->Is()); - auto* str = type->Build(p->builder()); + auto str = type->Build(p->builder()); Program program = p->program(); EXPECT_EQ(test::ToString(program, str), "S"); } @@ -564,7 +564,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithBlockDecoration) { ASSERT_NE(type, nullptr); EXPECT_TRUE(type->Is()); - auto* str = type->Build(p->builder()); + auto str = type->Build(p->builder()); Program program = p->program(); EXPECT_EQ(test::ToString(program, str), "S"); } @@ -586,7 +586,7 @@ TEST_F(SpvParserTest, ConvertType_StructWithMemberDecorations) { ASSERT_NE(type, nullptr); EXPECT_TRUE(type->Is()); - auto* str = type->Build(p->builder()); + auto str = type->Build(p->builder()); Program program = p->program(); EXPECT_EQ(test::ToString(program, str), "S"); } diff --git a/src/tint/reader/spirv/parser_impl_test_helper.cc b/src/tint/reader/spirv/parser_impl_test_helper.cc index 2a6dd06d6d..d0b6ef7c15 100644 --- a/src/tint/reader/spirv/parser_impl_test_helper.cc +++ b/src/tint/reader/spirv/parser_impl_test_helper.cc @@ -66,13 +66,6 @@ std::string ToString(const Program& program, const ast::Node* node) { } return writer.result(); }, - [&](const ast::Type* ty) { - std::stringstream out; - if (!writer.EmitType(out, ty)) { - return "WGSL writer error: " + writer.error(); - } - return out.str(); - }, [&](const ast::Identifier* ident) { return program.Symbols().NameFor(ident->symbol); }, [&](Default) { return "TypeInfo().name) + ">"; diff --git a/src/tint/reader/spirv/parser_type.cc b/src/tint/reader/spirv/parser_type.cc index 77b9df4d9f..9051b78459 100644 --- a/src/tint/reader/spirv/parser_type.cc +++ b/src/tint/reader/spirv/parser_type.cc @@ -149,23 +149,23 @@ static bool operator==(const StorageTexture& a, const StorageTexture& b) { } //! @endcond -const ast::Type* Void::Build(ProgramBuilder& b) const { +ast::Type Void::Build(ProgramBuilder& b) const { return b.ty.void_(); } -const ast::Type* Bool::Build(ProgramBuilder& b) const { +ast::Type Bool::Build(ProgramBuilder& b) const { return b.ty.bool_(); } -const ast::Type* U32::Build(ProgramBuilder& b) const { +ast::Type U32::Build(ProgramBuilder& b) const { return b.ty.u32(); } -const ast::Type* F32::Build(ProgramBuilder& b) const { +ast::Type F32::Build(ProgramBuilder& b) const { return b.ty.f32(); } -const ast::Type* I32::Build(ProgramBuilder& b) const { +ast::Type I32::Build(ProgramBuilder& b) const { return b.ty.i32(); } @@ -179,7 +179,7 @@ Pointer::Pointer(const Type* t, type::AddressSpace s, type::Access a) : type(t), address_space(s), access(a) {} Pointer::Pointer(const Pointer&) = default; -const ast::Type* Pointer::Build(ProgramBuilder& b) const { +ast::Type Pointer::Build(ProgramBuilder& b) const { auto store_type = type->Build(b); if (!store_type) { // TODO(crbug.com/tint/1838): We should not be constructing pointers with 'void' store @@ -193,28 +193,28 @@ Reference::Reference(const Type* t, type::AddressSpace s, type::Access a) : type(t), address_space(s), access(a) {} Reference::Reference(const Reference&) = default; -const ast::Type* Reference::Build(ProgramBuilder& b) const { +ast::Type Reference::Build(ProgramBuilder& b) const { return type->Build(b); } Vector::Vector(const Type* t, uint32_t s) : type(t), size(s) {} Vector::Vector(const Vector&) = default; -const ast::Type* Vector::Build(ProgramBuilder& b) const { +ast::Type Vector::Build(ProgramBuilder& b) const { return b.ty.vec(type->Build(b), size); } Matrix::Matrix(const Type* t, uint32_t c, uint32_t r) : type(t), columns(c), rows(r) {} Matrix::Matrix(const Matrix&) = default; -const ast::Type* Matrix::Build(ProgramBuilder& b) const { +ast::Type Matrix::Build(ProgramBuilder& b) const { return b.ty.mat(type->Build(b), columns, rows); } Array::Array(const Type* t, uint32_t sz, uint32_t st) : type(t), size(sz), stride(st) {} Array::Array(const Array&) = default; -const ast::Type* Array::Build(ProgramBuilder& b) const { +ast::Type Array::Build(ProgramBuilder& b) const { if (size > 0) { if (stride > 0) { return b.ty.array(type->Build(b), u32(size), utils::Vector{b.Stride(stride)}); @@ -223,9 +223,9 @@ const ast::Type* Array::Build(ProgramBuilder& b) const { } } else { if (stride > 0) { - return b.ty.array(type->Build(b), nullptr, utils::Vector{b.Stride(stride)}); + return b.ty.array(type->Build(b), utils::Vector{b.Stride(stride)}); } else { - return b.ty.array(type->Build(b), nullptr); + return b.ty.array(type->Build(b)); } } } @@ -233,7 +233,7 @@ const ast::Type* Array::Build(ProgramBuilder& b) const { Sampler::Sampler(type::SamplerKind k) : kind(k) {} Sampler::Sampler(const Sampler&) = default; -const ast::Type* Sampler::Build(ProgramBuilder& b) const { +ast::Type Sampler::Build(ProgramBuilder& b) const { return b.ty.sampler(kind); } @@ -243,14 +243,14 @@ Texture::Texture(const Texture&) = default; DepthTexture::DepthTexture(type::TextureDimension d) : Base(d) {} DepthTexture::DepthTexture(const DepthTexture&) = default; -const ast::Type* DepthTexture::Build(ProgramBuilder& b) const { +ast::Type DepthTexture::Build(ProgramBuilder& b) const { return b.ty.depth_texture(dims); } DepthMultisampledTexture::DepthMultisampledTexture(type::TextureDimension d) : Base(d) {} DepthMultisampledTexture::DepthMultisampledTexture(const DepthMultisampledTexture&) = default; -const ast::Type* DepthMultisampledTexture::Build(ProgramBuilder& b) const { +ast::Type DepthMultisampledTexture::Build(ProgramBuilder& b) const { return b.ty.depth_multisampled_texture(dims); } @@ -258,14 +258,14 @@ MultisampledTexture::MultisampledTexture(type::TextureDimension d, const Type* t : Base(d), type(t) {} MultisampledTexture::MultisampledTexture(const MultisampledTexture&) = default; -const ast::Type* MultisampledTexture::Build(ProgramBuilder& b) const { +ast::Type MultisampledTexture::Build(ProgramBuilder& b) const { return b.ty.multisampled_texture(dims, type->Build(b)); } SampledTexture::SampledTexture(type::TextureDimension d, const Type* t) : Base(d), type(t) {} SampledTexture::SampledTexture(const SampledTexture&) = default; -const ast::Type* SampledTexture::Build(ProgramBuilder& b) const { +ast::Type SampledTexture::Build(ProgramBuilder& b) const { return b.ty.sampled_texture(dims, type->Build(b)); } @@ -273,7 +273,7 @@ StorageTexture::StorageTexture(type::TextureDimension d, type::TexelFormat f, ty : Base(d), format(f), access(a) {} StorageTexture::StorageTexture(const StorageTexture&) = default; -const ast::Type* StorageTexture::Build(ProgramBuilder& b) const { +ast::Type StorageTexture::Build(ProgramBuilder& b) const { return b.ty.storage_texture(dims, format, access); } @@ -284,7 +284,7 @@ Named::~Named() = default; Alias::Alias(Symbol n, const Type* ty) : Base(n), type(ty) {} Alias::Alias(const Alias&) = default; -const ast::Type* Alias::Build(ProgramBuilder& b) const { +ast::Type Alias::Build(ProgramBuilder& b) const { return b.ty(name); } @@ -292,7 +292,7 @@ Struct::Struct(Symbol n, TypeList m) : Base(n), members(std::move(m)) {} Struct::Struct(const Struct&) = default; Struct::~Struct() = default; -const ast::Type* Struct::Build(ProgramBuilder& b) const { +ast::Type Struct::Build(ProgramBuilder& b) const { return b.ty(name); } diff --git a/src/tint/reader/spirv/parser_type.h b/src/tint/reader/spirv/parser_type.h index 04c8c67928..98056075f2 100644 --- a/src/tint/reader/spirv/parser_type.h +++ b/src/tint/reader/spirv/parser_type.h @@ -19,6 +19,7 @@ #include #include +#include "src/tint/ast/type.h" #include "src/tint/castable.h" #include "src/tint/symbol.h" #include "src/tint/type/access.h" @@ -32,9 +33,6 @@ namespace tint { class ProgramBuilder; } // namespace tint -namespace tint::ast { -class Type; -} // namespace tint::ast namespace tint::reader::spirv { @@ -50,7 +48,7 @@ class Type : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - virtual const ast::Type* Build(ProgramBuilder& b) const = 0; + virtual ast::Type Build(ProgramBuilder& b) const = 0; /// @returns the inner most store type if this is a pointer, `this` otherwise const Type* UnwrapPtr() const; @@ -102,7 +100,7 @@ using TypeList = std::vector; struct Void final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -114,7 +112,7 @@ struct Void final : public Castable { struct Bool final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -126,7 +124,7 @@ struct Bool final : public Castable { struct U32 final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -138,7 +136,7 @@ struct U32 final : public Castable { struct F32 final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -150,7 +148,7 @@ struct F32 final : public Castable { struct I32 final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -172,7 +170,7 @@ struct Pointer final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -203,7 +201,7 @@ struct Reference final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -231,7 +229,7 @@ struct Vector final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -258,7 +256,7 @@ struct Matrix final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -288,7 +286,7 @@ struct Array final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -315,7 +313,7 @@ struct Sampler final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -354,7 +352,7 @@ struct DepthTexture final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -374,7 +372,7 @@ struct DepthMultisampledTexture final : public Castable /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -419,7 +417,7 @@ struct SampledTexture final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -444,7 +442,7 @@ struct StorageTexture final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; #ifndef NDEBUG /// @returns a string representation of the type, for debug purposes only @@ -493,7 +491,7 @@ struct Alias final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; /// the aliased type Type const* const type; @@ -515,7 +513,7 @@ struct Struct final : public Castable { /// @param b the ProgramBuilder used to construct the AST types /// @returns the constructed ast::Type node for the given type - const ast::Type* Build(ProgramBuilder& b) const override; + ast::Type Build(ProgramBuilder& b) const override; /// the member types const TypeList members; diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index 3021bf616c..0fbb29f950 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -16,7 +16,6 @@ #include -#include "src/tint/ast/array.h" #include "src/tint/ast/assignment_statement.h" #include "src/tint/ast/bitcast_expression.h" #include "src/tint/ast/break_if_statement.h" @@ -32,10 +31,8 @@ #include "src/tint/ast/return_statement.h" #include "src/tint/ast/stage_attribute.h" #include "src/tint/ast/switch_statement.h" -#include "src/tint/ast/type_name.h" #include "src/tint/ast/unary_op_expression.h" #include "src/tint/ast/variable_decl_statement.h" -#include "src/tint/ast/vector.h" #include "src/tint/ast/workgroup_attribute.h" #include "src/tint/reader/wgsl/classify_template_args.h" #include "src/tint/reader/wgsl/lexer.h" @@ -180,7 +177,7 @@ ParserImpl::TypedIdentifier::TypedIdentifier() = default; ParserImpl::TypedIdentifier::TypedIdentifier(const TypedIdentifier&) = default; -ParserImpl::TypedIdentifier::TypedIdentifier(const ast::Type* type_in, +ParserImpl::TypedIdentifier::TypedIdentifier(ast::Type type_in, std::string name_in, Source source_in) : type(type_in), name(std::move(name_in)), source(std::move(source_in)) {} @@ -194,7 +191,7 @@ ParserImpl::FunctionHeader::FunctionHeader(const FunctionHeader&) = default; ParserImpl::FunctionHeader::FunctionHeader(Source src, std::string n, utils::VectorRef p, - const ast::Type* ret_ty, + ast::Type ret_ty, utils::VectorRef ret_attrs) : source(src), name(n), @@ -215,7 +212,7 @@ ParserImpl::VarDeclInfo::VarDeclInfo(Source source_in, std::string name_in, type::AddressSpace address_space_in, type::Access access_in, - const ast::Type* type_in) + ast::Type type_in) : source(std::move(source_in)), name(std::move(name_in)), address_space(address_space_in), @@ -733,7 +730,7 @@ Maybe ParserImpl::variable_decl() { // | multisampled_texture_type LESS_THAN type_specifier GREATER_THAN // | storage_texture_type LESS_THAN texel_format // COMMA access_mode GREATER_THAN -Maybe ParserImpl::texture_and_sampler_types() { +Maybe ParserImpl::texture_and_sampler_types() { auto type = sampler_type(); if (type.matched) { return type; @@ -811,7 +808,7 @@ Maybe ParserImpl::texture_and_sampler_types() { // sampler_type // : SAMPLER // | SAMPLER_COMPARISON -Maybe ParserImpl::sampler_type() { +Maybe ParserImpl::sampler_type() { Source source; if (match(Token::Type::kSampler, &source)) { return builder_.ty.sampler(source, type::SamplerKind::kSampler); @@ -861,7 +858,7 @@ Maybe ParserImpl::sampled_texture_type() { // external_texture // : TEXTURE_EXTERNAL -Maybe ParserImpl::external_texture() { +Maybe ParserImpl::external_texture() { Source source; if (match(Token::Type::kTextureExternal, &source)) { return builder_.ty.external_texture(source); @@ -908,7 +905,7 @@ Maybe ParserImpl::storage_texture_type() { // | TEXTURE_DEPTH_CUBE // | TEXTURE_DEPTH_CUBE_ARRAY // | TEXTURE_DEPTH_MULTISAMPLED_2D -Maybe ParserImpl::depth_texture_type() { +Maybe ParserImpl::depth_texture_type() { Source source; if (match(Token::Type::kTextureDepth2d, &source)) { return builder_.ty.depth_texture(source, type::TextureDimension::k2d); @@ -958,7 +955,7 @@ Expect ParserImpl::expect_ident_with_optional_type_ } if (allow_inferred && !peek_is(Token::Type::kColon)) { - return TypedIdentifier{nullptr, ident.value, ident.source}; + return TypedIdentifier{ast::Type{}, ident.value, ident.source}; } if (!expect(use, Token::Type::kColon)) { @@ -1130,7 +1127,7 @@ Maybe ParserImpl::mat_prefix() { // | mat_prefix LESS_THAN type_specifier GREATER_THAN // | vec_prefix LESS_THAN type_specifier GREATER_THAN // | texture_and_sampler_types -Maybe ParserImpl::type_specifier_without_ident() { +Maybe ParserImpl::type_specifier_without_ident() { auto& t = peek(); if (match(Token::Type::kBool)) { @@ -1198,7 +1195,7 @@ Maybe ParserImpl::type_specifier_without_ident() { // type_specifier // : IDENTIFIER // | type_specifier_without_ident -Maybe ParserImpl::type_specifier() { +Maybe ParserImpl::type_specifier() { auto& t = peek(); Source source; if (match(Token::Type::kIdentifier, &source)) { @@ -1243,7 +1240,7 @@ Expect ParserImpl::expect_enum(std::string_view name, return add_error(t.source(), err.str()); } -Expect ParserImpl::expect_type(std::string_view use) { +Expect ParserImpl::expect_type(std::string_view use) { auto type = type_specifier(); if (type.errored) { return Failure::kErrored; @@ -1255,13 +1252,13 @@ Expect ParserImpl::expect_type(std::string_view use) { } // LESS_THAN address_space COMMA type_specifier ( COMMA access_mode )? GREATER_THAN -Expect ParserImpl::expect_type_specifier_pointer(const Source& s) { +Expect ParserImpl::expect_type_specifier_pointer(const Source& s) { const char* use = "ptr declaration"; auto address_space = type::AddressSpace::kNone; auto access = type::Access::kUndefined; - auto subtype = expect_template_arg_block(use, [&]() -> Expect { + auto subtype = expect_template_arg_block(use, [&]() -> Expect { auto sc = expect_address_space(use); if (sc.errored) { return Failure::kErrored; @@ -1296,7 +1293,7 @@ Expect ParserImpl::expect_type_specifier_pointer(const Source& } // LESS_THAN type_specifier GREATER_THAN -Expect ParserImpl::expect_type_specifier_atomic(const Source& s) { +Expect ParserImpl::expect_type_specifier_atomic(const Source& s) { const char* use = "atomic declaration"; auto subtype = expect_template_arg_block(use, [&] { return expect_type(use); }); @@ -1308,7 +1305,7 @@ Expect ParserImpl::expect_type_specifier_atomic(const Source& } // LESS_THAN type_specifier GREATER_THAN -Expect ParserImpl::expect_type_specifier_vector(const Source& s, uint32_t count) { +Expect ParserImpl::expect_type_specifier_vector(const Source& s, uint32_t count) { const char* use = "vector"; auto ty = expect_template_arg_block(use, [&] { return expect_type(use); }); if (ty.errored) { @@ -1319,11 +1316,11 @@ Expect ParserImpl::expect_type_specifier_vector(const Source& } // LESS_THAN type_specifier ( COMMA element_count_expression )? GREATER_THAN -Expect ParserImpl::expect_type_specifier_array(const Source& s) { +Expect ParserImpl::expect_type_specifier_array(const Source& s) { const char* use = "array declaration"; struct TypeAndSize { - const ast::Type* type = nullptr; + ast::Type type; const ast::Expression* size = nullptr; }; @@ -1352,12 +1349,16 @@ Expect ParserImpl::expect_type_specifier_array(const Source& s return Failure::kErrored; } - return builder_.ty.array(make_source_range_from(s), type_size->type, type_size->size); + if (type_size->size) { + return builder_.ty.array(make_source_range_from(s), type_size->type, type_size->size); + } else { + return builder_.ty.array(make_source_range_from(s), type_size->type); + } } // LESS_THAN type_specifier GREATER_THAN -Expect ParserImpl::expect_type_specifier_matrix(const Source& s, - const MatrixDimensions& dims) { +Expect ParserImpl::expect_type_specifier_matrix(const Source& s, + const MatrixDimensions& dims) { const char* use = "matrix"; auto ty = expect_template_arg_block(use, [&] { return expect_type(use); }); if (ty.errored) { @@ -1542,7 +1543,7 @@ Maybe ParserImpl::function_header() { } } - const ast::Type* return_type = nullptr; + ast::Type return_type; AttributeList return_attributes; if (match(Token::Type::kArrow)) { @@ -2417,10 +2418,7 @@ Maybe ParserImpl::func_call_statement() { return builder_.CallStmt( t.source(), - create( - t.source(), - create(t.source(), builder_.Symbols().Register(t.to_str())), - std::move(params.value))); + builder_.Call(t.source(), builder_.Expr(t.source(), t.to_str()), std::move(params.value))); } // break_statement @@ -2530,7 +2528,7 @@ Maybe ParserImpl::continuing_statement() { // Note, `ident` is pulled out to `primary_expression` as it's the only one that // doesn't create a `type`. Then we can just return a `type` from here on match and // deal with `ident` in `primary_expression. -Maybe ParserImpl::callable() { +Maybe ParserImpl::callable() { auto& t = peek(); // This _must_ match `type_specifier_without_ident` before any of the other types as they're @@ -2541,22 +2539,22 @@ Maybe ParserImpl::callable() { return Failure::kErrored; } if (ty.matched) { - return ty.value; + return ty->expr; } if (match(Token::Type::kArray)) { - return builder_.ty.array(make_source_range_from(t.source()), nullptr, nullptr); + return builder_.ty.array(make_source_range_from(t.source())); } auto vec = vec_prefix(); if (vec.matched) { - return builder_.ty.vec(make_source_range_from(t.source()), nullptr, vec.value); + return builder_.ty.vec(make_source_range_from(t.source()), vec.value); } auto mat = mat_prefix(); if (mat.matched) { - return builder_.ty.mat(make_source_range_from(t.source()), nullptr, mat.value.columns, - mat.value.rows); + return builder_.ty.mat(make_source_range_from(t.source()), mat.value.columns, + mat.value.rows); } return Failure::kNoMatch; diff --git a/src/tint/reader/wgsl/parser_impl.h b/src/tint/reader/wgsl/parser_impl.h index 933611bf78..455300d8dc 100644 --- a/src/tint/reader/wgsl/parser_impl.h +++ b/src/tint/reader/wgsl/parser_impl.h @@ -220,12 +220,12 @@ class ParserImpl { /// @param type_in parsed type /// @param name_in parsed identifier /// @param source_in source to the identifier - TypedIdentifier(const ast::Type* type_in, std::string name_in, Source source_in); + TypedIdentifier(ast::Type type_in, std::string name_in, Source source_in); /// Destructor ~TypedIdentifier(); - /// Parsed type. May be nullptr for inferred types. - const ast::Type* type = nullptr; + /// Parsed type. type.expr be nullptr for inferred types. + ast::Type type; /// Parsed identifier. std::string name; /// Source to the identifier. @@ -248,7 +248,7 @@ class ParserImpl { FunctionHeader(Source src, std::string n, utils::VectorRef p, - const ast::Type* ret_ty, + ast::Type ret_ty, utils::VectorRef ret_attrs); /// Destructor ~FunctionHeader(); @@ -264,7 +264,7 @@ class ParserImpl { /// Function parameters utils::Vector params; /// Function return type - const ast::Type* return_type = nullptr; + ast::Type return_type; /// Function return type attributes AttributeList return_type_attributes; }; @@ -286,7 +286,7 @@ class ParserImpl { std::string name_in, type::AddressSpace address_space_in, type::Access access_in, - const ast::Type* type_in); + ast::Type type_in); /// Destructor ~VarDeclInfo(); @@ -299,7 +299,7 @@ class ParserImpl { /// Variable access control type::Access access = type::Access::kUndefined; /// Variable type - const ast::Type* type = nullptr; + ast::Type type; }; /// VariableQualifier contains the parsed information for a variable qualifier @@ -449,7 +449,7 @@ class ParserImpl { Maybe type_alias_decl(); /// Parses a `callable` grammar element /// @returns the type or nullptr - Maybe callable(); + Maybe callable(); /// Parses a `vec_prefix` grammar element /// @returns the vector size or nullptr Maybe vec_prefix(); @@ -458,10 +458,10 @@ class ParserImpl { Maybe mat_prefix(); /// Parses a `type_specifier_without_ident` grammar element /// @returns the parsed Type or nullptr if none matched. - Maybe type_specifier_without_ident(); + Maybe type_specifier_without_ident(); /// Parses a `type_specifier` grammar element /// @returns the parsed Type or nullptr if none matched. - Maybe type_specifier(); + Maybe type_specifier(); /// Parses an `address_space` grammar element, erroring on parse failure. /// @param use a description of what was being parsed if an error was raised. /// @returns the address space or type::AddressSpace::kNone if none matched @@ -483,10 +483,10 @@ class ParserImpl { Maybe function_decl(AttributeList& attrs); /// Parses a `texture_and_sampler_types` grammar element /// @returns the parsed Type or nullptr if none matched. - Maybe texture_and_sampler_types(); + Maybe texture_and_sampler_types(); /// Parses a `sampler_type` grammar element /// @returns the parsed Type or nullptr if none matched. - Maybe sampler_type(); + Maybe sampler_type(); /// Parses a `multisampled_texture_type` grammar element /// @returns returns the multisample texture dimension or kNone if none /// matched. @@ -500,10 +500,10 @@ class ParserImpl { Maybe storage_texture_type(); /// Parses a `depth_texture_type` grammar element /// @returns the parsed Type or nullptr if none matched. - Maybe depth_texture_type(); + Maybe depth_texture_type(); /// Parses a 'texture_external_type' grammar element /// @returns the parsed Type or nullptr if none matched - Maybe external_texture(); + Maybe external_texture(); /// Parses a `texel_format` grammar element /// @param use a description of what was being parsed if an error was raised /// @returns returns the texel format or kNone if none matched. @@ -891,12 +891,11 @@ class ParserImpl { /// Used to ensure that all attributes are consumed. bool expect_attributes_consumed(utils::VectorRef list); - Expect expect_type_specifier_pointer(const Source& s); - Expect expect_type_specifier_atomic(const Source& s); - Expect expect_type_specifier_vector(const Source& s, uint32_t count); - Expect expect_type_specifier_array(const Source& s); - Expect expect_type_specifier_matrix(const Source& s, - const MatrixDimensions& dims); + Expect expect_type_specifier_pointer(const Source& s); + Expect expect_type_specifier_atomic(const Source& s); + Expect expect_type_specifier_vector(const Source& s, uint32_t count); + Expect expect_type_specifier_array(const Source& s); + Expect expect_type_specifier_matrix(const Source& s, const MatrixDimensions& dims); /// Parses the given enum, providing sensible error messages if the next token does not match /// any of the enum values. @@ -910,7 +909,7 @@ class ParserImpl { const char* const (&strings)[N], std::string_view use = ""); - Expect expect_type(std::string_view use); + Expect expect_type(std::string_view use); Maybe non_block_statement(); Maybe for_header_initializer(); diff --git a/src/tint/reader/wgsl/parser_impl_call_stmt_test.cc b/src/tint/reader/wgsl/parser_impl_call_stmt_test.cc index 59aeb3cb57..63f957413d 100644 --- a/src/tint/reader/wgsl/parser_impl_call_stmt_test.cc +++ b/src/tint/reader/wgsl/parser_impl_call_stmt_test.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "src/tint/ast/call_statement.h" +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -34,7 +35,7 @@ TEST_F(ParserImplTest, Statement_Call) { ASSERT_TRUE(e->Is()); auto* c = e->As()->expr; - EXPECT_EQ(c->target.name->symbol, p->builder().Symbols().Get("a")); + ast::CheckIdentifier(p->builder().Symbols(), c->target, "a"); EXPECT_EQ(c->args.Length(), 0u); } @@ -50,7 +51,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams) { ASSERT_TRUE(e->Is()); auto* c = e->As()->expr; - EXPECT_EQ(c->target.name->symbol, p->builder().Symbols().Get("a")); + ast::CheckIdentifier(p->builder().Symbols(), c->target, "a"); EXPECT_EQ(c->args.Length(), 3u); EXPECT_TRUE(c->args[0]->Is()); @@ -69,7 +70,7 @@ TEST_F(ParserImplTest, Statement_Call_WithParams_TrailingComma) { ASSERT_TRUE(e->Is()); auto* c = e->As()->expr; - EXPECT_EQ(c->target.name->symbol, p->builder().Symbols().Get("a")); + ast::CheckIdentifier(p->builder().Symbols(), c->target, "a"); EXPECT_EQ(c->args.Length(), 2u); EXPECT_TRUE(c->args[0]->Is()); diff --git a/src/tint/reader/wgsl/parser_impl_callable_test.cc b/src/tint/reader/wgsl/parser_impl_callable_test.cc index 408a36f783..647e2b28fe 100644 --- a/src/tint/reader/wgsl/parser_impl_callable_test.cc +++ b/src/tint/reader/wgsl/parser_impl_callable_test.cc @@ -12,11 +12,14 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { namespace { +using namespace tint::number_suffixes; // NOLINT + TEST_F(ParserImplTest, Callable_Array) { auto p = parser("array"); auto t = p->callable(); @@ -25,12 +28,8 @@ TEST_F(ParserImplTest, Callable_Array) { EXPECT_FALSE(t.errored); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - EXPECT_FALSE(a->IsRuntimeArray()); - EXPECT_EQ(a->type, nullptr); - EXPECT_EQ(a->count, nullptr); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "array"); } TEST_F(ParserImplTest, Callable_VecPrefix) { @@ -41,11 +40,8 @@ TEST_F(ParserImplTest, Callable_VecPrefix) { EXPECT_FALSE(t.errored); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->Is()); - auto* v = t.value->As(); - EXPECT_EQ(v->type, nullptr); - EXPECT_EQ(v->width, 3u); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "vec3"); } TEST_F(ParserImplTest, Callable_MatPrefix) { @@ -56,12 +52,8 @@ TEST_F(ParserImplTest, Callable_MatPrefix) { EXPECT_FALSE(t.errored); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->Is()); - auto* m = t.value->As(); - EXPECT_EQ(m->type, nullptr); - EXPECT_EQ(m->columns, 3u); - EXPECT_EQ(m->rows, 2u); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "mat3x2"); } TEST_F(ParserImplTest, Callable_TypeDecl_Array) { @@ -72,18 +64,8 @@ TEST_F(ParserImplTest, Callable_TypeDecl_Array) { EXPECT_FALSE(t.errored); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - EXPECT_FALSE(a->IsRuntimeArray()); - - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); - - auto* size = a->count->As(); - ASSERT_NE(size, nullptr); - EXPECT_EQ(size->value, 2); - EXPECT_EQ(size->suffix, ast::IntLiteralExpression::Suffix::kNone); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", 2_a)); } TEST_F(ParserImplTest, Callable_TypeDecl_Array_Runtime) { @@ -94,15 +76,8 @@ TEST_F(ParserImplTest, Callable_TypeDecl_Array_Runtime) { EXPECT_FALSE(t.errored); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - EXPECT_TRUE(a->IsRuntimeArray()); - - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); - - ASSERT_EQ(a->count, nullptr); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32")); } TEST_F(ParserImplTest, Callable_TypeDecl_VecPrefix) { @@ -113,14 +88,8 @@ TEST_F(ParserImplTest, Callable_TypeDecl_VecPrefix) { EXPECT_FALSE(t.errored); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->Is()); - auto* v = t.value->As(); - - ASSERT_TRUE(v->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As()->name->symbol), "f32"); - - EXPECT_EQ(v->width, 3u); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("vec3", "f32")); } TEST_F(ParserImplTest, Callable_TypeDecl_MatPrefix) { @@ -131,15 +100,8 @@ TEST_F(ParserImplTest, Callable_TypeDecl_MatPrefix) { EXPECT_FALSE(t.errored); ASSERT_FALSE(p->has_error()) << p->error(); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->Is()); - auto* m = t.value->As(); - - ASSERT_TRUE(m->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As()->name->symbol), "f32"); - - EXPECT_EQ(m->columns, 3u); - EXPECT_EQ(m->rows, 2u); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("mat3x2", "f32")); } TEST_F(ParserImplTest, Callable_NoMatch) { diff --git a/src/tint/reader/wgsl/parser_impl_depth_texture_test.cc b/src/tint/reader/wgsl/parser_impl_depth_texture_test.cc index e04bed3305..f8079430c3 100644 --- a/src/tint/reader/wgsl/parser_impl_depth_texture_test.cc +++ b/src/tint/reader/wgsl/parser_impl_depth_texture_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" #include "src/tint/type/depth_texture.h" #include "src/tint/type/texture_dimension.h" @@ -33,9 +34,8 @@ TEST_F(ParserImplTest, DepthTextureType_2d) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), - "texture_depth_2d"); - EXPECT_FALSE(p->has_error()); + + ast::CheckIdentifier(p->builder().Symbols(), t.value, "texture_depth_2d"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); } @@ -45,9 +45,8 @@ TEST_F(ParserImplTest, DepthTextureType_2dArray) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), - "texture_depth_2d_array"); - EXPECT_FALSE(p->has_error()); + + ast::CheckIdentifier(p->builder().Symbols(), t.value, "texture_depth_2d_array"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 23u}})); } @@ -57,9 +56,8 @@ TEST_F(ParserImplTest, DepthTextureType_Cube) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), - "texture_depth_cube"); - EXPECT_FALSE(p->has_error()); + + ast::CheckIdentifier(p->builder().Symbols(), t.value, "texture_depth_cube"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); } @@ -69,9 +67,8 @@ TEST_F(ParserImplTest, DepthTextureType_CubeArray) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), - "texture_depth_cube_array"); - EXPECT_FALSE(p->has_error()); + + ast::CheckIdentifier(p->builder().Symbols(), t.value, "texture_depth_cube_array"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25u}})); } @@ -81,9 +78,8 @@ TEST_F(ParserImplTest, DepthTextureType_Multisampled2d) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), - "texture_depth_multisampled_2d"); - EXPECT_FALSE(p->has_error()); + + ast::CheckIdentifier(p->builder().Symbols(), t.value, "texture_depth_multisampled_2d"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 30u}})); } diff --git a/src/tint/reader/wgsl/parser_impl_diagnostic_attribute_test.cc b/src/tint/reader/wgsl/parser_impl_diagnostic_attribute_test.cc index c383c4d3d0..6c5e6f6b7c 100644 --- a/src/tint/reader/wgsl/parser_impl_diagnostic_attribute_test.cc +++ b/src/tint/reader/wgsl/parser_impl_diagnostic_attribute_test.cc @@ -15,6 +15,7 @@ #include "src/tint/reader/wgsl/parser_impl_test_helper.h" #include "src/tint/ast/diagnostic_control.h" +#include "src/tint/ast/test_helper.h" namespace tint::reader::wgsl { namespace { @@ -29,7 +30,7 @@ TEST_F(ParserImplTest, DiagnosticAttribute_Valid) { EXPECT_EQ(d->control.severity, ast::DiagnosticSeverity::kOff); auto* r = d->control.rule_name; ASSERT_NE(r, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(r->symbol), "foo"); + ast::CheckIdentifier(p->builder().Symbols(), r, "foo"); } } // namespace diff --git a/src/tint/reader/wgsl/parser_impl_diagnostic_control_test.cc b/src/tint/reader/wgsl/parser_impl_diagnostic_control_test.cc index 7c4b417d70..4454a9d6e2 100644 --- a/src/tint/reader/wgsl/parser_impl_diagnostic_control_test.cc +++ b/src/tint/reader/wgsl/parser_impl_diagnostic_control_test.cc @@ -15,6 +15,7 @@ #include "src/tint/reader/wgsl/parser_impl_test_helper.h" #include "src/tint/ast/diagnostic_control.h" +#include "src/tint/ast/test_helper.h" namespace tint::reader::wgsl { namespace { @@ -32,7 +33,7 @@ TEST_P(DiagnosticControlParserTest, DiagnosticControl_Valid) { auto* r = e->rule_name; ASSERT_NE(r, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(r->symbol), "foo"); + ast::CheckIdentifier(p->builder().Symbols(), r, "foo"); } INSTANTIATE_TEST_SUITE_P(DiagnosticControlParserTest, DiagnosticControlParserTest, @@ -50,7 +51,7 @@ TEST_F(ParserImplTest, DiagnosticControl_Valid_TrailingComma) { auto* r = e->rule_name; ASSERT_NE(r, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(r->symbol), "foo"); + ast::CheckIdentifier(p->builder().Symbols(), r, "foo"); } TEST_F(ParserImplTest, DiagnosticControl_MissingOpenParen) { diff --git a/src/tint/reader/wgsl/parser_impl_diagnostic_directive_test.cc b/src/tint/reader/wgsl/parser_impl_diagnostic_directive_test.cc index e3e767d1e8..ab50f34032 100644 --- a/src/tint/reader/wgsl/parser_impl_diagnostic_directive_test.cc +++ b/src/tint/reader/wgsl/parser_impl_diagnostic_directive_test.cc @@ -15,6 +15,7 @@ #include "src/tint/reader/wgsl/parser_impl_test_helper.h" #include "src/tint/ast/diagnostic_control.h" +#include "src/tint/ast/test_helper.h" namespace tint::reader::wgsl { namespace { @@ -32,7 +33,7 @@ TEST_F(ParserImplTest, DiagnosticDirective_Valid) { auto* r = directive->control.rule_name; ASSERT_NE(r, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(r->symbol), "foo"); + ast::CheckIdentifier(p->builder().Symbols(), r, "foo"); } TEST_F(ParserImplTest, DiagnosticDirective_MissingSemicolon) { diff --git a/src/tint/reader/wgsl/parser_impl_function_attribute_test.cc b/src/tint/reader/wgsl/parser_impl_function_attribute_test.cc index a9b9818831..05151d0d4d 100644 --- a/src/tint/reader/wgsl/parser_impl_function_attribute_test.cc +++ b/src/tint/reader/wgsl/parser_impl_function_attribute_test.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "src/tint/ast/stage_attribute.h" +#include "src/tint/ast/test_helper.h" #include "src/tint/ast/workgroup_attribute.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" @@ -310,9 +311,7 @@ TEST_F(ParserImplTest, Attribute_Workgroup_WithIdent) { ast::IntLiteralExpression::Suffix::kNone); ASSERT_NE(values[1], nullptr); - auto* y_ident = values[1]->As(); - ASSERT_NE(y_ident, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(y_ident->identifier->symbol), "height"); + ast::CheckIdentifier(p->builder().Symbols(), values[1], "height"); ASSERT_EQ(values[2], nullptr); } diff --git a/src/tint/reader/wgsl/parser_impl_function_decl_test.cc b/src/tint/reader/wgsl/parser_impl_function_decl_test.cc index dad9b5564c..2c26bacfe0 100644 --- a/src/tint/reader/wgsl/parser_impl_function_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_function_decl_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/ast/workgroup_attribute.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" #include "src/tint/utils/string.h" @@ -240,9 +241,7 @@ TEST_F(ParserImplTest, FunctionDecl_ReturnTypeAttributeList) { EXPECT_EQ(f->name->symbol, p->builder().Symbols().Get("main")); ASSERT_NE(f->return_type, nullptr); - ASSERT_TRUE(f->return_type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(f->return_type->As()->name->symbol), - "f32"); + ast::CheckIdentifier(p->builder().Symbols(), f->return_type, "f32"); ASSERT_EQ(f->params.Length(), 0u); diff --git a/src/tint/reader/wgsl/parser_impl_function_header_test.cc b/src/tint/reader/wgsl/parser_impl_function_header_test.cc index 7007c98dd9..f68ea69cb2 100644 --- a/src/tint/reader/wgsl/parser_impl_function_header_test.cc +++ b/src/tint/reader/wgsl/parser_impl_function_header_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -52,9 +53,7 @@ TEST_F(ParserImplTest, FunctionHeader_AttributeReturnType) { EXPECT_EQ(f->name, "main"); EXPECT_EQ(f->params.Length(), 0u); - ASSERT_TRUE(f->return_type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(f->return_type->As()->name->symbol), - "f32"); + ast::CheckIdentifier(p->builder().Symbols(), f->return_type, "f32"); ASSERT_EQ(f->return_type_attributes.Length(), 1u); auto* loc = f->return_type_attributes[0]->As(); @@ -73,9 +72,7 @@ TEST_F(ParserImplTest, FunctionHeader_InvariantReturnType) { EXPECT_EQ(f->name, "main"); EXPECT_EQ(f->params.Length(), 0u); - ASSERT_TRUE(f->return_type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(f->return_type->As()->name->symbol), - "f32"); + ast::CheckIdentifier(p->builder().Symbols(), f->return_type, "f32"); ASSERT_EQ(f->return_type_attributes.Length(), 1u); EXPECT_TRUE(f->return_type_attributes[0]->Is()); } diff --git a/src/tint/reader/wgsl/parser_impl_global_constant_decl_test.cc b/src/tint/reader/wgsl/parser_impl_global_constant_decl_test.cc index 7bb7a6fe63..98f3de1106 100644 --- a/src/tint/reader/wgsl/parser_impl_global_constant_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_global_constant_decl_test.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "src/tint/ast/id_attribute.h" +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -44,8 +45,7 @@ TEST_F(ParserImplTest, GlobalConstDecl) { EXPECT_EQ(c->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(c->type, nullptr); - ASSERT_TRUE(c->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(c->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), c->type, "f32"); EXPECT_EQ(c->source.range.begin.line, 1u); EXPECT_EQ(c->source.range.begin.column, 7u); @@ -121,9 +121,7 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithId) { EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(override->type, nullptr); - ASSERT_TRUE(override->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(override->type->As()->name->symbol), - "f32"); + ast::CheckIdentifier(p->builder().Symbols(), override->type, "f32"); EXPECT_EQ(override->source.range.begin.line, 1u); EXPECT_EQ(override->source.range.begin.column, 17u); @@ -153,9 +151,7 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithId_TrailingComma) { EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(override->type, nullptr); - ASSERT_TRUE(override->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(override->type->As()->name->symbol), - "f32"); + ast::CheckIdentifier(p->builder().Symbols(), override->type, "f32"); EXPECT_EQ(override->source.range.begin.line, 1u); EXPECT_EQ(override->source.range.begin.column, 18u); @@ -185,9 +181,7 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithoutId) { EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(override->type, nullptr); - ASSERT_TRUE(override->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(override->type->As()->name->symbol), - "f32"); + ast::CheckIdentifier(p->builder().Symbols(), override->type, "f32"); EXPECT_EQ(override->source.range.begin.line, 1u); EXPECT_EQ(override->source.range.begin.column, 10u); diff --git a/src/tint/reader/wgsl/parser_impl_global_decl_test.cc b/src/tint/reader/wgsl/parser_impl_global_decl_test.cc index db5db00586..a14507c979 100644 --- a/src/tint/reader/wgsl/parser_impl_global_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_global_decl_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -33,7 +34,7 @@ TEST_F(ParserImplTest, GlobalDecl_GlobalVariable) { auto* v = program.AST().GlobalVariables()[0]; EXPECT_EQ(v->name->symbol, program.Symbols().Get("a")); - EXPECT_TRUE(Is(v->type)); + ast::CheckIdentifier(program.Symbols(), v->type, ast::Template("vec2", "i32")); } TEST_F(ParserImplTest, GlobalDecl_GlobalVariable_Inferred) { @@ -106,9 +107,8 @@ TEST_F(ParserImplTest, GlobalDecl_TypeAlias) { auto program = p->program(); ASSERT_EQ(program.AST().TypeDecls().Length(), 1u); ASSERT_TRUE(program.AST().TypeDecls()[0]->Is()); - EXPECT_EQ( - program.Symbols().NameFor(program.AST().TypeDecls()[0]->As()->name->symbol), - "A"); + ast::CheckIdentifier(program.Symbols(), program.AST().TypeDecls()[0]->As()->name, + "A"); } TEST_F(ParserImplTest, GlobalDecl_TypeAlias_StructIdent) { @@ -129,9 +129,7 @@ alias B = A;)"); ASSERT_TRUE(program.AST().TypeDecls()[1]->Is()); auto* alias = program.AST().TypeDecls()[1]->As(); EXPECT_EQ(alias->name->symbol, program.Symbols().Get("B")); - auto* tn = alias->type->As(); - EXPECT_NE(tn, nullptr); - EXPECT_EQ(tn->name->symbol, str->name->symbol); + ast::CheckIdentifier(program.Symbols(), alias->type, "A"); } // TODO(crbug.com/tint/1812): DEPRECATED @@ -143,9 +141,8 @@ TEST_F(ParserImplTest, DEPRECATED_GlobalDecl_TypeAlias) { auto program = p->program(); ASSERT_EQ(program.AST().TypeDecls().Length(), 1u); ASSERT_TRUE(program.AST().TypeDecls()[0]->Is()); - EXPECT_EQ( - program.Symbols().NameFor(program.AST().TypeDecls()[0]->As()->name->symbol), - "A"); + ast::CheckIdentifier(program.Symbols(), program.AST().TypeDecls()[0]->As()->name, + "A"); } // TODO(crbug.com/tint/1812): DEPRECATED @@ -167,9 +164,7 @@ type B = A;)"); ASSERT_TRUE(program.AST().TypeDecls()[1]->Is()); auto* alias = program.AST().TypeDecls()[1]->As(); EXPECT_EQ(alias->name->symbol, program.Symbols().Get("B")); - auto* tn = alias->type->As(); - EXPECT_NE(tn, nullptr); - EXPECT_EQ(tn->name->symbol, str->name->symbol); + ast::CheckIdentifier(program.Symbols(), alias->type, "A"); } TEST_F(ParserImplTest, GlobalDecl_TypeAlias_MissingSemicolon) { @@ -196,7 +191,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function) { auto program = p->program(); ASSERT_EQ(program.AST().Functions().Length(), 1u); - EXPECT_EQ(program.Symbols().NameFor(program.AST().Functions()[0]->name->symbol), "main"); + ast::CheckIdentifier(program.Symbols(), program.AST().Functions()[0]->name, "main"); } TEST_F(ParserImplTest, GlobalDecl_Function_WithAttribute) { @@ -206,7 +201,7 @@ TEST_F(ParserImplTest, GlobalDecl_Function_WithAttribute) { auto program = p->program(); ASSERT_EQ(program.AST().Functions().Length(), 1u); - EXPECT_EQ(program.Symbols().NameFor(program.AST().Functions()[0]->name->symbol), "main"); + ast::CheckIdentifier(program.Symbols(), program.AST().Functions()[0]->name, "main"); } TEST_F(ParserImplTest, GlobalDecl_Function_Invalid) { diff --git a/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc b/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc index 867e7004de..92272cce5a 100644 --- a/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -29,10 +30,9 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutInitializer) { auto* var = e.value->As(); ASSERT_NE(var, nullptr); - EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a")); + ast::CheckIdentifier(p->builder().Symbols(), var->name, "a"); - ASSERT_TRUE(var->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(var->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), var->type, "f32"); EXPECT_EQ(var->declared_address_space, type::AddressSpace::kPrivate); @@ -56,10 +56,8 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithInitializer) { auto* var = e.value->As(); ASSERT_NE(var, nullptr); - EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a")); - - ASSERT_TRUE(var->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(var->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), var->name, "a"); + ast::CheckIdentifier(p->builder().Symbols(), var->type, "f32"); EXPECT_EQ(var->declared_address_space, type::AddressSpace::kPrivate); @@ -84,11 +82,10 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute) { auto* var = e.value->As(); ASSERT_NE(var, nullptr); - EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a")); + ast::CheckIdentifier(p->builder().Symbols(), var->name, "a"); ASSERT_NE(var->type, nullptr); - ASSERT_TRUE(var->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(var->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), var->type, "f32"); EXPECT_EQ(var->declared_address_space, type::AddressSpace::kUniform); @@ -118,11 +115,9 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute_MulitpleGroups) { auto* var = e.value->As(); ASSERT_NE(var, nullptr); - EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a")); + ast::CheckIdentifier(p->builder().Symbols(), var->name, "a"); ASSERT_NE(var->type, nullptr); - - ASSERT_TRUE(var->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(var->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), var->type, "f32"); EXPECT_EQ(var->declared_address_space, type::AddressSpace::kUniform); diff --git a/src/tint/reader/wgsl/parser_impl_param_list_test.cc b/src/tint/reader/wgsl/parser_impl_param_list_test.cc index 14d23631fb..4829294ae1 100644 --- a/src/tint/reader/wgsl/parser_impl_param_list_test.cc +++ b/src/tint/reader/wgsl/parser_impl_param_list_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -26,9 +27,7 @@ TEST_F(ParserImplTest, ParamList_Single) { EXPECT_EQ(e.value.Length(), 1u); EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(e.value[0]->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(e.value[0]->type->As()->name->symbol), - "i32"); + ast::CheckIdentifier(p->builder().Symbols(), e.value[0]->type, "i32"); EXPECT_TRUE(e.value[0]->Is()); ASSERT_EQ(e.value[0]->source.range.begin.line, 1u); @@ -46,9 +45,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) { EXPECT_EQ(e.value.Length(), 3u); EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("a")); - ASSERT_TRUE(e.value[0]->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(e.value[0]->type->As()->name->symbol), - "i32"); + ast::CheckIdentifier(p->builder().Symbols(), e.value[0]->type, "i32"); EXPECT_TRUE(e.value[0]->Is()); ASSERT_EQ(e.value[0]->source.range.begin.line, 1u); @@ -57,9 +54,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) { ASSERT_EQ(e.value[0]->source.range.end.column, 2u); EXPECT_EQ(e.value[1]->name->symbol, p->builder().Symbols().Get("b")); - ASSERT_TRUE(e.value[1]->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(e.value[1]->type->As()->name->symbol), - "f32"); + ast::CheckIdentifier(p->builder().Symbols(), e.value[1]->type, "f32"); EXPECT_TRUE(e.value[1]->Is()); ASSERT_EQ(e.value[1]->source.range.begin.line, 1u); @@ -68,12 +63,7 @@ TEST_F(ParserImplTest, ParamList_Multiple) { ASSERT_EQ(e.value[1]->source.range.end.column, 11u); EXPECT_EQ(e.value[2]->name->symbol, p->builder().Symbols().Get("c")); - ASSERT_TRUE(e.value[2]->type->Is()); - ASSERT_TRUE(e.value[2]->type->As()->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor( - e.value[2]->type->As()->type->As()->name->symbol), - "f32"); - EXPECT_EQ(e.value[2]->type->As()->width, 2u); + ast::CheckIdentifier(p->builder().Symbols(), e.value[2]->type, ast::Template("vec2", "f32")); EXPECT_TRUE(e.value[2]->Is()); ASSERT_EQ(e.value[2]->source.range.begin.line, 1u); @@ -107,12 +97,7 @@ TEST_F(ParserImplTest, ParamList_Attributes) { ASSERT_EQ(e.value.Length(), 2u); EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("coord")); - ASSERT_TRUE(e.value[0]->type->Is()); - ASSERT_TRUE(e.value[0]->type->As()->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor( - e.value[0]->type->As()->type->As()->name->symbol), - "f32"); - EXPECT_EQ(e.value[0]->type->As()->width, 4u); + ast::CheckIdentifier(p->builder().Symbols(), e.value[0]->type, ast::Template("vec4", "f32")); EXPECT_TRUE(e.value[0]->Is()); auto attrs_0 = e.value[0]->attributes; ASSERT_EQ(attrs_0.Length(), 1u); @@ -125,9 +110,7 @@ TEST_F(ParserImplTest, ParamList_Attributes) { ASSERT_EQ(e.value[0]->source.range.end.column, 25u); EXPECT_EQ(e.value[1]->name->symbol, p->builder().Symbols().Get("loc1")); - ASSERT_TRUE(e.value[1]->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(e.value[1]->type->As()->name->symbol), - "f32"); + ast::CheckIdentifier(p->builder().Symbols(), e.value[1]->type, "f32"); EXPECT_TRUE(e.value[1]->Is()); auto attrs_1 = e.value[1]->attributes; ASSERT_EQ(attrs_1.Length(), 1u); diff --git a/src/tint/reader/wgsl/parser_impl_primary_expression_test.cc b/src/tint/reader/wgsl/parser_impl_primary_expression_test.cc index 517a7b697b..b7b0d856f6 100644 --- a/src/tint/reader/wgsl/parser_impl_primary_expression_test.cc +++ b/src/tint/reader/wgsl/parser_impl_primary_expression_test.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "src/tint/ast/bitcast_expression.h" +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -26,8 +27,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Ident) { EXPECT_FALSE(p->has_error()) << p->error(); ASSERT_NE(e.value, nullptr); ASSERT_TRUE(e->Is()); - auto* ident_expr = e->As(); - EXPECT_EQ(ident_expr->identifier->symbol, p->builder().Symbols().Get("a")); + ast::CheckIdentifier(p->builder().Symbols(), e.value, "a"); } TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) { @@ -40,8 +40,6 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl) { ASSERT_TRUE(e->Is()); auto* call = e->As(); - EXPECT_NE(call->target.type, nullptr); - ASSERT_EQ(call->args.Length(), 4u); const auto& val = call->args; ASSERT_TRUE(val[0]->Is()); @@ -137,8 +135,8 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructInitializer_Empty) { ASSERT_TRUE(e->Is()); auto* call = e->As(); - ASSERT_NE(call->target.name, nullptr); - EXPECT_EQ(call->target.name->symbol, p->builder().Symbols().Get("S")); + ASSERT_NE(call->target, nullptr); + ast::CheckIdentifier(p->builder().Symbols(), call->target, "S"); ASSERT_EQ(call->args.Length(), 0u); } @@ -161,8 +159,8 @@ TEST_F(ParserImplTest, PrimaryExpression_TypeDecl_StructInitializer_NotEmpty) { ASSERT_TRUE(e->Is()); auto* call = e->As(); - ASSERT_NE(call->target.name, nullptr); - EXPECT_EQ(call->target.name->symbol, p->builder().Symbols().Get("S")); + ASSERT_NE(call->target, nullptr); + ast::CheckIdentifier(p->builder().Symbols(), call->target, "S"); ASSERT_EQ(call->args.Length(), 2u); @@ -237,10 +235,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) { ASSERT_TRUE(e->Is()); auto* call = e->As(); - - auto* type_name = As(call->target.type); - ASSERT_NE(type_name, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(type_name->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), call->target, "f32"); ASSERT_EQ(call->args.Length(), 1u); ASSERT_TRUE(call->args[0]->Is()); @@ -258,8 +253,7 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) { auto* c = e->As(); - ASSERT_TRUE(c->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(c->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), c->type, "f32"); ASSERT_TRUE(c->expr->Is()); } diff --git a/src/tint/reader/wgsl/parser_impl_sampler_test.cc b/src/tint/reader/wgsl/parser_impl_sampler_test.cc index c1869eac22..b88ac2d537 100644 --- a/src/tint/reader/wgsl/parser_impl_sampler_test.cc +++ b/src/tint/reader/wgsl/parser_impl_sampler_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -32,8 +33,7 @@ TEST_F(ParserImplTest, SamplerType_Sampler) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), - "sampler"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "sampler"); EXPECT_FALSE(p->has_error()); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 8u}})); } @@ -44,8 +44,7 @@ TEST_F(ParserImplTest, SamplerType_ComparisonSampler) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), - "sampler_comparison"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "sampler_comparison"); EXPECT_FALSE(p->has_error()); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); } diff --git a/src/tint/reader/wgsl/parser_impl_singular_expression_test.cc b/src/tint/reader/wgsl/parser_impl_singular_expression_test.cc index 4bfc5a89c9..dfde6fa184 100644 --- a/src/tint/reader/wgsl/parser_impl_singular_expression_test.cc +++ b/src/tint/reader/wgsl/parser_impl_singular_expression_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -97,7 +98,7 @@ TEST_F(ParserImplTest, SingularExpression_Call_Empty) { ASSERT_TRUE(e->Is()); auto* c = e->As(); - EXPECT_EQ(c->target.name->symbol, p->builder().Symbols().Get("a")); + ast::CheckIdentifier(p->builder().Symbols(), c->target, "a"); EXPECT_EQ(c->args.Length(), 0u); } @@ -113,7 +114,7 @@ TEST_F(ParserImplTest, SingularExpression_Call_WithArgs) { ASSERT_TRUE(e->Is()); auto* c = e->As(); - EXPECT_EQ(c->target.name->symbol, p->builder().Symbols().Get("test")); + ast::CheckIdentifier(p->builder().Symbols(), c->target, "test"); EXPECT_EQ(c->args.Length(), 3u); EXPECT_TRUE(c->args[0]->Is()); diff --git a/src/tint/reader/wgsl/parser_impl_struct_body_decl_test.cc b/src/tint/reader/wgsl/parser_impl_struct_body_decl_test.cc index 1ae5adf061..d01c266075 100644 --- a/src/tint/reader/wgsl/parser_impl_struct_body_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_struct_body_decl_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -29,8 +30,7 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses) { const auto* mem = m.value[0]; EXPECT_EQ(mem->name->symbol, builder.Symbols().Get("a")); - ASSERT_TRUE(mem->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(mem->type->As()->name->symbol), "i32"); + ast::CheckIdentifier(p->builder().Symbols(), mem->type, "i32"); EXPECT_EQ(mem->attributes.Length(), 0u); } @@ -46,8 +46,7 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses_TrailingComma) { const auto* mem = m.value[0]; EXPECT_EQ(mem->name->symbol, builder.Symbols().Get("a")); - ASSERT_TRUE(mem->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(mem->type->As()->name->symbol), "i32"); + ast::CheckIdentifier(p->builder().Symbols(), mem->type, "i32"); EXPECT_EQ(mem->attributes.Length(), 0u); } diff --git a/src/tint/reader/wgsl/parser_impl_struct_member_test.cc b/src/tint/reader/wgsl/parser_impl_struct_member_test.cc index 09f25b85fb..3c27a9f335 100644 --- a/src/tint/reader/wgsl/parser_impl_struct_member_test.cc +++ b/src/tint/reader/wgsl/parser_impl_struct_member_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -20,16 +21,13 @@ namespace { TEST_F(ParserImplTest, StructMember_Parses) { auto p = parser("a : i32,"); - auto& builder = p->builder(); - auto m = p->expect_struct_member(); ASSERT_FALSE(p->has_error()); ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m->name->symbol, builder.Symbols().Get("a")); - ASSERT_TRUE(m->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As()->name->symbol), "i32"); + ast::CheckIdentifier(p->builder().Symbols(), m->name, "a"); + ast::CheckIdentifier(p->builder().Symbols(), m->type, "i32"); EXPECT_EQ(m->attributes.Length(), 0u); EXPECT_EQ(m->source.range, (Source::Range{{1u, 1u}, {1u, 2u}})); @@ -39,16 +37,13 @@ TEST_F(ParserImplTest, StructMember_Parses) { TEST_F(ParserImplTest, StructMember_ParsesWithAlignAttribute) { auto p = parser("@align(2) a : i32,"); - auto& builder = p->builder(); - auto m = p->expect_struct_member(); ASSERT_FALSE(p->has_error()); ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m->name->symbol, builder.Symbols().Get("a")); - ASSERT_TRUE(m->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As()->name->symbol), "i32"); + ast::CheckIdentifier(p->builder().Symbols(), m->name, "a"); + ast::CheckIdentifier(p->builder().Symbols(), m->type, "i32"); EXPECT_EQ(m->attributes.Length(), 1u); EXPECT_TRUE(m->attributes[0]->Is()); @@ -65,16 +60,13 @@ TEST_F(ParserImplTest, StructMember_ParsesWithAlignAttribute) { TEST_F(ParserImplTest, StructMember_ParsesWithSizeAttribute) { auto p = parser("@size(2) a : i32,"); - auto& builder = p->builder(); - auto m = p->expect_struct_member(); ASSERT_FALSE(p->has_error()); ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m->name->symbol, builder.Symbols().Get("a")); - ASSERT_TRUE(m->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As()->name->symbol), "i32"); + ast::CheckIdentifier(p->builder().Symbols(), m->name, "a"); + ast::CheckIdentifier(p->builder().Symbols(), m->type, "i32"); EXPECT_EQ(m->attributes.Length(), 1u); ASSERT_TRUE(m->attributes[0]->Is()); auto* s = m->attributes[0]->As(); @@ -90,16 +82,13 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleattributes) { auto p = parser(R"(@size(2) @align(4) a : i32,)"); - auto& builder = p->builder(); - auto m = p->expect_struct_member(); ASSERT_FALSE(p->has_error()); ASSERT_FALSE(m.errored); ASSERT_NE(m.value, nullptr); - EXPECT_EQ(m->name->symbol, builder.Symbols().Get("a")); - ASSERT_TRUE(m->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As()->name->symbol), "i32"); + ast::CheckIdentifier(p->builder().Symbols(), m->name, "a"); + ast::CheckIdentifier(p->builder().Symbols(), m->type, "i32"); EXPECT_EQ(m->attributes.Length(), 2u); ASSERT_TRUE(m->attributes[0]->Is()); auto* size_attr = m->attributes[0]->As(); diff --git a/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc b/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc index 37dbd97d55..3163377b06 100644 --- a/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc +++ b/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc @@ -38,9 +38,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_Sampler) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), - "sampler"); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 8u}})); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "sampler"); + EXPECT_EQ(t->expr->source.range, (Source::Range{{1u, 1u}, {1u, 8u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_SamplerComparison) { @@ -49,10 +48,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SamplerComparison) { ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); - ASSERT_NE(t.value, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), - "sampler_comparison"); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "sampler_comparison"); + EXPECT_EQ(t->expr->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) { @@ -62,9 +59,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_DepthTexture) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), - "texture_depth_2d"); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "texture_depth_2d"); + EXPECT_EQ(t->expr->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) { @@ -74,13 +70,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_F32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor( - t->As()->type->As()->name->symbol), - "f32"); - EXPECT_EQ(t->As()->dim, type::TextureDimension::k1d); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 16u}})); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("texture_1d", "f32")); + EXPECT_EQ(t->expr->source.range, (Source::Range{{1u, 1u}, {1u, 16u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) { @@ -90,13 +81,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_I32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor( - t->As()->type->As()->name->symbol), - "i32"); - EXPECT_EQ(t->As()->dim, type::TextureDimension::k2d); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 16u}})); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("texture_2d", "i32")); + EXPECT_EQ(t->expr->source.range, (Source::Range{{1u, 1u}, {1u, 16u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { @@ -106,42 +92,8 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor( - t->As()->type->As()->name->symbol), - "u32"); - EXPECT_EQ(t->As()->dim, type::TextureDimension::k3d); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 16u}})); -} - -TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingType) { - auto p = parser("texture_1d<>"); - auto t = p->texture_and_sampler_types(); - ASSERT_TRUE(p->has_error()); - EXPECT_EQ(t.value, nullptr); - EXPECT_FALSE(t.matched); - EXPECT_TRUE(t.errored); - EXPECT_EQ(p->error(), "1:12: invalid type for sampled texture type"); -} - -TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingLessThan) { - auto p = parser("texture_1d"); - auto t = p->texture_and_sampler_types(); - ASSERT_TRUE(p->has_error()); - EXPECT_EQ(t.value, nullptr); - EXPECT_FALSE(t.matched); - EXPECT_TRUE(t.errored); - EXPECT_EQ(p->error(), "1:11: expected '<' for sampled texture type"); -} - -TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_MissingGreaterThan) { - auto p = parser("texture_1dtexture_and_sampler_types(); - ASSERT_TRUE(p->has_error()); - EXPECT_EQ(t.value, nullptr); - EXPECT_FALSE(t.matched); - EXPECT_TRUE(t.errored); - EXPECT_EQ(p->error(), "1:11: missing closing '>' for sampled texture type"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("texture_3d", "u32")); + EXPECT_EQ(t->expr->source.range, (Source::Range{{1u, 1u}, {1u, 16u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) { @@ -151,13 +103,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_I32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor( - t->As()->type->As()->name->symbol), - "i32"); - EXPECT_EQ(t->As()->dim, type::TextureDimension::k2d); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 29u}})); + ast::CheckIdentifier(p->builder().Symbols(), t.value, + ast::Template("texture_multisampled_2d", "i32")); + EXPECT_EQ(t->expr->source.range, (Source::Range{{1u, 1u}, {1u, 29u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_MultisampledTexture_MissingType) { @@ -196,9 +144,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Readonly1dRg32Float) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ast::CheckIdentifier(p->builder().Symbols(), t->As()->name, + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("texture_storage_1d", "rg32float", "read")); - EXPECT_EQ(t->source.range, (Source::Range{{1u, 1u}, {1u, 36u}})); + EXPECT_EQ(t->expr->source.range, (Source::Range{{1u, 1u}, {1u, 36u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR32Uint) { @@ -209,43 +157,9 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_Writeonly2dR32Uint) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ast::CheckIdentifier(p->builder().Symbols(), t->As()->name, + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("texture_storage_2d", "r32uint", "write")); - EXPECT_EQ(t->source.range, (Source::Range{{1u, 1u}, {1u, 35u}})); -} - -TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidType) { - auto p = parser("texture_storage_1d"); - auto t = p->texture_and_sampler_types(); - EXPECT_EQ(t.value, nullptr); - EXPECT_FALSE(t.matched); - EXPECT_TRUE(t.errored); - EXPECT_EQ(p->error(), R"(1:20: expected texel format for storage texture type -Possible values: 'bgra8unorm', 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm')"); -} - -TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidTypeSuggest) { - auto p = parser("texture_storage_1d"); - auto t = p->texture_and_sampler_types(); - EXPECT_EQ(t.value, nullptr); - EXPECT_FALSE(t.matched); - EXPECT_TRUE(t.errored); - EXPECT_EQ(p->error(), - R"(1:20: expected texel format for storage texture type -Did you mean 'rg32float'? -Possible values: 'bgra8unorm', 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm')"); -} - -TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_InvalidAccess) { - auto p = parser("texture_storage_1d"); - auto t = p->texture_and_sampler_types(); - EXPECT_EQ(t.value, nullptr); - EXPECT_FALSE(t.matched); - EXPECT_TRUE(t.errored); - EXPECT_EQ(p->error(), - R"(1:30: expected access control for storage texture type -Did you mean 'read'? -Possible values: 'read', 'read_write', 'write')"); + EXPECT_EQ(t->expr->source.range, (Source::Range{{1u, 1u}, {1u, 35u}})); } TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingType) { @@ -258,15 +172,6 @@ TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingType) { Possible values: 'bgra8unorm', 'r32float', 'r32sint', 'r32uint', 'rg32float', 'rg32sint', 'rg32uint', 'rgba16float', 'rgba16sint', 'rgba16uint', 'rgba32float', 'rgba32sint', 'rgba32uint', 'rgba8sint', 'rgba8snorm', 'rgba8uint', 'rgba8unorm')"); } -TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingLessThan) { - auto p = parser("texture_storage_1d"); - auto t = p->texture_and_sampler_types(); - EXPECT_EQ(t.value, nullptr); - EXPECT_FALSE(t.matched); - EXPECT_TRUE(t.errored); - EXPECT_EQ(p->error(), "1:19: expected '<' for storage texture type"); -} - TEST_F(ParserImplTest, TextureSamplerTypes_StorageTexture_MissingGreaterThan) { auto p = parser("texture_storage_1dtexture_and_sampler_types(); diff --git a/src/tint/reader/wgsl/parser_impl_type_alias_test.cc b/src/tint/reader/wgsl/parser_impl_type_alias_test.cc index de85b2ca88..1c2b4fe109 100644 --- a/src/tint/reader/wgsl/parser_impl_type_alias_test.cc +++ b/src/tint/reader/wgsl/parser_impl_type_alias_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -27,9 +28,7 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); auto* alias = t->As(); - ASSERT_TRUE(alias->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(alias->type->As()->name->symbol), - "i32"); + ast::CheckIdentifier(p->builder().Symbols(), alias->type, "i32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 13u}})); } @@ -43,8 +42,8 @@ TEST_F(ParserImplTest, TypeDecl_Parses_Ident) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t.value->Is()); auto* alias = t.value->As(); - EXPECT_EQ(p->builder().Symbols().NameFor(alias->name->symbol), "a"); - EXPECT_TRUE(alias->type->Is()); + ast::CheckIdentifier(p->builder().Symbols(), alias->name, "a"); + ast::CheckIdentifier(p->builder().Symbols(), alias->type, "B"); EXPECT_EQ(alias->source.range, (Source::Range{{1u, 1u}, {1u, 11u}})); } @@ -62,10 +61,8 @@ TEST_F(ParserImplTest, TypeDecl_Unicode_Parses_Ident) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t.value->Is()); auto* alias = t.value->As(); - EXPECT_EQ(p->builder().Symbols().NameFor(alias->name->symbol), ident); - ASSERT_TRUE(alias->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(alias->type->As()->name->symbol), - "i32"); + ast::CheckIdentifier(p->builder().Symbols(), alias->name, ident); + ast::CheckIdentifier(p->builder().Symbols(), alias->type, "i32"); EXPECT_EQ(alias->source.range, (Source::Range{{1u, 1u}, {1u, 37u}})); } diff --git a/src/tint/reader/wgsl/parser_impl_type_decl_test.cc b/src/tint/reader/wgsl/parser_impl_type_decl_test.cc index 612e1023a3..d1adde2b91 100644 --- a/src/tint/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_type_decl_test.cc @@ -13,14 +13,15 @@ // limitations under the License. #include "src/tint/ast/alias.h" -#include "src/tint/ast/array.h" -#include "src/tint/ast/matrix.h" +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" #include "src/tint/type/sampled_texture.h" namespace tint::reader::wgsl { namespace { +using namespace tint::number_suffixes; // NOLINT + TEST_F(ParserImplTest, TypeDecl_Invalid) { auto p = parser("1234"); auto t = p->type_specifier(); @@ -37,10 +38,8 @@ TEST_F(ParserImplTest, TypeDecl_Identifier) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - auto* type_name = t.value->As(); - ASSERT_NE(type_name, nullptr); - EXPECT_EQ(p->builder().Symbols().Get("A"), type_name->name->symbol); - EXPECT_EQ(type_name->source.range, (Source::Range{{1u, 1u}, {1u, 2u}})); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "A"); + EXPECT_EQ(t->expr->source.range, (Source::Range{{1u, 1u}, {1u, 2u}})); } TEST_F(ParserImplTest, TypeDecl_Bool) { @@ -50,8 +49,7 @@ TEST_F(ParserImplTest, TypeDecl_Bool) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "bool"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "bool"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 5u}})); } @@ -62,8 +60,7 @@ TEST_F(ParserImplTest, TypeDecl_F16) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "f16"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "f16"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -74,8 +71,7 @@ TEST_F(ParserImplTest, TypeDecl_F32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "f32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -86,8 +82,7 @@ TEST_F(ParserImplTest, TypeDecl_I32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "i32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "i32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -98,8 +93,7 @@ TEST_F(ParserImplTest, TypeDecl_U32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "u32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "u32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -123,8 +117,8 @@ TEST_P(VecTest, Parse) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - EXPECT_TRUE(t.value->Is()); - EXPECT_EQ(t.value->As()->width, params.count); + ast::CheckIdentifier(p->builder().Symbols(), t.value, + ast::Template("vec" + std::to_string(params.count), "f32")); EXPECT_EQ(t.value->source.range, params.range); } INSTANTIATE_TEST_SUITE_P(ParserImplTest, @@ -176,12 +170,8 @@ TEST_F(ParserImplTest, TypeDecl_Ptr) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(ptr->type->As()->name->symbol), "f32"); - ASSERT_EQ(ptr->address_space, type::AddressSpace::kFunction); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("ptr", "function", "f32")); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); } @@ -192,13 +182,9 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_WithAccess) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(ptr->type->As()->name->symbol), "f32"); - ASSERT_EQ(ptr->address_space, type::AddressSpace::kFunction); - ASSERT_EQ(ptr->access, type::Access::kRead); + ast::CheckIdentifier(p->builder().Symbols(), t.value, + ast::Template("ptr", "function", "f32", "read")); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25u}})); } @@ -209,16 +195,10 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_ToVec) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type->Is()); - ASSERT_EQ(ptr->address_space, type::AddressSpace::kFunction); + ast::CheckIdentifier(p->builder().Symbols(), t.value, + ast::Template("ptr", "function", ast::Template("vec2", "f32"))); - auto* vec = ptr->type->As(); - ASSERT_EQ(vec->width, 2u); - ASSERT_TRUE(vec->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(vec->type->As()->name->symbol), "f32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25}})); } @@ -346,12 +326,8 @@ TEST_F(ParserImplTest, TypeDecl_Atomic) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* atomic = t.value->As(); - ASSERT_TRUE(atomic->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(atomic->type->As()->name->symbol), - "f32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("atomic", "f32")); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 12u}})); } @@ -362,15 +338,9 @@ TEST_F(ParserImplTest, TypeDecl_Atomic_ToVec) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* atomic = t.value->As(); - ASSERT_TRUE(atomic->type->Is()); - - auto* vec = atomic->type->As(); - ASSERT_EQ(vec->width, 2u); - ASSERT_TRUE(vec->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(vec->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, + ast::Template("atomic", ast::Template("vec2", "f32"))); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}})); } @@ -411,19 +381,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_AbstractIntLiteralSize) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); - EXPECT_EQ(a->attributes.Length(), 0u); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 14u}})); - - auto* size = a->count->As(); - ASSERT_NE(size, nullptr); - EXPECT_EQ(size->value, 5); - EXPECT_EQ(size->suffix, ast::IntLiteralExpression::Suffix::kNone); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", 5_a)); } TEST_F(ParserImplTest, TypeDecl_Array_SintLiteralSize) { @@ -433,19 +392,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_SintLiteralSize) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); - EXPECT_EQ(a->attributes.Length(), 0u); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 15u}})); - - auto* size = a->count->As(); - ASSERT_NE(size, nullptr); - EXPECT_EQ(size->value, 5); - EXPECT_EQ(size->suffix, ast::IntLiteralExpression::Suffix::kI); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", 5_i)); } TEST_F(ParserImplTest, TypeDecl_Array_UintLiteralSize) { @@ -455,18 +403,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_UintLiteralSize) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); - EXPECT_EQ(a->attributes.Length(), 0u); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 15u}})); - - auto* size = a->count->As(); - ASSERT_NE(size, nullptr); - EXPECT_EQ(size->suffix, ast::IntLiteralExpression::Suffix::kU); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", 5_u)); } TEST_F(ParserImplTest, TypeDecl_Array_ConstantSize) { @@ -476,18 +414,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_ConstantSize) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); - EXPECT_EQ(a->attributes.Length(), 0u); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); - - auto* count_expr = a->count->As(); - ASSERT_NE(count_expr, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(count_expr->identifier->symbol), "size"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", "size")); } TEST_F(ParserImplTest, TypeDecl_Array_ExpressionSize) { @@ -497,25 +425,30 @@ TEST_F(ParserImplTest, TypeDecl_Array_ExpressionSize) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); - EXPECT_EQ(a->attributes.Length(), 0u); + auto name_for = [&](const Symbol& sym) { return p->builder().Symbols().NameFor(sym); }; - ASSERT_TRUE(a->count->Is()); - auto* count_expr = a->count->As(); - EXPECT_EQ(ast::BinaryOp::kAdd, count_expr->op); + auto* arr = t->expr->identifier->As(); + EXPECT_EQ(name_for(arr->symbol), "array"); + EXPECT_TRUE(arr->attributes.IsEmpty()); - ASSERT_TRUE(count_expr->lhs->Is()); - auto* ident_expr = count_expr->lhs->As(); - EXPECT_EQ(p->builder().Symbols().NameFor(ident_expr->identifier->symbol), "size"); + ASSERT_EQ(arr->arguments.Length(), 2u); - ASSERT_TRUE(count_expr->rhs->Is()); - auto* val = count_expr->rhs->As(); - EXPECT_EQ(2, static_cast(val->value)); + auto* ty = As(arr->arguments[0]); + ASSERT_NE(ty, nullptr); + EXPECT_EQ(name_for(ty->identifier->symbol), "f32"); + + auto* count = As(arr->arguments[1]); + ASSERT_NE(count, nullptr); + EXPECT_EQ(ast::BinaryOp::kAdd, count->op); + + auto* count_lhs = As(count->lhs); + ASSERT_NE(count_lhs, nullptr); + EXPECT_EQ(name_for(count_lhs->identifier->symbol), "size"); + + auto* count_rhs = As(count->rhs); + ASSERT_NE(count_rhs, nullptr); + EXPECT_EQ(count_rhs->value, static_cast(2)); } TEST_F(ParserImplTest, TypeDecl_Array_Runtime) { @@ -525,12 +458,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "u32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "u32")); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 11u}})); } @@ -541,16 +470,9 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Vec) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(a->type->As()->width, 4u); - ASSERT_TRUE(a->type->As()->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor( - a->type->As()->type->As()->name->symbol), - "u32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, + ast::Template("array", ast::Template("vec4", "u32"))); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); } @@ -615,10 +537,11 @@ TEST_P(MatrixTest, Parse) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - EXPECT_TRUE(t.value->Is()); - auto* mat = t.value->As(); - EXPECT_EQ(mat->rows, params.rows); - EXPECT_EQ(mat->columns, params.columns); + + std::string expected_name = + "mat" + std::to_string(GetParam().columns) + "x" + std::to_string(GetParam().rows); + + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template(expected_name, "f32")); EXPECT_EQ(t.value->source.range, params.range); } INSTANTIATE_TEST_SUITE_P(ParserImplTest, @@ -688,8 +611,8 @@ TEST_F(ParserImplTest, TypeDecl_Sampler) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), - "sampler"); + + ast::CheckIdentifier(p->builder().Symbols(), t.value, "sampler"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 8u}})); } @@ -700,13 +623,8 @@ TEST_F(ParserImplTest, TypeDecl_Texture) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->Is()); - ASSERT_TRUE(t.value->Is()); - ASSERT_TRUE(t.value->As()->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor( - t.value->As()->type->As()->name->symbol), - "f32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("texture_cube", "f32")); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}})); } diff --git a/src/tint/reader/wgsl/parser_impl_type_decl_without_ident_test.cc b/src/tint/reader/wgsl/parser_impl_type_decl_without_ident_test.cc index ba2fe61d01..bd385a654f 100644 --- a/src/tint/reader/wgsl/parser_impl_type_decl_without_ident_test.cc +++ b/src/tint/reader/wgsl/parser_impl_type_decl_without_ident_test.cc @@ -13,14 +13,15 @@ // limitations under the License. #include "src/tint/ast/alias.h" -#include "src/tint/ast/array.h" -#include "src/tint/ast/matrix.h" +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" #include "src/tint/type/sampled_texture.h" namespace tint::reader::wgsl { namespace { +using namespace tint::number_suffixes; // NOLINT + TEST_F(ParserImplTest, TypeDeclWithoutIdent_Invalid) { auto p = parser("1234"); auto t = p->type_specifier_without_ident(); @@ -45,8 +46,7 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Bool) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "bool"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "bool"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 5u}})); } @@ -56,8 +56,7 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_F16) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "f16"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "f16"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -67,8 +66,7 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_F32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "f32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -78,8 +76,7 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_I32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "i32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "i32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -89,8 +86,7 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_U32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - ASSERT_TRUE(t.value->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "u32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "u32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -114,8 +110,9 @@ TEST_P(TypeDeclWithoutIdent_VecTest, Parse) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - EXPECT_TRUE(t.value->Is()); - EXPECT_EQ(t.value->As()->width, params.count); + + ast::CheckIdentifier(p->builder().Symbols(), t.value, + ast::Template("vec" + std::to_string(params.count), "f32")); EXPECT_EQ(t.value->source.range, params.range); } INSTANTIATE_TEST_SUITE_P(ParserImplTest, @@ -167,12 +164,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(ptr->type->As()->name->symbol), "f32"); - ASSERT_EQ(ptr->address_space, type::AddressSpace::kFunction); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("ptr", "function", "f32")); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); } @@ -183,13 +176,9 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_WithAccess) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(ptr->type->As()->name->symbol), "f32"); - ASSERT_EQ(ptr->address_space, type::AddressSpace::kFunction); - ASSERT_EQ(ptr->access, type::Access::kRead); + ast::CheckIdentifier(p->builder().Symbols(), t.value, + ast::Template("ptr", "function", "f32", "read")); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25u}})); } @@ -200,16 +189,9 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_ToVec) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type->Is()); - ASSERT_EQ(ptr->address_space, type::AddressSpace::kFunction); - - auto* vec = ptr->type->As(); - ASSERT_EQ(vec->width, 2u); - ASSERT_TRUE(vec->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(vec->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, + ast::Template("ptr", "function", ast::Template("vec2", "f32"))); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25}})); } @@ -337,12 +319,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Atomic) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* atomic = t.value->As(); - ASSERT_TRUE(atomic->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(atomic->type->As()->name->symbol), - "f32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("atomic", "f32")); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 12u}})); } @@ -353,15 +331,9 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Atomic_ToVec) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* atomic = t.value->As(); - ASSERT_TRUE(atomic->type->Is()); - - auto* vec = atomic->type->As(); - ASSERT_EQ(vec->width, 2u); - ASSERT_TRUE(vec->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(vec->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, + ast::Template("atomic", ast::Template("vec2", "f32"))); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}})); } @@ -402,19 +374,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_AbstractIntLiteralSize) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); - EXPECT_EQ(a->attributes.Length(), 0u); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 14u}})); - - auto* size = a->count->As(); - ASSERT_NE(size, nullptr); - EXPECT_EQ(size->value, 5); - EXPECT_EQ(size->suffix, ast::IntLiteralExpression::Suffix::kNone); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", 5_a)); } TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_SintLiteralSize) { @@ -424,19 +385,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_SintLiteralSize) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); - EXPECT_EQ(a->attributes.Length(), 0u); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 15u}})); - - auto* size = a->count->As(); - ASSERT_NE(size, nullptr); - EXPECT_EQ(size->value, 5); - EXPECT_EQ(size->suffix, ast::IntLiteralExpression::Suffix::kI); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", 5_i)); } TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_UintLiteralSize) { @@ -446,18 +396,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_UintLiteralSize) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); - EXPECT_EQ(a->attributes.Length(), 0u); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 15u}})); - - auto* size = a->count->As(); - ASSERT_NE(size, nullptr); - EXPECT_EQ(size->suffix, ast::IntLiteralExpression::Suffix::kU); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", 5_u)); } TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_ConstantSize) { @@ -467,18 +407,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_ConstantSize) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); - EXPECT_EQ(a->attributes.Length(), 0u); - EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); - - auto* count_expr = a->count->As(); - ASSERT_NE(count_expr, nullptr); - EXPECT_EQ(p->builder().Symbols().NameFor(count_expr->identifier->symbol), "size"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "f32", "size")); } TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_ExpressionSize) { @@ -488,25 +418,30 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_ExpressionSize) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); - EXPECT_EQ(a->attributes.Length(), 0u); + auto name_for = [&](const Symbol& sym) { return p->builder().Symbols().NameFor(sym); }; - ASSERT_TRUE(a->count->Is()); - auto* count_expr = a->count->As(); - EXPECT_EQ(ast::BinaryOp::kAdd, count_expr->op); + auto* arr = t->expr->identifier->As(); + EXPECT_EQ(name_for(arr->symbol), "array"); + EXPECT_TRUE(arr->attributes.IsEmpty()); - ASSERT_TRUE(count_expr->lhs->Is()); - auto* ident = count_expr->lhs->As(); - EXPECT_EQ(p->builder().Symbols().NameFor(ident->identifier->symbol), "size"); + ASSERT_EQ(arr->arguments.Length(), 2u); - ASSERT_TRUE(count_expr->rhs->Is()); - auto* val = count_expr->rhs->As(); - EXPECT_EQ(2, static_cast(val->value)); + auto* ty = As(arr->arguments[0]); + ASSERT_NE(ty, nullptr); + EXPECT_EQ(name_for(ty->identifier->symbol), "f32"); + + auto* count = As(arr->arguments[1]); + ASSERT_NE(count, nullptr); + EXPECT_EQ(ast::BinaryOp::kAdd, count->op); + + auto* count_lhs = As(count->lhs); + ASSERT_NE(count_lhs, nullptr); + EXPECT_EQ(name_for(count_lhs->identifier->symbol), "size"); + + auto* count_rhs = As(count->rhs); + ASSERT_NE(count_rhs, nullptr); + EXPECT_EQ(count_rhs->value, static_cast(2)); } TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_Runtime) { @@ -516,13 +451,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_Runtime) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_TRUE(a->IsRuntimeArray()); - - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "u32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("array", "u32")); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 11u}})); } @@ -533,16 +463,9 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_Runtime_Vec) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - ASSERT_TRUE(t.value->Is()); - auto* a = t.value->As(); - ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); - EXPECT_EQ(a->type->As()->width, 4u); - ASSERT_TRUE(a->type->As()->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor( - a->type->As()->type->As()->name->symbol), - "u32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, + ast::Template("array", ast::Template("vec4", "u32"))); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); } @@ -607,10 +530,12 @@ TEST_P(TypeDeclWithoutIdent_MatrixTest, Parse) { EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); ASSERT_FALSE(p->has_error()); - EXPECT_TRUE(t.value->Is()); - auto* mat = t.value->As(); - EXPECT_EQ(mat->rows, params.rows); - EXPECT_EQ(mat->columns, params.columns); + + std::string expected_name = + "mat" + std::to_string(GetParam().columns) + "x" + std::to_string(GetParam().rows); + + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template(expected_name, "f32")); + EXPECT_EQ(t.value->source.range, params.range); } INSTANTIATE_TEST_SUITE_P(ParserImplTest, @@ -681,8 +606,7 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Sampler) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr) << p->error(); - EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), - "sampler"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, "sampler"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 8u}})); } @@ -693,12 +617,7 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Texture) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->Is()); - ASSERT_TRUE(t.value->Is()); - ASSERT_TRUE(t.value->As()->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor( - t.value->As()->type->As()->name->symbol), - "f32"); + ast::CheckIdentifier(p->builder().Symbols(), t.value, ast::Template("texture_cube", "f32")); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 18u}})); } diff --git a/src/tint/reader/wgsl/parser_impl_variable_decl_test.cc b/src/tint/reader/wgsl/parser_impl_variable_decl_test.cc index 13f900541f..9138d55a7a 100644 --- a/src/tint/reader/wgsl/parser_impl_variable_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_variable_decl_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -25,8 +26,7 @@ TEST_F(ParserImplTest, VariableDecl_Parses) { EXPECT_EQ(v->name, "my_var"); EXPECT_NE(v->type, nullptr); - ASSERT_TRUE(v->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), v->type, "f32"); EXPECT_EQ(v->source.range, (Source::Range{{1u, 5u}, {1u, 11u}})); EXPECT_EQ(v->type->source.range, (Source::Range{{1u, 14u}, {1u, 17u}})); @@ -46,8 +46,7 @@ TEST_F(ParserImplTest, VariableDecl_Unicode_Parses) { EXPECT_EQ(v->name, ident); EXPECT_NE(v->type, nullptr); - ASSERT_TRUE(v->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), v->type, "f32"); EXPECT_EQ(v->source.range, (Source::Range{{1u, 5u}, {1u, 48u}})); EXPECT_EQ(v->type->source.range, (Source::Range{{1u, 51u}, {1u, 54u}})); @@ -84,8 +83,7 @@ TEST_F(ParserImplTest, VariableDecl_WithAddressSpace) { EXPECT_FALSE(p->has_error()); EXPECT_EQ(v->name, "my_var"); - ASSERT_TRUE(v->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), v->type, "f32"); EXPECT_EQ(v->address_space, type::AddressSpace::kPrivate); @@ -103,8 +101,7 @@ TEST_F(ParserImplTest, VariableDecl_WithPushConstant) { EXPECT_FALSE(p->has_error()); EXPECT_EQ(v->name, "my_var"); - ASSERT_TRUE(v->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), v->type, "f32"); EXPECT_EQ(v->address_space, type::AddressSpace::kPushConstant); } diff --git a/src/tint/reader/wgsl/parser_impl_variable_ident_decl_test.cc b/src/tint/reader/wgsl/parser_impl_variable_ident_decl_test.cc index 373eb75df1..467fa8098e 100644 --- a/src/tint/reader/wgsl/parser_impl_variable_ident_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_variable_ident_decl_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -24,8 +25,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_Parses) { ASSERT_FALSE(decl.errored); ASSERT_EQ(decl->name, "my_var"); ASSERT_NE(decl->type, nullptr); - ASSERT_TRUE(decl->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(decl->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), decl->type, "f32"); EXPECT_EQ(decl->source.range, (Source::Range{{1u, 1u}, {1u, 7u}})); EXPECT_EQ(decl->type->source.range, (Source::Range{{1u, 10u}, {1u, 13u}})); @@ -38,8 +38,7 @@ TEST_F(ParserImplTest, VariableIdentDecl_Parses_AllowInferredType) { ASSERT_FALSE(decl.errored); ASSERT_EQ(decl->name, "my_var"); ASSERT_NE(decl->type, nullptr); - ASSERT_TRUE(decl->type->Is()); - EXPECT_EQ(p->builder().Symbols().NameFor(decl->type->As()->name->symbol), "f32"); + ast::CheckIdentifier(p->builder().Symbols(), decl->type, "f32"); EXPECT_EQ(decl->source.range, (Source::Range{{1u, 1u}, {1u, 7u}})); EXPECT_EQ(decl->type->source.range, (Source::Range{{1u, 10u}, {1u, 13u}})); diff --git a/src/tint/reader/wgsl/parser_impl_variable_stmt_test.cc b/src/tint/reader/wgsl/parser_impl_variable_stmt_test.cc index 6233dc52ee..bd3ee19613 100644 --- a/src/tint/reader/wgsl/parser_impl_variable_stmt_test.cc +++ b/src/tint/reader/wgsl/parser_impl_variable_stmt_test.cc @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +#include "src/tint/ast/test_helper.h" #include "src/tint/reader/wgsl/parser_impl_test_helper.h" namespace tint::reader::wgsl { @@ -80,8 +81,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit) { ASSERT_NE(e->variable->initializer, nullptr); auto* call = e->variable->initializer->As(); ASSERT_NE(call, nullptr); - EXPECT_EQ(call->target.name, nullptr); - EXPECT_NE(call->target.type, nullptr); + ast::CheckIdentifier(p->builder().Symbols(), call->target, ast::Template("array", "i32")); } TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit_NoSpace) { @@ -98,8 +98,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_ArrayInit_NoSpace) { ASSERT_NE(e->variable->initializer, nullptr); auto* call = e->variable->initializer->As(); ASSERT_NE(call, nullptr); - EXPECT_EQ(call->target.name, nullptr); - EXPECT_NE(call->target.type, nullptr); + ast::CheckIdentifier(p->builder().Symbols(), call->target, ast::Template("array", "i32")); } TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit) { @@ -115,9 +114,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit) { ASSERT_NE(e->variable->initializer, nullptr); auto* call = e->variable->initializer->As(); - ASSERT_NE(call, nullptr); - EXPECT_EQ(call->target.name, nullptr); - EXPECT_NE(call->target.type, nullptr); + ast::CheckIdentifier(p->builder().Symbols(), call->target, ast::Template("vec2", "i32")); } TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit_NoSpace) { @@ -134,8 +131,7 @@ TEST_F(ParserImplTest, VariableStmt_VariableDecl_VecInit_NoSpace) { ASSERT_NE(e->variable->initializer, nullptr); auto* call = e->variable->initializer->As(); ASSERT_NE(call, nullptr); - EXPECT_EQ(call->target.name, nullptr); - EXPECT_NE(call->target.type, nullptr); + ast::CheckIdentifier(p->builder().Symbols(), call->target, ast::Template("vec2", "i32")); } TEST_F(ParserImplTest, VariableStmt_Let) { @@ -172,11 +168,11 @@ TEST_F(ParserImplTest, VariableStmt_Let_ComplexExpression) { ASSERT_TRUE(expr->lhs->Is()); auto* ident_expr = expr->lhs->As(); - EXPECT_EQ(ident_expr->identifier->symbol, p->builder().Symbols().Get("collide")); + ast::CheckIdentifier(p->builder().Symbols(), ident_expr->identifier, "collide"); ASSERT_TRUE(expr->rhs->Is()); ident_expr = expr->rhs->As(); - EXPECT_EQ(ident_expr->identifier->symbol, p->builder().Symbols().Get("collide_1")); + ast::CheckIdentifier(p->builder().Symbols(), ident_expr->identifier, "collide_1"); } TEST_F(ParserImplTest, VariableStmt_Let_MissingEqual) { diff --git a/src/tint/resolver/address_space_validation_test.cc b/src/tint/resolver/address_space_validation_test.cc index fb4981e225..f96b29fca6 100644 --- a/src/tint/resolver/address_space_validation_test.cc +++ b/src/tint/resolver/address_space_validation_test.cc @@ -38,10 +38,10 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_NoAddressSpace_Fail) { TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_NoAddressSpace_Fail) { // type g = ptr; - Alias("g", ty.pointer(Source{{12, 34}}, ty.f32(), type::AddressSpace::kUndefined)); + Alias("g", ty(Source{{12, 34}}, "ptr", ty.f32())); EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: ptr missing address space"); + EXPECT_EQ(r()->error(), "12:34 error: 'ptr' requires at least 2 template arguments"); } TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_FunctionAddressSpace_Fail) { @@ -473,7 +473,7 @@ TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_NotStorage_AccessMode) } TEST_F(ResolverAddressSpaceValidationTest, PointerAlias_NotStorage_AccessMode) { - // type t = ptr; + // type t = ptr; Alias("t", ty.pointer(Source{{12, 34}}, ty.i32(), type::AddressSpace::kPrivate, type::Access::kRead)); diff --git a/src/tint/resolver/alias_analysis_test.cc b/src/tint/resolver/alias_analysis_test.cc index 44db995b74..cc55f0b7c9 100644 --- a/src/tint/resolver/alias_analysis_test.cc +++ b/src/tint/resolver/alias_analysis_test.cc @@ -759,7 +759,7 @@ TEST_F(ResolverAliasAnalysisTest, Read_MemberAccessor) { ty.void_(), utils::Vector{ Assign(Phony(), MemberAccessor(Deref("p2"), "a")), - Assign(Deref("p1"), Call(ty("S"))), + Assign(Deref("p1"), Call("S")), }); Func("f1", utils::Empty, ty.void_(), utils::Vector{ diff --git a/src/tint/resolver/assignment_validation_test.cc b/src/tint/resolver/assignment_validation_test.cc index 642340b710..cf8b505e7b 100644 --- a/src/tint/resolver/assignment_validation_test.cc +++ b/src/tint/resolver/assignment_validation_test.cc @@ -373,8 +373,8 @@ TEST_F(ResolverAssignmentValidationTest, AssignToPhony_Pass) { Assign(Phony(), 3_f), // Assign(Phony(), 4_a), // Assign(Phony(), 5.0_a), // - Assign(Phony(), vec(nullptr, 2u, 6_a)), // - Assign(Phony(), vec(nullptr, 3u, 7.0_a)), // + Assign(Phony(), vec2(6_a)), // + Assign(Phony(), vec3(7.0_a)), // Assign(Phony(), vec4()), // Assign(Phony(), "tex"), // Assign(Phony(), "smp"), // diff --git a/src/tint/resolver/atomics_validation_test.cc b/src/tint/resolver/atomics_validation_test.cc index f57cf0b4b7..bd0c5ccca5 100644 --- a/src/tint/resolver/atomics_validation_test.cc +++ b/src/tint/resolver/atomics_validation_test.cc @@ -173,9 +173,9 @@ TEST_F(ResolverAtomicValidationTest, InvalidAddressSpace_Complex) { // var g : S0; auto* atomic_array = Alias("AtomicArray", ty.atomic(ty.i32())); - auto* array_i32_4 = ty.array(); - auto* array_atomic_u32_8 = ty.array(ty.atomic(ty.u32()), 8_u); - auto* array_atomic_i32_4 = ty.array(ty.atomic(ty.i32()), 4_u); + auto array_i32_4 = ty.array(); + auto array_atomic_u32_8 = ty.array(ty.atomic(ty.u32()), 8_u); + auto array_atomic_i32_4 = ty.array(ty.atomic(ty.i32()), 4_u); auto* s6 = Structure("S6", utils::Vector{Member("x", array_i32_4)}); auto* s5 = Structure("S5", utils::Vector{Member("x", ty.Of(s6)), // @@ -272,9 +272,9 @@ TEST_F(ResolverAtomicValidationTest, InvalidAccessMode_Complex) { // var g : S0; auto* atomic_array = Alias("AtomicArray", ty.atomic(ty.i32())); - auto* array_i32_4 = ty.array(); - auto* array_atomic_u32_8 = ty.array(ty.atomic(ty.u32()), 8_u); - auto* array_atomic_i32_4 = ty.array(ty.atomic(ty.i32()), 4_u); + auto array_i32_4 = ty.array(); + auto array_atomic_u32_8 = ty.array(ty.atomic(ty.u32()), 8_u); + auto array_atomic_i32_4 = ty.array(ty.atomic(ty.i32()), 4_u); auto* s6 = Structure("S6", utils::Vector{Member("x", array_i32_4)}); auto* s5 = Structure("S5", utils::Vector{Member("x", ty.Of(s6)), // diff --git a/src/tint/resolver/attribute_validation_test.cc b/src/tint/resolver/attribute_validation_test.cc index 196796fdbe..0f09306ca4 100644 --- a/src/tint/resolver/attribute_validation_test.cc +++ b/src/tint/resolver/attribute_validation_test.cc @@ -849,7 +849,7 @@ using ArrayAttributeTest = TestWithParams; TEST_P(ArrayAttributeTest, IsValid) { auto& params = GetParam(); - auto* arr = ty.array(ty.f32(), nullptr, createAttributes(Source{{12, 34}}, *this, params.kind)); + auto arr = ty.array(ty.f32(), createAttributes(Source{{12, 34}}, *this, params.kind)); Structure("mystruct", utils::Vector{ Member("a", arr), }); @@ -1145,17 +1145,17 @@ struct TestWithParams : ResolverTestWithParam {}; using ArrayStrideTest = TestWithParams; TEST_P(ArrayStrideTest, All) { auto& params = GetParam(); - auto* el_ty = params.create_el_type(*this); + ast::Type el_ty = params.create_el_type(*this); std::stringstream ss; ss << "el_ty: " << FriendlyName(el_ty) << ", stride: " << params.stride << ", should_pass: " << params.should_pass; SCOPED_TRACE(ss.str()); - auto* arr = ty.array(el_ty, 4_u, - utils::Vector{ - create(Source{{12, 34}}, params.stride), - }); + auto arr = ty.array(el_ty, 4_u, + utils::Vector{ + create(Source{{12, 34}}, params.stride), + }); GlobalVar("myarray", arr, type::AddressSpace::kPrivate); @@ -1234,11 +1234,11 @@ INSTANTIATE_TEST_SUITE_P(ResolverAttributeValidationTest, ParamsFor>((default_mat4x4.align - 1) * 7, false))); TEST_F(ArrayStrideTest, DuplicateAttribute) { - auto* arr = ty.array(Source{{12, 34}}, ty.i32(), 4_u, - utils::Vector{ - create(Source{{12, 34}}, 4u), - create(Source{{56, 78}}, 4u), - }); + auto arr = ty.array(Source{{12, 34}}, ty.i32(), 4_u, + utils::Vector{ + create(Source{{12, 34}}, 4u), + create(Source{{56, 78}}, 4u), + }); GlobalVar("myarray", arr, type::AddressSpace::kPrivate); diff --git a/src/tint/resolver/builtin_test.cc b/src/tint/resolver/builtin_test.cc index 74c1d6027b..dc49f3af9d 100644 --- a/src/tint/resolver/builtin_test.cc +++ b/src/tint/resolver/builtin_test.cc @@ -213,7 +213,7 @@ namespace array_builtin_tests { using ResolverBuiltinArrayTest = ResolverTest; TEST_F(ResolverBuiltinArrayTest, ArrayLength_Vector) { - auto* ary = ty.array(); + auto ary = ty.array(); auto* str = Structure("S", utils::Vector{Member("x", ary)}); GlobalVar("a", ty.Of(str), type::AddressSpace::kStorage, type::Access::kRead, Binding(0_a), Group(0_a)); @@ -2097,33 +2097,26 @@ class ResolverBuiltinTest_TextureOperation : public ResolverTestWithParamAs()) { - auto n = Symbols().NameFor(type_name->name->symbol); - if (utils::HasPrefix(n, "texture") || utils::HasPrefix(n, "sampler")) { - GlobalVar(name, type, Binding(0_a), Group(0_a)); - return; - } - } - - if (type->Is()) { + void add_call_param(std::string name, ast::Type type, ExpressionList* call_params) { + std::string type_name = Symbols().NameFor(type->identifier->symbol); + if (utils::HasPrefix(type_name, "texture") || utils::HasPrefix(type_name, "sampler")) { GlobalVar(name, type, Binding(0_a), Group(0_a)); } else { GlobalVar(name, type, type::AddressSpace::kPrivate); @@ -2131,7 +2124,7 @@ class ResolverBuiltinTest_TextureOperation : public ResolverTestWithParamPush(Expr(name)); } - const ast::Type* subtype(Texture type) { + ast::Type subtype(Texture type) { if (type == Texture::kF32) { return ty.f32(); } @@ -2147,9 +2140,9 @@ TEST_P(ResolverBuiltinTest_SampledTextureOperation, TextureLoadSampled) { auto dim = GetParam().dim; auto type = GetParam().type; - auto* s = subtype(type); - auto* coords_type = GetCoordsType(dim, ty.i32()); - auto* texture_type = ty.sampled_texture(dim, s); + ast::Type s = subtype(type); + ast::Type coords_type = GetCoordsType(dim, ty.i32()); + auto texture_type = ty.sampled_texture(dim, s); ExpressionList call_params; diff --git a/src/tint/resolver/builtin_validation_test.cc b/src/tint/resolver/builtin_validation_test.cc index 2750d975fe..b9c31c9daa 100644 --- a/src/tint/resolver/builtin_validation_test.cc +++ b/src/tint/resolver/builtin_validation_test.cc @@ -115,7 +115,8 @@ TEST_F(ResolverBuiltinValidationTest, BuiltinRedeclaredAsFunctionUsedAsVariable) WrapInFunction(Decl(Var("v", Expr(Source{{56, 78}}, "mix")))); EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), R"(56:78 error: missing '(' for function call)"); + EXPECT_EQ(r()->error(), R"(56:78 error: cannot use function 'mix' as value +12:34 note: function 'mix' declared here)"); } TEST_F(ResolverBuiltinValidationTest, BuiltinRedeclaredAsGlobalConstUsedAsVariable) { @@ -159,7 +160,7 @@ TEST_F(ResolverBuiltinValidationTest, BuiltinRedeclaredAsAliasUsedAsFunction) { TEST_F(ResolverBuiltinValidationTest, BuiltinRedeclaredAsAliasUsedAsType) { auto* mix = Alias(Source{{12, 34}}, "mix", ty.i32()); - auto* use = Call(ty("mix")); + auto* use = Call("mix"); WrapInFunction(use); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -183,7 +184,7 @@ TEST_F(ResolverBuiltinValidationTest, BuiltinRedeclaredAsStructUsedAsType) { auto* mix = Structure("mix", utils::Vector{ Member("m", ty.i32()), }); - auto* use = Call(ty("mix")); + auto* use = Call("mix"); WrapInFunction(use); ASSERT_TRUE(r()->Resolve()) << r()->error(); diff --git a/src/tint/resolver/const_eval_binary_op_test.cc b/src/tint/resolver/const_eval_binary_op_test.cc index 09b124731d..e7f6f1473b 100644 --- a/src/tint/resolver/const_eval_binary_op_test.cc +++ b/src/tint/resolver/const_eval_binary_op_test.cc @@ -1953,8 +1953,7 @@ TEST_F(ResolverConstEvalTest, ShortCircuit_And_Error_StructInit) { Structure("S", utils::Vector{Member("a", ty.i32()), Member("b", ty.f32())}); GlobalConst("one", Expr(1_a)); auto* lhs = Equal("one", 0_a); - auto* rhs = - Equal(MemberAccessor(Call(ty("S"), Expr(1_a), Expr(Source{{12, 34}}, true)), "a"), 0_a); + auto* rhs = Equal(MemberAccessor(Call("S", Expr(1_a), Expr(Source{{12, 34}}, true)), "a"), 0_a); GlobalConst("result", LogicalAnd(lhs, rhs)); EXPECT_FALSE(r()->Resolve()); @@ -1973,8 +1972,7 @@ TEST_F(ResolverConstEvalTest, ShortCircuit_Or_Error_StructInit) { Structure("S", utils::Vector{Member("a", ty.i32()), Member("b", ty.f32())}); GlobalConst("one", Expr(1_a)); auto* lhs = Equal("one", 1_a); - auto* rhs = - Equal(MemberAccessor(Call(ty("S"), Expr(1_a), Expr(Source{{12, 34}}, true)), "a"), 0_a); + auto* rhs = Equal(MemberAccessor(Call("S", Expr(1_a), Expr(Source{{12, 34}}, true)), "a"), 0_a); GlobalConst("result", LogicalOr(lhs, rhs)); EXPECT_FALSE(r()->Resolve()); @@ -2146,7 +2144,7 @@ TEST_F(ResolverConstEvalTest, ShortCircuit_And_Error_MemberAccess) { // const one = 1; // const result = (one == 0) && (s.c == 0); Structure("S", utils::Vector{Member("a", ty.i32()), Member("b", ty.f32())}); - GlobalConst("s", Call(ty("S"), Expr(1_a), Expr(2.0_a))); + GlobalConst("s", Call("S", Expr(1_a), Expr(2.0_a))); GlobalConst("one", Expr(1_a)); auto* lhs = Equal("one", 0_a); auto* rhs = Equal(MemberAccessor(Source{{12, 34}}, "s", "c"), 0_a); @@ -2165,7 +2163,7 @@ TEST_F(ResolverConstEvalTest, ShortCircuit_Or_Error_MemberAccess) { // const one = 1; // const result = (one == 1) || (s.c == 0); Structure("S", utils::Vector{Member("a", ty.i32()), Member("b", ty.f32())}); - GlobalConst("s", Call(ty("S"), Expr(1_a), Expr(2.0_a))); + GlobalConst("s", Call("S", Expr(1_a), Expr(2.0_a))); GlobalConst("one", Expr(1_a)); auto* lhs = Equal("one", 1_a); auto* rhs = Equal(MemberAccessor(Source{{12, 34}}, "s", "c"), 0_a); @@ -2187,7 +2185,7 @@ TEST_F(ResolverConstEvalTest, ShortCircuit_And_Error_Swizzle) { // const result = (one == 0) && (vec2(1, 2).z == 0); GlobalConst("one", Expr(1_a)); auto* lhs = Equal("one", 0_a); - auto* rhs = Equal(MemberAccessor(vec2(1_a, 2_a), Ident(Source{{12, 34}}, "z")), 0_a); + auto* rhs = Equal(MemberAccessor(vec2(1_a, 2_a), Ident(Source{{12, 34}}, "z")), 0_a); GlobalConst("result", LogicalAnd(lhs, rhs)); EXPECT_FALSE(r()->Resolve()); @@ -2199,7 +2197,7 @@ TEST_F(ResolverConstEvalTest, ShortCircuit_Or_Error_Swizzle) { // const result = (one == 1) || (vec2(1, 2).z == 0); GlobalConst("one", Expr(1_a)); auto* lhs = Equal("one", 1_a); - auto* rhs = Equal(MemberAccessor(vec2(1_a, 2_a), Ident(Source{{12, 34}}, "z")), 0_a); + auto* rhs = Equal(MemberAccessor(vec2(1_a, 2_a), Ident(Source{{12, 34}}, "z")), 0_a); GlobalConst("result", LogicalOr(lhs, rhs)); EXPECT_FALSE(r()->Resolve()); diff --git a/src/tint/resolver/const_eval_bitcast_test.cc b/src/tint/resolver/const_eval_bitcast_test.cc index 32c138235b..cbb09d5cdc 100644 --- a/src/tint/resolver/const_eval_bitcast_test.cc +++ b/src/tint/resolver/const_eval_bitcast_test.cc @@ -64,7 +64,7 @@ TEST_P(ResolverConstEvalBitcastTest, Test) { target_create_ptrs = expected.Failure().create_ptrs; } - auto* target_ty = target_create_ptrs.ast(*this); + auto target_ty = target_create_ptrs.ast(*this); ASSERT_NE(target_ty, nullptr); auto* input_val = input.Expr(*this); const ast::Expression* expr = Bitcast(Source{{12, 34}}, target_ty, input_val); diff --git a/src/tint/resolver/const_eval_construction_test.cc b/src/tint/resolver/const_eval_construction_test.cc index 80f0c1198a..fbf751535a 100644 --- a/src/tint/resolver/const_eval_construction_test.cc +++ b/src/tint/resolver/const_eval_construction_test.cc @@ -148,7 +148,7 @@ using ResolverConstEvalZeroInitTest = ResolverTestWithParam; TEST_P(ResolverConstEvalZeroInitTest, Test) { Enable(ast::Extension::kF16); auto& param = GetParam(); - auto* ty = param.type(*this); + auto ty = param.type(*this); auto* expr = Call(ty); auto* a = Const("a", expr); WrapInFunction(a); @@ -552,7 +552,7 @@ TEST_F(ResolverConstEvalTest, Vec3_Splat_bool) { } TEST_F(ResolverConstEvalTest, Vec3_FullConstruct_AInt) { - auto* expr = vec3(1_a, 2_a, 3_a); + auto* expr = vec3(1_a, 2_a, 3_a); auto* a = Const("a", expr); WrapInFunction(a); @@ -586,7 +586,7 @@ TEST_F(ResolverConstEvalTest, Vec3_FullConstruct_AInt) { } TEST_F(ResolverConstEvalTest, Vec3_FullConstruct_AFloat) { - auto* expr = vec3(1.0_a, 2.0_a, 3.0_a); + auto* expr = vec3(1.0_a, 2.0_a, 3.0_a); auto* a = Const("a", expr); WrapInFunction(a); @@ -1392,7 +1392,7 @@ TEST_F(ResolverConstEvalTest, Mat2x3_ZeroInit_f16) { } TEST_F(ResolverConstEvalTest, Mat3x2_Construct_Scalars_af) { - auto* expr = Call(ty.mat(nullptr, 3, 2), 1.0_a, 2.0_a, 3.0_a, 4.0_a, 5.0_a, 6.0_a); + auto* expr = Call(ty.mat3x2(), 1.0_a, 2.0_a, 3.0_a, 4.0_a, 5.0_a, 6.0_a); WrapInFunction(expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -1441,10 +1441,10 @@ TEST_F(ResolverConstEvalTest, Mat3x2_Construct_Scalars_af) { } TEST_F(ResolverConstEvalTest, Mat3x2_Construct_Columns_af) { - auto* expr = Call(ty.mat(nullptr, 3, 2), // - vec(nullptr, 2u, 1.0_a, 2.0_a), // - vec(nullptr, 2u, 3.0_a, 4.0_a), // - vec(nullptr, 2u, 5.0_a, 6.0_a)); + auto* expr = Call(ty.mat(3, 2), // + vec2(1.0_a, 2.0_a), // + vec2(3.0_a, 4.0_a), // + vec2(5.0_a, 6.0_a)); WrapInFunction(expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -1853,9 +1853,9 @@ TEST_F(ResolverConstEvalTest, Array_Struct_f32_Elements) { Member("m1", ty.f32()), Member("m2", ty.f32()), }); - auto* expr = Call(ty.array(ty("S"), 2_u), // - Call(ty("S"), 1_f, 2_f), // - Call(ty("S"), 3_f, 4_f)); + auto* expr = Call(ty.array(ty("S"), 2_u), // + Call("S", 1_f, 2_f), // + Call("S", 3_f, 4_f)); WrapInFunction(expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -1992,7 +1992,7 @@ TEST_F(ResolverConstEvalTest, Struct_Nested_ZeroInit) { TEST_F(ResolverConstEvalTest, Struct_I32s_ZeroInit) { Structure( "S", utils::Vector{Member("m1", ty.i32()), Member("m2", ty.i32()), Member("m3", ty.i32())}); - auto* expr = Call(ty("S")); + auto* expr = Call("S"); WrapInFunction(expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -2037,7 +2037,7 @@ TEST_F(ResolverConstEvalTest, Struct_MixedScalars_ZeroInit) { Member("m4", ty.f16()), Member("m5", ty.bool_()), }); - auto* expr = Call(ty("S")); + auto* expr = Call("S"); WrapInFunction(expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -2090,7 +2090,7 @@ TEST_F(ResolverConstEvalTest, Struct_VectorF32s_ZeroInit) { Member("m2", ty.vec3()), Member("m3", ty.vec3()), }); - auto* expr = Call(ty("S")); + auto* expr = Call("S"); WrapInFunction(expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -2147,7 +2147,7 @@ TEST_F(ResolverConstEvalTest, Struct_MixedVectors_ZeroInit) { Member("m4", ty.vec3()), Member("m5", ty.vec2()), }); - auto* expr = Call(ty("S")); + auto* expr = Call("S"); WrapInFunction(expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -2224,7 +2224,7 @@ TEST_F(ResolverConstEvalTest, Struct_Struct_ZeroInit) { Member("m1", ty("Inner")), Member("m2", ty("Inner")), }); - auto* expr = Call(ty("Outer")); + auto* expr = Call("Outer"); WrapInFunction(expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -2267,7 +2267,7 @@ TEST_F(ResolverConstEvalTest, Struct_MixedScalars_Construct) { Member("m4", ty.f16()), Member("m5", ty.bool_()), }); - auto* expr = Call(ty("S"), 1_i, 2_u, 3_f, 4_h, false); + auto* expr = Call("S", 1_i, 2_u, 3_f, 4_h, false); WrapInFunction(expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -2324,7 +2324,7 @@ TEST_F(ResolverConstEvalTest, Struct_MixedVectors_Construct) { Member("m4", ty.vec3()), Member("m5", ty.vec2()), }); - auto* expr = Call(ty("S"), vec2(1_i), vec3(2_u), vec4(3_f), vec3(4_h), + auto* expr = Call("S", vec2(1_i), vec3(2_u), vec4(3_f), vec3(4_h), vec2(false)); WrapInFunction(expr); @@ -2402,8 +2402,8 @@ TEST_F(ResolverConstEvalTest, Struct_Struct_Construct) { Member("m1", ty("Inner")), Member("m2", ty("Inner")), }); - auto* expr = Call(ty("Outer"), // - Call(ty("Inner"), 1_i, 2_u, 3_f), Call(ty("Inner"), 4_i, 0_u, 6_f)); + auto* expr = Call("Outer", // + Call("Inner", 1_i, 2_u, 3_f), Call("Inner", 4_i, 0_u, 6_f)); WrapInFunction(expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -2441,7 +2441,7 @@ TEST_F(ResolverConstEvalTest, Struct_Array_Construct) { Member("m1", ty.array()), Member("m2", ty.array()), }); - auto* expr = Call(ty("S"), // + auto* expr = Call("S", // Call(ty.array(), 1_i, 2_i), Call(ty.array(), 1_f, 2_f, 3_f)); WrapInFunction(expr); diff --git a/src/tint/resolver/const_eval_conversion_test.cc b/src/tint/resolver/const_eval_conversion_test.cc index 739294df32..e159b0eb53 100644 --- a/src/tint/resolver/const_eval_conversion_test.cc +++ b/src/tint/resolver/const_eval_conversion_test.cc @@ -73,7 +73,7 @@ TEST_P(ResolverConstEvalConvTest, Test) { auto* input_val = input.Expr(*this); auto* expr = Call(type.ast(*this), input_val); if (kind == Kind::kVector) { - expr = Call(ty.vec(nullptr, 3), expr); + expr = Call(ty.vec(3), expr); } WrapInFunction(expr); diff --git a/src/tint/resolver/const_eval_member_access_test.cc b/src/tint/resolver/const_eval_member_access_test.cc index c1fcfa1a1d..e93d63b82d 100644 --- a/src/tint/resolver/const_eval_member_access_test.cc +++ b/src/tint/resolver/const_eval_member_access_test.cc @@ -31,8 +31,8 @@ TEST_F(ResolverConstEvalTest, StructMemberAccess) { Member("o1", ty("Inner")), Member("o2", ty("Inner")), }); - auto* outer_expr = Call(ty("Outer"), // - Call(ty("Inner"), 1_i, 2_u, 3_f, true), Call(ty("Inner"))); + auto* outer_expr = Call("Outer", // + Call("Inner", 1_i, 2_u, 3_f, true), Call("Inner")); auto* o1_expr = MemberAccessor(outer_expr, "o1"); auto* i2_expr = MemberAccessor(o1_expr, "i2"); WrapInFunction(i2_expr); @@ -71,9 +71,9 @@ TEST_F(ResolverConstEvalTest, StructMemberAccess) { } TEST_F(ResolverConstEvalTest, Matrix_AFloat_Construct_From_AInt_Vectors) { - auto* c = Const("a", Call(ty.mat(nullptr, 2, 2), // - Call(ty.vec(nullptr, 2), Expr(1_a), Expr(2_a)), - Call(ty.vec(nullptr, 2), Expr(3_a), Expr(4_a)))); + auto* c = Const("a", Call(ty.mat2x2(), // + Call(ty.vec(2), Expr(1_a), Expr(2_a)), + Call(ty.vec(2), Expr(3_a), Expr(4_a)))); WrapInFunction(c); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -97,9 +97,9 @@ TEST_F(ResolverConstEvalTest, Matrix_AFloat_Construct_From_AInt_Vectors) { } TEST_F(ResolverConstEvalTest, MatrixMemberAccess_AFloat) { - auto* c = Const("a", Call(ty.mat(nullptr, 2, 3), // - Call(ty.vec(nullptr, 3), Expr(1.0_a), Expr(2.0_a), Expr(3.0_a)), - Call(ty.vec(nullptr, 3), Expr(4.0_a), Expr(5.0_a), Expr(6.0_a)))); + auto* c = Const("a", Call(ty.mat2x3(), // + Call(ty.vec3(), Expr(1.0_a), Expr(2.0_a), Expr(3.0_a)), + Call(ty.vec3(), Expr(4.0_a), Expr(5.0_a), Expr(6.0_a)))); auto* col_0 = Const("col_0", IndexAccessor("a", Expr(0_i))); auto* col_1 = Const("col_1", IndexAccessor("a", Expr(1_i))); @@ -174,9 +174,9 @@ TEST_F(ResolverConstEvalTest, MatrixMemberAccess_AFloat) { } TEST_F(ResolverConstEvalTest, MatrixMemberAccess_f32) { - auto* c = Const("a", Call(ty.mat(nullptr, 2, 3), // - Call(ty.vec(nullptr, 3), Expr(1.0_f), Expr(2.0_f), Expr(3.0_f)), - Call(ty.vec(nullptr, 3), Expr(4.0_f), Expr(5.0_f), Expr(6.0_f)))); + auto* c = Const("a", Call(ty.mat2x3(), // + Call(ty.vec3(), Expr(1.0_f), Expr(2.0_f), Expr(3.0_f)), + Call(ty.vec3(), Expr(4.0_f), Expr(5.0_f), Expr(6.0_f)))); auto* col_0 = Const("col_0", IndexAccessor("a", Expr(0_i))); auto* col_1 = Const("col_1", IndexAccessor("a", Expr(1_i))); diff --git a/src/tint/resolver/dependency_graph.cc b/src/tint/resolver/dependency_graph.cc index e581b9aa0d..16a3f8ec15 100644 --- a/src/tint/resolver/dependency_graph.cc +++ b/src/tint/resolver/dependency_graph.cc @@ -19,9 +19,7 @@ #include #include "src/tint/ast/alias.h" -#include "src/tint/ast/array.h" #include "src/tint/ast/assignment_statement.h" -#include "src/tint/ast/atomic.h" #include "src/tint/ast/block_statement.h" #include "src/tint/ast/break_if_statement.h" #include "src/tint/ast/break_statement.h" @@ -41,12 +39,8 @@ #include "src/tint/ast/invariant_attribute.h" #include "src/tint/ast/location_attribute.h" #include "src/tint/ast/loop_statement.h" -#include "src/tint/ast/matrix.h" -#include "src/tint/ast/multisampled_texture.h" #include "src/tint/ast/override.h" -#include "src/tint/ast/pointer.h" #include "src/tint/ast/return_statement.h" -#include "src/tint/ast/sampled_texture.h" #include "src/tint/ast/stage_attribute.h" #include "src/tint/ast/stride_attribute.h" #include "src/tint/ast/struct.h" @@ -56,10 +50,8 @@ #include "src/tint/ast/switch_statement.h" #include "src/tint/ast/templated_identifier.h" #include "src/tint/ast/traverse_expressions.h" -#include "src/tint/ast/type_name.h" #include "src/tint/ast/var.h" #include "src/tint/ast/variable_decl_statement.h" -#include "src/tint/ast/vector.h" #include "src/tint/ast/while_statement.h" #include "src/tint/ast/workgroup_attribute.h" #include "src/tint/scope_stack.h" @@ -180,12 +172,12 @@ class DependencyScanner { Declare(str->name->symbol, str); for (auto* member : str->members) { TraverseAttributes(member->attributes); - TraverseType(member->type); + TraverseTypeExpression(member->type); } }, [&](const ast::Alias* alias) { Declare(alias->name->symbol, alias); - TraverseType(alias->type); + TraverseTypeExpression(alias->type); }, [&](const ast::Function* func) { Declare(func->name->symbol, func); @@ -193,10 +185,10 @@ class DependencyScanner { }, [&](const ast::Variable* var) { Declare(var->name->symbol, var); - TraverseType(var->type); + TraverseTypeExpression(var->type); TraverseAttributes(var->attributes); if (var->initializer) { - TraverseExpression(var->initializer); + TraverseValueExpression(var->initializer); } }, [&](const ast::DiagnosticDirective*) { @@ -205,7 +197,9 @@ class DependencyScanner { [&](const ast::Enable*) { // Enable directives do not affect the dependency graph. }, - [&](const ast::ConstAssert* assertion) { TraverseExpression(assertion->condition); }, + [&](const ast::ConstAssert* assertion) { + TraverseValueExpression(assertion->condition); + }, [&](Default) { UnhandledNode(diagnostics_, global->node); }); } @@ -220,10 +214,10 @@ class DependencyScanner { // with the same identifier as its type. for (auto* param : func->params) { TraverseAttributes(param->attributes); - TraverseType(param->type); + TraverseTypeExpression(param->type); } // Resolve the return type - TraverseType(func->return_type); + TraverseTypeExpression(func->return_type); // Push the scope stack for the parameters and function body. scope_stack_.Push(); @@ -257,29 +251,29 @@ class DependencyScanner { Switch( stmt, // [&](const ast::AssignmentStatement* a) { - TraverseExpression(a->lhs); - TraverseExpression(a->rhs); + TraverseValueExpression(a->lhs); + TraverseValueExpression(a->rhs); }, [&](const ast::BlockStatement* b) { scope_stack_.Push(); TINT_DEFER(scope_stack_.Pop()); TraverseStatements(b->statements); }, - [&](const ast::BreakIfStatement* b) { TraverseExpression(b->condition); }, - [&](const ast::CallStatement* r) { TraverseExpression(r->expr); }, + [&](const ast::BreakIfStatement* b) { TraverseValueExpression(b->condition); }, + [&](const ast::CallStatement* r) { TraverseValueExpression(r->expr); }, [&](const ast::CompoundAssignmentStatement* a) { - TraverseExpression(a->lhs); - TraverseExpression(a->rhs); + TraverseValueExpression(a->lhs); + TraverseValueExpression(a->rhs); }, [&](const ast::ForLoopStatement* l) { scope_stack_.Push(); TINT_DEFER(scope_stack_.Pop()); TraverseStatement(l->initializer); - TraverseExpression(l->condition); + TraverseValueExpression(l->condition); TraverseStatement(l->continuing); TraverseStatement(l->body); }, - [&](const ast::IncrementDecrementStatement* i) { TraverseExpression(i->lhs); }, + [&](const ast::IncrementDecrementStatement* i) { TraverseValueExpression(i->lhs); }, [&](const ast::LoopStatement* l) { scope_stack_.Push(); TINT_DEFER(scope_stack_.Pop()); @@ -287,18 +281,18 @@ class DependencyScanner { TraverseStatement(l->continuing); }, [&](const ast::IfStatement* i) { - TraverseExpression(i->condition); + TraverseValueExpression(i->condition); TraverseStatement(i->body); if (i->else_statement) { TraverseStatement(i->else_statement); } }, - [&](const ast::ReturnStatement* r) { TraverseExpression(r->value); }, + [&](const ast::ReturnStatement* r) { TraverseValueExpression(r->value); }, [&](const ast::SwitchStatement* s) { - TraverseExpression(s->condition); + TraverseValueExpression(s->condition); for (auto* c : s->body) { for (auto* sel : c->selectors) { - TraverseExpression(sel->expr); + TraverseValueExpression(sel->expr); } TraverseStatement(c->body); } @@ -307,17 +301,19 @@ class DependencyScanner { if (auto* shadows = scope_stack_.Get(v->variable->name->symbol)) { graph_.shadows.Add(v->variable, shadows); } - TraverseType(v->variable->type); - TraverseExpression(v->variable->initializer); + TraverseTypeExpression(v->variable->type); + TraverseValueExpression(v->variable->initializer); Declare(v->variable->name->symbol, v->variable); }, [&](const ast::WhileStatement* w) { scope_stack_.Push(); TINT_DEFER(scope_stack_.Pop()); - TraverseExpression(w->condition); + TraverseValueExpression(w->condition); TraverseStatement(w->body); }, - [&](const ast::ConstAssert* assertion) { TraverseExpression(assertion->condition); }, + [&](const ast::ConstAssert* assertion) { + TraverseValueExpression(assertion->condition); + }, [&](Default) { if (TINT_UNLIKELY((!stmt->IsAnyOf()))) { @@ -337,87 +333,63 @@ class DependencyScanner { } } - /// Traverses the expression, performing symbol resolution and determining global dependencies. - void TraverseExpression(const ast::Expression* root) { - if (!root) { + /// Traverses the expression @p root_expr for the intended use as a value, performing symbol + /// resolution and determining global dependencies. + void TraverseValueExpression(const ast::Expression* root) { + TraverseExpression(root, "identifier", "references"); + } + + /// Traverses the expression @p root_expr for the intended use as a type, performing symbol + /// resolution and determining global dependencies. + void TraverseTypeExpression(const ast::Expression* root) { + TraverseExpression(root, "type", "references"); + } + + /// Traverses the expression @p root_expr for the intended use as a call target, performing + /// symbol resolution and determining global dependencies. + void TraverseCallableExpression(const ast::Expression* root) { + TraverseExpression(root, "function", "calls"); + } + + /// Traverses the expression @p root_expr, performing symbol resolution and determining global + /// dependencies. + void TraverseExpression(const ast::Expression* root_expr, + const char* root_use, + const char* root_action) { + if (!root_expr) { return; } - utils::Vector pending{root}; + + struct Pending { + const ast::Expression* expr; + const char* use; + const char* action; + }; + utils::Vector pending{{root_expr, root_use, root_action}}; while (!pending.IsEmpty()) { - ast::TraverseExpressions(pending.Pop(), diagnostics_, [&](const ast::Expression* expr) { + auto next = pending.Pop(); + ast::TraverseExpressions(next.expr, diagnostics_, [&](const ast::Expression* expr) { Switch( expr, [&](const ast::IdentifierExpression* e) { - AddDependency(e->identifier, e->identifier->symbol, "identifier", - "references"); + AddDependency(e->identifier, e->identifier->symbol, next.use, next.action); if (auto* tmpl_ident = e->identifier->As()) { for (auto* arg : tmpl_ident->arguments) { - pending.Push(arg); + pending.Push({arg, "identifier", "references"}); } } }, [&](const ast::CallExpression* call) { - if (call->target.name) { - AddDependency(call->target.name, call->target.name->symbol, "function", - "calls"); - if (auto* tmpl_ident = - call->target.name->As()) { - for (auto* arg : tmpl_ident->arguments) { - pending.Push(arg); - } - } - } - if (call->target.type) { - TraverseType(call->target.type); - } + TraverseCallableExpression(call->target); }, - [&](const ast::BitcastExpression* cast) { TraverseType(cast->type); }); + [&](const ast::BitcastExpression* cast) { + TraverseTypeExpression(cast->type); + }); return ast::TraverseAction::Descend; }); } } - /// Traverses the type node, performing symbol resolution and determining - /// global dependencies. - void TraverseType(const ast::Type* ty) { - if (!ty) { - return; - } - Switch( - ty, // - [&](const ast::Array* arr) { - TraverseType(arr->type); // - TraverseExpression(arr->count); - }, - [&](const ast::Atomic* atomic) { // - TraverseType(atomic->type); - }, - [&](const ast::Matrix* mat) { // - TraverseType(mat->type); - }, - [&](const ast::Pointer* ptr) { // - TraverseType(ptr->type); - }, - [&](const ast::TypeName* tn) { // - AddDependency(tn->name, tn->name->symbol, "type", "references"); - if (auto* tmpl_ident = tn->name->As()) { - for (auto* arg : tmpl_ident->arguments) { - TraverseExpression(arg); - } - } - }, - [&](const ast::Vector* vec) { // - TraverseType(vec->type); - }, - [&](const ast::SampledTexture* tex) { // - TraverseType(tex->type); - }, - [&](const ast::MultisampledTexture* tex) { // - TraverseType(tex->type); - }, - [&](Default) { UnhandledNode(diagnostics_, ty); }); - } - /// Traverses the attribute list, performing symbol resolution and /// determining global dependencies. void TraverseAttributes(utils::VectorRef attrs) { @@ -432,33 +404,33 @@ class DependencyScanner { bool handled = Switch( attr, [&](const ast::BindingAttribute* binding) { - TraverseExpression(binding->expr); + TraverseValueExpression(binding->expr); return true; }, [&](const ast::GroupAttribute* group) { - TraverseExpression(group->expr); + TraverseValueExpression(group->expr); return true; }, [&](const ast::IdAttribute* id) { - TraverseExpression(id->expr); + TraverseValueExpression(id->expr); return true; }, [&](const ast::LocationAttribute* loc) { - TraverseExpression(loc->expr); + TraverseValueExpression(loc->expr); return true; }, [&](const ast::StructMemberAlignAttribute* align) { - TraverseExpression(align->expr); + TraverseValueExpression(align->expr); return true; }, [&](const ast::StructMemberSizeAttribute* size) { - TraverseExpression(size->expr); + TraverseValueExpression(size->expr); return true; }, [&](const ast::WorkgroupAttribute* wg) { - TraverseExpression(wg->x); - TraverseExpression(wg->y); - TraverseExpression(wg->z); + TraverseValueExpression(wg->x); + TraverseValueExpression(wg->y); + TraverseValueExpression(wg->z); return true; }); if (handled) { @@ -517,8 +489,7 @@ class DependencyScanner { graph_.resolved_identifiers.Add(from, ResolvedIdentifier(resolved)); } - /// Appends an error to the diagnostics that the given symbol cannot be - /// resolved. + /// Appends an error to the diagnostics that the given symbol cannot be resolved. void UnknownSymbol(Symbol name, Source source, const char* use) { AddError(diagnostics_, "unknown " + std::string(use) + ": '" + symbols_.NameFor(name) + "'", source); diff --git a/src/tint/resolver/dependency_graph.h b/src/tint/resolver/dependency_graph.h index 8b2e668a11..7819b528de 100644 --- a/src/tint/resolver/dependency_graph.h +++ b/src/tint/resolver/dependency_graph.h @@ -21,6 +21,7 @@ #include "src/tint/ast/module.h" #include "src/tint/diagnostic/diagnostic.h" #include "src/tint/sem/builtin_type.h" +#include "src/tint/symbol_table.h" #include "src/tint/type/access.h" #include "src/tint/type/builtin.h" #include "src/tint/type/texel_format.h" diff --git a/src/tint/resolver/dependency_graph_test.cc b/src/tint/resolver/dependency_graph_test.cc index 7a98b2f40e..8d615997e0 100644 --- a/src/tint/resolver/dependency_graph_test.cc +++ b/src/tint/resolver/dependency_graph_test.cc @@ -277,26 +277,26 @@ std::ostream& operator<<(std::ostream& out, SymbolUseKind kind) { std::string DiagString(SymbolUseKind kind) { switch (kind) { case SymbolUseKind::GlobalVarType: + case SymbolUseKind::GlobalConstType: + case SymbolUseKind::AliasType: + case SymbolUseKind::StructMemberType: + case SymbolUseKind::ParameterType: + case SymbolUseKind::LocalVarType: + case SymbolUseKind::LocalLetType: + case SymbolUseKind::NestedLocalVarType: + case SymbolUseKind::NestedLocalLetType: + return "type"; case SymbolUseKind::GlobalVarArrayElemType: case SymbolUseKind::GlobalVarVectorElemType: case SymbolUseKind::GlobalVarMatrixElemType: case SymbolUseKind::GlobalVarSampledTexElemType: case SymbolUseKind::GlobalVarMultisampledTexElemType: - case SymbolUseKind::GlobalConstType: case SymbolUseKind::GlobalConstArrayElemType: case SymbolUseKind::GlobalConstVectorElemType: case SymbolUseKind::GlobalConstMatrixElemType: - case SymbolUseKind::AliasType: - case SymbolUseKind::StructMemberType: - case SymbolUseKind::ParameterType: - case SymbolUseKind::LocalVarType: case SymbolUseKind::LocalVarArrayElemType: case SymbolUseKind::LocalVarVectorElemType: case SymbolUseKind::LocalVarMatrixElemType: - case SymbolUseKind::LocalLetType: - case SymbolUseKind::NestedLocalVarType: - case SymbolUseKind::NestedLocalLetType: - return "type"; case SymbolUseKind::GlobalVarValue: case SymbolUseKind::GlobalVarArraySizeValue: case SymbolUseKind::GlobalConstValue: @@ -469,14 +469,14 @@ const ast::Identifier* SymbolTestHelper::Add(SymbolUseKind kind, auto& b = *builder; switch (kind) { case SymbolUseKind::GlobalVarType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); b.GlobalVar(b.Sym(), node, type::AddressSpace::kPrivate); - return node->name; + return node->identifier; } case SymbolUseKind::GlobalVarArrayElemType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); b.GlobalVar(b.Sym(), b.ty.array(node, 4_i), type::AddressSpace::kPrivate); - return node->name; + return node->identifier; } case SymbolUseKind::GlobalVarArraySizeValue: { auto* node = b.Expr(source, symbol); @@ -484,24 +484,24 @@ const ast::Identifier* SymbolTestHelper::Add(SymbolUseKind kind, return node->identifier; } case SymbolUseKind::GlobalVarVectorElemType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); b.GlobalVar(b.Sym(), b.ty.vec3(node), type::AddressSpace::kPrivate); - return node->name; + return node->identifier; } case SymbolUseKind::GlobalVarMatrixElemType: { - auto* node = b.ty(source, symbol); + ast::Type node = b.ty(source, symbol); b.GlobalVar(b.Sym(), b.ty.mat3x4(node), type::AddressSpace::kPrivate); - return node->name; + return node->identifier; } case SymbolUseKind::GlobalVarSampledTexElemType: { - auto* node = b.ty(source, symbol); + ast::Type node = b.ty(source, symbol); b.GlobalVar(b.Sym(), b.ty.sampled_texture(type::TextureDimension::k2d, node)); - return node->name; + return node->identifier; } case SymbolUseKind::GlobalVarMultisampledTexElemType: { - auto* node = b.ty(source, symbol); + ast::Type node = b.ty(source, symbol); b.GlobalVar(b.Sym(), b.ty.multisampled_texture(type::TextureDimension::k2d, node)); - return node->name; + return node->identifier; } case SymbolUseKind::GlobalVarValue: { auto* node = b.Expr(source, symbol); @@ -509,14 +509,14 @@ const ast::Identifier* SymbolTestHelper::Add(SymbolUseKind kind, return node->identifier; } case SymbolUseKind::GlobalConstType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); b.GlobalConst(b.Sym(), node, b.Expr(1_i)); - return node->name; + return node->identifier; } case SymbolUseKind::GlobalConstArrayElemType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); b.GlobalConst(b.Sym(), b.ty.array(node, 4_i), b.Expr(1_i)); - return node->name; + return node->identifier; } case SymbolUseKind::GlobalConstArraySizeValue: { auto* node = b.Expr(source, symbol); @@ -524,14 +524,14 @@ const ast::Identifier* SymbolTestHelper::Add(SymbolUseKind kind, return node->identifier; } case SymbolUseKind::GlobalConstVectorElemType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); b.GlobalConst(b.Sym(), b.ty.vec3(node), b.Expr(1_i)); - return node->name; + return node->identifier; } case SymbolUseKind::GlobalConstMatrixElemType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); b.GlobalConst(b.Sym(), b.ty.mat3x4(node), b.Expr(1_i)); - return node->name; + return node->identifier; } case SymbolUseKind::GlobalConstValue: { auto* node = b.Expr(source, symbol); @@ -539,14 +539,14 @@ const ast::Identifier* SymbolTestHelper::Add(SymbolUseKind kind, return node->identifier; } case SymbolUseKind::AliasType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); b.Alias(b.Sym(), node); - return node->name; + return node->identifier; } case SymbolUseKind::StructMemberType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); b.Structure(b.Sym(), utils::Vector{b.Member("m", node)}); - return node->name; + return node->identifier; } case SymbolUseKind::CallFunction: { auto* node = b.Ident(source, symbol); @@ -554,19 +554,19 @@ const ast::Identifier* SymbolTestHelper::Add(SymbolUseKind kind, return node; } case SymbolUseKind::ParameterType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); parameters.Push(b.Param(b.Sym(), node)); - return node->name; + return node->identifier; } case SymbolUseKind::LocalVarType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); statements.Push(b.Decl(b.Var(b.Sym(), node))); - return node->name; + return node->identifier; } case SymbolUseKind::LocalVarArrayElemType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); statements.Push(b.Decl(b.Var(b.Sym(), b.ty.array(node, 4_u), b.Expr(1_i)))); - return node->name; + return node->identifier; } case SymbolUseKind::LocalVarArraySizeValue: { auto* node = b.Expr(source, symbol); @@ -574,14 +574,14 @@ const ast::Identifier* SymbolTestHelper::Add(SymbolUseKind kind, return node->identifier; } case SymbolUseKind::LocalVarVectorElemType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); statements.Push(b.Decl(b.Var(b.Sym(), b.ty.vec3(node)))); - return node->name; + return node->identifier; } case SymbolUseKind::LocalVarMatrixElemType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); statements.Push(b.Decl(b.Var(b.Sym(), b.ty.mat3x4(node)))); - return node->name; + return node->identifier; } case SymbolUseKind::LocalVarValue: { auto* node = b.Expr(source, symbol); @@ -589,9 +589,9 @@ const ast::Identifier* SymbolTestHelper::Add(SymbolUseKind kind, return node->identifier; } case SymbolUseKind::LocalLetType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); statements.Push(b.Decl(b.Let(b.Sym(), node, b.Expr(1_i)))); - return node->name; + return node->identifier; } case SymbolUseKind::LocalLetValue: { auto* node = b.Expr(source, symbol); @@ -599,9 +599,9 @@ const ast::Identifier* SymbolTestHelper::Add(SymbolUseKind kind, return node->identifier; } case SymbolUseKind::NestedLocalVarType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); nested_statements.Push(b.Decl(b.Var(b.Sym(), node))); - return node->name; + return node->identifier; } case SymbolUseKind::NestedLocalVarValue: { auto* node = b.Expr(source, symbol); @@ -609,9 +609,9 @@ const ast::Identifier* SymbolTestHelper::Add(SymbolUseKind kind, return node->identifier; } case SymbolUseKind::NestedLocalLetType: { - auto* node = b.ty(source, symbol); + auto node = b.ty(source, symbol); nested_statements.Push(b.Decl(b.Let(b.Sym(), node, b.Expr(1_i)))); - return node->name; + return node->identifier; } case SymbolUseKind::NestedLocalLetValue: { auto* node = b.Expr(source, symbol); @@ -666,7 +666,7 @@ TEST_F(ResolverDependencyGraphUsedBeforeDeclTest, TypeConstructed) { // type T = i32; Func("F", utils::Empty, ty.void_(), - utils::Vector{Block(Ignore(Call(ty(Source{{12, 34}}, "T"))))}); + utils::Vector{Block(Ignore(Call(Ident(Source{{12, 34}}, "T"))))}); Alias(Source{{56, 78}}, "T", ty.i32()); Build(); @@ -1638,10 +1638,6 @@ static const ast::Identifier* IdentifierOf(const ast::IdentifierExpression* expr return expr->identifier; } -static const ast::Identifier* IdentifierOf(const ast::TypeName* ty) { - return ty->name; -} - static const ast::Identifier* IdentifierOf(const ast::Identifier* ident) { return ident; } @@ -1665,7 +1661,7 @@ TEST_F(ResolverDependencyGraphTraversalTest, SymbolsReached) { utils::Vector symbol_uses; - auto add_use = [&](const ast::Node* decl, auto* use, int line, const char* kind) { + auto add_use = [&](const ast::Node* decl, auto use, int line, const char* kind) { symbol_uses.Push( SymbolUse{decl, IdentifierOf(use), std::string(__FILE__) + ":" + std::to_string(line) + ": " + kind}); @@ -1776,7 +1772,7 @@ TEST_F(ResolverDependencyGraphTraversalTest, chromium_1273451) { Structure("B", utils::Vector{Member("b", ty.i32())}); Func("f", utils::Vector{Param("a", ty("A"))}, ty("B"), utils::Vector{ - Return(Call(ty("B"))), + Return(Call("B")), }); Build(); } diff --git a/src/tint/resolver/evaluation_stage_test.cc b/src/tint/resolver/evaluation_stage_test.cc index 28c8a99ea5..2e148e58bb 100644 --- a/src/tint/resolver/evaluation_stage_test.cc +++ b/src/tint/resolver/evaluation_stage_test.cc @@ -270,7 +270,7 @@ TEST_F(ResolverEvaluationStageTest, MemberAccessor_Const) { // const str = S(); // str.m Structure("S", utils::Vector{Member("m", ty.i32())}); - auto* str = Const("str", Call(ty("S"))); + auto* str = Const("str", Call("S")); auto* expr = MemberAccessor(str, "m"); WrapInFunction(str, expr); @@ -284,7 +284,7 @@ TEST_F(ResolverEvaluationStageTest, MemberAccessor_Runtime) { // var str = S(); // str.m Structure("S", utils::Vector{Member("m", ty.i32())}); - auto* str = Var("str", Call(ty("S"))); + auto* str = Var("str", Call("S")); auto* expr = MemberAccessor(str, "m"); WrapInFunction(str, expr); diff --git a/src/tint/resolver/expression_kind_test.cc b/src/tint/resolver/expression_kind_test.cc index 773765471c..c8cea54e39 100644 --- a/src/tint/resolver/expression_kind_test.cc +++ b/src/tint/resolver/expression_kind_test.cc @@ -119,78 +119,144 @@ using ResolverExpressionKindTest = ResolverTestWithParam; TEST_P(ResolverExpressionKindTest, Test) { Symbol sym; + std::function check_expr; switch (GetParam().def) { - case Def::kAccess: + case Def::kAccess: { sym = Sym("write"); + check_expr = [](const sem::Expression* expr) { + ASSERT_NE(expr, nullptr); + auto* enum_expr = expr->As>(); + ASSERT_NE(enum_expr, nullptr); + EXPECT_EQ(enum_expr->Value(), type::Access::kWrite); + }; break; - case Def::kAddressSpace: + } + case Def::kAddressSpace: { sym = Sym("workgroup"); + check_expr = [](const sem::Expression* expr) { + ASSERT_NE(expr, nullptr); + auto* enum_expr = expr->As>(); + ASSERT_NE(enum_expr, nullptr); + EXPECT_EQ(enum_expr->Value(), type::AddressSpace::kWorkgroup); + }; break; - case Def::kBuiltinFunction: + } + case Def::kBuiltinFunction: { sym = Sym("workgroupBarrier"); + check_expr = [](const sem::Expression* expr) { EXPECT_EQ(expr, nullptr); }; break; - case Def::kBuiltinType: + } + case Def::kBuiltinType: { sym = Sym("vec4f"); + check_expr = [](const sem::Expression* expr) { + ASSERT_NE(expr, nullptr); + auto* ty_expr = expr->As(); + ASSERT_NE(ty_expr, nullptr); + EXPECT_TRUE(ty_expr->Type()->Is()); + }; break; - case Def::kFunction: - Func(kDefSource, "FUNCTION", utils::Empty, ty.i32(), Return(1_i)); + } + case Def::kFunction: { + auto* fn = Func(kDefSource, "FUNCTION", utils::Empty, ty.i32(), Return(1_i)); sym = Sym("FUNCTION"); + check_expr = [fn](const sem::Expression* expr) { + ASSERT_NE(expr, nullptr); + auto* fn_expr = expr->As(); + ASSERT_NE(fn_expr, nullptr); + EXPECT_EQ(fn_expr->Function()->Declaration(), fn); + }; break; - case Def::kStruct: - Structure(kDefSource, "STRUCT", utils::Vector{Member("m", ty.i32())}); + } + case Def::kStruct: { + auto* s = Structure(kDefSource, "STRUCT", utils::Vector{Member("m", ty.i32())}); sym = Sym("STRUCT"); + check_expr = [s](const sem::Expression* expr) { + ASSERT_NE(expr, nullptr); + auto* ty_expr = expr->As(); + ASSERT_NE(ty_expr, nullptr); + auto* got = ty_expr->Type()->As(); + ASSERT_NE(got, nullptr); + EXPECT_EQ(got->Declaration(), s); + }; break; - case Def::kTexelFormat: + } + case Def::kTexelFormat: { sym = Sym("rgba8unorm"); + check_expr = [](const sem::Expression* expr) { + ASSERT_NE(expr, nullptr); + auto* enum_expr = expr->As>(); + ASSERT_NE(enum_expr, nullptr); + EXPECT_EQ(enum_expr->Value(), type::TexelFormat::kRgba8Unorm); + }; break; - case Def::kTypeAlias: + } + case Def::kTypeAlias: { Alias(kDefSource, "ALIAS", ty.i32()); sym = Sym("ALIAS"); + check_expr = [](const sem::Expression* expr) { + ASSERT_NE(expr, nullptr); + auto* ty_expr = expr->As(); + ASSERT_NE(ty_expr, nullptr); + EXPECT_TRUE(ty_expr->Type()->Is()); + }; break; - case Def::kVariable: - GlobalConst(kDefSource, "VARIABLE", Expr(1_i)); + } + case Def::kVariable: { + auto* c = GlobalConst(kDefSource, "VARIABLE", Expr(1_i)); sym = Sym("VARIABLE"); + check_expr = [c](const sem::Expression* expr) { + ASSERT_NE(expr, nullptr); + auto* var_expr = expr->As(); + ASSERT_NE(var_expr, nullptr); + EXPECT_EQ(var_expr->Variable()->Declaration(), c); + }; break; + } } + auto* expr = Expr(Ident(kUseSource, sym)); switch (GetParam().use) { case Use::kAccess: - GlobalVar("v", ty("texture_storage_2d", "rgba8unorm", sym), Group(0_u), Binding(0_u)); + GlobalVar("v", ty("texture_storage_2d", "rgba8unorm", expr), Group(0_u), Binding(0_u)); break; case Use::kAddressSpace: - return; // TODO(crbug.com/tint/1810) + Enable(ast::Extension::kChromiumExperimentalFullPtrParameters); + Func("f", utils::Vector{Param("p", ty("ptr", expr, ty.f32()))}, ty.void_(), + utils::Empty); + break; case Use::kCallExpr: - Func("f", utils::Empty, ty.void_(), Decl(Var("v", Call(Ident(kUseSource, sym))))); + Func("f", utils::Empty, ty.void_(), Decl(Var("v", Call(expr)))); break; case Use::kCallStmt: - Func("f", utils::Empty, ty.void_(), CallStmt(Call(Ident(kUseSource, sym)))); + Func("f", utils::Empty, ty.void_(), CallStmt(Call(expr))); break; case Use::kBinaryOp: - GlobalVar("v", type::AddressSpace::kPrivate, Mul(1_a, Expr(kUseSource, sym))); + GlobalVar("v", type::AddressSpace::kPrivate, Mul(1_a, expr)); break; case Use::kFunctionReturnType: - Func("f", utils::Empty, ty(kUseSource, sym), Return(Call(sym))); + Func("f", utils::Empty, ty(expr), Return(Call(sym))); break; case Use::kMemberType: - Structure("s", utils::Vector{Member("m", ty(kUseSource, sym))}); + Structure("s", utils::Vector{Member("m", ty(expr))}); break; case Use::kTexelFormat: - GlobalVar("v", ty("texture_storage_2d", sym, "write"), Group(0_u), Binding(0_u)); + GlobalVar("v", ty("texture_storage_2d", ty(expr), "write"), Group(0_u), Binding(0_u)); break; case Use::kValueExpression: - GlobalVar("v", type::AddressSpace::kPrivate, Expr(kUseSource, sym)); + GlobalVar("v", type::AddressSpace::kPrivate, expr); break; case Use::kVariableType: - GlobalVar("v", type::AddressSpace::kPrivate, ty(kUseSource, sym)); + GlobalVar("v", type::AddressSpace::kPrivate, ty(expr)); break; case Use::kUnaryOp: - GlobalVar("v", type::AddressSpace::kPrivate, Negation(Expr(kUseSource, sym))); + GlobalVar("v", type::AddressSpace::kPrivate, Negation(expr)); break; } if (GetParam().error == kPass) { EXPECT_TRUE(r()->Resolve()); EXPECT_EQ(r()->error(), ""); + check_expr(Sem().Get(expr)); } else { EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), GetParam().error); @@ -202,19 +268,21 @@ INSTANTIATE_TEST_SUITE_P( ResolverExpressionKindTest, testing::ValuesIn(std::vector{ {Def::kAccess, Use::kAccess, kPass}, - {Def::kAccess, Use::kAddressSpace, R"(TODO(crbug.com/tint/1810))"}, + {Def::kAccess, Use::kAddressSpace, + R"(5:6 error: cannot use access 'write' as address space)"}, {Def::kAccess, Use::kBinaryOp, R"(5:6 error: cannot use access 'write' as value)"}, {Def::kAccess, Use::kCallExpr, R"(5:6 error: cannot use access 'write' as call target)"}, {Def::kAccess, Use::kCallStmt, R"(5:6 error: cannot use access 'write' as call target)"}, {Def::kAccess, Use::kFunctionReturnType, R"(5:6 error: cannot use access 'write' as type)"}, {Def::kAccess, Use::kMemberType, R"(5:6 error: cannot use access 'write' as type)"}, - {Def::kAccess, Use::kTexelFormat, R"(error: cannot use access 'write' as texel format)"}, + {Def::kAccess, Use::kTexelFormat, + R"(5:6 error: cannot use access 'write' as texel format)"}, {Def::kAccess, Use::kValueExpression, R"(5:6 error: cannot use access 'write' as value)"}, {Def::kAccess, Use::kVariableType, R"(5:6 error: cannot use access 'write' as type)"}, {Def::kAccess, Use::kUnaryOp, R"(5:6 error: cannot use access 'write' as value)"}, {Def::kAddressSpace, Use::kAccess, - R"(error: cannot use address space 'workgroup' as access)"}, + R"(5:6 error: cannot use address space 'workgroup' as access)"}, {Def::kAddressSpace, Use::kAddressSpace, kPass}, {Def::kAddressSpace, Use::kBinaryOp, R"(5:6 error: cannot use address space 'workgroup' as value)"}, @@ -227,7 +295,7 @@ INSTANTIATE_TEST_SUITE_P( {Def::kAddressSpace, Use::kMemberType, R"(5:6 error: cannot use address space 'workgroup' as type)"}, {Def::kAddressSpace, Use::kTexelFormat, - R"(error: cannot use address space 'workgroup' as texel format)"}, + R"(5:6 error: cannot use address space 'workgroup' as texel format)"}, {Def::kAddressSpace, Use::kValueExpression, R"(5:6 error: cannot use address space 'workgroup' as value)"}, {Def::kAddressSpace, Use::kVariableType, @@ -235,26 +303,29 @@ INSTANTIATE_TEST_SUITE_P( {Def::kAddressSpace, Use::kUnaryOp, R"(5:6 error: cannot use address space 'workgroup' as value)"}, - {Def::kBuiltinFunction, Use::kAccess, R"(error: missing '(' for builtin function call)"}, - {Def::kBuiltinFunction, Use::kAddressSpace, R"(TODO(crbug.com/tint/1810))"}, + {Def::kBuiltinFunction, Use::kAccess, + R"(7:8 error: missing '(' for builtin function call)"}, + {Def::kBuiltinFunction, Use::kAddressSpace, + R"(7:8 error: missing '(' for builtin function call)"}, {Def::kBuiltinFunction, Use::kBinaryOp, R"(7:8 error: missing '(' for builtin function call)"}, {Def::kBuiltinFunction, Use::kCallStmt, kPass}, {Def::kBuiltinFunction, Use::kFunctionReturnType, - R"(5:6 error: cannot use builtin function 'workgroupBarrier' as type)"}, + R"(7:8 error: missing '(' for builtin function call)"}, {Def::kBuiltinFunction, Use::kMemberType, - R"(5:6 error: cannot use builtin function 'workgroupBarrier' as type)"}, + R"(7:8 error: missing '(' for builtin function call)"}, {Def::kBuiltinFunction, Use::kTexelFormat, - R"(error: missing '(' for builtin function call)"}, + R"(7:8 error: missing '(' for builtin function call)"}, {Def::kBuiltinFunction, Use::kValueExpression, R"(7:8 error: missing '(' for builtin function call)"}, {Def::kBuiltinFunction, Use::kVariableType, - R"(5:6 error: cannot use builtin function 'workgroupBarrier' as type)"}, + R"(7:8 error: missing '(' for builtin function call)"}, {Def::kBuiltinFunction, Use::kUnaryOp, R"(7:8 error: missing '(' for builtin function call)"}, - {Def::kBuiltinType, Use::kAccess, R"(error: cannot use type 'vec4' as access)"}, - {Def::kBuiltinType, Use::kAddressSpace, kPass}, + {Def::kBuiltinType, Use::kAccess, R"(5:6 error: cannot use type 'vec4' as access)"}, + {Def::kBuiltinType, Use::kAddressSpace, + R"(5:6 error: cannot use type 'vec4' as address space)"}, {Def::kBuiltinType, Use::kBinaryOp, R"(5:6 error: cannot use type 'vec4' as value 7:8 note: are you missing '()' for type initializer?)"}, @@ -262,7 +333,7 @@ INSTANTIATE_TEST_SUITE_P( {Def::kBuiltinType, Use::kFunctionReturnType, kPass}, {Def::kBuiltinType, Use::kMemberType, kPass}, {Def::kBuiltinType, Use::kTexelFormat, - R"(error: cannot use type 'vec4' as texel format)"}, + R"(5:6 error: cannot use type 'vec4' as texel format)"}, {Def::kBuiltinType, Use::kValueExpression, R"(5:6 error: cannot use type 'vec4' as value 7:8 note: are you missing '()' for type initializer?)"}, @@ -271,9 +342,13 @@ INSTANTIATE_TEST_SUITE_P( R"(5:6 error: cannot use type 'vec4' as value 7:8 note: are you missing '()' for type initializer?)"}, - {Def::kFunction, Use::kAccess, R"(error: missing '(' for function call)"}, - {Def::kFunction, Use::kAddressSpace, R"(TODO(crbug.com/tint/1810))"}, - {Def::kFunction, Use::kBinaryOp, R"(7:8 error: missing '(' for function call)"}, + {Def::kFunction, Use::kAccess, R"(5:6 error: cannot use function 'FUNCTION' as access +1:2 note: function 'FUNCTION' declared here)"}, + {Def::kFunction, Use::kAddressSpace, + R"(5:6 error: cannot use function 'FUNCTION' as address space +1:2 note: function 'FUNCTION' declared here)"}, + {Def::kFunction, Use::kBinaryOp, R"(5:6 error: cannot use function 'FUNCTION' as value +1:2 note: function 'FUNCTION' declared here)"}, {Def::kFunction, Use::kCallExpr, kPass}, {Def::kFunction, Use::kCallStmt, kPass}, {Def::kFunction, Use::kFunctionReturnType, @@ -282,21 +357,27 @@ INSTANTIATE_TEST_SUITE_P( {Def::kFunction, Use::kMemberType, R"(5:6 error: cannot use function 'FUNCTION' as type 1:2 note: function 'FUNCTION' declared here)"}, - {Def::kFunction, Use::kTexelFormat, R"(error: missing '(' for function call)"}, - {Def::kFunction, Use::kValueExpression, R"(7:8 error: missing '(' for function call)"}, + {Def::kFunction, Use::kTexelFormat, + R"(5:6 error: cannot use function 'FUNCTION' as texel format +1:2 note: function 'FUNCTION' declared here)"}, + {Def::kFunction, Use::kValueExpression, + R"(5:6 error: cannot use function 'FUNCTION' as value +1:2 note: function 'FUNCTION' declared here)"}, {Def::kFunction, Use::kVariableType, R"(5:6 error: cannot use function 'FUNCTION' as type 1:2 note: function 'FUNCTION' declared here)"}, - {Def::kFunction, Use::kUnaryOp, R"(7:8 error: missing '(' for function call)"}, + {Def::kFunction, Use::kUnaryOp, R"(5:6 error: cannot use function 'FUNCTION' as value +1:2 note: function 'FUNCTION' declared here)"}, - {Def::kStruct, Use::kAccess, R"(error: cannot use type 'STRUCT' as access)"}, - {Def::kStruct, Use::kAddressSpace, R"(TODO(crbug.com/tint/1810))"}, + {Def::kStruct, Use::kAccess, R"(5:6 error: cannot use type 'STRUCT' as access)"}, + {Def::kStruct, Use::kAddressSpace, + R"(5:6 error: cannot use type 'STRUCT' as address space)"}, {Def::kStruct, Use::kBinaryOp, R"(5:6 error: cannot use type 'STRUCT' as value 7:8 note: are you missing '()' for type initializer? 1:2 note: struct 'STRUCT' declared here)"}, {Def::kStruct, Use::kFunctionReturnType, kPass}, {Def::kStruct, Use::kMemberType, kPass}, - {Def::kStruct, Use::kTexelFormat, R"(error: cannot use type 'STRUCT' as texel format)"}, + {Def::kStruct, Use::kTexelFormat, R"(5:6 error: cannot use type 'STRUCT' as texel format)"}, {Def::kStruct, Use::kValueExpression, R"(5:6 error: cannot use type 'STRUCT' as value 7:8 note: are you missing '()' for type initializer? @@ -308,8 +389,9 @@ INSTANTIATE_TEST_SUITE_P( 1:2 note: struct 'STRUCT' declared here)"}, {Def::kTexelFormat, Use::kAccess, - R"(error: cannot use texel format 'rgba8unorm' as access)"}, - {Def::kTexelFormat, Use::kAddressSpace, R"(TODO(crbug.com/tint/1810))"}, + R"(5:6 error: cannot use texel format 'rgba8unorm' as access)"}, + {Def::kTexelFormat, Use::kAddressSpace, + R"(5:6 error: cannot use texel format 'rgba8unorm' as address space)"}, {Def::kTexelFormat, Use::kBinaryOp, R"(5:6 error: cannot use texel format 'rgba8unorm' as value)"}, {Def::kTexelFormat, Use::kCallExpr, @@ -328,15 +410,16 @@ INSTANTIATE_TEST_SUITE_P( {Def::kTexelFormat, Use::kUnaryOp, R"(5:6 error: cannot use texel format 'rgba8unorm' as value)"}, - {Def::kTypeAlias, Use::kAccess, R"(error: cannot use type 'i32' as access)"}, - {Def::kTypeAlias, Use::kAddressSpace, R"(TODO(crbug.com/tint/1810))"}, + {Def::kTypeAlias, Use::kAccess, R"(5:6 error: cannot use type 'i32' as access)"}, + {Def::kTypeAlias, Use::kAddressSpace, + R"(5:6 error: cannot use type 'i32' as address space)"}, {Def::kTypeAlias, Use::kBinaryOp, R"(5:6 error: cannot use type 'i32' as value 7:8 note: are you missing '()' for type initializer?)"}, {Def::kTypeAlias, Use::kCallExpr, kPass}, {Def::kTypeAlias, Use::kFunctionReturnType, kPass}, {Def::kTypeAlias, Use::kMemberType, kPass}, - {Def::kTypeAlias, Use::kTexelFormat, R"(error: cannot use type 'i32' as texel format)"}, + {Def::kTypeAlias, Use::kTexelFormat, R"(5:6 error: cannot use type 'i32' as texel format)"}, {Def::kTypeAlias, Use::kValueExpression, R"(5:6 error: cannot use type 'i32' as value 7:8 note: are you missing '()' for type initializer?)"}, @@ -345,8 +428,11 @@ INSTANTIATE_TEST_SUITE_P( R"(5:6 error: cannot use type 'i32' as value 7:8 note: are you missing '()' for type initializer?)"}, - {Def::kVariable, Use::kAccess, R"(error: cannot use 'VARIABLE' of type 'i32' as access)"}, - {Def::kVariable, Use::kAddressSpace, R"(TODO(crbug.com/tint/1810))"}, + {Def::kVariable, Use::kAccess, R"(5:6 error: cannot use const 'VARIABLE' as access +1:2 note: const 'VARIABLE' declared here)"}, + {Def::kVariable, Use::kAddressSpace, + R"(5:6 error: cannot use const 'VARIABLE' as address space +1:2 note: const 'VARIABLE' declared here)"}, {Def::kVariable, Use::kBinaryOp, kPass}, {Def::kVariable, Use::kCallStmt, R"(5:6 error: cannot use const 'VARIABLE' as call target @@ -361,7 +447,8 @@ INSTANTIATE_TEST_SUITE_P( R"(5:6 error: cannot use const 'VARIABLE' as type 1:2 note: const 'VARIABLE' declared here)"}, {Def::kVariable, Use::kTexelFormat, - R"(error: cannot use 'VARIABLE' of type 'i32' as texel format)"}, + R"(5:6 error: cannot use const 'VARIABLE' as texel format +1:2 note: const 'VARIABLE' declared here)"}, {Def::kVariable, Use::kValueExpression, kPass}, {Def::kVariable, Use::kVariableType, R"(5:6 error: cannot use const 'VARIABLE' as type diff --git a/src/tint/resolver/f16_extension_test.cc b/src/tint/resolver/f16_extension_test.cc index 1d327e53df..f0d515f80f 100644 --- a/src/tint/resolver/f16_extension_test.cc +++ b/src/tint/resolver/f16_extension_test.cc @@ -65,7 +65,7 @@ TEST_F(ResolverF16ExtensionTest, Vec2TypeInitUsedWithExtension) { // var v = vec2(); Enable(ast::Extension::kF16); - GlobalVar("v", Call(ty.vec2()), type::AddressSpace::kPrivate); + GlobalVar("v", vec2(), type::AddressSpace::kPrivate); EXPECT_TRUE(r()->Resolve()) << r()->error(); } @@ -83,15 +83,14 @@ TEST_F(ResolverF16ExtensionTest, Vec2TypeConvUsedWithExtension) { // var v = vec2(vec2()); Enable(ast::Extension::kF16); - GlobalVar("v", Call(ty.vec2(), Call(ty.vec2())), type::AddressSpace::kPrivate); + GlobalVar("v", vec2(vec2()), type::AddressSpace::kPrivate); EXPECT_TRUE(r()->Resolve()) << r()->error(); } TEST_F(ResolverF16ExtensionTest, Vec2TypeConvUsedWithoutExtension) { // var v = vec2(vec2()); - GlobalVar("v", Call(ty.vec2(ty.f16(Source{{12, 34}})), Call(ty.vec2())), - type::AddressSpace::kPrivate); + GlobalVar("v", vec2(ty.f16(Source{{12, 34}}), vec2()), type::AddressSpace::kPrivate); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 error: f16 type used without 'f16' extension enabled"); diff --git a/src/tint/resolver/function_validation_test.cc b/src/tint/resolver/function_validation_test.cc index 65aff491ec..511d37945f 100644 --- a/src/tint/resolver/function_validation_test.cc +++ b/src/tint/resolver/function_validation_test.cc @@ -936,7 +936,7 @@ TEST_F(ResolverFunctionValidationTest, WorkgroupSize_InvalidExpr_z) { } TEST_F(ResolverFunctionValidationTest, ReturnIsConstructible_NonPlain) { - auto* ret_type = ty.pointer(Source{{12, 34}}, ty.i32(), type::AddressSpace::kFunction); + auto ret_type = ty.pointer(Source{{12, 34}}, ty.i32(), type::AddressSpace::kFunction); Func("f", utils::Empty, ret_type, utils::Empty); EXPECT_FALSE(r()->Resolve()); @@ -944,7 +944,7 @@ TEST_F(ResolverFunctionValidationTest, ReturnIsConstructible_NonPlain) { } TEST_F(ResolverFunctionValidationTest, ReturnIsConstructible_AtomicInt) { - auto* ret_type = ty.atomic(Source{{12, 34}}, ty.i32()); + auto ret_type = ty.atomic(Source{{12, 34}}, ty.i32()); Func("f", utils::Empty, ret_type, utils::Empty); EXPECT_FALSE(r()->Resolve()); @@ -952,7 +952,7 @@ TEST_F(ResolverFunctionValidationTest, ReturnIsConstructible_AtomicInt) { } TEST_F(ResolverFunctionValidationTest, ReturnIsConstructible_ArrayOfAtomic) { - auto* ret_type = ty.array(Source{{12, 34}}, ty.atomic(ty.i32()), 10_u); + auto ret_type = ty.array(Source{{12, 34}}, ty.atomic(ty.i32()), 10_u); Func("f", utils::Empty, ret_type, utils::Empty); EXPECT_FALSE(r()->Resolve()); @@ -963,7 +963,7 @@ TEST_F(ResolverFunctionValidationTest, ReturnIsConstructible_StructOfAtomic) { Structure("S", utils::Vector{ Member("m", ty.atomic(ty.i32())), }); - auto* ret_type = ty(Source{{12, 34}}, "S"); + auto ret_type = ty(Source{{12, 34}}, "S"); Func("f", utils::Empty, ret_type, utils::Empty); EXPECT_FALSE(r()->Resolve()); @@ -971,7 +971,7 @@ TEST_F(ResolverFunctionValidationTest, ReturnIsConstructible_StructOfAtomic) { } TEST_F(ResolverFunctionValidationTest, ReturnIsConstructible_RuntimeArray) { - auto* ret_type = ty.array(Source{{12, 34}}, ty.i32()); + auto ret_type = ty.array(Source{{12, 34}}, ty.i32()); Func("f", utils::Empty, ret_type, utils::Empty); EXPECT_FALSE(r()->Resolve()); @@ -982,7 +982,7 @@ TEST_F(ResolverFunctionValidationTest, ParameterStoreType_NonAtomicFree) { Structure("S", utils::Vector{ Member("m", ty.atomic(ty.i32())), }); - auto* ret_type = ty(Source{{12, 34}}, "S"); + auto ret_type = ty(Source{{12, 34}}, "S"); auto* bar = Param("bar", ret_type); Func("f", utils::Vector{bar}, ty.void_(), utils::Empty); @@ -994,7 +994,7 @@ TEST_F(ResolverFunctionValidationTest, ParameterSotreType_AtomicFree) { Structure("S", utils::Vector{ Member("m", ty.i32()), }); - auto* ret_type = ty(Source{{12, 34}}, "S"); + auto ret_type = ty(Source{{12, 34}}, "S"); auto* bar = Param(Source{{12, 34}}, "bar", ret_type); Func("f", utils::Vector{bar}, ty.void_(), utils::Empty); @@ -1025,29 +1025,28 @@ TEST_F(ResolverFunctionValidationTest, ParametersOverLimit) { TEST_F(ResolverFunctionValidationTest, ParameterVectorNoType) { // fn f(p : vec3) {} - Func(Source{{12, 34}}, "f", - utils::Vector{Param("p", create(Source{{12, 34}}, nullptr, 3u))}, ty.void_(), - utils::Empty); - - EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: missing vector element type"); -} - -TEST_F(ResolverFunctionValidationTest, ParameterMatrixNoType) { - // fn f(p : vec3) {} - - Func(Source{{12, 34}}, "f", - utils::Vector{Param("p", create(Source{{12, 34}}, nullptr, 3u, 3u))}, + Func(Source{{12, 34}}, "f", utils::Vector{Param("p", ty.vec3(Source{{12, 34}}))}, ty.void_(), utils::Empty); EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: missing matrix element type"); + EXPECT_EQ(r()->error(), "12:34 error: expected '<' for 'vec3'"); +} + +TEST_F(ResolverFunctionValidationTest, ParameterMatrixNoType) { + // fn f(p : mat3x3) {} + + Func(Source{{12, 34}}, "f", utils::Vector{Param("p", ty.mat3x3(Source{{12, 34}}))}, + ty.void_(), utils::Empty); + + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), "12:34 error: expected '<' for 'mat3x3'"); } enum class Expectation { kAlwaysPass, kPassWithFullPtrParameterExtension, kAlwaysFail, + kInvalid, }; struct TestParams { type::AddressSpace address_space; @@ -1059,7 +1058,7 @@ struct TestWithParams : ResolverTestWithParam {}; using ResolverFunctionParameterValidationTest = TestWithParams; TEST_P(ResolverFunctionParameterValidationTest, AddressSpaceNoExtension) { auto& param = GetParam(); - auto* ptr_type = ty.pointer(Source{{12, 34}}, ty.i32(), param.address_space); + auto ptr_type = ty("ptr", Ident(Source{{12, 34}}, param.address_space), ty.i32()); auto* arg = Param(Source{{12, 34}}, "p", ptr_type); Func("f", utils::Vector{arg}, ty.void_(), utils::Empty); @@ -1069,37 +1068,48 @@ TEST_P(ResolverFunctionParameterValidationTest, AddressSpaceNoExtension) { std::stringstream ss; ss << param.address_space; EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: function parameter of pointer type cannot be in '" + - ss.str() + "' address space"); + if (param.expectation == Expectation::kInvalid) { + EXPECT_EQ(r()->error(), "12:34 error: unknown identifier: '" + ss.str() + "'"); + } else { + EXPECT_EQ(r()->error(), + "12:34 error: function parameter of pointer type cannot be in '" + ss.str() + + "' address space"); + } } } TEST_P(ResolverFunctionParameterValidationTest, AddressSpaceWithExtension) { auto& param = GetParam(); - auto* ptr_type = ty.pointer(Source{{12, 34}}, ty.i32(), param.address_space); + auto ptr_type = ty("ptr", Ident(Source{{12, 34}}, param.address_space), ty.i32()); auto* arg = Param(Source{{12, 34}}, "p", ptr_type); Enable(ast::Extension::kChromiumExperimentalFullPtrParameters); Func("f", utils::Vector{arg}, ty.void_(), utils::Empty); - if (param.expectation != Expectation::kAlwaysFail) { + if (param.expectation == Expectation::kAlwaysPass || + param.expectation == Expectation::kPassWithFullPtrParameterExtension) { ASSERT_TRUE(r()->Resolve()) << r()->error(); } else { std::stringstream ss; ss << param.address_space; EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: function parameter of pointer type cannot be in '" + - ss.str() + "' address space"); + if (param.expectation == Expectation::kInvalid) { + EXPECT_EQ(r()->error(), "12:34 error: unknown identifier: '" + ss.str() + "'"); + } else { + EXPECT_EQ(r()->error(), + "12:34 error: function parameter of pointer type cannot be in '" + ss.str() + + "' address space"); + } } } INSTANTIATE_TEST_SUITE_P( ResolverTest, ResolverFunctionParameterValidationTest, testing::Values( - TestParams{type::AddressSpace::kNone, Expectation::kAlwaysFail}, - TestParams{type::AddressSpace::kIn, Expectation::kAlwaysFail}, - TestParams{type::AddressSpace::kOut, Expectation::kAlwaysFail}, + TestParams{type::AddressSpace::kNone, Expectation::kInvalid}, + TestParams{type::AddressSpace::kIn, Expectation::kInvalid}, + TestParams{type::AddressSpace::kOut, Expectation::kInvalid}, TestParams{type::AddressSpace::kUniform, Expectation::kPassWithFullPtrParameterExtension}, TestParams{type::AddressSpace::kWorkgroup, Expectation::kPassWithFullPtrParameterExtension}, - TestParams{type::AddressSpace::kHandle, Expectation::kAlwaysFail}, + TestParams{type::AddressSpace::kHandle, Expectation::kInvalid}, TestParams{type::AddressSpace::kStorage, Expectation::kPassWithFullPtrParameterExtension}, TestParams{type::AddressSpace::kPrivate, Expectation::kAlwaysPass}, TestParams{type::AddressSpace::kFunction, Expectation::kAlwaysPass})); diff --git a/src/tint/resolver/inferred_type_test.cc b/src/tint/resolver/inferred_type_test.cc index eba38ff87f..8a609d25b9 100644 --- a/src/tint/resolver/inferred_type_test.cc +++ b/src/tint/resolver/inferred_type_test.cc @@ -134,7 +134,7 @@ TEST_P(ResolverInferredTypeParamTest, LocalVar_Pass) { INSTANTIATE_TEST_SUITE_P(ResolverTest, ResolverInferredTypeParamTest, testing::ValuesIn(all_cases)); TEST_F(ResolverInferredTypeTest, InferArray_Pass) { - auto* type = ty.array(); + auto type = ty.array(); auto* expected_type = create( create(), create(10u), 4u, 4u * 10u, 4u, 4u); diff --git a/src/tint/resolver/load_test.cc b/src/tint/resolver/load_test.cc index 7a742248c1..23342271ca 100644 --- a/src/tint/resolver/load_test.cc +++ b/src/tint/resolver/load_test.cc @@ -154,7 +154,7 @@ TEST_F(ResolverLoadTest, MultiComponentSwizzle) { // var ref = vec4(1); // var v = ref.xyz; auto* ident = Expr("ref"); - WrapInFunction(Var("ref", Call(ty.vec4(), 1_i)), // + WrapInFunction(Var("ref", vec4(1_i)), // Var("v", MemberAccessor(ident, "xyz"))); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -230,7 +230,7 @@ TEST_F(ResolverLoadTest, FunctionArg_Handles) { }, ty.vec4(), utils::Vector{ - Return(Call("textureSampleLevel", "tp", "sp", Call(ty.vec2()), 0_a)), + Return(Call("textureSampleLevel", "tp", "sp", vec2(), 0_a)), }); auto* t_ident = Expr("t"); auto* s_ident = Expr("s"); diff --git a/src/tint/resolver/materialize_test.cc b/src/tint/resolver/materialize_test.cc index 366fbc31d2..acd69a8c74 100644 --- a/src/tint/resolver/materialize_test.cc +++ b/src/tint/resolver/materialize_test.cc @@ -350,7 +350,7 @@ TEST_P(MaterializeAbstractNumericToConcreteType, Test) { break; case Method::kStruct: Structure("S", utils::Vector{Member("v", target_ty())}); - WrapInFunction(Call(ty("S"), abstract_expr)); + WrapInFunction(Call("S", abstract_expr)); break; case Method::kBinaryOp: { // Add 0 to ensure no overflow with max float values @@ -1262,7 +1262,7 @@ TEST_F(MaterializeAbstractStructure, Modf_Scalar_DefaultType) { TEST_F(MaterializeAbstractStructure, Modf_Vector_DefaultType) { // var v = modf(vec2(1)); - auto* call = Call("modf", Call(ty.vec2(nullptr), 1_a)); + auto* call = Call("modf", Call(ty.vec2(), 1_a)); WrapInFunction(Decl(Var("v", call))); ASSERT_TRUE(r()->Resolve()) << r()->error(); auto* sem = Sem().Get(call); @@ -1302,8 +1302,8 @@ TEST_F(MaterializeAbstractStructure, Modf_Vector_ExplicitType) { // var v = modf(vec2(1_h)); // v is __modf_result_vec2_f16 // v = modf(vec2(1)); // __modf_result_vec2_f16 <- __modf_result_vec2_abstract Enable(ast::Extension::kF16); - auto* call = Call("modf", Call(ty.vec2(nullptr), 1_a)); - WrapInFunction(Decl(Var("v", Call("modf", Call(ty.vec2(nullptr), 1_h)))), Assign("v", call)); + auto* call = Call("modf", Call(ty.vec2(), 1_a)); + WrapInFunction(Decl(Var("v", Call("modf", Call(ty.vec2(), 1_h)))), Assign("v", call)); ASSERT_TRUE(r()->Resolve()) << r()->error(); auto* sem = Sem().Get(call); ASSERT_TRUE(sem->Is()); @@ -1339,7 +1339,7 @@ TEST_F(MaterializeAbstractStructure, Frexp_Scalar_DefaultType) { TEST_F(MaterializeAbstractStructure, Frexp_Vector_DefaultType) { // var v = frexp(vec2(1)); - auto* call = Call("frexp", Call(ty.vec2(nullptr), 1_a)); + auto* call = Call("frexp", Call(ty.vec2(), 1_a)); WrapInFunction(Decl(Var("v", call))); ASSERT_TRUE(r()->Resolve()) << r()->error(); auto* sem = Sem().Get(call); @@ -1385,8 +1385,8 @@ TEST_F(MaterializeAbstractStructure, Frexp_Vector_ExplicitType) { // var v = frexp(vec2(1_h)); // v is __frexp_result_vec2_f16 // v = frexp(vec2(1)); // __frexp_result_vec2_f16 <- __frexp_result_vec2_abstract Enable(ast::Extension::kF16); - auto* call = Call("frexp", Call(ty.vec2(nullptr), 1_a)); - WrapInFunction(Decl(Var("v", Call("frexp", Call(ty.vec2(nullptr), 1_h)))), Assign("v", call)); + auto* call = Call("frexp", Call(ty.vec2(), 1_a)); + WrapInFunction(Decl(Var("v", Call("frexp", Call(ty.vec2(), 1_h)))), Assign("v", call)); ASSERT_TRUE(r()->Resolve()) << r()->error(); auto* sem = Sem().Get(call); ASSERT_TRUE(sem->Is()); diff --git a/src/tint/resolver/override_test.cc b/src/tint/resolver/override_test.cc index 813d4de37a..2fd48ed7b6 100644 --- a/src/tint/resolver/override_test.cc +++ b/src/tint/resolver/override_test.cc @@ -208,8 +208,8 @@ TEST_F(ResolverOverrideTest, TransitiveReferences_ViaAttribute) { TEST_F(ResolverOverrideTest, TransitiveReferences_ViaArraySize) { auto* a = Override("a", ty.i32()); auto* b = Override("b", ty.i32(), Mul(2_a, "a")); - auto* arr_ty = ty.array(ty.i32(), Mul(2_a, "b")); - auto* arr = GlobalVar("arr", type::AddressSpace::kWorkgroup, arr_ty); + auto* arr = GlobalVar("arr", type::AddressSpace::kWorkgroup, ty.array(ty.i32(), Mul(2_a, "b"))); + auto arr_ty = arr->type; Override("unused", ty.i32(), Expr(1_a)); auto* func = Func("foo", utils::Empty, ty.void_(), utils::Vector{ @@ -219,7 +219,7 @@ TEST_F(ResolverOverrideTest, TransitiveReferences_ViaArraySize) { EXPECT_TRUE(r()->Resolve()) << r()->error(); { - auto* r = Sem().TransitivelyReferencedOverrides(Sem().Get(arr_ty)); + auto* r = Sem().TransitivelyReferencedOverrides(TypeOf(arr_ty)); ASSERT_NE(r, nullptr); auto& refs = *r; ASSERT_EQ(refs.Length(), 2u); @@ -248,8 +248,9 @@ TEST_F(ResolverOverrideTest, TransitiveReferences_ViaArraySize) { TEST_F(ResolverOverrideTest, TransitiveReferences_ViaArraySize_Alias) { auto* a = Override("a", ty.i32()); auto* b = Override("b", ty.i32(), Mul(2_a, "a")); - auto* arr_ty = Alias("arr_ty", ty.array(ty.i32(), Mul(2_a, "b"))); + Alias("arr_ty", ty.array(ty.i32(), Mul(2_a, "b"))); auto* arr = GlobalVar("arr", type::AddressSpace::kWorkgroup, ty("arr_ty")); + auto arr_ty = arr->type; Override("unused", ty.i32(), Expr(1_a)); auto* func = Func("foo", utils::Empty, ty.void_(), utils::Vector{ @@ -259,7 +260,7 @@ TEST_F(ResolverOverrideTest, TransitiveReferences_ViaArraySize_Alias) { EXPECT_TRUE(r()->Resolve()) << r()->error(); { - auto* r = Sem().TransitivelyReferencedOverrides(Sem().Get(arr_ty->type)); + auto* r = Sem().TransitivelyReferencedOverrides(TypeOf(arr_ty)); ASSERT_NE(r, nullptr); auto& refs = *r; ASSERT_EQ(refs.Length(), 2u); diff --git a/src/tint/resolver/ptr_ref_test.cc b/src/tint/resolver/ptr_ref_test.cc index 64b21aef38..692bd3b513 100644 --- a/src/tint/resolver/ptr_ref_test.cc +++ b/src/tint/resolver/ptr_ref_test.cc @@ -88,7 +88,7 @@ TEST_F(ResolverPtrRefTest, DefaultPtrAddressSpace) { WrapInFunction(function, function_ptr, private_ptr, workgroup_ptr, uniform_ptr, storage_ptr); - EXPECT_TRUE(r()->Resolve()) << r()->error(); + ASSERT_TRUE(r()->Resolve()) << r()->error(); ASSERT_TRUE(TypeOf(function_ptr)->Is()) << "function_ptr is " << TypeOf(function_ptr)->TypeInfo().name; diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index ab1970a499..352c5e4fcc 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -21,7 +21,6 @@ #include #include "src/tint/ast/alias.h" -#include "src/tint/ast/array.h" #include "src/tint/ast/assignment_statement.h" #include "src/tint/ast/attribute.h" #include "src/tint/ast/bitcast_expression.h" @@ -36,16 +35,11 @@ #include "src/tint/ast/internal_attribute.h" #include "src/tint/ast/interpolate_attribute.h" #include "src/tint/ast/loop_statement.h" -#include "src/tint/ast/matrix.h" -#include "src/tint/ast/pointer.h" #include "src/tint/ast/return_statement.h" -#include "src/tint/ast/sampled_texture.h" #include "src/tint/ast/switch_statement.h" #include "src/tint/ast/traverse_expressions.h" -#include "src/tint/ast/type_name.h" #include "src/tint/ast/unary_op_expression.h" #include "src/tint/ast/variable_decl_statement.h" -#include "src/tint/ast/vector.h" #include "src/tint/ast/while_statement.h" #include "src/tint/ast/workgroup_attribute.h" #include "src/tint/resolver/uniformity.h" @@ -54,6 +48,7 @@ #include "src/tint/sem/call.h" #include "src/tint/sem/for_loop_statement.h" #include "src/tint/sem/function.h" +#include "src/tint/sem/function_expression.h" #include "src/tint/sem/if_statement.h" #include "src/tint/sem/index_accessor_expression.h" #include "src/tint/sem/load.h" @@ -217,138 +212,6 @@ bool Resolver::ResolveInternal() { return result; } -type::Type* Resolver::Type(const ast::Type* ty) { - if (ty == nullptr) { - return builder_->create(); - } - - Mark(ty); - auto* s = Switch( - ty, // - [&](const ast::Vector* t) -> type::Vector* { - if (!t->type) { - AddError("missing vector element type", t->source.End()); - return nullptr; - } - if (auto* el = Type(t->type)) { - if (auto* vector = builder_->create(el, t->width)) { - if (validator_.Vector(vector, t->source)) { - return vector; - } - } - } - return nullptr; - }, - [&](const ast::Matrix* t) -> type::Matrix* { - if (!t->type) { - AddError("missing matrix element type", t->source.End()); - return nullptr; - } - if (auto* el = Type(t->type)) { - if (auto* column_type = builder_->create(el, t->rows)) { - if (auto* matrix = builder_->create(column_type, t->columns)) { - if (validator_.Matrix(matrix, t->source)) { - return matrix; - } - } - } - } - return nullptr; - }, - [&](const ast::Array* t) { return Array(t); }, - [&](const ast::Atomic* t) -> type::Atomic* { - if (auto* el = Type(t->type)) { - auto* a = builder_->create(el); - if (!validator_.Atomic(t, a)) { - return nullptr; - } - return a; - } - return nullptr; - }, - [&](const ast::Pointer* t) -> type::Pointer* { - if (auto* el = Type(t->type)) { - auto access = t->access; - if (access == type::Access::kUndefined) { - access = DefaultAccessForAddressSpace(t->address_space); - } - auto ptr = builder_->create(el, t->address_space, access); - if (!ptr) { - return nullptr; - } - if (!validator_.Pointer(t, ptr)) { - return nullptr; - } - if (!ApplyAddressSpaceUsageToType(t->address_space, el, t->type->source)) { - AddNote("while instantiating " + builder_->FriendlyName(ptr), t->source); - return nullptr; - } - return ptr; - } - return nullptr; - }, - [&](const ast::SampledTexture* t) -> type::SampledTexture* { - if (auto* el = Type(t->type)) { - auto* sem = builder_->create(t->dim, el); - if (!validator_.SampledTexture(sem, t->source)) { - return nullptr; - } - return sem; - } - return nullptr; - }, - [&](const ast::MultisampledTexture* t) -> type::MultisampledTexture* { - if (auto* el = Type(t->type)) { - auto* sem = builder_->create(t->dim, el); - if (!validator_.MultisampledTexture(sem, t->source)) { - return nullptr; - } - return sem; - } - return nullptr; - }, - [&](const ast::TypeName* t) -> type::Type* { - Mark(t->name); - - auto resolved = dependencies_.resolved_identifiers.Get(t->name); - if (!resolved) { - TINT_ICE(Resolver, diagnostics_) - << "identifier '" << builder_->Symbols().NameFor(t->name->symbol) - << "' was not resolved"; - return nullptr; - } - - if (auto* ast_node = resolved->Node()) { - auto* type = sem_.Get(ast_node); - if (TINT_UNLIKELY(!type)) { - ErrorMismatchedResolvedIdentifier(t->source, *resolved, "type"); - return nullptr; - } - - if (TINT_UNLIKELY(t->name->Is())) { - AddError("type '" + builder_->Symbols().NameFor(t->name->symbol) + - "' does not take template arguments", - t->source); - NoteDeclarationSource(ast_node); - return nullptr; - } - - return type; - } - if (auto b = resolved->BuiltinType(); b != type::Builtin::kUndefined) { - return BuiltinType(b, t->name); - } - - ErrorMismatchedResolvedIdentifier(t->source, *resolved, "type"); - return nullptr; - }); - - if (s) { - builder_->Sem().Add(ty, s); - } - return s; -} - sem::Variable* Resolver::Variable(const ast::Variable* v, bool is_global) { Mark(v->name); @@ -576,7 +439,7 @@ sem::Variable* Resolver::Var(const ast::Var* var, bool is_global) { const type::Type* storage_ty = nullptr; // If the variable has a declared type, resolve it. - if (auto* ty = var->type) { + if (auto ty = var->type) { storage_ty = Type(ty); if (!storage_ty) { return nullptr; @@ -1032,7 +895,7 @@ sem::Function* Resolver::Function(const ast::Function* decl) { // Resolve the return type type::Type* return_type = nullptr; - if (auto* ty = decl->return_type) { + if (auto ty = decl->return_type) { return_type = Type(ty); if (!return_type) { return nullptr; @@ -1601,7 +1464,37 @@ sem::Expression* Resolver::Expression(const ast::Expression* root) { } sem::ValueExpression* Resolver::ValueExpression(const ast::Expression* expr) { - return sem_.AsValue(Expression(expr)); + return sem_.AsValueExpression(Expression(expr)); +} + +sem::TypeExpression* Resolver::TypeExpression(const ast::Expression* expr) { + return sem_.AsTypeExpression(Expression(expr)); +} + +sem::FunctionExpression* Resolver::FunctionExpression(const ast::Expression* expr) { + return sem_.AsFunctionExpression(Expression(expr)); +} + +type::Type* Resolver::Type(const ast::Expression* ast) { + auto* type_expr = TypeExpression(ast); + if (!type_expr) { + return nullptr; + } + return const_cast(type_expr->Type()); +} + +sem::BuiltinEnumExpression* Resolver::AddressSpaceExpression( + const ast::Expression* expr) { + return sem_.AsAddressSpace(Expression(expr)); +} + +sem::BuiltinEnumExpression* Resolver::TexelFormatExpression( + const ast::Expression* expr) { + return sem_.AsTexelFormat(Expression(expr)); +} + +sem::BuiltinEnumExpression* Resolver::AccessExpression(const ast::Expression* expr) { + return sem_.AsAccess(Expression(expr)); } void Resolver::RegisterStore(const sem::ValueExpression* expr) { @@ -2002,6 +1895,11 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) { // * A builtin call. // * A type initializer. // * A type conversion. + auto* target = expr->target; + Mark(target); + + auto* ident = target->identifier; + Mark(ident); // Resolve all of the arguments, their types and the set of behaviors. utils::Vector args; @@ -2023,9 +1921,9 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) { bool has_side_effects = std::any_of(args.begin(), args.end(), [](auto* e) { return e->HasSideEffects(); }); - // ct_init_or_conv is a helper for building either a sem::TypeInitializer or + // init_or_conv is a helper for building either a sem::TypeInitializer or // sem::TypeConversion call for a InitConvIntrinsic with an optional template argument type. - auto ct_init_or_conv = [&](InitConvIntrinsic ty, const type::Type* template_arg) -> sem::Call* { + auto init_or_conv = [&](InitConvIntrinsic ty, const type::Type* template_arg) -> sem::Call* { auto arg_tys = utils::Transform(args, [](auto* arg) { return arg->Type(); }); auto ctor_or_conv = intrinsic_table_->Lookup(ty, template_arg, arg_tys, args_stage, expr->source); @@ -2087,26 +1985,24 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) { current_statement_, value, has_side_effects); }; - // ty_init_or_conv is a helper for building either a sem::TypeInitializer or - // sem::TypeConversion call for the given semantic type. - auto ty_init_or_conv = [&](const type::Type* ty) { + auto ty_init_or_conv = [&](const type::Type* type) { return Switch( - ty, // - [&](const type::Vector* v) { - return ct_init_or_conv(VectorInitConvIntrinsic(v->Width()), v->type()); - }, - [&](const type::Matrix* m) { - return ct_init_or_conv(MatrixInitConvIntrinsic(m->columns(), m->rows()), m->type()); - }, - [&](const type::I32*) { return ct_init_or_conv(InitConvIntrinsic::kI32, nullptr); }, - [&](const type::U32*) { return ct_init_or_conv(InitConvIntrinsic::kU32, nullptr); }, + type, // + [&](const type::I32*) { return init_or_conv(InitConvIntrinsic::kI32, nullptr); }, + [&](const type::U32*) { return init_or_conv(InitConvIntrinsic::kU32, nullptr); }, [&](const type::F16*) { return validator_.CheckF16Enabled(expr->source) - ? ct_init_or_conv(InitConvIntrinsic::kF16, nullptr) + ? init_or_conv(InitConvIntrinsic::kF16, nullptr) : nullptr; }, - [&](const type::F32*) { return ct_init_or_conv(InitConvIntrinsic::kF32, nullptr); }, - [&](const type::Bool*) { return ct_init_or_conv(InitConvIntrinsic::kBool, nullptr); }, + [&](const type::F32*) { return init_or_conv(InitConvIntrinsic::kF32, nullptr); }, + [&](const type::Bool*) { return init_or_conv(InitConvIntrinsic::kBool, nullptr); }, + [&](const type::Vector* v) { + return init_or_conv(VectorInitConvIntrinsic(v->Width()), v->type()); + }, + [&](const type::Matrix* m) { + return init_or_conv(MatrixInitConvIntrinsic(m->columns(), m->rows()), m->type()); + }, [&](const type::Array* arr) -> sem::Call* { auto* call_target = array_inits_.GetOrCreate( ArrayInitializerSig{{arr, args.Length(), args_stage}}, @@ -2169,170 +2065,117 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) { }); }; - // ast::CallExpression has a target which is either an ast::Type or an - // ast::IdentifierExpression + auto inferred_array = [&]() -> tint::sem::Call* { + auto el_count = + builder_->create(static_cast(args.Length())); + auto arg_tys = utils::Transform(args, [](auto* arg) { return arg->Type()->UnwrapRef(); }); + auto el_ty = type::Type::Common(arg_tys); + if (!el_ty) { + AddError("cannot infer common array element type from initializer arguments", + expr->source); + utils::Hashset types; + for (size_t i = 0; i < args.Length(); i++) { + if (types.Add(args[i]->Type())) { + AddNote("argument " + std::to_string(i) + " is of type '" + + sem_.TypeNameOf(args[i]->Type()) + "'", + args[i]->Declaration()->source); + } + } + return nullptr; + } + auto* arr = Array(expr->source, expr->source, el_ty, el_count, /* explicit_stride */ 0); + if (!arr) { + return nullptr; + } + return ty_init_or_conv(arr); + }; + auto call = [&]() -> sem::Call* { - if (expr->target.type) { - // ast::CallExpression has an ast::Type as the target. - // This call is either a type initializer or type conversion. + auto resolved = dependencies_.resolved_identifiers.Get(ident); + if (!resolved) { + TINT_ICE(Resolver, diagnostics_) + << "identifier '" << builder_->Symbols().NameFor(ident->symbol) + << "' was not resolved"; + return nullptr; + } + + if (auto* ast_node = resolved->Node()) { return Switch( - expr->target.type, - [&](const ast::Vector* v) -> sem::Call* { - Mark(v); - // vector element type must be inferred if it was not specified. - type::Type* template_arg = nullptr; - if (v->type) { - template_arg = Type(v->type); - if (!template_arg) { - return nullptr; - } - } - if (auto* c = - ct_init_or_conv(VectorInitConvIntrinsic(v->width), template_arg)) { - builder_->Sem().Add(expr->target.type, c->Target()->ReturnType()); - return c; - } - return nullptr; - }, - [&](const ast::Matrix* m) -> sem::Call* { - Mark(m); - // matrix element type must be inferred if it was not specified. - type::Type* template_arg = nullptr; - if (m->type) { - template_arg = Type(m->type); - if (!template_arg) { - return nullptr; - } - } - if (auto* c = ct_init_or_conv(MatrixInitConvIntrinsic(m->columns, m->rows), - template_arg)) { - builder_->Sem().Add(expr->target.type, c->Target()->ReturnType()); - return c; - } - return nullptr; - }, - [&](const ast::Array* a) -> sem::Call* { - Mark(a); - // array element type must be inferred if it was not specified. - const type::ArrayCount* el_count = nullptr; - const type::Type* el_ty = nullptr; - if (a->type) { - el_ty = Type(a->type); - if (!el_ty) { - return nullptr; - } - if (!a->count) { - AddError("cannot construct a runtime-sized array", expr->source); - return nullptr; - } - el_count = ArrayCount(a->count); - if (!el_count) { - return nullptr; - } - // Note: validation later will detect any mismatches between explicit array - // size and number of initializer expressions. - } else { - el_count = builder_->create( - static_cast(args.Length())); - auto arg_tys = utils::Transform( - args, [](auto* arg) { return arg->Type()->UnwrapRef(); }); - el_ty = type::Type::Common(arg_tys); - if (!el_ty) { - AddError( - "cannot infer common array element type from initializer arguments", - expr->source); - utils::Hashset types; - for (size_t i = 0; i < args.Length(); i++) { - if (types.Add(args[i]->Type())) { - AddNote("argument " + std::to_string(i) + " is of type '" + - sem_.TypeNameOf(args[i]->Type()) + "'", - args[i]->Declaration()->source); - } - } - return nullptr; - } - } - uint32_t explicit_stride = 0; - if (!ArrayAttributes(a->attributes, el_ty, explicit_stride)) { - return nullptr; - } - - auto* arr = Array(a->type ? a->type->source : a->source, - a->count ? a->count->source : a->source, // - el_ty, el_count, explicit_stride); - if (!arr) { - return nullptr; - } - builder_->Sem().Add(a, arr); - - return ty_init_or_conv(arr); - }, - [&](const ast::Type* ast) -> sem::Call* { - // Handler for AST types that do not have an optional element type. - if (auto* ty = Type(ast)) { - return ty_init_or_conv(ty); - } + sem_.Get(ast_node), // + [&](type::Type* t) { return ty_init_or_conv(t); }, + [&](sem::Function* f) { return FunctionCall(expr, f, args, arg_behaviors); }, + [&](sem::Expression* e) { + sem_.ErrorUnexpectedExprKind(e, "call target"); return nullptr; }, [&](Default) { - TINT_ICE(Resolver, diagnostics_) - << expr->source << " unhandled CallExpression target:\n" - << "type: " - << (expr->target.type ? expr->target.type->TypeInfo().name : ""); + ErrorMismatchedResolvedIdentifier(ident->source, *resolved, "call target"); return nullptr; }); - } else { - // ast::CallExpression has an ast::IdentifierExpression as the target. - // This call is either a function call, builtin call, type initializer or type - // conversion. - auto* ident = expr->target.name; - Mark(ident); + } - auto resolved = dependencies_.resolved_identifiers.Get(ident); - if (!resolved) { - TINT_ICE(Resolver, diagnostics_) - << "identifier '" << builder_->Symbols().NameFor(ident->symbol) - << "' was not resolved"; + if (auto f = resolved->BuiltinFunction(); f != sem::BuiltinType::kNone) { + return BuiltinCall(expr, f, args); + } + + if (auto b = resolved->BuiltinType(); b != type::Builtin::kUndefined) { + if (!ident->Is()) { + // No template arguments provided. + // Check to see if this is an inferred-element-type call. + switch (b) { + case type::Builtin::kArray: + return inferred_array(); + case type::Builtin::kVec2: + return init_or_conv(InitConvIntrinsic::kVec2, nullptr); + case type::Builtin::kVec3: + return init_or_conv(InitConvIntrinsic::kVec3, nullptr); + case type::Builtin::kVec4: + return init_or_conv(InitConvIntrinsic::kVec4, nullptr); + case type::Builtin::kMat2X2: + return init_or_conv(InitConvIntrinsic::kMat2x2, nullptr); + case type::Builtin::kMat2X3: + return init_or_conv(InitConvIntrinsic::kMat2x3, nullptr); + case type::Builtin::kMat2X4: + return init_or_conv(InitConvIntrinsic::kMat2x4, nullptr); + case type::Builtin::kMat3X2: + return init_or_conv(InitConvIntrinsic::kMat3x2, nullptr); + case type::Builtin::kMat3X3: + return init_or_conv(InitConvIntrinsic::kMat3x3, nullptr); + case type::Builtin::kMat3X4: + return init_or_conv(InitConvIntrinsic::kMat3x4, nullptr); + case type::Builtin::kMat4X2: + return init_or_conv(InitConvIntrinsic::kMat4x2, nullptr); + case type::Builtin::kMat4X3: + return init_or_conv(InitConvIntrinsic::kMat4x3, nullptr); + case type::Builtin::kMat4X4: + return init_or_conv(InitConvIntrinsic::kMat4x4, nullptr); + default: + break; + } + } + auto* ty = BuiltinType(b, ident); + if (TINT_UNLIKELY(!ty)) { return nullptr; } - - if (auto* ast_node = resolved->Node()) { - return Switch( - sem_.Get(ast_node), // - [&](const type::Type* ty) { - // A type initializer or conversions. - // Note: Unlike the code path where we're resolving the call target from an - // ast::Type, all types must already have the element type explicitly - // specified, so there's no need to infer element types. - return ty_init_or_conv(ty); - }, - [&](sem::Function* func) { - return FunctionCall(expr, func, args, arg_behaviors); - }, - [&](Default) { - ErrorMismatchedResolvedIdentifier(ident->source, *resolved, "call target"); - return nullptr; - }); - } - - if (auto f = resolved->BuiltinFunction(); f != sem::BuiltinType::kNone) { - return BuiltinCall(expr, f, args); - } - - if (auto b = resolved->BuiltinType(); b != type::Builtin::kUndefined) { - auto* ty = BuiltinType(b, expr->target.name); - return ty ? ty_init_or_conv(ty) : nullptr; - } - - ErrorMismatchedResolvedIdentifier(ident->source, *resolved, "call target"); - return nullptr; + return ty_init_or_conv(ty); } + + ErrorMismatchedResolvedIdentifier(ident->source, *resolved, "call target"); + return nullptr; }(); if (!call) { return nullptr; } + if (call->Target()->IsAnyOf()) { + // The target of the call was a type. + // Associate the target identifier expression with the resolved type. + auto* ty_expr = + builder_->create(target, current_statement_, call->Type()); + builder_->Sem().Add(target, ty_expr); + } + return validator_.Call(call, current_statement_) ? call : nullptr; } @@ -2444,32 +2287,224 @@ type::Type* Resolver::BuiltinType(type::Builtin builtin_ty, const ast::Identifie auto f16 = [&] { return validator_.CheckF16Enabled(ident->source) ? b.create() : nullptr; }; - auto vec = [&](type::Type* el, uint32_t n) { - return el ? b.create(el, n) : nullptr; - }; - auto mat = [&](type::Type* el, uint32_t num_columns, uint32_t num_rows) { - return el ? b.create(vec(el, num_rows), num_columns) : nullptr; - }; - auto templated_identifier = [&](size_t num_args) -> const ast::TemplatedIdentifier* { + auto templated_identifier = + [&](size_t min_args, size_t max_args = /* use min */ 0) -> const ast::TemplatedIdentifier* { + if (max_args == 0) { + max_args = min_args; + } auto* tmpl_ident = ident->As(); - if (TINT_UNLIKELY(!tmpl_ident)) { - AddError("expected '<' for '" + b.Symbols().NameFor(ident->symbol) + "'", - Source{ident->source.range.end}); + if (!tmpl_ident) { + if (TINT_UNLIKELY(min_args != 0)) { + AddError("expected '<' for '" + b.Symbols().NameFor(ident->symbol) + "'", + Source{ident->source.range.end}); + } return nullptr; } - if (TINT_UNLIKELY(tmpl_ident->arguments.Length() != num_args)) { - AddError("'" + b.Symbols().NameFor(ident->symbol) + "' requires " + - std::to_string(num_args) + " template arguments", - ident->source); - return nullptr; + if (min_args == max_args) { + if (TINT_UNLIKELY(tmpl_ident->arguments.Length() != min_args)) { + AddError("'" + b.Symbols().NameFor(ident->symbol) + "' requires " + + std::to_string(min_args) + " template arguments", + ident->source); + return nullptr; + } + } else { + if (TINT_UNLIKELY(tmpl_ident->arguments.Length() < min_args)) { + AddError("'" + b.Symbols().NameFor(ident->symbol) + "' requires at least " + + std::to_string(min_args) + " template arguments", + ident->source); + return nullptr; + } + if (TINT_UNLIKELY(tmpl_ident->arguments.Length() > max_args)) { + AddError("'" + b.Symbols().NameFor(ident->symbol) + "' requires at most " + + std::to_string(max_args) + " template arguments", + ident->source); + return nullptr; + } } return tmpl_ident; }; + auto vec = [&](type::Type* el, uint32_t n) -> type::Vector* { + if (TINT_UNLIKELY(!el)) { + return nullptr; + } + if (TINT_UNLIKELY(!validator_.Vector(el, ident->source))) { + return nullptr; + } + return b.create(el, n); + }; + auto mat = [&](type::Type* el, uint32_t num_columns, uint32_t num_rows) -> type::Matrix* { + if (TINT_UNLIKELY(!el)) { + return nullptr; + } + if (TINT_UNLIKELY(!validator_.Matrix(el, ident->source))) { + return nullptr; + } + auto* column = vec(el, num_rows); + if (!column) { + return nullptr; + } + return b.create(column, num_columns); + }; + auto vec_t = [&](uint32_t n) -> type::Vector* { + auto* tmpl_ident = templated_identifier(1); + if (TINT_UNLIKELY(!tmpl_ident)) { + return nullptr; + } + auto* ty = Type(tmpl_ident->arguments[0]); + if (TINT_UNLIKELY(!ty)) { + return nullptr; + } + return vec(const_cast(ty), n); + }; + auto mat_t = [&](uint32_t num_columns, uint32_t num_rows) -> type::Matrix* { + auto* tmpl_ident = templated_identifier(1); + if (TINT_UNLIKELY(!tmpl_ident)) { + return nullptr; + } + auto* ty = Type(tmpl_ident->arguments[0]); + if (TINT_UNLIKELY(!ty)) { + return nullptr; + } + return mat(const_cast(ty), num_columns, num_rows); + }; + auto array = [&]() -> type::Array* { + utils::UniqueVector transitively_referenced_overrides; + TINT_SCOPED_ASSIGNMENT(resolved_overrides_, &transitively_referenced_overrides); + + auto* tmpl_ident = templated_identifier(1, 2); + if (TINT_UNLIKELY(!tmpl_ident)) { + return nullptr; + } + auto* ast_el_ty = tmpl_ident->arguments[0]; + auto* ast_count = (tmpl_ident->arguments.Length() > 1) ? tmpl_ident->arguments[1] : nullptr; + + auto* el_ty = Type(ast_el_ty); + if (!el_ty) { + return nullptr; + } + + const type::ArrayCount* el_count = + ast_count ? ArrayCount(ast_count) : builder_->create(); + if (!el_count) { + return nullptr; + } + + // Look for explicit stride via @stride(n) attribute + uint32_t explicit_stride = 0; + if (!ArrayAttributes(tmpl_ident->attributes, el_ty, explicit_stride)) { + return nullptr; + } + + auto* out = Array(ast_el_ty->source, // + ast_count ? ast_count->source : ident->source, // + el_ty, el_count, explicit_stride); + if (!out) { + return nullptr; + } + + if (el_ty->Is()) { + atomic_composite_info_.Add(out, &ast_el_ty->source); + } else { + if (auto found = atomic_composite_info_.Get(el_ty)) { + atomic_composite_info_.Add(out, *found); + } + } + + // Track the pipeline-overridable constants that are transitively referenced by this + // array type. + for (auto* var : transitively_referenced_overrides) { + builder_->Sem().AddTransitivelyReferencedOverride(out, var); + } + return out; + }; + auto atomic = [&]() -> type::Atomic* { + auto* tmpl_ident = templated_identifier(1); // atomic + if (TINT_UNLIKELY(!tmpl_ident)) { + return nullptr; + } + + auto* ty_expr = TypeExpression(tmpl_ident->arguments[0]); + if (TINT_UNLIKELY(!ty_expr)) { + return nullptr; + } + auto* ty = ty_expr->Type(); + + auto* out = builder_->create(ty); + if (!validator_.Atomic(tmpl_ident, out)) { + return nullptr; + } + return out; + }; + auto ptr = [&]() -> type::Pointer* { + auto* tmpl_ident = templated_identifier(2, 3); // ptr + if (TINT_UNLIKELY(!tmpl_ident)) { + return nullptr; + } + + auto* address_space_expr = AddressSpaceExpression(tmpl_ident->arguments[0]); + if (TINT_UNLIKELY(!address_space_expr)) { + return nullptr; + } + auto address_space = address_space_expr->Value(); + + auto* store_ty_expr = TypeExpression(tmpl_ident->arguments[1]); + if (TINT_UNLIKELY(!store_ty_expr)) { + return nullptr; + } + auto* store_ty = const_cast(store_ty_expr->Type()); + + auto access = DefaultAccessForAddressSpace(address_space); + if (tmpl_ident->arguments.Length() > 2) { + auto* access_expr = AccessExpression(tmpl_ident->arguments[2]); + if (TINT_UNLIKELY(!access_expr)) { + return nullptr; + } + access = access_expr->Value(); + } + + auto* out = b.create(store_ty, address_space, access); + if (!validator_.Pointer(tmpl_ident, out)) { + return nullptr; + } + if (!ApplyAddressSpaceUsageToType(address_space, store_ty, + store_ty_expr->Declaration()->source)) { + AddNote("while instantiating " + builder_->FriendlyName(out), ident->source); + return nullptr; + } + return out; + }; + auto sampled_texture = [&](type::TextureDimension dim) -> type::SampledTexture* { + auto* tmpl_ident = templated_identifier(1); + if (TINT_UNLIKELY(!tmpl_ident)) { + return nullptr; + } + + auto* ty_expr = TypeExpression(tmpl_ident->arguments[0]); + if (TINT_UNLIKELY(!ty_expr)) { + return nullptr; + } + auto* out = b.create(dim, ty_expr->Type()); + return validator_.SampledTexture(out, ident->source) ? out : nullptr; + }; + auto multisampled_texture = [&](type::TextureDimension dim) -> type::MultisampledTexture* { + auto* tmpl_ident = templated_identifier(1); + if (TINT_UNLIKELY(!tmpl_ident)) { + return nullptr; + } + + auto* ty_expr = TypeExpression(tmpl_ident->arguments[0]); + if (TINT_UNLIKELY(!ty_expr)) { + return nullptr; + } + auto* out = b.create(dim, ty_expr->Type()); + return validator_.MultisampledTexture(out, ident->source) ? out : nullptr; + }; auto storage_texture = [&](type::TextureDimension dim) -> type::StorageTexture* { auto* tmpl_ident = templated_identifier(2); if (TINT_UNLIKELY(!tmpl_ident)) { return nullptr; } + auto* format = sem_.AsTexelFormat(Expression(tmpl_ident->arguments[0])); if (TINT_UNLIKELY(!format)) { return nullptr; @@ -2497,6 +2532,30 @@ type::Type* Resolver::BuiltinType(type::Builtin builtin_ty, const ast::Identifie return check_no_tmpl_args(f16()); case type::Builtin::kF32: return check_no_tmpl_args(b.create()); + case type::Builtin::kVec2: + return vec_t(2); + case type::Builtin::kVec3: + return vec_t(3); + case type::Builtin::kVec4: + return vec_t(4); + case type::Builtin::kMat2X2: + return mat_t(2, 2); + case type::Builtin::kMat2X3: + return mat_t(2, 3); + case type::Builtin::kMat2X4: + return mat_t(2, 4); + case type::Builtin::kMat3X2: + return mat_t(3, 2); + case type::Builtin::kMat3X3: + return mat_t(3, 3); + case type::Builtin::kMat3X4: + return mat_t(3, 4); + case type::Builtin::kMat4X2: + return mat_t(4, 2); + case type::Builtin::kMat4X3: + return mat_t(4, 3); + case type::Builtin::kMat4X4: + return mat_t(4, 4); case type::Builtin::kMat2X2F: return check_no_tmpl_args(mat(f32(), 2u, 2u)); case type::Builtin::kMat2X3F: @@ -2557,11 +2616,29 @@ type::Type* Resolver::BuiltinType(type::Builtin builtin_ty, const ast::Identifie return check_no_tmpl_args(vec(u32(), 3u)); case type::Builtin::kVec4U: return check_no_tmpl_args(vec(u32(), 4u)); + case type::Builtin::kArray: + return array(); + case type::Builtin::kAtomic: + return atomic(); + case type::Builtin::kPtr: + return ptr(); case type::Builtin::kSampler: return check_no_tmpl_args(builder_->create(type::SamplerKind::kSampler)); case type::Builtin::kSamplerComparison: return check_no_tmpl_args( builder_->create(type::SamplerKind::kComparisonSampler)); + case type::Builtin::kTexture1D: + return sampled_texture(type::TextureDimension::k1d); + case type::Builtin::kTexture2D: + return sampled_texture(type::TextureDimension::k2d); + case type::Builtin::kTexture2DArray: + return sampled_texture(type::TextureDimension::k2dArray); + case type::Builtin::kTexture3D: + return sampled_texture(type::TextureDimension::k3d); + case type::Builtin::kTextureCube: + return sampled_texture(type::TextureDimension::kCube); + case type::Builtin::kTextureCubeArray: + return sampled_texture(type::TextureDimension::kCubeArray); case type::Builtin::kTextureDepth2D: return check_no_tmpl_args( builder_->create(type::TextureDimension::k2d)); @@ -2579,6 +2656,8 @@ type::Type* Resolver::BuiltinType(type::Builtin builtin_ty, const ast::Identifie builder_->create(type::TextureDimension::k2d)); case type::Builtin::kTextureExternal: return check_no_tmpl_args(builder_->create()); + case type::Builtin::kTextureMultisampled2D: + return multisampled_texture(type::TextureDimension::k2d); case type::Builtin::kTextureStorage1D: return storage_texture(type::TextureDimension::k1d); case type::Builtin::kTextureStorage2D: @@ -2626,9 +2705,6 @@ sem::Call* Resolver::FunctionCall(const ast::CallExpression* expr, sem::Function* target, utils::Vector& args, sem::Behaviors arg_behaviors) { - auto sym = expr->target.name->symbol; - auto name = builder_->Symbols().NameFor(sym); - if (!MaybeMaterializeAndLoadArguments(args, target)) { return nullptr; } @@ -2671,6 +2747,11 @@ sem::Call* Resolver::FunctionCall(const ast::CallExpression* expr, CollectTextureSamplerPairs(target, call->Arguments()); } + // Associate the target identifier expression with the resolved function. + auto* fn_expr = + builder_->create(expr->target, current_statement_, target); + builder_->Sem().Add(expr->target, fn_expr); + return call; } @@ -2758,13 +2839,13 @@ sem::ValueExpression* Resolver::Literal(const ast::LiteralExpression* literal) { } sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) { - Mark(expr->identifier); + auto* ident = expr->identifier; + Mark(ident); - auto resolved = dependencies_.resolved_identifiers.Get(expr->identifier); + auto resolved = dependencies_.resolved_identifiers.Get(ident); if (!resolved) { TINT_ICE(Resolver, diagnostics_) - << "identifier '" << builder_->Symbols().NameFor(expr->identifier->symbol) - << "' was not resolved"; + << "identifier '" << builder_->Symbols().NameFor(ident->symbol) << "' was not resolved"; return nullptr; } @@ -2773,7 +2854,7 @@ sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) { return Switch( resolved_node, // [&](sem::Variable* variable) -> sem::VariableUser* { - auto symbol = expr->identifier->symbol; + auto symbol = ident->symbol; auto* user = builder_->create(expr, current_statement_, variable); @@ -2844,17 +2925,32 @@ sem::Expression* Resolver::Identifier(const ast::IdentifierExpression* expr) { variable->AddUser(user); return user; }, - [&](const type::Type* ty) { + [&](const type::Type* ty) -> sem::TypeExpression* { + if (TINT_UNLIKELY(ident->Is())) { + AddError("type '" + builder_->Symbols().NameFor(ident->symbol) + + "' does not take template arguments", + ident->source); + sem_.NoteDeclarationSource(ast_node); + return nullptr; + } + return builder_->create(expr, current_statement_, ty); }, - [&](const sem::Function*) { - AddError("missing '(' for function call", expr->source.End()); - return nullptr; + [&](const sem::Function* fn) -> sem::FunctionExpression* { + if (TINT_UNLIKELY(ident->Is())) { + AddError("function '" + builder_->Symbols().NameFor(ident->symbol) + + "' does not take template arguments", + ident->source); + sem_.NoteDeclarationSource(ast_node); + return nullptr; + } + + return builder_->create(expr, current_statement_, fn); }); } if (auto builtin_ty = resolved->BuiltinType(); builtin_ty != type::Builtin::kUndefined) { - auto* ty = BuiltinType(builtin_ty, expr->identifier); + auto* ty = BuiltinType(builtin_ty, ident); if (!ty) { return nullptr; } @@ -3237,62 +3333,6 @@ type::Type* Resolver::TypeDecl(const ast::TypeDecl* named_type) { return result; } -type::Array* Resolver::Array(const ast::Array* arr) { - if (!arr->type) { - AddError("missing array element type", arr->source.End()); - return nullptr; - } - - utils::UniqueVector transitively_referenced_overrides; - TINT_SCOPED_ASSIGNMENT(resolved_overrides_, &transitively_referenced_overrides); - - auto* el_ty = Type(arr->type); - if (!el_ty) { - return nullptr; - } - - // Look for explicit stride via @stride(n) attribute - uint32_t explicit_stride = 0; - if (!ArrayAttributes(arr->attributes, el_ty, explicit_stride)) { - return nullptr; - } - - const type::ArrayCount* el_count = nullptr; - - // Evaluate the constant array count expression. - if (auto* count_expr = arr->count) { - el_count = ArrayCount(count_expr); - if (!el_count) { - return nullptr; - } - } else { - el_count = builder_->create(); - } - - auto* out = Array(arr->type->source, // - arr->count ? arr->count->source : arr->source, // - el_ty, el_count, explicit_stride); - if (out == nullptr) { - return nullptr; - } - - if (el_ty->Is()) { - atomic_composite_info_.Add(out, &arr->type->source); - } else { - if (auto found = atomic_composite_info_.Get(el_ty)) { - atomic_composite_info_.Add(out, *found); - } - } - - // Track the pipeline-overridable constants that are transitively referenced by this array - // type. - for (auto* var : transitively_referenced_overrides) { - builder_->Sem().AddTransitivelyReferencedOverride(out, var); - } - - return out; -} - const type::ArrayCount* Resolver::ArrayCount(const ast::Expression* count_expr) { // Evaluate the constant array count expression. const auto* count_sem = Materialize(ValueExpression(count_expr)); @@ -3442,7 +3482,7 @@ sem::Struct* Resolver::Structure(const ast::Struct* str) { } // Resolve member type - auto* type = Type(member->type); + auto type = Type(member->type); if (!type) { return nullptr; } @@ -4074,45 +4114,7 @@ void Resolver::ErrorMismatchedResolvedIdentifier(const Source& source, AddError("cannot use " + resolved.String(builder_->Symbols(), diagnostics_) + " as " + std::string(wanted), source); - NoteDeclarationSource(resolved.Node()); -} - -void Resolver::NoteDeclarationSource(const ast::Node* node) { - Switch( - node, - [&](const ast::Struct* n) { - AddNote("struct '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", - n->source); - }, - [&](const ast::Alias* n) { - AddNote("alias '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", - n->source); - }, - [&](const ast::Var* n) { - AddNote("var '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", - n->source); - }, - [&](const ast::Let* n) { - AddNote("let '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", - n->source); - }, - [&](const ast::Override* n) { - AddNote("override '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", - n->source); - }, - [&](const ast::Const* n) { - AddNote("const '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", - n->source); - }, - [&](const ast::Parameter* n) { - AddNote( - "parameter '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", - n->source); - }, - [&](const ast::Function* n) { - AddNote("function '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", - n->source); - }); + sem_.NoteDeclarationSource(resolved.Node()); } void Resolver::AddError(const std::string& msg, const Source& source) const { diff --git a/src/tint/resolver/resolver.h b/src/tint/resolver/resolver.h index bc8821a576..c5223db3d6 100644 --- a/src/tint/resolver/resolver.h +++ b/src/tint/resolver/resolver.h @@ -126,7 +126,36 @@ class Resolver { /// not a sem::ValueExpression, then an error diagnostic is raised and nullptr is returned. sem::ValueExpression* ValueExpression(const ast::Expression* expr); - /// Expression traverses the graph of expressions starting at `expr`, building a postordered + /// @returns the call of Expression() cast to a sem::TypeExpression. If the sem::Expression is + /// not a sem::TypeExpression, then an error diagnostic is raised and nullptr is returned. + sem::TypeExpression* TypeExpression(const ast::Expression* expr); + + /// @returns the call of Expression() cast to a sem::FunctionExpression. If the sem::Expression + /// is not a sem::FunctionExpression, then an error diagnostic is raised and nullptr is + /// returned. + sem::FunctionExpression* FunctionExpression(const ast::Expression* expr); + + /// @returns the resolved type from an expression, or nullptr on error + type::Type* Type(const ast::Expression* ast); + + /// @returns the call of Expression() cast to a sem::BuiltinEnumExpression. + /// If the sem::Expression is not a sem::BuiltinEnumExpression, then an + /// error diagnostic is raised and nullptr is returned. + sem::BuiltinEnumExpression* AddressSpaceExpression( + const ast::Expression* expr); + + /// @returns the call of Expression() cast to a sem::BuiltinEnumExpression. + /// If the sem::Expression is not a sem::BuiltinEnumExpression, then an error + /// diagnostic is raised and nullptr is returned. + sem::BuiltinEnumExpression* TexelFormatExpression( + const ast::Expression* expr); + + /// @returns the call of Expression() cast to a sem::BuiltinEnumExpression*. + /// If the sem::Expression is not a sem::BuiltinEnumExpression*, then an error + /// diagnostic is raised and nullptr is returned. + sem::BuiltinEnumExpression* AccessExpression(const ast::Expression* expr); + + /// Expression traverses the graph of expressions starting at `expr`, building a post-ordered /// list (leaf-first) of all the expression nodes. Each of the expressions are then resolved by /// dispatching to the appropriate expression handlers below. /// @returns the resolved semantic node for the expression `expr`, or nullptr on failure. @@ -259,12 +288,6 @@ class Resolver { /// current_function_ bool WorkgroupSize(const ast::Function*); - /// @returns the type::Type for the ast::Type `ty`, building it if it - /// hasn't been constructed already. If an error is raised, nullptr is - /// returned. - /// @param ty the ast::Type - type::Type* Type(const ast::Type* ty); - /// @param control the diagnostic control /// @returns true on success, false on failure bool DiagnosticControl(const ast::DiagnosticControl& control); @@ -277,13 +300,6 @@ class Resolver { /// @returns the resolved semantic type type::Type* TypeDecl(const ast::TypeDecl* named_type); - /// Builds and returns the semantic information for the AST array `arr`. - /// This method does not mark the ast::Array node, nor attach the generated semantic information - /// to the AST node. - /// @returns the semantic Array information, or nullptr if an error is raised. - /// @param arr the Array to get semantic information for - type::Array* Array(const ast::Array* arr); - /// Resolves and validates the expression used as the count parameter of an array. /// @param count_expr the expression used as the second template parameter to an array<>. /// @returns the number of elements in the array. @@ -432,11 +448,6 @@ class Resolver { const ResolvedIdentifier& resolved, std::string_view wanted); - /// If @p node is a module-scope type, variable or function declaration, then appends a note - /// diagnostic where this declaration was declared, otherwise the function does nothing. - /// @param node the AST node. - void NoteDeclarationSource(const ast::Node* node); - /// Adds the given error message to the diagnostics void AddError(const std::string& msg, const Source& source) const; diff --git a/src/tint/resolver/resolver_behavior_test.cc b/src/tint/resolver/resolver_behavior_test.cc index af69c3c6e8..bc4af42fd7 100644 --- a/src/tint/resolver/resolver_behavior_test.cc +++ b/src/tint/resolver/resolver_behavior_test.cc @@ -82,7 +82,7 @@ TEST_F(ResolverBehaviorTest, ExprIndex_Arr) { Func("ArrayDiscardOrNext", utils::Empty, ty.array(), utils::Vector{ If(true, Block(Discard())), - Return(Call(ty.array())), + Return(array()), }); auto* stmt = Decl(Var("lhs", ty.i32(), IndexAccessor(Call("ArrayDiscardOrNext"), 1_i))); diff --git a/src/tint/resolver/resolver_test.cc b/src/tint/resolver/resolver_test.cc index 0630eb92c9..3d327998d6 100644 --- a/src/tint/resolver/resolver_test.cc +++ b/src/tint/resolver/resolver_test.cc @@ -1641,8 +1641,8 @@ using Expr_Binary_Test_Valid = ResolverTestWithParam; TEST_P(Expr_Binary_Test_Valid, All) { auto& params = GetParam(); - auto* lhs_type = params.create_lhs_type(*this); - auto* rhs_type = params.create_rhs_type(*this); + ast::Type lhs_type = params.create_lhs_type(*this); + ast::Type rhs_type = params.create_rhs_type(*this); auto* result_type = params.create_result_type(*this); std::stringstream ss; @@ -1674,8 +1674,8 @@ TEST_P(Expr_Binary_Test_WithAlias_Valid, All) { ? params.create_rhs_alias_type : params.create_rhs_type; - auto* lhs_type = create_lhs_type(*this); - auto* rhs_type = create_rhs_type(*this); + ast::Type lhs_type = create_lhs_type(*this); + ast::Type rhs_type = create_rhs_type(*this); std::stringstream ss; ss << FriendlyName(lhs_type) << " " << params.op << " " << FriendlyName(rhs_type); @@ -1723,8 +1723,8 @@ TEST_P(Expr_Binary_Test_Invalid, All) { } } - auto* lhs_type = lhs_create_type_func(*this); - auto* rhs_type = rhs_create_type_func(*this); + ast::Type lhs_type = lhs_create_type_func(*this); + ast::Type rhs_type = rhs_create_type_func(*this); std::stringstream ss; ss << FriendlyName(lhs_type) << " " << op << " " << FriendlyName(rhs_type); @@ -1753,8 +1753,8 @@ TEST_P(Expr_Binary_Test_Invalid_VectorMatrixMultiply, All) { uint32_t mat_rows = std::get<2>(GetParam()); uint32_t mat_cols = std::get<3>(GetParam()); - const ast::Type* lhs_type = nullptr; - const ast::Type* rhs_type = nullptr; + ast::Type lhs_type; + ast::Type rhs_type; const type::Type* result_type = nullptr; bool is_valid_expr; @@ -1800,8 +1800,8 @@ TEST_P(Expr_Binary_Test_Invalid_MatrixMatrixMultiply, All) { uint32_t rhs_mat_rows = std::get<2>(GetParam()); uint32_t rhs_mat_cols = std::get<3>(GetParam()); - auto* lhs_type = ty.mat(lhs_mat_cols, lhs_mat_rows); - auto* rhs_type = ty.mat(rhs_mat_cols, rhs_mat_rows); + auto lhs_type = ty.mat(lhs_mat_cols, lhs_mat_rows); + auto rhs_type = ty.mat(rhs_mat_cols, rhs_mat_rows); auto* f32 = create(); auto* col = create(f32, lhs_mat_rows); @@ -1876,7 +1876,7 @@ TEST_F(ResolverTest, AddressSpace_SetsIfMissing) { } TEST_F(ResolverTest, AddressSpace_SetForSampler) { - auto* t = ty.sampler(type::SamplerKind::kSampler); + auto t = ty.sampler(type::SamplerKind::kSampler); auto* var = GlobalVar("var", t, Binding(0_a), Group(0_a)); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -1885,7 +1885,7 @@ TEST_F(ResolverTest, AddressSpace_SetForSampler) { } TEST_F(ResolverTest, AddressSpace_SetForTexture) { - auto* t = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); + auto t = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); auto* var = GlobalVar("var", t, Binding(0_a), Group(0_a)); EXPECT_TRUE(r()->Resolve()) << r()->error(); diff --git a/src/tint/resolver/resolver_test_helper.h b/src/tint/resolver/resolver_test_helper.h index ee913f462e..67d71b8772 100644 --- a/src/tint/resolver/resolver_test_helper.h +++ b/src/tint/resolver/resolver_test_helper.h @@ -112,7 +112,7 @@ class TestHelper : public ProgramBuilder { /// @param type a type /// @returns the name for `type` that closely resembles how it would be /// declared in WGSL. - std::string FriendlyName(const ast::Type* type) { return type->FriendlyName(Symbols()); } + std::string FriendlyName(ast::Type type) { return Symbols().NameFor(type->identifier->symbol); } /// @param type a type /// @returns the name for `type` that closely resembles how it would be @@ -199,7 +199,7 @@ T As(const Scalar& s) { return std::visit([](auto&& v) { return static_cast(v); }, s); } -using ast_type_func_ptr = const ast::Type* (*)(ProgramBuilder& b); +using ast_type_func_ptr = ast::Type (*)(ProgramBuilder& b); using ast_expr_func_ptr = const ast::Expression* (*)(ProgramBuilder& b, utils::VectorRef args); using ast_expr_from_double_func_ptr = const ast::Expression* (*)(ProgramBuilder& b, double v); @@ -222,7 +222,7 @@ struct DataType { using ElementType = void; /// @return nullptr - static inline const ast::Type* AST(ProgramBuilder&) { return nullptr; } + static inline ast::Type AST(ProgramBuilder&) { return {}; } /// @return nullptr static inline const type::Type* Sem(ProgramBuilder&) { return nullptr; } }; @@ -238,7 +238,7 @@ struct DataType { /// @param b the ProgramBuilder /// @return a new AST bool type - static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.bool_(); } + static inline ast::Type AST(ProgramBuilder& b) { return b.ty.bool_(); } /// @param b the ProgramBuilder /// @return the semantic bool type static inline const type::Type* Sem(ProgramBuilder& b) { return b.create(); } @@ -269,7 +269,7 @@ struct DataType { /// @param b the ProgramBuilder /// @return a new AST i32 type - static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.i32(); } + static inline ast::Type AST(ProgramBuilder& b) { return b.ty.i32(); } /// @param b the ProgramBuilder /// @return the semantic i32 type static inline const type::Type* Sem(ProgramBuilder& b) { return b.create(); } @@ -300,7 +300,7 @@ struct DataType { /// @param b the ProgramBuilder /// @return a new AST u32 type - static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.u32(); } + static inline ast::Type AST(ProgramBuilder& b) { return b.ty.u32(); } /// @param b the ProgramBuilder /// @return the semantic u32 type static inline const type::Type* Sem(ProgramBuilder& b) { return b.create(); } @@ -331,7 +331,7 @@ struct DataType { /// @param b the ProgramBuilder /// @return a new AST f32 type - static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.f32(); } + static inline ast::Type AST(ProgramBuilder& b) { return b.ty.f32(); } /// @param b the ProgramBuilder /// @return the semantic f32 type static inline const type::Type* Sem(ProgramBuilder& b) { return b.create(); } @@ -362,7 +362,7 @@ struct DataType { /// @param b the ProgramBuilder /// @return a new AST f16 type - static inline const ast::Type* AST(ProgramBuilder& b) { return b.ty.f16(); } + static inline ast::Type AST(ProgramBuilder& b) { return b.ty.f16(); } /// @param b the ProgramBuilder /// @return the semantic f16 type static inline const type::Type* Sem(ProgramBuilder& b) { return b.create(); } @@ -392,7 +392,7 @@ struct DataType { static constexpr bool is_composite = false; /// @returns nullptr, as abstract floats are un-typeable - static inline const ast::Type* AST(ProgramBuilder&) { return nullptr; } + static inline ast::Type AST(ProgramBuilder&) { return {}; } /// @param b the ProgramBuilder /// @return the semantic abstract-float type static inline const type::Type* Sem(ProgramBuilder& b) { @@ -424,7 +424,7 @@ struct DataType { static constexpr bool is_composite = false; /// @returns nullptr, as abstract integers are un-typeable - static inline const ast::Type* AST(ProgramBuilder&) { return nullptr; } + static inline ast::Type AST(ProgramBuilder&) { return {}; } /// @param b the ProgramBuilder /// @return the semantic abstract-int type static inline const type::Type* Sem(ProgramBuilder& b) { return b.create(); } @@ -455,8 +455,12 @@ struct DataType> { /// @param b the ProgramBuilder /// @return a new AST vector type - static inline const ast::Type* AST(ProgramBuilder& b) { - return b.ty.vec(DataType::AST(b), N); + static inline ast::Type AST(ProgramBuilder& b) { + if (IsInferOrAbstract) { + return b.ty.vec(); + } else { + return b.ty.vec(DataType::AST(b), N); + } } /// @param b the ProgramBuilder /// @return the semantic vector type @@ -503,8 +507,12 @@ struct DataType> { /// @param b the ProgramBuilder /// @return a new AST matrix type - static inline const ast::Type* AST(ProgramBuilder& b) { - return b.ty.mat(DataType::AST(b), N, M); + static inline ast::Type AST(ProgramBuilder& b) { + if (IsInferOrAbstract) { + return b.ty.mat(); + } else { + return b.ty.mat(DataType::AST(b), N, M); + } } /// @param b the ProgramBuilder /// @return the semantic matrix type @@ -562,14 +570,15 @@ struct DataType> { /// @param b the ProgramBuilder /// @return a new AST alias type - static inline const ast::Type* AST(ProgramBuilder& b) { + static inline ast::Type AST(ProgramBuilder& b) { auto name = b.Symbols().Register("alias_" + std::to_string(ID)); if (!b.AST().LookupType(name)) { - auto* type = DataType::AST(b); + auto type = DataType::AST(b); b.AST().AddTypeDecl(b.ty.alias(name, type)); } return b.ty(name); } + /// @param b the ProgramBuilder /// @return the semantic aliased type static inline const type::Type* Sem(ProgramBuilder& b) { return DataType::Sem(b); } @@ -618,9 +627,9 @@ struct DataType> { /// @param b the ProgramBuilder /// @return a new AST alias type - static inline const ast::Type* AST(ProgramBuilder& b) { - return b.create(DataType::AST(b), type::AddressSpace::kPrivate, - type::Access::kUndefined); + static inline ast::Type AST(ProgramBuilder& b) { + return b.ty.pointer(DataType::AST(b), type::AddressSpace::kPrivate, + type::Access::kUndefined); } /// @param b the ProgramBuilder /// @return the semantic aliased type @@ -660,11 +669,11 @@ struct DataType> { /// @param b the ProgramBuilder /// @return a new AST array type - static inline const ast::Type* AST(ProgramBuilder& b) { - if (auto* ast = DataType::AST(b)) { + static inline ast::Type AST(ProgramBuilder& b) { + if (auto ast = DataType::AST(b)) { return b.ty.array(ast, u32(N)); } - return b.ty.array(nullptr, nullptr); + return b.ty.array(); } /// @param b the ProgramBuilder /// @return the semantic array type diff --git a/src/tint/resolver/sem_helper.cc b/src/tint/resolver/sem_helper.cc index e2887072a6..01a737cae5 100644 --- a/src/tint/resolver/sem_helper.cc +++ b/src/tint/resolver/sem_helper.cc @@ -15,6 +15,8 @@ #include "src/tint/resolver/sem_helper.h" #include "src/tint/sem/builtin_enum_expression.h" +#include "src/tint/sem/function.h" +#include "src/tint/sem/function_expression.h" #include "src/tint/sem/type_expression.h" #include "src/tint/sem/value_expression.h" @@ -42,11 +44,18 @@ void SemHelper::ErrorUnexpectedExprKind(const sem::Expression* expr, Switch( expr, // [&](const sem::VariableUser* var_expr) { - auto name = - builder_->Symbols().NameFor(var_expr->Variable()->Declaration()->name->symbol); - auto type = var_expr->Type()->FriendlyName(builder_->Symbols()); - AddError("cannot use '" + name + "' of type '" + type + "' as " + std::string(wanted), + auto* variable = var_expr->Variable()->Declaration(); + auto name = builder_->Symbols().NameFor(variable->name->symbol); + std::string kind = Switch( + variable, // + [&](const ast::Var*) { return "var"; }, // + [&](const ast::Const*) { return "const"; }, // + [&](const ast::Parameter*) { return "parameter"; }, // + [&](const ast::Override*) { return "override"; }, // + [&](Default) { return "variable"; }); + AddError("cannot use " + kind + " '" + name + "' as " + std::string(wanted), var_expr->Declaration()->source); + NoteDeclarationSource(variable); }, [&](const sem::ValueExpression* val_expr) { auto type = val_expr->Type()->FriendlyName(builder_->Symbols()); @@ -58,6 +67,13 @@ void SemHelper::ErrorUnexpectedExprKind(const sem::Expression* expr, AddError("cannot use type '" + name + "' as " + std::string(wanted), ty_expr->Declaration()->source); }, + [&](const sem::FunctionExpression* fn_expr) { + auto* fn = fn_expr->Function()->Declaration(); + auto name = builder_->Symbols().NameFor(fn->name->symbol); + AddError("cannot use function '" + name + "' as " + std::string(wanted), + fn_expr->Declaration()->source); + NoteDeclarationSource(fn); + }, [&](const sem::BuiltinEnumExpression* access) { AddError("cannot use access '" + utils::ToString(access->Value()) + "' as " + std::string(wanted), @@ -93,6 +109,44 @@ void SemHelper::ErrorExpectedValueExpr(const sem::Expression* expr) const { } } +void SemHelper::NoteDeclarationSource(const ast::Node* node) const { + Switch( + node, + [&](const ast::Struct* n) { + AddNote("struct '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", + n->source); + }, + [&](const ast::Alias* n) { + AddNote("alias '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", + n->source); + }, + [&](const ast::Var* n) { + AddNote("var '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", + n->source); + }, + [&](const ast::Let* n) { + AddNote("let '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", + n->source); + }, + [&](const ast::Override* n) { + AddNote("override '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", + n->source); + }, + [&](const ast::Const* n) { + AddNote("const '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", + n->source); + }, + [&](const ast::Parameter* n) { + AddNote( + "parameter '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", + n->source); + }, + [&](const ast::Function* n) { + AddNote("function '" + builder_->Symbols().NameFor(n->name->symbol) + "' declared here", + n->source); + }); +} + void SemHelper::AddError(const std::string& msg, const Source& source) const { builder_->Diagnostics().add_error(diag::System::Resolver, msg, source); } diff --git a/src/tint/resolver/sem_helper.h b/src/tint/resolver/sem_helper.h index db3eda4496..dd752d3ca3 100644 --- a/src/tint/resolver/sem_helper.h +++ b/src/tint/resolver/sem_helper.h @@ -21,6 +21,8 @@ #include "src/tint/program_builder.h" #include "src/tint/resolver/dependency_graph.h" #include "src/tint/sem/builtin_enum_expression.h" +#include "src/tint/sem/function_expression.h" +#include "src/tint/sem/type_expression.h" #include "src/tint/utils/map.h" namespace tint::resolver { @@ -58,31 +60,73 @@ class SemHelper { /// @returns the sem node for @p ast template auto* GetVal(const AST* ast) const { - return AsValue(Get(ast)); + return AsValueExpression(Get(ast)); } /// @param expr the semantic node /// @returns nullptr if @p expr is nullptr, or @p expr cast to sem::ValueExpression if the cast /// is successful, otherwise an error diagnostic is raised. - sem::ValueExpression* AsValue(sem::Expression* expr) const { + sem::ValueExpression* AsValueExpression(sem::Expression* expr) const { if (TINT_LIKELY(expr)) { - if (auto* val = expr->As(); TINT_LIKELY(val)) { - return val; + if (auto* val_expr = expr->As(); TINT_LIKELY(val_expr)) { + return val_expr; } ErrorExpectedValueExpr(expr); } return nullptr; } + /// @param expr the semantic node + /// @returns nullptr if @p expr is nullptr, or @p expr cast to type::Type if the cast is + /// successful, otherwise an error diagnostic is raised. + sem::TypeExpression* AsTypeExpression(sem::Expression* expr) const { + if (TINT_LIKELY(expr)) { + if (auto* ty_expr = expr->As(); TINT_LIKELY(ty_expr)) { + return ty_expr; + } + ErrorUnexpectedExprKind(expr, "type"); + } + return nullptr; + } + + /// @param expr the semantic node + /// @returns nullptr if @p expr is nullptr, or @p expr cast to sem::Function if the cast is + /// successful, otherwise an error diagnostic is raised. + sem::FunctionExpression* AsFunctionExpression(sem::Expression* expr) const { + if (TINT_LIKELY(expr)) { + auto* fn_expr = expr->As(); + if (TINT_LIKELY(fn_expr)) { + return fn_expr; + } + ErrorUnexpectedExprKind(expr, "function"); + } + return nullptr; + } + + /// @param expr the semantic node + /// @returns nullptr if @p expr is nullptr, or @p expr cast to + /// sem::BuiltinEnumExpression if the cast is successful, otherwise an error + /// diagnostic is raised. + sem::BuiltinEnumExpression* AsAddressSpace(sem::Expression* expr) const { + if (TINT_LIKELY(expr)) { + auto* enum_expr = expr->As>(); + if (TINT_LIKELY(enum_expr)) { + return enum_expr; + } + ErrorUnexpectedExprKind(expr, "address space"); + } + return nullptr; + } + /// @param expr the semantic node /// @returns nullptr if @p expr is nullptr, or @p expr cast to /// sem::BuiltinEnumExpression if the cast is successful, otherwise an error /// diagnostic is raised. sem::BuiltinEnumExpression* AsTexelFormat(sem::Expression* expr) const { if (TINT_LIKELY(expr)) { - if (auto* val = expr->As>(); - TINT_LIKELY(val)) { - return val; + auto* enum_expr = expr->As>(); + if (TINT_LIKELY(enum_expr)) { + return enum_expr; } ErrorUnexpectedExprKind(expr, "texel format"); } @@ -95,9 +139,9 @@ class SemHelper { /// diagnostic is raised. sem::BuiltinEnumExpression* AsAccess(sem::Expression* expr) const { if (TINT_LIKELY(expr)) { - if (auto* val = expr->As>(); - TINT_LIKELY(val)) { - return val; + auto* enum_expr = expr->As>(); + if (TINT_LIKELY(enum_expr)) { + return enum_expr; } ErrorUnexpectedExprKind(expr, "access"); } @@ -121,11 +165,17 @@ class SemHelper { /// @param expr the expression void ErrorExpectedValueExpr(const sem::Expression* expr) const; - private: /// Raises an error diagnostic that the expression @p got was not of the kind @p wanted. /// @param expr the expression + /// @param wanted the expected expression kind void ErrorUnexpectedExprKind(const sem::Expression* expr, std::string_view wanted) const; + /// If @p node is a module-scope type, variable or function declaration, then appends a note + /// diagnostic where this declaration was declared, otherwise the function does nothing. + /// @param node the AST node. + void NoteDeclarationSource(const ast::Node* node) const; + + private: /// Adds the given error message to the diagnostics void AddError(const std::string& msg, const Source& source) const; diff --git a/src/tint/resolver/struct_address_space_use_test.cc b/src/tint/resolver/struct_address_space_use_test.cc index 6500158f0b..2d011bbc22 100644 --- a/src/tint/resolver/struct_address_space_use_test.cc +++ b/src/tint/resolver/struct_address_space_use_test.cc @@ -99,7 +99,7 @@ TEST_F(ResolverAddressSpaceUseTest, StructReachableViaGlobalStruct) { TEST_F(ResolverAddressSpaceUseTest, StructReachableViaGlobalArray) { auto* s = Structure("S", utils::Vector{Member("a", ty.f32())}); - auto* a = ty.array(ty.Of(s), 3_u); + auto a = ty.array(ty.Of(s), 3_u); GlobalVar("g", a, type::AddressSpace::kPrivate); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -147,7 +147,7 @@ TEST_F(ResolverAddressSpaceUseTest, StructReachableViaLocalStruct) { TEST_F(ResolverAddressSpaceUseTest, StructReachableViaLocalArray) { auto* s = Structure("S", utils::Vector{Member("a", ty.f32())}); - auto* a = ty.array(ty.Of(s), 3_u); + auto a = ty.array(ty.Of(s), 3_u); WrapInFunction(Var("g", a)); ASSERT_TRUE(r()->Resolve()) << r()->error(); diff --git a/src/tint/resolver/struct_layout_test.cc b/src/tint/resolver/struct_layout_test.cc index 8d9dee9aa8..728844981a 100644 --- a/src/tint/resolver/struct_layout_test.cc +++ b/src/tint/resolver/struct_layout_test.cc @@ -256,8 +256,8 @@ TEST_F(ResolverStructLayoutTest, ExplicitStrideArrayRuntimeSized) { } TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayOfExplicitStrideArray) { - auto* inner = ty.array(utils::Vector{Stride(16)}); // size: 32 - auto* outer = ty.array(inner, 12_u); // size: 12 * 32 + auto inner = ty.array(utils::Vector{Stride(16)}); // size: 32 + auto outer = ty.array(inner, 12_u); // size: 12 * 32 auto* s = Structure("S", utils::Vector{ Member("c", outer), }); @@ -283,8 +283,8 @@ TEST_F(ResolverStructLayoutTest, ImplicitStrideArrayOfStructure) { Member("a", ty.vec2()), Member("b", ty.vec3()), Member("c", ty.vec4()), - }); // size: 48 - auto* outer = ty.array(ty.Of(inner), 12_u); // size: 12 * 48 + }); // size: 48 + auto outer = ty.array(ty.Of(inner), 12_u); // size: 12 * 48 auto* s = Structure("S", utils::Vector{ Member("c", outer), }); diff --git a/src/tint/resolver/type_initializer_validation_test.cc b/src/tint/resolver/type_initializer_validation_test.cc index c1212ec328..0f7144bbb4 100644 --- a/src/tint/resolver/type_initializer_validation_test.cc +++ b/src/tint/resolver/type_initializer_validation_test.cc @@ -346,9 +346,9 @@ TEST_P(ConversionInitializerValidTest, All) { Enable(ast::Extension::kF16); // var a : = (()); - auto* lhs_type1 = params.lhs_type(*this); - auto* lhs_type2 = params.lhs_type(*this); - auto* rhs_type = params.rhs_type(*this); + auto lhs_type1 = params.lhs_type(*this); + auto lhs_type2 = params.lhs_type(*this); + auto rhs_type = params.rhs_type(*this); auto* rhs_value_expr = params.rhs_value_expr(*this, 0); std::stringstream ss; @@ -439,9 +439,9 @@ TEST_P(ConversionInitializerInvalidTest, All) { } // var a : = (()); - auto* lhs_type1 = lhs_params.ast(*this); - auto* lhs_type2 = lhs_params.ast(*this); - auto* rhs_type = rhs_params.ast(*this); + auto lhs_type1 = lhs_params.ast(*this); + auto lhs_type2 = lhs_params.ast(*this); + auto rhs_type = rhs_params.ast(*this); auto* rhs_value_expr = rhs_params.expr_from_double(*this, 0); std::stringstream ss; @@ -523,7 +523,7 @@ TEST_F(ResolverTypeInitializerValidationTest, Array_U32U32U32) { TEST_F(ResolverTypeInitializerValidationTest, InferredArray_U32U32U32) { // array(0u, 10u, 20u); - auto* tc = array(Source{{12, 34}}, nullptr, nullptr, 0_u, 10_u, 20_u); + auto* tc = array(Source{{12, 34}}, 0_u, 10_u, 20_u); WrapInFunction(tc); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -561,7 +561,7 @@ TEST_F(ResolverTypeInitializerValidationTest, Array_U32AIU32) { TEST_F(ResolverTypeInitializerValidationTest, InferredArray_U32AIU32) { // array(0u, 10u, 20u); - auto* tc = array(Source{{12, 34}}, nullptr, nullptr, 0_u, 10_a, 20_u); + auto* tc = array(Source{{12, 34}}, 0_u, 10_a, 20_u); WrapInFunction(tc); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -599,7 +599,7 @@ TEST_F(ResolverTypeInitializerValidationTest, ArrayU32_AIAIAI) { TEST_F(ResolverTypeInitializerValidationTest, InferredArray_AIAIAI) { // const c = array(0, 10, 20); - auto* tc = array(Source{{12, 34}}, nullptr, nullptr, 0_a, 10_a, 20_a); + auto* tc = array(Source{{12, 34}}, 0_a, 10_a, 20_a); WrapInFunction(Decl(Const("C", tc))); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -618,9 +618,9 @@ TEST_F(ResolverTypeInitializerValidationTest, InferredArray_AIAIAI) { TEST_F(ResolverTypeInitializerValidationTest, InferredArrayU32_VecI32_VecAI) { // array(vec2(10i), vec2(20)); - auto* tc = array(Source{{12, 34}}, nullptr, nullptr, // - Call(ty.vec(nullptr, 2), 20_i), // - Call(ty.vec(nullptr, 2), 20_a)); + auto* tc = array(Source{{12, 34}}, // + Call(ty.vec(2), 20_i), // + Call(ty.vec(2), 20_a)); WrapInFunction(tc); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -640,9 +640,9 @@ TEST_F(ResolverTypeInitializerValidationTest, InferredArrayU32_VecI32_VecAI) { TEST_F(ResolverTypeInitializerValidationTest, InferredArrayU32_VecAI_VecF32) { // array(vec2(20), vec2(10f)); - auto* tc = array(Source{{12, 34}}, nullptr, nullptr, // - Call(ty.vec(nullptr, 2), 20_a), // - Call(ty.vec(nullptr, 2), 20_f)); + auto* tc = array(Source{{12, 34}}, // + Call(ty.vec(2), 20_a), // + Call(ty.vec(2), 20_f)); WrapInFunction(tc); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -671,7 +671,7 @@ TEST_F(ResolverTypeInitializerValidationTest, ArrayArgumentTypeMismatch_U32F32) TEST_F(ResolverTypeInitializerValidationTest, InferredArrayArgumentTypeMismatch_U32F32) { // array(0u, 1.0f, 20u); - auto* tc = array(Source{{12, 34}}, nullptr, nullptr, 0_u, 1_f, 20_u); + auto* tc = array(Source{{12, 34}}, 0_u, 1_f, 20_u); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -692,7 +692,7 @@ TEST_F(ResolverTypeInitializerValidationTest, ArrayArgumentTypeMismatch_F32I32) TEST_F(ResolverTypeInitializerValidationTest, InferredArrayArgumentTypeMismatch_F32I32) { // array(1f, 1i); - auto* tc = array(Source{{12, 34}}, nullptr, nullptr, 1_f, 1_i); + auto* tc = array(Source{{12, 34}}, 1_f, 1_i); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -713,7 +713,7 @@ TEST_F(ResolverTypeInitializerValidationTest, ArrayArgumentTypeMismatch_U32I32) TEST_F(ResolverTypeInitializerValidationTest, InferredArrayArgumentTypeMismatch_U32I32) { // array(1i, 0u, 0u, 0u, 0u, 0u); - auto* tc = array(Source{{12, 34}}, nullptr, nullptr, 1_i, 0_u, 0_u, 0_u, 0_u); + auto* tc = array(Source{{12, 34}}, 1_i, 0_u, 0_u, 0_u, 0_u); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -734,7 +734,7 @@ TEST_F(ResolverTypeInitializerValidationTest, ArrayArgumentTypeMismatch_I32Vec2) TEST_F(ResolverTypeInitializerValidationTest, InferredArrayArgumentTypeMismatch_I32Vec2) { // array(1i, vec2()); - auto* tc = array(Source{{12, 34}}, nullptr, nullptr, 1_i, vec2()); + auto* tc = array(Source{{12, 34}}, 1_i, vec2()); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -755,7 +755,7 @@ TEST_F(ResolverTypeInitializerValidationTest, ArrayArgumentTypeMismatch_Vec3i32_ TEST_F(ResolverTypeInitializerValidationTest, InferredArrayArgumentTypeMismatch_Vec3i32_Vec3u32) { // array(vec3(), vec3()); - auto* t = array(Source{{12, 34}}, nullptr, nullptr, vec3(), vec3()); + auto* t = array(Source{{12, 34}}, vec3(), vec3()); WrapInFunction(t); EXPECT_FALSE(r()->Resolve()); @@ -767,7 +767,7 @@ note: argument 1 is of type 'vec3')"); TEST_F(ResolverTypeInitializerValidationTest, InferredArrayArgumentTypeMismatch_Vec3i32_Vec3AF) { // array(vec3(), vec3(1.0)); - auto* t = array(Source{{12, 34}}, nullptr, nullptr, vec3(), Call(ty.vec3(nullptr), 1._a)); + auto* t = array(Source{{12, 34}}, vec3(), Call("vec3", 1._a)); WrapInFunction(t); EXPECT_FALSE(r()->Resolve()); @@ -789,7 +789,7 @@ TEST_F(ResolverTypeInitializerValidationTest, ArrayArgumentTypeMismatch_Vec3i32_ TEST_F(ResolverTypeInitializerValidationTest, InferredArrayArgumentTypeMismatch_Vec3i32_Vec3bool) { // array(vec3(), vec3()); - auto* t = array(Source{{12, 34}}, nullptr, nullptr, vec3(), vec3()); + auto* t = array(Source{{12, 34}}, vec3(), vec3()); WrapInFunction(t); EXPECT_FALSE(r()->Resolve()); @@ -811,7 +811,7 @@ TEST_F(ResolverTypeInitializerValidationTest, ArrayOfArray_SubElemSizeMismatch) TEST_F(ResolverTypeInitializerValidationTest, InferredArrayOfArray_SubElemSizeMismatch) { // array, 2u>(array(), array()); - auto* t = array(Source{{12, 34}}, nullptr, nullptr, array(), array()); + auto* t = array(Source{{12, 34}}, array(), array()); WrapInFunction(t); EXPECT_FALSE(r()->Resolve()); @@ -833,7 +833,7 @@ TEST_F(ResolverTypeInitializerValidationTest, ArrayOfArray_SubElemTypeMismatch) TEST_F(ResolverTypeInitializerValidationTest, InferredArrayOfArray_SubElemTypeMismatch) { // array, 2u>(array(), array()); - auto* t = array(Source{{12, 34}}, nullptr, nullptr, array(), array()); + auto* t = array(Source{{12, 34}}, array(), array()); WrapInFunction(t); EXPECT_FALSE(r()->Resolve()); @@ -869,7 +869,7 @@ TEST_F(ResolverTypeInitializerValidationTest, Array_TooManyElements) { TEST_F(ResolverTypeInitializerValidationTest, Array_Runtime) { // array(1i); - auto* tc = array(Source{{12, 34}}, ty.i32(), nullptr, Expr(1_i)); + auto* tc = array(Source{{12, 34}}, Expr(1_i)); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -878,7 +878,7 @@ TEST_F(ResolverTypeInitializerValidationTest, Array_Runtime) { TEST_F(ResolverTypeInitializerValidationTest, Array_RuntimeZeroValue) { // array(); - auto* tc = array(Source{{12, 34}}, ty.i32(), nullptr); + auto* tc = array(Source{{12, 34}}); WrapInFunction(tc); EXPECT_FALSE(r()->Resolve()); @@ -1992,7 +1992,7 @@ TEST_F(ResolverTypeInitializerValidationTest, Vector_ElementTypeAlias_Error) { auto* f32_alias = Alias("Float32", ty.f32()); // vec2(1.0f, 1u) - auto* vec_type = ty.vec(ty.Of(f32_alias), 2); + auto vec_type = ty.vec(ty.Of(f32_alias), 2); WrapInFunction(Call(Source{{12, 34}}, vec_type, 1_f, 1_u)); EXPECT_FALSE(r()->Resolve()); @@ -2004,7 +2004,7 @@ TEST_F(ResolverTypeInitializerValidationTest, Vector_ElementTypeAlias_Success) { auto* f32_alias = Alias("Float32", ty.f32()); // vec2(1.0f, 1.0f) - auto* vec_type = ty.vec(ty.Of(f32_alias), 2); + auto vec_type = ty.vec(ty.Of(f32_alias), 2); auto* tc = Call(Source{{12, 34}}, vec_type, 1_f, 1_f); WrapInFunction(tc); @@ -2015,7 +2015,7 @@ TEST_F(ResolverTypeInitializerValidationTest, Vector_ArgumentElementTypeAlias_Er auto* f32_alias = Alias("Float32", ty.f32()); // vec3(vec(), 1.0f) - auto* vec_type = ty.vec(ty.Of(f32_alias), 2); + auto vec_type = ty.vec(ty.Of(f32_alias), 2); WrapInFunction(vec3(Source{{12, 34}}, Call(vec_type), 1_f)); EXPECT_FALSE(r()->Resolve()); @@ -2027,7 +2027,7 @@ TEST_F(ResolverTypeInitializerValidationTest, Vector_ArgumentElementTypeAlias_Su auto* f32_alias = Alias("Float32", ty.f32()); // vec3(vec(), 1.0f) - auto* vec_type = ty.vec(ty.Of(f32_alias), 2); + auto vec_type = ty.vec(ty.Of(f32_alias), 2); auto* tc = vec3(Call(Source{{12, 34}}, vec_type), 1_f); WrapInFunction(tc); @@ -2037,11 +2037,11 @@ TEST_F(ResolverTypeInitializerValidationTest, Vector_ArgumentElementTypeAlias_Su TEST_F(ResolverTypeInitializerValidationTest, InferVec2ElementTypeFromScalars) { Enable(ast::Extension::kF16); - auto* vec2_bool = Call(create(nullptr, 2u), Expr(true), Expr(false)); - auto* vec2_i32 = Call(create(nullptr, 2u), Expr(1_i), Expr(2_i)); - auto* vec2_u32 = Call(create(nullptr, 2u), Expr(1_u), Expr(2_u)); - auto* vec2_f32 = Call(create(nullptr, 2u), Expr(1_f), Expr(2_f)); - auto* vec2_f16 = Call(create(nullptr, 2u), Expr(1_h), Expr(2_h)); + auto* vec2_bool = vec2(true, false); + auto* vec2_i32 = vec2(1_i, 2_i); + auto* vec2_u32 = vec2(1_u, 2_u); + auto* vec2_f32 = vec2(1_f, 2_f); + auto* vec2_f16 = vec2(1_h, 2_h); WrapInFunction(vec2_bool, vec2_i32, vec2_u32, vec2_f32, vec2_f16); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -2061,21 +2061,16 @@ TEST_F(ResolverTypeInitializerValidationTest, InferVec2ElementTypeFromScalars) { EXPECT_EQ(TypeOf(vec2_u32)->As()->Width(), 2u); EXPECT_EQ(TypeOf(vec2_f32)->As()->Width(), 2u); EXPECT_EQ(TypeOf(vec2_f16)->As()->Width(), 2u); - EXPECT_EQ(TypeOf(vec2_bool), TypeOf(vec2_bool->target.type)); - EXPECT_EQ(TypeOf(vec2_i32), TypeOf(vec2_i32->target.type)); - EXPECT_EQ(TypeOf(vec2_u32), TypeOf(vec2_u32->target.type)); - EXPECT_EQ(TypeOf(vec2_f32), TypeOf(vec2_f32->target.type)); - EXPECT_EQ(TypeOf(vec2_f16), TypeOf(vec2_f16->target.type)); } TEST_F(ResolverTypeInitializerValidationTest, InferVec2ElementTypeFromVec2) { Enable(ast::Extension::kF16); - auto* vec2_bool = Call(create(nullptr, 2u), vec2(true, false)); - auto* vec2_i32 = Call(create(nullptr, 2u), vec2(1_i, 2_i)); - auto* vec2_u32 = Call(create(nullptr, 2u), vec2(1_u, 2_u)); - auto* vec2_f32 = Call(create(nullptr, 2u), vec2(1_f, 2_f)); - auto* vec2_f16 = Call(create(nullptr, 2u), vec2(1_h, 2_h)); + auto* vec2_bool = vec2(vec2(true, false)); + auto* vec2_i32 = vec2(vec2(1_i, 2_i)); + auto* vec2_u32 = vec2(vec2(1_u, 2_u)); + auto* vec2_f32 = vec2(vec2(1_f, 2_f)); + auto* vec2_f16 = vec2(vec2(1_h, 2_h)); WrapInFunction(vec2_bool, vec2_i32, vec2_u32, vec2_f32, vec2_f16); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -2095,21 +2090,16 @@ TEST_F(ResolverTypeInitializerValidationTest, InferVec2ElementTypeFromVec2) { EXPECT_EQ(TypeOf(vec2_u32)->As()->Width(), 2u); EXPECT_EQ(TypeOf(vec2_f32)->As()->Width(), 2u); EXPECT_EQ(TypeOf(vec2_f16)->As()->Width(), 2u); - EXPECT_EQ(TypeOf(vec2_bool), TypeOf(vec2_bool->target.type)); - EXPECT_EQ(TypeOf(vec2_i32), TypeOf(vec2_i32->target.type)); - EXPECT_EQ(TypeOf(vec2_u32), TypeOf(vec2_u32->target.type)); - EXPECT_EQ(TypeOf(vec2_f32), TypeOf(vec2_f32->target.type)); - EXPECT_EQ(TypeOf(vec2_f16), TypeOf(vec2_f16->target.type)); } TEST_F(ResolverTypeInitializerValidationTest, InferVec3ElementTypeFromScalars) { Enable(ast::Extension::kF16); - auto* vec3_bool = Call(create(nullptr, 3u), Expr(true), Expr(false), Expr(true)); - auto* vec3_i32 = Call(create(nullptr, 3u), Expr(1_i), Expr(2_i), Expr(3_i)); - auto* vec3_u32 = Call(create(nullptr, 3u), Expr(1_u), Expr(2_u), Expr(3_u)); - auto* vec3_f32 = Call(create(nullptr, 3u), Expr(1_f), Expr(2_f), Expr(3_f)); - auto* vec3_f16 = Call(create(nullptr, 3u), Expr(1_h), Expr(2_h), Expr(3_h)); + auto* vec3_bool = vec3(Expr(true), Expr(false), Expr(true)); + auto* vec3_i32 = vec3(Expr(1_i), Expr(2_i), Expr(3_i)); + auto* vec3_u32 = vec3(Expr(1_u), Expr(2_u), Expr(3_u)); + auto* vec3_f32 = vec3(Expr(1_f), Expr(2_f), Expr(3_f)); + auto* vec3_f16 = vec3(Expr(1_h), Expr(2_h), Expr(3_h)); WrapInFunction(vec3_bool, vec3_i32, vec3_u32, vec3_f32, vec3_f16); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -2129,21 +2119,16 @@ TEST_F(ResolverTypeInitializerValidationTest, InferVec3ElementTypeFromScalars) { EXPECT_EQ(TypeOf(vec3_u32)->As()->Width(), 3u); EXPECT_EQ(TypeOf(vec3_f32)->As()->Width(), 3u); EXPECT_EQ(TypeOf(vec3_f16)->As()->Width(), 3u); - EXPECT_EQ(TypeOf(vec3_bool), TypeOf(vec3_bool->target.type)); - EXPECT_EQ(TypeOf(vec3_i32), TypeOf(vec3_i32->target.type)); - EXPECT_EQ(TypeOf(vec3_u32), TypeOf(vec3_u32->target.type)); - EXPECT_EQ(TypeOf(vec3_f32), TypeOf(vec3_f32->target.type)); - EXPECT_EQ(TypeOf(vec3_f16), TypeOf(vec3_f16->target.type)); } TEST_F(ResolverTypeInitializerValidationTest, InferVec3ElementTypeFromVec3) { Enable(ast::Extension::kF16); - auto* vec3_bool = Call(create(nullptr, 3u), vec3(true, false, true)); - auto* vec3_i32 = Call(create(nullptr, 3u), vec3(1_i, 2_i, 3_i)); - auto* vec3_u32 = Call(create(nullptr, 3u), vec3(1_u, 2_u, 3_u)); - auto* vec3_f32 = Call(create(nullptr, 3u), vec3(1_f, 2_f, 3_f)); - auto* vec3_f16 = Call(create(nullptr, 3u), vec3(1_h, 2_h, 3_h)); + auto* vec3_bool = vec3(vec3(true, false, true)); + auto* vec3_i32 = vec3(vec3(1_i, 2_i, 3_i)); + auto* vec3_u32 = vec3(vec3(1_u, 2_u, 3_u)); + auto* vec3_f32 = vec3(vec3(1_f, 2_f, 3_f)); + auto* vec3_f16 = vec3(vec3(1_h, 2_h, 3_h)); WrapInFunction(vec3_bool, vec3_i32, vec3_u32, vec3_f32, vec3_f16); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -2163,21 +2148,16 @@ TEST_F(ResolverTypeInitializerValidationTest, InferVec3ElementTypeFromVec3) { EXPECT_EQ(TypeOf(vec3_u32)->As()->Width(), 3u); EXPECT_EQ(TypeOf(vec3_f32)->As()->Width(), 3u); EXPECT_EQ(TypeOf(vec3_f16)->As()->Width(), 3u); - EXPECT_EQ(TypeOf(vec3_bool), TypeOf(vec3_bool->target.type)); - EXPECT_EQ(TypeOf(vec3_i32), TypeOf(vec3_i32->target.type)); - EXPECT_EQ(TypeOf(vec3_u32), TypeOf(vec3_u32->target.type)); - EXPECT_EQ(TypeOf(vec3_f32), TypeOf(vec3_f32->target.type)); - EXPECT_EQ(TypeOf(vec3_f16), TypeOf(vec3_f16->target.type)); } TEST_F(ResolverTypeInitializerValidationTest, InferVec3ElementTypeFromScalarAndVec2) { Enable(ast::Extension::kF16); - auto* vec3_bool = Call(create(nullptr, 3u), Expr(true), vec2(false, true)); - auto* vec3_i32 = Call(create(nullptr, 3u), Expr(1_i), vec2(2_i, 3_i)); - auto* vec3_u32 = Call(create(nullptr, 3u), Expr(1_u), vec2(2_u, 3_u)); - auto* vec3_f32 = Call(create(nullptr, 3u), Expr(1_f), vec2(2_f, 3_f)); - auto* vec3_f16 = Call(create(nullptr, 3u), Expr(1_h), vec2(2_h, 3_h)); + auto* vec3_bool = vec3(Expr(true), vec2(false, true)); + auto* vec3_i32 = vec3(Expr(1_i), vec2(2_i, 3_i)); + auto* vec3_u32 = vec3(Expr(1_u), vec2(2_u, 3_u)); + auto* vec3_f32 = vec3(Expr(1_f), vec2(2_f, 3_f)); + auto* vec3_f16 = vec3(Expr(1_h), vec2(2_h, 3_h)); WrapInFunction(vec3_bool, vec3_i32, vec3_u32, vec3_f32, vec3_f16); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -2197,26 +2177,16 @@ TEST_F(ResolverTypeInitializerValidationTest, InferVec3ElementTypeFromScalarAndV EXPECT_EQ(TypeOf(vec3_u32)->As()->Width(), 3u); EXPECT_EQ(TypeOf(vec3_f32)->As()->Width(), 3u); EXPECT_EQ(TypeOf(vec3_f16)->As()->Width(), 3u); - EXPECT_EQ(TypeOf(vec3_bool), TypeOf(vec3_bool->target.type)); - EXPECT_EQ(TypeOf(vec3_i32), TypeOf(vec3_i32->target.type)); - EXPECT_EQ(TypeOf(vec3_u32), TypeOf(vec3_u32->target.type)); - EXPECT_EQ(TypeOf(vec3_f32), TypeOf(vec3_f32->target.type)); - EXPECT_EQ(TypeOf(vec3_f16), TypeOf(vec3_f16->target.type)); } TEST_F(ResolverTypeInitializerValidationTest, InferVec4ElementTypeFromScalars) { Enable(ast::Extension::kF16); - auto* vec4_bool = - Call(create(nullptr, 4u), Expr(true), Expr(false), Expr(true), Expr(false)); - auto* vec4_i32 = - Call(create(nullptr, 4u), Expr(1_i), Expr(2_i), Expr(3_i), Expr(4_i)); - auto* vec4_u32 = - Call(create(nullptr, 4u), Expr(1_u), Expr(2_u), Expr(3_u), Expr(4_u)); - auto* vec4_f32 = - Call(create(nullptr, 4u), Expr(1_f), Expr(2_f), Expr(3_f), Expr(4_f)); - auto* vec4_f16 = - Call(create(nullptr, 4u), Expr(1_h), Expr(2_h), Expr(3_h), Expr(4_h)); + auto* vec4_bool = vec4(Expr(true), Expr(false), Expr(true), Expr(false)); + auto* vec4_i32 = vec4(Expr(1_i), Expr(2_i), Expr(3_i), Expr(4_i)); + auto* vec4_u32 = vec4(Expr(1_u), Expr(2_u), Expr(3_u), Expr(4_u)); + auto* vec4_f32 = vec4(Expr(1_f), Expr(2_f), Expr(3_f), Expr(4_f)); + auto* vec4_f16 = vec4(Expr(1_h), Expr(2_h), Expr(3_h), Expr(4_h)); WrapInFunction(vec4_bool, vec4_i32, vec4_u32, vec4_f32, vec4_f16); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -2236,21 +2206,16 @@ TEST_F(ResolverTypeInitializerValidationTest, InferVec4ElementTypeFromScalars) { EXPECT_EQ(TypeOf(vec4_u32)->As()->Width(), 4u); EXPECT_EQ(TypeOf(vec4_f32)->As()->Width(), 4u); EXPECT_EQ(TypeOf(vec4_f16)->As()->Width(), 4u); - EXPECT_EQ(TypeOf(vec4_bool), TypeOf(vec4_bool->target.type)); - EXPECT_EQ(TypeOf(vec4_i32), TypeOf(vec4_i32->target.type)); - EXPECT_EQ(TypeOf(vec4_u32), TypeOf(vec4_u32->target.type)); - EXPECT_EQ(TypeOf(vec4_f32), TypeOf(vec4_f32->target.type)); - EXPECT_EQ(TypeOf(vec4_f16), TypeOf(vec4_f16->target.type)); } TEST_F(ResolverTypeInitializerValidationTest, InferVec4ElementTypeFromVec4) { Enable(ast::Extension::kF16); - auto* vec4_bool = Call(create(nullptr, 4u), vec4(true, false, true, false)); - auto* vec4_i32 = Call(create(nullptr, 4u), vec4(1_i, 2_i, 3_i, 4_i)); - auto* vec4_u32 = Call(create(nullptr, 4u), vec4(1_u, 2_u, 3_u, 4_u)); - auto* vec4_f32 = Call(create(nullptr, 4u), vec4(1_f, 2_f, 3_f, 4_f)); - auto* vec4_f16 = Call(create(nullptr, 4u), vec4(1_h, 2_h, 3_h, 4_h)); + auto* vec4_bool = vec4(vec4(true, false, true, false)); + auto* vec4_i32 = vec4(vec4(1_i, 2_i, 3_i, 4_i)); + auto* vec4_u32 = vec4(vec4(1_u, 2_u, 3_u, 4_u)); + auto* vec4_f32 = vec4(vec4(1_f, 2_f, 3_f, 4_f)); + auto* vec4_f16 = vec4(vec4(1_h, 2_h, 3_h, 4_h)); WrapInFunction(vec4_bool, vec4_i32, vec4_u32, vec4_f32, vec4_f16); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -2270,22 +2235,16 @@ TEST_F(ResolverTypeInitializerValidationTest, InferVec4ElementTypeFromVec4) { EXPECT_EQ(TypeOf(vec4_u32)->As()->Width(), 4u); EXPECT_EQ(TypeOf(vec4_f32)->As()->Width(), 4u); EXPECT_EQ(TypeOf(vec4_f16)->As()->Width(), 4u); - EXPECT_EQ(TypeOf(vec4_bool), TypeOf(vec4_bool->target.type)); - EXPECT_EQ(TypeOf(vec4_i32), TypeOf(vec4_i32->target.type)); - EXPECT_EQ(TypeOf(vec4_u32), TypeOf(vec4_u32->target.type)); - EXPECT_EQ(TypeOf(vec4_f32), TypeOf(vec4_f32->target.type)); - EXPECT_EQ(TypeOf(vec4_f16), TypeOf(vec4_f16->target.type)); } TEST_F(ResolverTypeInitializerValidationTest, InferVec4ElementTypeFromScalarAndVec3) { Enable(ast::Extension::kF16); - auto* vec4_bool = - Call(create(nullptr, 4u), Expr(true), vec3(false, true, false)); - auto* vec4_i32 = Call(create(nullptr, 4u), Expr(1_i), vec3(2_i, 3_i, 4_i)); - auto* vec4_u32 = Call(create(nullptr, 4u), Expr(1_u), vec3(2_u, 3_u, 4_u)); - auto* vec4_f32 = Call(create(nullptr, 4u), Expr(1_f), vec3(2_f, 3_f, 4_f)); - auto* vec4_f16 = Call(create(nullptr, 4u), Expr(1_h), vec3(2_h, 3_h, 4_h)); + auto* vec4_bool = vec4(Expr(true), vec3(false, true, false)); + auto* vec4_i32 = vec4(Expr(1_i), vec3(2_i, 3_i, 4_i)); + auto* vec4_u32 = vec4(Expr(1_u), vec3(2_u, 3_u, 4_u)); + auto* vec4_f32 = vec4(Expr(1_f), vec3(2_f, 3_f, 4_f)); + auto* vec4_f16 = vec4(Expr(1_h), vec3(2_h, 3_h, 4_h)); WrapInFunction(vec4_bool, vec4_i32, vec4_u32, vec4_f32, vec4_f16); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -2305,26 +2264,16 @@ TEST_F(ResolverTypeInitializerValidationTest, InferVec4ElementTypeFromScalarAndV EXPECT_EQ(TypeOf(vec4_u32)->As()->Width(), 4u); EXPECT_EQ(TypeOf(vec4_f32)->As()->Width(), 4u); EXPECT_EQ(TypeOf(vec4_f16)->As()->Width(), 4u); - EXPECT_EQ(TypeOf(vec4_bool), TypeOf(vec4_bool->target.type)); - EXPECT_EQ(TypeOf(vec4_i32), TypeOf(vec4_i32->target.type)); - EXPECT_EQ(TypeOf(vec4_u32), TypeOf(vec4_u32->target.type)); - EXPECT_EQ(TypeOf(vec4_f32), TypeOf(vec4_f32->target.type)); - EXPECT_EQ(TypeOf(vec4_f16), TypeOf(vec4_f16->target.type)); } TEST_F(ResolverTypeInitializerValidationTest, InferVec4ElementTypeFromVec2AndVec2) { Enable(ast::Extension::kF16); - auto* vec4_bool = - Call(create(nullptr, 4u), vec2(true, false), vec2(true, false)); - auto* vec4_i32 = - Call(create(nullptr, 4u), vec2(1_i, 2_i), vec2(3_i, 4_i)); - auto* vec4_u32 = - Call(create(nullptr, 4u), vec2(1_u, 2_u), vec2(3_u, 4_u)); - auto* vec4_f32 = - Call(create(nullptr, 4u), vec2(1_f, 2_f), vec2(3_f, 4_f)); - auto* vec4_f16 = - Call(create(nullptr, 4u), vec2(1_h, 2_h), vec2(3_h, 4_h)); + auto* vec4_bool = vec4(vec2(true, false), vec2(true, false)); + auto* vec4_i32 = vec4(vec2(1_i, 2_i), vec2(3_i, 4_i)); + auto* vec4_u32 = vec4(vec2(1_u, 2_u), vec2(3_u, 4_u)); + auto* vec4_f32 = vec4(vec2(1_f, 2_f), vec2(3_f, 4_f)); + auto* vec4_f16 = vec4(vec2(1_h, 2_h), vec2(3_h, 4_h)); WrapInFunction(vec4_bool, vec4_i32, vec4_u32, vec4_f32, vec4_f16); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -2344,22 +2293,17 @@ TEST_F(ResolverTypeInitializerValidationTest, InferVec4ElementTypeFromVec2AndVec EXPECT_EQ(TypeOf(vec4_u32)->As()->Width(), 4u); EXPECT_EQ(TypeOf(vec4_f32)->As()->Width(), 4u); EXPECT_EQ(TypeOf(vec4_f16)->As()->Width(), 4u); - EXPECT_EQ(TypeOf(vec4_bool), TypeOf(vec4_bool->target.type)); - EXPECT_EQ(TypeOf(vec4_i32), TypeOf(vec4_i32->target.type)); - EXPECT_EQ(TypeOf(vec4_u32), TypeOf(vec4_u32->target.type)); - EXPECT_EQ(TypeOf(vec4_f32), TypeOf(vec4_f32->target.type)); - EXPECT_EQ(TypeOf(vec4_f16), TypeOf(vec4_f16->target.type)); } TEST_F(ResolverTypeInitializerValidationTest, CannotInferVectorElementTypeWithoutArgs) { - WrapInFunction(Call(Source{{12, 34}}, create(nullptr, 3u))); + WrapInFunction(Call(Source{{12, 34}}, "vec3")); EXPECT_FALSE(r()->Resolve()); EXPECT_THAT(r()->error(), HasSubstr("12:34 error: no matching initializer for vec3()")); } TEST_F(ResolverTypeInitializerValidationTest, CannotInferVec2ElementTypeFromScalarsMismatch) { - WrapInFunction(Call(Source{{1, 1}}, create(nullptr, 2u), + WrapInFunction(Call(Source{{1, 1}}, "vec2", // Expr(Source{{1, 2}}, 1_i), // Expr(Source{{1, 3}}, 2_u))); @@ -2368,7 +2312,7 @@ TEST_F(ResolverTypeInitializerValidationTest, CannotInferVec2ElementTypeFromScal } TEST_F(ResolverTypeInitializerValidationTest, CannotInferVec3ElementTypeFromScalarsMismatch) { - WrapInFunction(Call(Source{{1, 1}}, create(nullptr, 3u), + WrapInFunction(Call(Source{{1, 1}}, "vec3", // Expr(Source{{1, 2}}, 1_i), // Expr(Source{{1, 3}}, 2_u), // Expr(Source{{1, 4}}, 3_i))); @@ -2379,7 +2323,7 @@ TEST_F(ResolverTypeInitializerValidationTest, CannotInferVec3ElementTypeFromScal } TEST_F(ResolverTypeInitializerValidationTest, CannotInferVec3ElementTypeFromScalarAndVec2Mismatch) { - WrapInFunction(Call(Source{{1, 1}}, create(nullptr, 3u), + WrapInFunction(Call(Source{{1, 1}}, "vec3", // Expr(Source{{1, 2}}, 1_i), // Call(Source{{1, 3}}, ty.vec2(), 2_f, 3_f))); @@ -2389,7 +2333,7 @@ TEST_F(ResolverTypeInitializerValidationTest, CannotInferVec3ElementTypeFromScal } TEST_F(ResolverTypeInitializerValidationTest, CannotInferVec4ElementTypeFromScalarsMismatch) { - WrapInFunction(Call(Source{{1, 1}}, create(nullptr, 4u), + WrapInFunction(Call(Source{{1, 1}}, "vec4", // Expr(Source{{1, 2}}, 1_i), // Expr(Source{{1, 3}}, 2_i), // Expr(Source{{1, 4}}, 3_f), // @@ -2401,7 +2345,7 @@ TEST_F(ResolverTypeInitializerValidationTest, CannotInferVec4ElementTypeFromScal } TEST_F(ResolverTypeInitializerValidationTest, CannotInferVec4ElementTypeFromScalarAndVec3Mismatch) { - WrapInFunction(Call(Source{{1, 1}}, create(nullptr, 4u), + WrapInFunction(Call(Source{{1, 1}}, "vec4", // Expr(Source{{1, 2}}, 1_i), // Call(Source{{1, 3}}, ty.vec3(), 2_u, 3_u, 4_u))); @@ -2411,7 +2355,7 @@ TEST_F(ResolverTypeInitializerValidationTest, CannotInferVec4ElementTypeFromScal } TEST_F(ResolverTypeInitializerValidationTest, CannotInferVec4ElementTypeFromVec2AndVec2Mismatch) { - WrapInFunction(Call(Source{{1, 1}}, create(nullptr, 4u), + WrapInFunction(Call(Source{{1, 1}}, "vec4", // Call(Source{{1, 2}}, ty.vec2(), 3_i, 4_i), // Call(Source{{1, 3}}, ty.vec2(), 3_u, 4_u))); @@ -2468,7 +2412,7 @@ TEST_P(MatrixInitializerTest, ColumnInitializer_Error_TooFewArguments) { std::stringstream args_tys; utils::Vector args; for (uint32_t i = 0; i < param.columns - 1; i++) { - auto* vec_type = param.create_column_ast_type(*this); + ast::Type vec_type = param.create_column_ast_type(*this); args.Push(Call(vec_type)); if (i > 0) { args_tys << ", "; @@ -2476,7 +2420,7 @@ TEST_P(MatrixInitializerTest, ColumnInitializer_Error_TooFewArguments) { args_tys << "vec" << param.rows << "<" + element_type_name + ">"; } - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* tc = Call(Source{{12, 34}}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2504,7 +2448,7 @@ TEST_P(MatrixInitializerTest, ElementInitializer_Error_TooFewArguments) { args_tys << element_type_name; } - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* tc = Call(Source{{12, 34}}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2525,7 +2469,7 @@ TEST_P(MatrixInitializerTest, ColumnInitializer_Error_TooManyArguments) { std::stringstream args_tys; utils::Vector args; for (uint32_t i = 0; i < param.columns + 1; i++) { - auto* vec_type = param.create_column_ast_type(*this); + ast::Type vec_type = param.create_column_ast_type(*this); args.Push(Call(vec_type)); if (i > 0) { args_tys << ", "; @@ -2533,7 +2477,7 @@ TEST_P(MatrixInitializerTest, ColumnInitializer_Error_TooManyArguments) { args_tys << "vec" << param.rows << "<" + element_type_name + ">"; } - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* tc = Call(Source{{12, 34}}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2561,7 +2505,7 @@ TEST_P(MatrixInitializerTest, ElementInitializer_Error_TooManyArguments) { args_tys << element_type_name; } - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* tc = Call(Source{{12, 34}}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2581,7 +2525,7 @@ TEST_P(MatrixInitializerTest, ColumnInitializer_Error_InvalidArgumentType) { std::stringstream args_tys; utils::Vector args; for (uint32_t i = 0; i < param.columns; i++) { - auto* vec_type = ty.vec(param.rows); + auto vec_type = ty.vec(param.rows); args.Push(Call(vec_type)); if (i > 0) { args_tys << ", "; @@ -2589,7 +2533,7 @@ TEST_P(MatrixInitializerTest, ColumnInitializer_Error_InvalidArgumentType) { args_tys << "vec" << param.rows << ""; } - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* tc = Call(Source{{12, 34}}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2616,7 +2560,7 @@ TEST_P(MatrixInitializerTest, ElementInitializer_Error_InvalidArgumentType) { args_tys << "u32"; } - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* tc = Call(Source{{12, 34}}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2642,7 +2586,7 @@ TEST_P(MatrixInitializerTest, ColumnInitializer_Error_TooFewRowsInVectorArgument std::stringstream args_tys; utils::Vector args; for (uint32_t i = 0; i < param.columns; i++) { - auto* valid_vec_type = param.create_column_ast_type(*this); + ast::Type valid_vec_type = param.create_column_ast_type(*this); args.Push(Call(valid_vec_type)); if (i > 0) { args_tys << ", "; @@ -2650,11 +2594,11 @@ TEST_P(MatrixInitializerTest, ColumnInitializer_Error_TooFewRowsInVectorArgument args_tys << "vec" << param.rows << "<" + element_type_name + ">"; } const size_t kInvalidLoc = 2 * (param.columns - 1); - auto* invalid_vec_type = ty.vec(param.create_element_ast_type(*this), param.rows - 1); + auto invalid_vec_type = ty.vec(param.create_element_ast_type(*this), param.rows - 1); args.Push(Call(Source{{12, kInvalidLoc}}, invalid_vec_type)); args_tys << ", vec" << (param.rows - 1) << "<" + element_type_name + ">"; - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* tc = Call(Source{{12, 34}}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2680,18 +2624,18 @@ TEST_P(MatrixInitializerTest, ColumnInitializer_Error_TooManyRowsInVectorArgumen std::stringstream args_tys; utils::Vector args; for (uint32_t i = 0; i < param.columns; i++) { - auto* valid_vec_type = param.create_column_ast_type(*this); + ast::Type valid_vec_type = param.create_column_ast_type(*this); args.Push(Call(valid_vec_type)); if (i > 0) { args_tys << ", "; } args_tys << "vec" << param.rows << "<" + element_type_name + ">"; } - auto* invalid_vec_type = ty.vec(param.create_element_ast_type(*this), param.rows + 1); + auto invalid_vec_type = ty.vec(param.create_element_ast_type(*this), param.rows + 1); args.Push(Call(invalid_vec_type)); args_tys << ", vec" << (param.rows + 1) << "<" + element_type_name + ">"; - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* tc = Call(Source{{12, 34}}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2708,7 +2652,7 @@ TEST_P(MatrixInitializerTest, ZeroValue_Success) { Enable(ast::Extension::kF16); - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* tc = Call(Source{{12, 40}}, matrix_type); WrapInFunction(tc); @@ -2725,11 +2669,11 @@ TEST_P(MatrixInitializerTest, WithColumns_Success) { utils::Vector args; for (uint32_t i = 0; i < param.columns; i++) { - auto* vec_type = param.create_column_ast_type(*this); + ast::Type vec_type = param.create_column_ast_type(*this); args.Push(Call(vec_type)); } - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* tc = Call(matrix_type, std::move(args)); WrapInFunction(tc); @@ -2749,7 +2693,7 @@ TEST_P(MatrixInitializerTest, WithElements_Success) { args.Push(Call(param.create_element_ast_type(*this))); } - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* tc = Call(matrix_type, std::move(args)); WrapInFunction(tc); @@ -2769,7 +2713,7 @@ TEST_P(MatrixInitializerTest, ElementTypeAlias_Error) { std::stringstream args_tys; utils::Vector args; for (uint32_t i = 0; i < param.columns; i++) { - auto* vec_type = ty.vec(ty.u32(), param.rows); + auto vec_type = ty.vec(ty.u32(), param.rows); args.Push(Call(vec_type)); if (i > 0) { args_tys << ", "; @@ -2777,7 +2721,7 @@ TEST_P(MatrixInitializerTest, ElementTypeAlias_Error) { args_tys << "vec" << param.rows << ""; } - auto* matrix_type = ty.mat(ty.Of(elem_type_alias), param.columns, param.rows); + auto matrix_type = ty.mat(ty.Of(elem_type_alias), param.columns, param.rows); auto* tc = Call(Source{{12, 34}}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2798,11 +2742,11 @@ TEST_P(MatrixInitializerTest, ElementTypeAlias_Success) { utils::Vector args; for (uint32_t i = 0; i < param.columns; i++) { - auto* vec_type = param.create_column_ast_type(*this); + ast::Type vec_type = param.create_column_ast_type(*this); args.Push(Call(vec_type)); } - auto* matrix_type = ty.mat(ty.Of(elem_type_alias), param.columns, param.rows); + auto matrix_type = ty.mat(ty.Of(elem_type_alias), param.columns, param.rows); auto* tc = Call(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2825,8 +2769,8 @@ TEST_P(MatrixInitializerTest, ArgumentTypeAlias_Success) { Enable(ast::Extension::kF16); - auto* matrix_type = param.create_mat_ast_type(*this); - auto* vec_type = param.create_column_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); + ast::Type vec_type = param.create_column_ast_type(*this); auto* vec_alias = Alias("ColVectorAlias", vec_type); utils::Vector args; @@ -2845,13 +2789,13 @@ TEST_P(MatrixInitializerTest, ArgumentElementTypeAlias_Error) { Enable(ast::Extension::kF16); - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* u32_type_alias = Alias("UnsignedInt", ty.u32()); std::stringstream args_tys; utils::Vector args; for (uint32_t i = 0; i < param.columns; i++) { - auto* vec_type = ty.vec(ty.Of(u32_type_alias), param.rows); + auto vec_type = ty.vec(ty.Of(u32_type_alias), param.rows); args.Push(Call(vec_type)); if (i > 0) { args_tys << ", "; @@ -2876,11 +2820,11 @@ TEST_P(MatrixInitializerTest, ArgumentElementTypeAlias_Success) { utils::Vector args; for (uint32_t i = 0; i < param.columns; i++) { - auto* vec_type = ty.vec(ty.Of(elem_type_alias), param.rows); + auto vec_type = ty.vec(ty.Of(elem_type_alias), param.rows); args.Push(Call(vec_type)); } - auto* matrix_type = param.create_mat_ast_type(*this); + ast::Type matrix_type = param.create_mat_ast_type(*this); auto* tc = Call(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2897,7 +2841,7 @@ TEST_P(MatrixInitializerTest, InferElementTypeFromVectors) { args.Push(Call(param.create_column_ast_type(*this))); } - auto* matrix_type = create(nullptr, param.rows, param.columns); + auto matrix_type = ty.mat(param.columns, param.rows); auto* tc = Call(Source{}, matrix_type, std::move(args)); WrapInFunction(tc); @@ -2914,7 +2858,7 @@ TEST_P(MatrixInitializerTest, InferElementTypeFromScalars) { args.Push(param.create_element_ast_value(*this, static_cast(i))); } - auto* matrix_type = create(nullptr, param.rows, param.columns); + auto matrix_type = ty.mat(param.columns, param.rows); WrapInFunction(Call(Source{{12, 34}}, matrix_type, std::move(args))); ASSERT_TRUE(r()->Resolve()) << r()->error(); @@ -2944,7 +2888,7 @@ TEST_P(MatrixInitializerTest, CannotInferElementTypeFromVectors_Mismatch) { } } - auto* matrix_type = create(nullptr, param.rows, param.columns); + auto matrix_type = ty.mat(param.columns, param.rows); WrapInFunction(Call(Source{{12, 34}}, matrix_type, std::move(args))); EXPECT_FALSE(r()->Resolve()); @@ -2976,7 +2920,7 @@ TEST_P(MatrixInitializerTest, CannotInferElementTypeFromScalars_Mismatch) { err << ")"; - auto* matrix_type = create(nullptr, param.rows, param.columns); + auto matrix_type = ty.mat(param.columns, param.rows); WrapInFunction(Call(Source{{12, 34}}, matrix_type, std::move(args))); EXPECT_FALSE(r()->Resolve()); @@ -3049,7 +2993,7 @@ TEST_P(StructInitializerInputsTest, TooFew) { utils::Vector members; utils::Vector values; for (uint32_t i = 0; i < N; i++) { - auto* struct_type = str_params.ast(*this); + ast::Type struct_type = str_params.ast(*this); members.Push(Member("member_" + std::to_string(i), struct_type)); if (i < N - 1) { auto* ctor_value_expr = str_params.expr_from_double(*this, 0); @@ -3075,7 +3019,7 @@ TEST_P(StructInitializerInputsTest, TooMany) { utils::Vector values; for (uint32_t i = 0; i < N + 1; i++) { if (i < N) { - auto* struct_type = str_params.ast(*this); + ast::Type struct_type = str_params.ast(*this); members.Push(Member("member_" + std::to_string(i), struct_type)); } auto* ctor_value_expr = str_params.expr_from_double(*this, 0); @@ -3113,7 +3057,7 @@ TEST_P(StructInitializerTypeTest, AllTypes) { // make the last value of the initializer to have a different type uint32_t initializer_value_with_different_type = N - 1; for (uint32_t i = 0; i < N; i++) { - auto* struct_type = str_params.ast(*this); + ast::Type struct_type = str_params.ast(*this); members.Push(Member("member_" + std::to_string(i), struct_type)); auto* ctor_value_expr = (i == initializer_value_with_different_type) ? ctor_params.expr_from_double(*this, 0) @@ -3124,11 +3068,9 @@ TEST_P(StructInitializerTypeTest, AllTypes) { auto* tc = Call(ty.Of(s), values); WrapInFunction(tc); - std::string found = FriendlyName(ctor_params.ast(*this)); - std::string expected = FriendlyName(str_params.ast(*this)); std::stringstream err; err << "error: type in struct initializer does not match struct member "; - err << "type: expected '" << expected << "', found '" << found << "'"; + err << "type: expected '" << str_params.name() << "', found '" << ctor_params.name() << "'"; EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), err.str()); } diff --git a/src/tint/resolver/type_validation_test.cc b/src/tint/resolver/type_validation_test.cc index 70b3837553..0e69da87fe 100644 --- a/src/tint/resolver/type_validation_test.cc +++ b/src/tint/resolver/type_validation_test.cc @@ -612,11 +612,11 @@ TEST_F(ResolverTypeValidationTest, Struct_Member_VectorNoType) { // }; Structure("S", utils::Vector{ - Member("a", create(Source{{12, 34}}, nullptr, 3u)), + Member("a", ty.vec3(Source{{12, 34}})), }); EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: missing vector element type"); + EXPECT_EQ(r()->error(), "12:34 error: expected '<' for 'vec3'"); } TEST_F(ResolverTypeValidationTest, Struct_Member_MatrixNoType) { @@ -624,11 +624,11 @@ TEST_F(ResolverTypeValidationTest, Struct_Member_MatrixNoType) { // a: mat3x3; // }; Structure("S", utils::Vector{ - Member("a", create(Source{{12, 34}}, nullptr, 3u, 3u)), + Member("a", ty.mat3x3(Source{{12, 34}})), }); EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: missing matrix element type"); + EXPECT_EQ(r()->error(), "12:34 error: expected '<' for 'mat3x3'"); } TEST_F(ResolverTypeValidationTest, Struct_TooBig) { @@ -641,11 +641,9 @@ TEST_F(ResolverTypeValidationTest, Struct_TooBig) { // } Structure(Source{{10, 34}}, "Bar", utils::Vector{Member("a", ty.array())}); - Structure( - Source{{12, 34}}, "Foo", - utils::Vector{ - Member("a", ty.array(ty(Source{{12, 30}}, "Bar"), Expr(Source{{12, 34}}, 65535_a))), - Member("b", ty.array(ty(Source{{12, 30}}, "Bar"), Expr(Source{{12, 34}}, 65535_a)))}); + Structure(Source{{12, 34}}, "Foo", + utils::Vector{Member("a", ty.array(ty(Source{{12, 30}}, "Bar"), Expr(65535_a))), + Member("b", ty.array(ty("Bar"), Expr(65535_a)))}); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), @@ -865,7 +863,7 @@ TEST_F(ResolverTypeValidationTest, AliasRuntimeArrayIsLast_Pass) { } TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableType) { - auto* tex_ty = ty.sampled_texture(Source{{12, 34}}, type::TextureDimension::k2d, ty.f32()); + auto tex_ty = ty.sampled_texture(Source{{12, 34}}, type::TextureDimension::k2d, ty.f32()); GlobalVar("arr", ty.array(tex_ty, 4_i), type::AddressSpace::kPrivate); EXPECT_FALSE(r()->Resolve()); @@ -874,7 +872,7 @@ TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableType) { } TEST_F(ResolverTypeValidationTest, ArrayOfNonStorableTypeWithStride) { - auto* ptr_ty = ty.pointer(Source{{12, 34}}, type::AddressSpace::kUniform); + auto ptr_ty = ty.pointer(Source{{12, 34}}, type::AddressSpace::kUniform); GlobalVar("arr", ty.array(ptr_ty, 4_i, utils::Vector{Stride(16)}), type::AddressSpace::kPrivate); @@ -922,7 +920,7 @@ using CanonicalTest = ResolverTestWithParam; TEST_P(CanonicalTest, All) { auto& params = GetParam(); - auto* type = params.create_ast_type(*this); + ast::Type type = params.create_ast_type(*this); auto* var = Var("v", type); auto* expr = Expr("v"); @@ -941,15 +939,11 @@ INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, CanonicalTest, testing::Val } // namespace GetCanonicalTests namespace SampledTextureTests { -struct DimensionParams { - type::TextureDimension dim; - bool is_valid; -}; -using SampledTextureDimensionTest = ResolverTestWithParam; +using SampledTextureDimensionTest = ResolverTestWithParam; TEST_P(SampledTextureDimensionTest, All) { auto& params = GetParam(); - GlobalVar(Source{{12, 34}}, "a", ty.sampled_texture(params.dim, ty.i32()), Group(0_a), + GlobalVar(Source{{12, 34}}, "a", ty.sampled_texture(params, ty.i32()), Group(0_a), Binding(0_a)); EXPECT_TRUE(r()->Resolve()) << r()->error(); @@ -957,35 +951,24 @@ TEST_P(SampledTextureDimensionTest, All) { INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, SampledTextureDimensionTest, testing::Values( // - DimensionParams{type::TextureDimension::k1d, true}, - DimensionParams{type::TextureDimension::k2d, true}, - DimensionParams{type::TextureDimension::k2dArray, true}, - DimensionParams{type::TextureDimension::k3d, true}, - DimensionParams{type::TextureDimension::kCube, true}, - DimensionParams{type::TextureDimension::kCubeArray, true})); + type::TextureDimension::k1d, + type::TextureDimension::k2d, + type::TextureDimension::k2dArray, + type::TextureDimension::k3d, + type::TextureDimension::kCube, + type::TextureDimension::kCubeArray)); -using MultisampledTextureDimensionTest = ResolverTestWithParam; +using MultisampledTextureDimensionTest = ResolverTestWithParam; TEST_P(MultisampledTextureDimensionTest, All) { auto& params = GetParam(); - GlobalVar("a", ty.multisampled_texture(Source{{12, 34}}, params.dim, ty.i32()), Group(0_a), + GlobalVar("a", ty.multisampled_texture(Source{{12, 34}}, params, ty.i32()), Group(0_a), Binding(0_a)); - if (params.is_valid) { - EXPECT_TRUE(r()->Resolve()) << r()->error(); - } else { - EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: only 2d multisampled textures are supported"); - } + EXPECT_TRUE(r()->Resolve()) << r()->error(); } INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, MultisampledTextureDimensionTest, - testing::Values( // - DimensionParams{type::TextureDimension::k1d, false}, - DimensionParams{type::TextureDimension::k2d, true}, - DimensionParams{type::TextureDimension::k2dArray, false}, - DimensionParams{type::TextureDimension::k3d, false}, - DimensionParams{type::TextureDimension::kCube, false}, - DimensionParams{type::TextureDimension::kCubeArray, false})); + testing::Values(type::TextureDimension::k2d)); struct TypeParams { builder::ast_type_func_ptr type_func; @@ -1082,8 +1065,8 @@ TEST_P(StorageTextureDimensionTest, All) { // var a : texture_storage_*; auto& params = GetParam(); - auto* st = ty(Source{{12, 34}}, params.name, utils::ToString(type::TexelFormat::kR32Uint), - utils::ToString(type::Access::kWrite)); + auto st = ty(Source{{12, 34}}, params.name, utils::ToString(type::TexelFormat::kR32Uint), + utils::ToString(type::Access::kWrite)); GlobalVar("a", st, Group(0_a), Binding(0_a)); @@ -1133,19 +1116,19 @@ TEST_P(StorageTextureFormatTest, All) { // @group(0) @binding(3) // var d : texture_storage_3d<*, write>; - auto* st_a = ty.storage_texture(Source{{12, 34}}, type::TextureDimension::k1d, params.format, - type::Access::kWrite); + auto st_a = ty.storage_texture(Source{{12, 34}}, type::TextureDimension::k1d, params.format, + type::Access::kWrite); GlobalVar("a", st_a, Group(0_a), Binding(0_a)); - auto* st_b = + ast::Type st_b = ty.storage_texture(type::TextureDimension::k2d, params.format, type::Access::kWrite); GlobalVar("b", st_b, Group(0_a), Binding(1_a)); - auto* st_c = + ast::Type st_c = ty.storage_texture(type::TextureDimension::k2dArray, params.format, type::Access::kWrite); GlobalVar("c", st_c, Group(0_a), Binding(2_a)); - auto* st_d = + ast::Type st_d = ty.storage_texture(type::TextureDimension::k3d, params.format, type::Access::kWrite); GlobalVar("d", st_d, Group(0_a), Binding(3_a)); @@ -1155,7 +1138,7 @@ TEST_P(StorageTextureFormatTest, All) { EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 error: image format must be one of the texel formats specified for " - "storage textues in https://gpuweb.github.io/gpuweb/wgsl/#texel-formats"); + "storage textures in https://gpuweb.github.io/gpuweb/wgsl/#texel-formats"); } } INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, @@ -1168,7 +1151,7 @@ TEST_F(StorageTextureAccessTest, MissingTemplates) { // @group(0) @binding(0) // var a : texture_storage_1d; - auto* st = ty(Source{{12, 34}}, "texture_storage_1d"); + auto st = ty(Source{{12, 34}}, "texture_storage_1d"); GlobalVar("a", st, Group(0_a), Binding(0_a)); @@ -1180,7 +1163,7 @@ TEST_F(StorageTextureAccessTest, MissingAccess_Fail) { // @group(0) @binding(0) // var a : texture_storage_1d; - auto* st = ty(Source{{12, 34}}, "texture_storage_1d", "r32uint"); + auto st = ty(Source{{12, 34}}, "texture_storage_1d", "r32uint"); GlobalVar("a", st, Group(0_a), Binding(0_a)); @@ -1192,8 +1175,8 @@ TEST_F(StorageTextureAccessTest, RWAccess_Fail) { // @group(0) @binding(0) // var a : texture_storage_1d; - auto* st = ty.storage_texture(Source{{12, 34}}, type::TextureDimension::k1d, - type::TexelFormat::kR32Uint, type::Access::kReadWrite); + auto st = ty.storage_texture(Source{{12, 34}}, type::TextureDimension::k1d, + type::TexelFormat::kR32Uint, type::Access::kReadWrite); GlobalVar("a", st, Group(0_a), Binding(0_a)); @@ -1206,8 +1189,8 @@ TEST_F(StorageTextureAccessTest, ReadOnlyAccess_Fail) { // @group(0) @binding(0) // var a : texture_storage_1d; - auto* st = ty.storage_texture(Source{{12, 34}}, type::TextureDimension::k1d, - type::TexelFormat::kR32Uint, type::Access::kRead); + auto st = ty.storage_texture(Source{{12, 34}}, type::TextureDimension::k1d, + type::TexelFormat::kR32Uint, type::Access::kRead); GlobalVar("a", st, Group(0_a), Binding(0_a)); @@ -1220,8 +1203,8 @@ TEST_F(StorageTextureAccessTest, WriteOnlyAccess_Pass) { // @group(0) @binding(0) // var a : texture_storage_1d; - auto* st = ty.storage_texture(type::TextureDimension::k1d, type::TexelFormat::kR32Uint, - type::Access::kWrite); + auto st = ty.storage_texture(type::TextureDimension::k1d, type::TexelFormat::kR32Uint, + type::Access::kWrite); GlobalVar("a", st, Group(0_a), Binding(0_a)); @@ -1250,8 +1233,9 @@ TEST_P(ValidMatrixTypes, Okay) { Enable(ast::Extension::kF16); - GlobalVar("a", ty.mat(params.elem_ty(*this), params.columns, params.rows), - type::AddressSpace::kPrivate); + ast::Type el_ty = params.elem_ty(*this); + + GlobalVar("a", ty.mat(el_ty, params.columns, params.rows), type::AddressSpace::kPrivate); EXPECT_TRUE(r()->Resolve()) << r()->error(); } INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, @@ -1289,7 +1273,9 @@ TEST_P(InvalidMatrixElementTypes, InvalidElementType) { Enable(ast::Extension::kF16); - GlobalVar("a", ty.mat(Source{{12, 34}}, params.elem_ty(*this), params.columns, params.rows), + ast::Type el_ty = params.elem_ty(*this); + + GlobalVar("a", ty.mat(Source{{12, 34}}, el_ty, params.columns, params.rows), type::AddressSpace::kPrivate); EXPECT_FALSE(r()->Resolve()); EXPECT_EQ(r()->error(), "12:34 error: matrix element type must be 'f32' or 'f16'"); @@ -1417,7 +1403,7 @@ TEST_P(BuiltinTypeAliasTest, Construct) { Enable(ast::Extension::kF16); - WrapInFunction(Decl(Var("v", params.type(*this), Call(ty(params.alias))))); + WrapInFunction(Decl(Var("v", params.type(*this), Call(params.alias)))); EXPECT_TRUE(r()->Resolve()) << r()->error(); } INSTANTIATE_TEST_SUITE_P(ResolverTypeValidationTest, @@ -1474,7 +1460,7 @@ TEST_P(ResolverUntemplatedTypeUsedWithTemplateArgs, Builtin_UseWithTemplateArgs) TEST_P(ResolverUntemplatedTypeUsedWithTemplateArgs, BuiltinAlias_UseWithTemplateArgs) { // enable f16; // alias A = f32; - // var v : S; + // var v : A; Enable(ast::Extension::kF16); Alias(Source{{56, 78}}, "A", ty(GetParam())); diff --git a/src/tint/resolver/uniformity.cc b/src/tint/resolver/uniformity.cc index 403ac53ba6..0b8fd7f991 100644 --- a/src/tint/resolver/uniformity.cc +++ b/src/tint/resolver/uniformity.cc @@ -386,12 +386,27 @@ class UniformityGraph { return current_function_->CreateNode(std::move(tag_list), ast); } - /// Get the symbol name of an AST node. - /// @param ast the AST node to get the symbol name of + /// Get the symbol name of an AST expression. + /// @param expr the expression to get the symbol name of /// @returns the symbol name - template - inline std::string NameFor(const T* ast) { - return builder_->Symbols().NameFor(ast->symbol); + inline std::string NameFor(const ast::IdentifierExpression* expr) { + return builder_->Symbols().NameFor(expr->identifier->symbol); + } + + /// @param var the variable to get the name of + /// @returns the name of the variable @p var + inline std::string NameFor(const ast::Variable* var) { + return builder_->Symbols().NameFor(var->name->symbol); + } + + /// @param var the variable to get the name of + /// @returns the name of the variable @p var + inline std::string NameFor(const sem::Variable* var) { return NameFor(var->Declaration()); } + + /// @param fn the function to get the name of + /// @returns the name of the function @p fn + inline std::string NameFor(const sem::Function* fn) { + return builder_->Symbols().NameFor(fn->Declaration()->name->symbol); } /// Process a function. @@ -621,7 +636,7 @@ class UniformityGraph { // Add an edge from the variable exit node to its value at this point. auto* exit_node = info.var_exit_nodes.GetOrCreate(var, [&]() { - auto name = NameFor(var->Declaration()->name); + auto name = NameFor(var); return CreateNode({name, "_value_", info.type, "_exit"}); }); exit_node->AddEdge(current_function_->variables.Get(var)); @@ -657,7 +672,7 @@ class UniformityGraph { // Add an edge from the variable exit node to its value at this point. auto* exit_node = info.var_exit_nodes.GetOrCreate(var, [&]() { - auto name = NameFor(var->Declaration()->name); + auto name = NameFor(var); return CreateNode({name, "_value_", info.type, "_exit"}); }); @@ -730,8 +745,7 @@ class UniformityGraph { // Create input nodes for any variables declared before this loop. for (auto* v : current_function_->local_var_decls) { - auto* in_node = - CreateNode({NameFor(v->Declaration()->name), "_value_forloop_in"}); + auto* in_node = CreateNode({NameFor(v), "_value_forloop_in"}); in_node->AddEdge(current_function_->variables.Get(v)); info.var_in_nodes.Replace(v, in_node); current_function_->variables.Set(v, in_node); @@ -748,7 +762,7 @@ class UniformityGraph { // Propagate assignments to the loop exit nodes. for (auto* var : current_function_->local_var_decls) { auto* exit_node = info.var_exit_nodes.GetOrCreate(var, [&]() { - auto name = NameFor(var->Declaration()->name); + auto name = NameFor(var); return CreateNode({name, "_value_", info.type, "_exit"}); }); exit_node->AddEdge(current_function_->variables.Get(var)); @@ -806,8 +820,7 @@ class UniformityGraph { // Create input nodes for any variables declared before this loop. for (auto* v : current_function_->local_var_decls) { - auto* in_node = - CreateNode({NameFor(v->Declaration()->name), "_value_forloop_in"}); + auto* in_node = CreateNode({NameFor(v), "_value_forloop_in"}); in_node->AddEdge(current_function_->variables.Get(v)); info.var_in_nodes.Replace(v, in_node); current_function_->variables.Set(v, in_node); @@ -825,7 +838,7 @@ class UniformityGraph { // Propagate assignments to the loop exit nodes. for (auto* var : current_function_->local_var_decls) { auto* exit_node = info.var_exit_nodes.GetOrCreate(var, [&]() { - auto name = NameFor(var->Declaration()->name); + auto name = NameFor(var); return CreateNode({name, "_value_", info.type, "_exit"}); }); exit_node->AddEdge(current_function_->variables.Get(var)); @@ -909,8 +922,7 @@ class UniformityGraph { } // Create an exit node for the variable. - auto* out_node = - CreateNode({NameFor(var->Declaration()->name), "_value_if_exit"}); + auto* out_node = CreateNode({NameFor(var), "_value_if_exit"}); // Add edges to the assigned value or the initial value. // Only add edges if the behavior for that block contains 'Next'. @@ -966,7 +978,7 @@ class UniformityGraph { // Create input nodes for any variables declared before this loop. for (auto* v : current_function_->local_var_decls) { - auto name = NameFor(v->Declaration()->name); + auto name = NameFor(v); auto* in_node = CreateNode({name, "_value_loop_in"}, v->Declaration()); in_node->AddEdge(current_function_->variables.Get(v)); info.var_in_nodes.Replace(v, in_node); @@ -1065,7 +1077,7 @@ class UniformityGraph { // Add an edge from the variable exit node to its new value. auto* exit_node = info.var_exit_nodes.GetOrCreate(var, [&]() { - auto name = NameFor(var->Declaration()->name); + auto name = NameFor(var); return CreateNode({name, "_value_", info.type, "_exit"}); }); exit_node->AddEdge(current_function_->variables.Get(var)); @@ -1144,7 +1156,7 @@ class UniformityGraph { return true; }; - auto* node = CreateNode({NameFor(ident->identifier), "_ident_expr"}, ident); + auto* node = CreateNode({NameFor(ident), "_ident_expr"}, ident); auto* sem_ident = sem_.GetVal(ident); TINT_ASSERT(Resolver, sem_ident); auto* var_user = sem_ident->Unwrap()->As(); @@ -1367,7 +1379,7 @@ class UniformityGraph { return std::make_pair(cf, current_function_->may_be_non_uniform); } else if (auto* local = sem->Variable()->As()) { // Create a new value node for this variable. - auto* value = CreateNode({NameFor(i->identifier), "_lvalue"}); + auto* value = CreateNode({NameFor(i), "_lvalue"}); auto* old_value = current_function_->variables.Set(local, value); // If i is part of an expression that is a partial reference to a variable (e.g. @@ -1404,7 +1416,7 @@ class UniformityGraph { // Cut the analysis short, since we only need to know the originating variable // that is being written to. auto* root_ident = sem_.Get(u)->RootIdentifier(); - auto* deref = CreateNode({NameFor(root_ident->Declaration()->name), "_deref"}); + auto* deref = CreateNode({NameFor(root_ident), "_deref"}); auto* old_value = current_function_->variables.Set(root_ident, deref); if (old_value) { @@ -1432,12 +1444,7 @@ class UniformityGraph { /// @param call the function call to process /// @returns a pair of (control flow node, value node) std::pair ProcessCall(Node* cf, const ast::CallExpression* call) { - std::string name; - if (call->target.name) { - name = NameFor(call->target.name); - } else { - name = call->target.type->FriendlyName(builder_->Symbols()); - } + std::string name = NameFor(call->target); // Process call arguments Node* cf_last_arg = cf; @@ -1771,10 +1778,10 @@ class UniformityGraph { std::ostringstream ss; if (auto* param = var->As()) { auto* func = param->Owner()->As(); - ss << param_type(param) << "'" << NameFor(ident->identifier) << "' of '" - << NameFor(func->Declaration()->name) << "' may be non-uniform"; + ss << param_type(param) << "'" << NameFor(ident) << "' of '" << NameFor(func) + << "' may be non-uniform"; } else { - ss << "reading from " << var_type(var) << "'" << NameFor(ident->identifier) + ss << "reading from " << var_type(var) << "'" << NameFor(ident) << "' may result in a non-uniform value"; } diagnostics_.add_note(diag::System::Resolver, ss.str(), ident->source); @@ -1782,12 +1789,12 @@ class UniformityGraph { [&](const ast::Variable* v) { auto* var = sem_.Get(v); std::ostringstream ss; - ss << "reading from " << var_type(var) << "'" << NameFor(v->name) + ss << "reading from " << var_type(var) << "'" << NameFor(v) << "' may result in a non-uniform value"; diagnostics_.add_note(diag::System::Resolver, ss.str(), v->source); }, [&](const ast::CallExpression* c) { - auto target_name = NameFor(c->target.name); + auto target_name = NameFor(c->target); switch (non_uniform_source->type) { case Node::kFunctionCallReturnValue: { diagnostics_.add_note( @@ -1799,8 +1806,7 @@ class UniformityGraph { auto* arg = c->args[non_uniform_source->arg_index]; auto* var = sem_.GetVal(arg)->RootIdentifier(); std::ostringstream ss; - ss << "reading from " << var_type(var) << "'" - << NameFor(var->Declaration()->name) + ss << "reading from " << var_type(var) << "'" << NameFor(var) << "' may result in a non-uniform value"; diagnostics_.add_note(diag::System::Resolver, ss.str(), var->Declaration()->source); @@ -1867,7 +1873,7 @@ class UniformityGraph { auto* call = cause->ast->As(); TINT_ASSERT(Resolver, call); auto* target = SemCall(call)->Target(); - auto func_name = NameFor(call->target.name); + auto func_name = NameFor(call->target); if (cause->type == Node::kFunctionCallArgumentValue || cause->type == Node::kFunctionCallArgumentContents) { @@ -1897,7 +1903,7 @@ class UniformityGraph { // Show a builtin was reachable from this call (which may be the call itself). // This will be the trigger location for the failure. std::ostringstream ss; - ss << "'" << NameFor(builtin_call->target.name) + ss << "'" << NameFor(builtin_call->target) << "' must only be called from uniform control flow"; report(builtin_call->source, ss.str(), /* note */ false); } diff --git a/src/tint/resolver/uniformity_test.cc b/src/tint/resolver/uniformity_test.cc index 719db08329..1cf996d86c 100644 --- a/src/tint/resolver/uniformity_test.cc +++ b/src/tint/resolver/uniformity_test.cc @@ -5330,7 +5330,7 @@ TEST_F(UniformityAnalysisTest, MaximumNumberOfPointerParameters) { args.Push(b.AddressOf(name)); } main_body.Push(b.Assign("v0", "non_uniform_global")); - main_body.Push(b.CallStmt(b.create(b.Ident("foo"), args))); + main_body.Push(b.CallStmt(b.Call("foo", args))); main_body.Push(b.If(b.Equal("v254", 0_i), b.Block(b.CallStmt(b.Call("workgroupBarrier"))))); b.Func("main", utils::Empty, ty.void_(), main_body); diff --git a/src/tint/resolver/validation_test.cc b/src/tint/resolver/validation_test.cc index bbfd4aa423..634e3a2f16 100644 --- a/src/tint/resolver/validation_test.cc +++ b/src/tint/resolver/validation_test.cc @@ -294,7 +294,7 @@ TEST_F(ResolverValidationTest, AddressSpace_FunctionVariableI32) { } TEST_F(ResolverValidationTest, AddressSpace_SamplerExplicitAddressSpace) { - auto* t = ty.sampler(type::SamplerKind::kSampler); + auto t = ty.sampler(type::SamplerKind::kSampler); GlobalVar(Source{{12, 34}}, "var", t, type::AddressSpace::kHandle, Binding(0_a), Group(0_a)); EXPECT_FALSE(r()->Resolve()); @@ -304,7 +304,7 @@ TEST_F(ResolverValidationTest, AddressSpace_SamplerExplicitAddressSpace) { } TEST_F(ResolverValidationTest, AddressSpace_TextureExplicitAddressSpace) { - auto* t = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); + auto t = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); GlobalVar(Source{{12, 34}}, "var", t, type::AddressSpace::kHandle, Binding(0_a), Group(0_a)); EXPECT_FALSE(r()->Resolve()) << r()->error(); diff --git a/src/tint/resolver/validator.cc b/src/tint/resolver/validator.cc index 71e39af01f..0a7abcf56c 100644 --- a/src/tint/resolver/validator.cc +++ b/src/tint/resolver/validator.cc @@ -19,7 +19,6 @@ #include #include "src/tint/ast/alias.h" -#include "src/tint/ast/array.h" #include "src/tint/ast/assignment_statement.h" #include "src/tint/ast/bitcast_expression.h" #include "src/tint/ast/break_statement.h" @@ -33,16 +32,11 @@ #include "src/tint/ast/internal_attribute.h" #include "src/tint/ast/interpolate_attribute.h" #include "src/tint/ast/loop_statement.h" -#include "src/tint/ast/matrix.h" -#include "src/tint/ast/pointer.h" #include "src/tint/ast/return_statement.h" -#include "src/tint/ast/sampled_texture.h" #include "src/tint/ast/switch_statement.h" #include "src/tint/ast/traverse_expressions.h" -#include "src/tint/ast/type_name.h" #include "src/tint/ast/unary_op_expression.h" #include "src/tint/ast/variable_decl_statement.h" -#include "src/tint/ast/vector.h" #include "src/tint/ast/workgroup_attribute.h" #include "src/tint/sem/break_if_statement.h" #include "src/tint/sem/call.h" @@ -283,28 +277,28 @@ const ast::Statement* Validator::ClosestContinuing(bool stop_at_loop, return nullptr; } -bool Validator::Atomic(const ast::Atomic* a, const type::Atomic* s) const { +bool Validator::Atomic(const ast::TemplatedIdentifier* a, const type::Atomic* s) const { // https://gpuweb.github.io/gpuweb/wgsl/#atomic-types // T must be either u32 or i32. if (!s->Type()->IsAnyOf()) { - AddError("atomic only supports i32 or u32 types", a->type ? a->type->source : a->source); + AddError("atomic only supports i32 or u32 types", a->arguments[0]->source); return false; } return true; } -bool Validator::Pointer(const ast::Pointer* a, const type::Pointer* s) const { +bool Validator::Pointer(const ast::TemplatedIdentifier* a, const type::Pointer* s) const { if (s->AddressSpace() == type::AddressSpace::kUndefined) { AddError("ptr missing address space", a->source); return false; } - if (a->access != type::Access::kUndefined) { + if (a->arguments.Length() > 2) { // ptr // https://www.w3.org/TR/WGSL/#access-mode-defaults // When writing a variable declaration or a pointer type in WGSL source: // * For the storage address space, the access mode is optional, and defaults to read. // * For other address spaces, the access mode must not be written. - if (a->address_space != type::AddressSpace::kStorage) { + if (s->AddressSpace() != type::AddressSpace::kStorage) { AddError("only pointers in address space may declare an access mode", a->source); return false; @@ -1567,10 +1561,10 @@ bool Validator::BuiltinCall(const sem::Call* call) const { } if (!is_call_statement) { // https://gpuweb.github.io/gpuweb/wgsl/#function-call-expr - // If the called function does not return a value, a function call - // statement should be used instead. - auto* ident = call->Declaration()->target.name; - auto name = symbols_.NameFor(ident->symbol); + // If the called function does not return a value, a function call statement should be + // used instead. + auto* builtin = call->Target()->As(); + auto name = utils::ToString(builtin->Type()); AddError("builtin '" + name + "' does not return a value", call->Declaration()->source); return false; } @@ -1685,7 +1679,7 @@ bool Validator::CheckF16Enabled(const Source& source) const { bool Validator::FunctionCall(const sem::Call* call, sem::Statement* current_statement) const { auto* decl = call->Declaration(); auto* target = call->Target()->As(); - auto sym = decl->target.name->symbol; + auto sym = target->Declaration()->name->symbol; auto name = symbols_.NameFor(sym); if (!current_statement) { // Function call at module-scope. @@ -1852,16 +1846,16 @@ bool Validator::ArrayInitializer(const ast::CallExpression* ctor, return true; } -bool Validator::Vector(const type::Vector* ty, const Source& source) const { - if (!ty->type()->is_scalar()) { +bool Validator::Vector(const type::Type* el_ty, const Source& source) const { + if (!el_ty->is_scalar()) { AddError("vector element type must be 'bool', 'f32', 'f16', 'i32' or 'u32'", source); return false; } return true; } -bool Validator::Matrix(const type::Matrix* ty, const Source& source) const { - if (!ty->is_float_matrix()) { +bool Validator::Matrix(const type::Type* el_ty, const Source& source) const { + if (!el_ty->is_float_scalar()) { AddError("matrix element type must be 'f32' or 'f16'", source); return false; } diff --git a/src/tint/resolver/validator.h b/src/tint/resolver/validator.h index 9e11f5058b..dc1bea64ef 100644 --- a/src/tint/resolver/validator.h +++ b/src/tint/resolver/validator.h @@ -185,13 +185,13 @@ class Validator { /// @param a the atomic ast node /// @param s the atomic sem node /// @returns true on success, false otherwise. - bool Atomic(const ast::Atomic* a, const type::Atomic* s) const; + bool Atomic(const ast::TemplatedIdentifier* a, const type::Atomic* s) const; /// Validates a pointer type /// @param a the pointer ast node /// @param s the pointer sem node /// @returns true on success, false otherwise. - bool Pointer(const ast::Pointer* a, const type::Pointer* s) const; + bool Pointer(const ast::TemplatedIdentifier* a, const type::Pointer* s) const; /// Validates an assignment /// @param a the assignment statement @@ -343,10 +343,10 @@ class Validator { bool Materialize(const type::Type* to, const type::Type* from, const Source& source) const; /// Validates a matrix - /// @param ty the matrix to validate + /// @param el_ty the matrix element type to validate /// @param source the source of the matrix /// @returns true on success, false otherwise - bool Matrix(const type::Matrix* ty, const Source& source) const; + bool Matrix(const type::Type* el_ty, const Source& source) const; /// Validates a function parameter /// @param func the function the variable is for @@ -440,10 +440,10 @@ class Validator { const sem::ValueExpression* initializer) const; /// Validates a vector - /// @param ty the vector to validate + /// @param el_ty the vector element type to validate /// @param source the source of the vector /// @returns true on success, false otherwise - bool Vector(const type::Vector* ty, const Source& source) const; + bool Vector(const type::Type* el_ty, const Source& source) const; /// Validates an array initializer /// @param ctor the call expresion to validate diff --git a/src/tint/resolver/variable_test.cc b/src/tint/resolver/variable_test.cc index 9d00a5ad7e..c5af49ce44 100644 --- a/src/tint/resolver/variable_test.cc +++ b/src/tint/resolver/variable_test.cc @@ -902,7 +902,7 @@ TEST_F(ResolverVariableTest, LocalConst_ExplicitType_Decls) { auto* c_vu32 = Const("e", ty.vec3(), vec3()); auto* c_vf32 = Const("f", ty.vec3(), vec3()); auto* c_mf32 = Const("g", ty.mat3x3(), mat3x3()); - auto* c_s = Const("h", ty("S"), Call(ty("S"))); + auto* c_s = Const("h", ty("S"), Call("S")); WrapInFunction(c_i32, c_u32, c_f32, c_vi32, c_vu32, c_vf32, c_mf32, c_s); @@ -947,14 +947,14 @@ TEST_F(ResolverVariableTest, LocalConst_ImplicitType_Decls) { auto* c_vi32 = Const("f", vec3()); auto* c_vu32 = Const("g", vec3()); auto* c_vf32 = Const("h", vec3()); - auto* c_vai = Const("i", Call(ty.vec(nullptr, 3), Expr(0_a))); - auto* c_vaf = Const("j", Call(ty.vec(nullptr, 3), Expr(0._a))); + auto* c_vai = Const("i", Call(ty.vec(3), Expr(0_a))); + auto* c_vaf = Const("j", Call(ty.vec(3), Expr(0._a))); auto* c_mf32 = Const("k", mat3x3()); auto* c_maf32 = - Const("l", Call(ty.mat(nullptr, 3, 3), // - Call(ty.vec(nullptr, 3), Expr(0._a)), Call(ty.vec(nullptr, 3), Expr(0._a)), - Call(ty.vec(nullptr, 3), Expr(0._a)))); - auto* c_s = Const("m", Call(ty("S"))); + Const("l", Call(ty.mat3x3(), // + Call(ty.vec(3), Expr(0._a)), Call(ty.vec(3), Expr(0._a)), + Call(ty.vec(3), Expr(0._a)))); + auto* c_s = Const("m", Call("S")); WrapInFunction(c_i32, c_u32, c_f32, c_ai, c_af, c_vi32, c_vu32, c_vf32, c_vai, c_vaf, c_mf32, c_maf32, c_s); @@ -1123,13 +1123,13 @@ TEST_F(ResolverVariableTest, GlobalConst_ImplicitType_Decls) { auto* c_vi32 = GlobalConst("f", vec3()); auto* c_vu32 = GlobalConst("g", vec3()); auto* c_vf32 = GlobalConst("h", vec3()); - auto* c_vai = GlobalConst("i", Call(ty.vec(nullptr, 3), Expr(0_a))); - auto* c_vaf = GlobalConst("j", Call(ty.vec(nullptr, 3), Expr(0._a))); + auto* c_vai = GlobalConst("i", Call(ty.vec(3), Expr(0_a))); + auto* c_vaf = GlobalConst("j", Call(ty.vec(3), Expr(0._a))); auto* c_mf32 = GlobalConst("k", mat3x3()); auto* c_maf32 = GlobalConst( - "l", Call(ty.mat(nullptr, 3, 3), // - Call(ty.vec(nullptr, 3), Expr(0._a)), Call(ty.vec(nullptr, 3), Expr(0._a)), - Call(ty.vec(nullptr, 3), Expr(0._a)))); + "l", Call(ty.mat3x3(), // + Call(ty.vec(3), Expr(0._a)), Call(ty.vec(3), Expr(0._a)), + Call(ty.vec(3), Expr(0._a)))); ASSERT_TRUE(r()->Resolve()) << r()->error(); diff --git a/src/tint/resolver/variable_validation_test.cc b/src/tint/resolver/variable_validation_test.cc index 543404260f..2649562bd1 100644 --- a/src/tint/resolver/variable_validation_test.cc +++ b/src/tint/resolver/variable_validation_test.cc @@ -369,52 +369,51 @@ TEST_F(ResolverVariableValidationTest, InvalidAddressSpaceForInitializer) { } TEST_F(ResolverVariableValidationTest, VectorConstNoType) { - // const a : mat3x3 = mat3x3(); - WrapInFunction(Const("a", create(Source{{12, 34}}, nullptr, 3u), vec3())); + // const a vec3 = vec3(); + WrapInFunction(Const("a", ty.vec3(Source{{12, 34}}), vec3())); EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: missing vector element type"); + EXPECT_EQ(r()->error(), "12:34 error: expected '<' for 'vec3'"); } TEST_F(ResolverVariableValidationTest, VectorLetNoType) { - // let a : mat3x3 = mat3x3(); - WrapInFunction(Let("a", create(Source{{12, 34}}, nullptr, 3u), vec3())); + // let a : vec3 = vec3(); + WrapInFunction(Let("a", ty.vec3(Source{{12, 34}}), vec3())); EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: missing vector element type"); + EXPECT_EQ(r()->error(), "12:34 error: expected '<' for 'vec3'"); } TEST_F(ResolverVariableValidationTest, VectorVarNoType) { - // var a : mat3x3; - WrapInFunction(Var("a", create(Source{{12, 34}}, nullptr, 3u))); + // var a : vec3; + WrapInFunction(Var("a", ty.vec3(Source{{12, 34}}))); EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: missing vector element type"); + EXPECT_EQ(r()->error(), "12:34 error: expected '<' for 'vec3'"); } TEST_F(ResolverVariableValidationTest, MatrixConstNoType) { // const a : mat3x3 = mat3x3(); - WrapInFunction( - Const("a", create(Source{{12, 34}}, nullptr, 3u, 3u), mat3x3())); + WrapInFunction(Const("a", ty.mat3x3(Source{{12, 34}}), mat3x3())); EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: missing matrix element type"); + EXPECT_EQ(r()->error(), "12:34 error: expected '<' for 'mat3x3'"); } TEST_F(ResolverVariableValidationTest, MatrixLetNoType) { // let a : mat3x3 = mat3x3(); - WrapInFunction(Let("a", create(Source{{12, 34}}, nullptr, 3u, 3u), mat3x3())); + WrapInFunction(Let("a", ty.mat3x3(Source{{12, 34}}), mat3x3())); EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: missing matrix element type"); + EXPECT_EQ(r()->error(), "12:34 error: expected '<' for 'mat3x3'"); } TEST_F(ResolverVariableValidationTest, MatrixVarNoType) { // var a : mat3x3; - WrapInFunction(Var("a", create(Source{{12, 34}}, nullptr, 3u, 3u))); + WrapInFunction(Var("a", ty.mat3x3(Source{{12, 34}}))); EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: missing matrix element type"); + EXPECT_EQ(r()->error(), "12:34 error: expected '<' for 'mat3x3'"); } TEST_F(ResolverVariableValidationTest, GlobalConstWithRuntimeExpression) { diff --git a/src/tint/sem/type_mappings.h b/src/tint/sem/type_mappings.h index 419a9c2087..fa7d8c61e3 100644 --- a/src/tint/sem/type_mappings.h +++ b/src/tint/sem/type_mappings.h @@ -23,7 +23,6 @@ class CastableBase; } // namespace tint namespace tint::ast { class AccessorExpression; -class Array; class BinaryExpression; class BitcastExpression; class CallExpression; @@ -39,7 +38,6 @@ class Statement; class Struct; class StructMember; class SwitchStatement; -class Type; class TypeDecl; class Variable; class WhileStatement; @@ -73,7 +71,6 @@ namespace tint::sem { /// rules will be used to infer the return type based on the argument type. struct TypeMappings { //! @cond Doxygen_Suppress - type::Array* operator()(ast::Array*); ForLoopStatement* operator()(ast::ForLoopStatement*); Function* operator()(ast::Function*); IfStatement* operator()(ast::IfStatement*); @@ -83,7 +80,6 @@ struct TypeMappings { Struct* operator()(ast::Struct*); StructMember* operator()(ast::StructMember*); SwitchStatement* operator()(ast::SwitchStatement*); - type::Type* operator()(ast::Type*); type::Type* operator()(ast::TypeDecl*); Expression* operator()(ast::Expression*); ValueExpression* operator()(ast::AccessorExpression*); diff --git a/src/tint/traits.h b/src/tint/traits.h index 1d0c2f6e94..8d74bf75f2 100644 --- a/src/tint/traits.h +++ b/src/tint/traits.h @@ -110,11 +110,6 @@ using EnableIf = typename std::enable_if::type; template using EnableIfIsType = EnableIf, T>; -/// If `T` is not of type `BASE`, or does not derive from `BASE`, then -/// EnableIfIsNotType resolves to type `T`, otherwise an invalid type. -template -using EnableIfIsNotType = EnableIf, T>; - /// @returns the std::index_sequence with all the indices shifted by OFFSET. template constexpr auto Shift(std::index_sequence) { diff --git a/src/tint/transform/add_block_attribute.cc b/src/tint/transform/add_block_attribute.cc index e2a0c000f0..2b1ec31b4e 100644 --- a/src/tint/transform/add_block_attribute.cc +++ b/src/tint/transform/add_block_attribute.cc @@ -78,7 +78,7 @@ Transform::ApplyResult AddBlockAttribute::Apply(const Program* src, ctx.InsertBefore(src->AST().GlobalDeclarations(), global, ret); return ret; }); - ctx.Replace(global->type, b.ty.Of(wrapper)); + ctx.Replace(global->type.expr, b.Expr(wrapper->name->symbol)); // Insert a member accessor to get the original type from the wrapper at // any usage of the original variable. diff --git a/src/tint/transform/binding_remapper.cc b/src/tint/transform/binding_remapper.cc index 470826d453..b6579807e3 100644 --- a/src/tint/transform/binding_remapper.cc +++ b/src/tint/transform/binding_remapper.cc @@ -138,7 +138,7 @@ Transform::ApplyResult BindingRemapper::Apply(const Program* src, return Program(std::move(b)); } auto* ty = sem->Type()->UnwrapRef(); - const ast::Type* inner_ty = CreateASTTypeFor(ctx, ty); + auto inner_ty = CreateASTTypeFor(ctx, ty); auto* new_var = b.Var(ctx.Clone(var->source), ctx.Clone(var->name->symbol), inner_ty, var->declared_address_space, ac, ctx.Clone(var->initializer), ctx.Clone(var->attributes)); diff --git a/src/tint/transform/builtin_polyfill.cc b/src/tint/transform/builtin_polyfill.cc index 3d647a745f..5baef8a7b4 100644 --- a/src/tint/transform/builtin_polyfill.cc +++ b/src/tint/transform/builtin_polyfill.cc @@ -176,7 +176,7 @@ struct BuiltinPolyfill::State { uint32_t width = WidthOf(ty); // Returns either u32 or vecN - auto U = [&]() -> const ast::Type* { + auto U = [&]() { if (width == 1) { return b.ty.u32(); } @@ -234,7 +234,7 @@ struct BuiltinPolyfill::State { uint32_t width = WidthOf(ty); // Returns either u32 or vecN - auto U = [&]() -> const ast::Type* { + auto U = [&]() { if (width == 1) { return b.ty.u32(); } @@ -351,7 +351,7 @@ struct BuiltinPolyfill::State { uint32_t width = WidthOf(ty); // Returns either u32 or vecN - auto U = [&]() -> const ast::Type* { + auto U = [&]() { if (width == 1) { return b.ty.u32(); } @@ -423,7 +423,7 @@ struct BuiltinPolyfill::State { uint32_t width = WidthOf(ty); // Returns either u32 or vecN - auto U = [&]() -> const ast::Type* { + auto U = [&]() { if (width == 1) { return b.ty.u32(); } @@ -825,7 +825,7 @@ struct BuiltinPolyfill::State { bool has_full_ptr_params; /// @returns the AST type for the given sem type - const ast::Type* T(const type::Type* ty) const { return CreateASTTypeFor(ctx, ty); } + ast::Type T(const type::Type* ty) const { return CreateASTTypeFor(ctx, ty); } /// @returns 1 if `ty` is not a vector, otherwise the vector width uint32_t WidthOf(const type::Type* ty) const { @@ -1067,15 +1067,17 @@ Transform::ApplyResult BuiltinPolyfill::Apply(const Program* src, break; } }, - [&](const ast::TypeName* type_name) { + [&](const ast::Expression* expr) { if (polyfill.bgra8unorm) { - if (auto* tex = src->Sem().Get(type_name)) { - if (tex->texel_format() == type::TexelFormat::kBgra8Unorm) { - ctx.Replace(type_name, [&ctx, tex] { - return ctx.dst->ty.storage_texture( - tex->dim(), type::TexelFormat::kRgba8Unorm, tex->access()); - }); - made_changes = true; + if (auto* ty_expr = src->Sem().Get(expr)) { + if (auto* tex = ty_expr->Type()->As()) { + if (tex->texel_format() == type::TexelFormat::kBgra8Unorm) { + ctx.Replace(expr, [&ctx, tex] { + return ctx.dst->Expr(ctx.dst->ty.storage_texture( + tex->dim(), type::TexelFormat::kRgba8Unorm, tex->access())); + }); + made_changes = true; + } } } } diff --git a/src/tint/transform/calculate_array_length.cc b/src/tint/transform/calculate_array_length.cc index 028f8c50ca..5ed6547f1a 100644 --- a/src/tint/transform/calculate_array_length.cc +++ b/src/tint/transform/calculate_array_length.cc @@ -104,10 +104,10 @@ Transform::ApplyResult CalculateArrayLength::Apply(const Program* src, auto get_buffer_size_intrinsic = [&](const type::Reference* buffer_type) { return utils::GetOrCreate(buffer_size_intrinsics, buffer_type, [&] { auto name = b.Sym(); - auto* type = CreateASTTypeFor(ctx, buffer_type); + auto type = CreateASTTypeFor(ctx, buffer_type); auto* disable_validation = b.Disable(ast::DisabledValidation::kFunctionParameter); - b.AST().AddFunction(b.create( - b.Ident(name), + b.Func( + name, utils::Vector{ b.Param("buffer", b.ty.pointer(type, buffer_type->AddressSpace(), buffer_type->Access()), @@ -117,8 +117,7 @@ Transform::ApplyResult CalculateArrayLength::Apply(const Program* src, b.ty.void_(), nullptr, utils::Vector{ b.ASTNodes().Create(b.ID(), b.AllocateNodeID()), - }, - utils::Empty)); + }); return name; }); diff --git a/src/tint/transform/canonicalize_entry_point_io.cc b/src/tint/transform/canonicalize_entry_point_io.cc index f51d4ccdac..81c2821ed9 100644 --- a/src/tint/transform/canonicalize_entry_point_io.cc +++ b/src/tint/transform/canonicalize_entry_point_io.cc @@ -130,7 +130,7 @@ struct CanonicalizeEntryPointIO::State { /// The name of the output value. std::string name; /// The type of the output value. - const ast::Type* type; + ast::Type type; /// The shader IO attributes. utils::Vector attributes; /// The value itself. @@ -210,7 +210,7 @@ struct CanonicalizeEntryPointIO::State { const type::Type* type, std::optional location, utils::Vector attributes) { - auto* ast_type = CreateASTTypeFor(ctx, type); + auto ast_type = CreateASTTypeFor(ctx, type); if (cfg.shader_style == ShaderStyle::kSpirv || cfg.shader_style == ShaderStyle::kGlsl) { // Vulkan requires that integer user-defined fragment inputs are always decorated with // `Flat`. See: @@ -524,7 +524,7 @@ struct CanonicalizeEntryPointIO::State { // Create the global variable and assign it the output value. auto name = ctx.dst->Symbols().New(outval.name); - auto* type = outval.type; + ast::Type type = outval.type; const ast::Expression* lhs = ctx.dst->Expr(name); if (HasSampleMask(attributes)) { // Vulkan requires the type of a SampleMask builtin to be an array. @@ -606,7 +606,7 @@ struct CanonicalizeEntryPointIO::State { auto* call_inner = CallInnerFunction(); // Process the return type, and start building the wrapper function body. - std::function wrapper_ret_type = [&] { return ctx.dst->ty.void_(); }; + std::function wrapper_ret_type = [&] { return ctx.dst->ty.void_(); }; if (func_sem->ReturnType()->Is()) { // The function call is just a statement with no result. wrapper_body.Push(ctx.dst->CallStmt(call_inner)); @@ -665,7 +665,7 @@ struct CanonicalizeEntryPointIO::State { } auto* wrapper_func = ctx.dst->create( - ctx.dst->Ident(name), wrapper_ep_parameters, wrapper_ret_type(), + ctx.dst->Ident(name), wrapper_ep_parameters, ctx.dst->ty(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); } @@ -727,7 +727,7 @@ struct CanonicalizeEntryPointIO::State { /// WGSL expects const ast::Expression* FromGLSLBuiltin(ast::BuiltinValue builtin, const ast::Expression* value, - const ast::Type*& ast_type) { + ast::Type& ast_type) { switch (builtin) { case ast::BuiltinValue::kVertexIndex: case ast::BuiltinValue::kInstanceIndex: diff --git a/src/tint/transform/clamp_frag_depth.cc b/src/tint/transform/clamp_frag_depth.cc index 2e6ef2d36d..0b8d8f747e 100644 --- a/src/tint/transform/clamp_frag_depth.cc +++ b/src/tint/transform/clamp_frag_depth.cc @@ -22,7 +22,6 @@ #include "src/tint/ast/function.h" #include "src/tint/ast/module.h" #include "src/tint/ast/struct.h" -#include "src/tint/ast/type.h" #include "src/tint/program_builder.h" #include "src/tint/sem/function.h" #include "src/tint/sem/statement.h" @@ -163,10 +162,9 @@ Transform::ApplyResult ClampFragDepth::Apply(const Program* src, const DataMap&, // } auto* struct_ty = sem.Get(fn)->ReturnType()->As()->Declaration(); auto helper = io_structs_clamp_helpers.GetOrCreate(struct_ty, [&] { - auto* return_ty = fn->return_type; + auto return_ty = fn->return_type; auto fn_sym = - b.Symbols().New("clamp_frag_depth_" + - sym.NameFor(return_ty->As()->name->symbol)); + b.Symbols().New("clamp_frag_depth_" + sym.NameFor(struct_ty->name->symbol)); utils::Vector initializer_args; for (auto* member : struct_ty->members) { diff --git a/src/tint/transform/combine_samplers.cc b/src/tint/transform/combine_samplers.cc index c3593efdda..7b9f9fd32d 100644 --- a/src/tint/transform/combine_samplers.cc +++ b/src/tint/transform/combine_samplers.cc @@ -115,7 +115,7 @@ struct CombineSamplers::State { if (it != binding_info->binding_map.end()) { name = it->second; } - const ast::Type* type = CreateCombinedASTTypeFor(texture_var, sampler_var); + ast::Type type = CreateCombinedASTTypeFor(texture_var, sampler_var); Symbol symbol = ctx.dst->Symbols().New(name); return ctx.dst->GlobalVar(symbol, type, Attributes()); } @@ -124,7 +124,7 @@ struct CombineSamplers::State { /// @param kind the sampler kind to create for /// @returns the newly-created global variable const ast::Variable* CreatePlaceholder(type::SamplerKind kind) { - const ast::Type* type = ctx.dst->ty.sampler(kind); + ast::Type type = ctx.dst->ty.sampler(kind); const char* name = kind == type::SamplerKind::kComparisonSampler ? "placeholder_comparison_sampler" : "placeholder_sampler"; @@ -132,18 +132,17 @@ struct CombineSamplers::State { return ctx.dst->GlobalVar(symbol, type, Attributes()); } - /// Creates ast::Type for a given texture and sampler variable pair. + /// Creates ast::Identifier for a given texture and sampler variable pair. /// Depth textures with no samplers are turned into the corresponding /// f32 texture (e.g., texture_depth_2d -> texture_2d). /// @param texture the texture variable of interest /// @param sampler the texture variable of interest /// @returns the newly-created type - const ast::Type* CreateCombinedASTTypeFor(const sem::Variable* texture, - const sem::Variable* sampler) { + ast::Type CreateCombinedASTTypeFor(const sem::Variable* texture, const sem::Variable* sampler) { const type::Type* texture_type = texture->Type()->UnwrapRef(); const type::DepthTexture* depth = texture_type->As(); if (depth && !sampler) { - return ctx.dst->create(depth->dim(), ctx.dst->ty.f32()); + return ctx.dst->ty.sampled_texture(depth->dim(), ctx.dst->ty.f32()); } else { return CreateASTTypeFor(ctx, texture_type); } @@ -158,7 +157,7 @@ struct CombineSamplers::State { // by combined samplers. for (auto* global : ctx.src->AST().GlobalVariables()) { auto* global_sem = sem.Get(global)->As(); - auto* type = sem.Get(global->type); + auto* type = ctx.src->TypeOf(global->type); if (tint::IsAnyOf(type) && !type->Is()) { ctx.Remove(ctx.src->AST().GlobalDeclarations(), global); @@ -199,7 +198,7 @@ struct CombineSamplers::State { } else { // Either texture or sampler (or both) is a function parameter; // add a new function parameter to represent the combined sampler. - auto* type = CreateCombinedASTTypeFor(texture_var, sampler_var); + ast::Type type = CreateCombinedASTTypeFor(texture_var, sampler_var); auto* var = ctx.dst->Param(ctx.dst->Symbols().New(name), type); params.Push(var); function_combined_texture_samplers_[fn][pair] = var; @@ -215,7 +214,7 @@ struct CombineSamplers::State { // Create a new function signature that differs only in the parameter // list. auto name = ctx.Clone(ast_fn->name); - auto* return_type = ctx.Clone(ast_fn->return_type); + 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); @@ -276,8 +275,7 @@ struct CombineSamplers::State { args.Push(ctx.Clone(arg)); } } - const ast::Expression* value = - ctx.dst->Call(ctx.Clone(expr->target.name), args); + const ast::Expression* value = ctx.dst->Call(ctx.Clone(expr->target), args); if (builtin->Type() == sem::BuiltinType::kTextureLoad && texture_var->Type()->UnwrapRef()->Is() && !call->Stmt()->Declaration()->Is()) { @@ -329,7 +327,7 @@ struct CombineSamplers::State { args.Push(ctx.Clone(arg)); } } - return ctx.dst->Call(ctx.Clone(expr->target.name), args); + return ctx.dst->Call(ctx.Clone(expr->target), args); } } return nullptr; diff --git a/src/tint/transform/decompose_memory_access.cc b/src/tint/transform/decompose_memory_access.cc index fc2003c94c..072c9c6661 100644 --- a/src/tint/transform/decompose_memory_access.cc +++ b/src/tint/transform/decompose_memory_access.cc @@ -23,7 +23,6 @@ #include "src/tint/ast/assignment_statement.h" #include "src/tint/ast/call_statement.h" #include "src/tint/ast/disable_validation_attribute.h" -#include "src/tint/ast/type_name.h" #include "src/tint/ast/unary_op.h" #include "src/tint/program_builder.h" #include "src/tint/sem/call.h" @@ -481,15 +480,12 @@ struct DecomposeMemoryAccess::State { auto name = b.Sym(); if (auto* intrinsic = IntrinsicLoadFor(ctx.dst, address_space, el_ty)) { - auto* el_ast_ty = CreateASTTypeFor(ctx, el_ty); - auto* func = b.create( - b.Ident(name), params, el_ast_ty, nullptr, - utils::Vector{ - intrinsic, - b.Disable(ast::DisabledValidation::kFunctionHasNoBody), - }, - utils::Empty); - b.AST().AddFunction(func); + auto el_ast_ty = CreateASTTypeFor(ctx, el_ty); + b.Func(name, params, el_ast_ty, nullptr, + utils::Vector{ + intrinsic, + b.Disable(ast::DisabledValidation::kFunctionHasNoBody), + }); } else if (auto* arr_ty = el_ty->As()) { // fn load_func(buffer : buf_ty, offset : u32) -> array { // var arr : array; @@ -581,14 +577,11 @@ struct DecomposeMemoryAccess::State { auto name = b.Sym(); if (auto* intrinsic = IntrinsicStoreFor(ctx.dst, address_space, el_ty)) { - auto* func = b.create( - b.Ident(name), params, b.ty.void_(), nullptr, - utils::Vector{ - intrinsic, - b.Disable(ast::DisabledValidation::kFunctionHasNoBody), - }, - utils::Empty); - b.AST().AddFunction(func); + b.Func(name, params, b.ty.void_(), nullptr, + utils::Vector{ + intrinsic, + b.Disable(ast::DisabledValidation::kFunctionHasNoBody), + }); } else { auto body = Switch>( el_ty, // @@ -695,7 +688,7 @@ struct DecomposeMemoryAccess::State { // Other parameters are copied as-is: for (size_t i = 1; i < intrinsic->Parameters().Length(); i++) { auto* param = intrinsic->Parameters()[i]; - auto* ty = CreateASTTypeFor(ctx, param->Type()); + auto ty = CreateASTTypeFor(ctx, param->Type()); params.Push(b.Param("param_" + std::to_string(i), ty)); } @@ -706,7 +699,7 @@ struct DecomposeMemoryAccess::State { << el_ty->TypeInfo().name; } - const ast::Type* ret_ty = nullptr; + ast::Type ret_ty; // For intrinsics that return a struct, there is no AST node for it, so create one now. if (intrinsic->Type() == sem::BuiltinType::kAtomicCompareExchangeWeak) { @@ -727,17 +720,13 @@ struct DecomposeMemoryAccess::State { ret_ty = CreateASTTypeFor(ctx, intrinsic->ReturnType()); } - auto* func = b.create( - b.Ident(b.Symbols().New(std::string{"tint_"} + intrinsic->str())), params, ret_ty, - nullptr, - utils::Vector{ - atomic, - b.Disable(ast::DisabledValidation::kFunctionHasNoBody), - }, - utils::Empty); - - b.AST().AddFunction(func); - return func->name->symbol; + auto name = b.Symbols().New(std::string{"tint_"} + intrinsic->str()); + b.Func(name, std::move(params), ret_ty, nullptr, + utils::Vector{ + atomic, + b.Disable(ast::DisabledValidation::kFunctionHasNoBody), + }); + return name; }); } }; diff --git a/src/tint/transform/decompose_memory_access_test.cc b/src/tint/transform/decompose_memory_access_test.cc index b58d340a4b..f0f441f39a 100644 --- a/src/tint/transform/decompose_memory_access_test.cc +++ b/src/tint/transform/decompose_memory_access_test.cc @@ -1584,16 +1584,16 @@ fn tint_symbol_33(@internal(disable_validation__function_parameter) buffer : ptr } fn tint_symbol_34(@internal(disable_validation__function_parameter) buffer : ptr, offset : u32, value : array, 2u>) { - var array = value; + var array_1 = value; for(var i = 0u; (i < 2u); i = (i + 1u)) { - tint_symbol_8(buffer, (offset + (i * 16u)), array[i]); + tint_symbol_8(buffer, (offset + (i * 16u)), array_1[i]); } } fn tint_symbol_35(@internal(disable_validation__function_parameter) buffer : ptr, offset : u32, value : array, 2u>) { - var array_1 = value; + var array_2 = value; for(var i_1 = 0u; (i_1 < 2u); i_1 = (i_1 + 1u)) { - tint_symbol_31(buffer, (offset + (i_1 * 16u)), array_1[i_1]); + tint_symbol_31(buffer, (offset + (i_1 * 16u)), array_2[i_1]); } } @@ -1889,16 +1889,16 @@ fn tint_symbol_33(@internal(disable_validation__function_parameter) buffer : ptr } fn tint_symbol_34(@internal(disable_validation__function_parameter) buffer : ptr, offset : u32, value : array, 2u>) { - var array = value; + var array_1 = value; for(var i = 0u; (i < 2u); i = (i + 1u)) { - tint_symbol_8(buffer, (offset + (i * 16u)), array[i]); + tint_symbol_8(buffer, (offset + (i * 16u)), array_1[i]); } } fn tint_symbol_35(@internal(disable_validation__function_parameter) buffer : ptr, offset : u32, value : array, 2u>) { - var array_1 = value; + var array_2 = value; for(var i_1 = 0u; (i_1 < 2u); i_1 = (i_1 + 1u)) { - tint_symbol_31(buffer, (offset + (i_1 * 16u)), array_1[i_1]); + tint_symbol_31(buffer, (offset + (i_1 * 16u)), array_2[i_1]); } } @@ -2733,16 +2733,16 @@ fn tint_symbol_34(@internal(disable_validation__function_parameter) buffer : ptr } fn tint_symbol_35(@internal(disable_validation__function_parameter) buffer : ptr, offset : u32, value : array, 2u>) { - var array = value; + var array_1 = value; for(var i = 0u; (i < 2u); i = (i + 1u)) { - tint_symbol_9(buffer, (offset + (i * 16u)), array[i]); + tint_symbol_9(buffer, (offset + (i * 16u)), array_1[i]); } } fn tint_symbol_36(@internal(disable_validation__function_parameter) buffer : ptr, offset : u32, value : array, 2u>) { - var array_1 = value; + var array_2 = value; for(var i_1 = 0u; (i_1 < 2u); i_1 = (i_1 + 1u)) { - tint_symbol_32(buffer, (offset + (i_1 * 16u)), array_1[i_1]); + tint_symbol_32(buffer, (offset + (i_1 * 16u)), array_2[i_1]); } } @@ -3007,16 +3007,16 @@ fn tint_symbol_34(@internal(disable_validation__function_parameter) buffer : ptr } fn tint_symbol_35(@internal(disable_validation__function_parameter) buffer : ptr, offset : u32, value : array, 2u>) { - var array = value; + var array_1 = value; for(var i = 0u; (i < 2u); i = (i + 1u)) { - tint_symbol_9(buffer, (offset + (i * 16u)), array[i]); + tint_symbol_9(buffer, (offset + (i * 16u)), array_1[i]); } } fn tint_symbol_36(@internal(disable_validation__function_parameter) buffer : ptr, offset : u32, value : array, 2u>) { - var array_1 = value; + var array_2 = value; for(var i_1 = 0u; (i_1 < 2u); i_1 = (i_1 + 1u)) { - tint_symbol_32(buffer, (offset + (i_1 * 16u)), array_1[i_1]); + tint_symbol_32(buffer, (offset + (i_1 * 16u)), array_2[i_1]); } } diff --git a/src/tint/transform/decompose_strided_array.cc b/src/tint/transform/decompose_strided_array.cc index 8602f14cbc..e92b85e16b 100644 --- a/src/tint/transform/decompose_strided_array.cc +++ b/src/tint/transform/decompose_strided_array.cc @@ -21,6 +21,7 @@ #include "src/tint/program_builder.h" #include "src/tint/sem/call.h" #include "src/tint/sem/member_accessor_expression.h" +#include "src/tint/sem/type_expression.h" #include "src/tint/sem/type_initializer.h" #include "src/tint/sem/value_expression.h" #include "src/tint/transform/simplify_pointers.h" @@ -36,8 +37,8 @@ using DecomposedArrays = std::unordered_map; bool ShouldRun(const Program* program) { for (auto* node : program->ASTNodes().Objects()) { - if (auto* ast = node->As()) { - if (ast::GetAttribute(ast->attributes)) { + if (auto* ident = node->As()) { + if (ast::GetAttribute(ident->attributes)) { return true; } } @@ -73,27 +74,45 @@ Transform::ApplyResult DecomposeStridedArray::Apply(const Program* src, // stride for the array element type, then replace the array element type with // a structure, holding a single field with a @size attribute equal to the // array stride. - ctx.ReplaceAll([&](const ast::Array* ast) -> const ast::Array* { - if (auto* arr = sem.Get(ast)) { - if (!arr->IsStrideImplicit()) { - auto el_ty = utils::GetOrCreate(decomposed, arr, [&] { - auto name = b.Symbols().New("strided_arr"); - auto* member_ty = ctx.Clone(ast->type); - auto* member = b.Member(kMemberName, member_ty, - utils::Vector{ - b.MemberSize(AInt(arr->Stride())), - }); - b.Structure(name, utils::Vector{member}); - return name; - }); - auto* count = ctx.Clone(ast->count); - return b.ty.array(b.ty(el_ty), count); + ctx.ReplaceAll([&](const ast::IdentifierExpression* expr) -> const ast::IdentifierExpression* { + auto* ident = expr->identifier->As(); + if (!ident) { + return nullptr; + } + auto* type_expr = sem.Get(expr); + if (!type_expr) { + return nullptr; + } + auto* arr = type_expr->Type()->As(); + if (!arr) { + return nullptr; + } + if (!arr->IsStrideImplicit()) { + auto el_ty = utils::GetOrCreate(decomposed, arr, [&] { + auto name = b.Symbols().New("strided_arr"); + auto* member_ty = ctx.Clone(ident->arguments[0]->As()); + auto* member = b.Member(kMemberName, ast::Type{member_ty}, + utils::Vector{ + b.MemberSize(AInt(arr->Stride())), + }); + b.Structure(name, utils::Vector{member}); + return name; + }); + if (ident->arguments.Length() > 1) { + auto* count = ctx.Clone(ident->arguments[1]); + return b.Expr(b.ty.array(b.ty(el_ty), count)); + } else { + return b.Expr(b.ty.array(b.ty(el_ty))); } - if (ast::GetAttribute(ast->attributes)) { - // Strip the @stride attribute - auto* ty = ctx.Clone(ast->type); - auto* count = ctx.Clone(ast->count); - return b.ty.array(ty, count); + } + if (ast::GetAttribute(ident->attributes)) { + // Strip the @stride attribute + auto* ty = ctx.Clone(ident->arguments[0]->As()); + if (ident->arguments.Length() > 1) { + auto* count = ctx.Clone(ident->arguments[1]); + return b.Expr(b.ty.array(ast::Type{ty}, count)); + } else { + return b.Expr(b.ty.array(ast::Type{ty})); } } return nullptr; @@ -133,12 +152,8 @@ Transform::ApplyResult DecomposeStridedArray::Apply(const Program* src, // decomposed. // If this is an aliased array, decomposed should already be // populated with any strided aliases. - ast::CallExpression::Target target; - if (expr->target.type) { - target.type = ctx.Clone(expr->target.type); - } else { - target.name = ctx.Clone(expr->target.name); - } + + auto* target = ctx.Clone(expr->target); utils::Vector args; if (auto it = decomposed.find(arr); it != decomposed.end()) { @@ -150,8 +165,7 @@ Transform::ApplyResult DecomposeStridedArray::Apply(const Program* src, args = ctx.Clone(expr->args); } - return target.type ? b.Call(target.type, std::move(args)) - : b.Call(target.name, std::move(args)); + return b.Call(target, std::move(args)); } } } diff --git a/src/tint/transform/decompose_strided_matrix.cc b/src/tint/transform/decompose_strided_matrix.cc index 8b72ac2771..4642c57dca 100644 --- a/src/tint/transform/decompose_strided_matrix.cc +++ b/src/tint/transform/decompose_strided_matrix.cc @@ -37,9 +37,8 @@ struct MatrixInfo { /// The type of the matrix const type::Matrix* matrix = nullptr; - /// @returns a new ast::Array that holds an vector column for each row of the - /// matrix. - const ast::Array* array(ProgramBuilder* b) const { + /// @returns the identifier of an array that holds an vector column for each row of the matrix. + ast::Type array(ProgramBuilder* b) const { return b->ty.array(b->ty.vec(matrix->rows()), u32(matrix->columns()), utils::Vector{ b->Stride(stride), diff --git a/src/tint/transform/demote_to_helper.cc b/src/tint/transform/demote_to_helper.cc index 128894d9e9..dc5384b101 100644 --- a/src/tint/transform/demote_to_helper.cc +++ b/src/tint/transform/demote_to_helper.cc @@ -177,7 +177,7 @@ Transform::ApplyResult DemoteToHelper::Apply(const Program* src, const DataMap&, // } // let y = x + tmp; auto result = b.Sym(); - const ast::Type* result_ty = nullptr; + ast::Type result_ty; const ast::Statement* masked_call = nullptr; if (builtin->Type() == sem::BuiltinType::kAtomicCompareExchangeWeak) { // Special case for atomicCompareExchangeWeak as we cannot name its diff --git a/src/tint/transform/direct_variable_access.cc b/src/tint/transform/direct_variable_access.cc index 3e89ca3a52..a8a1272f25 100644 --- a/src/tint/transform/direct_variable_access.cc +++ b/src/tint/transform/direct_variable_access.cc @@ -831,14 +831,14 @@ struct DirectVariableAccess::State { if (auto incoming_shape = variant_sig.Find(param)) { auto& symbols = *variant.ptr_param_symbols.Find(param); if (symbols.base_ptr.IsValid()) { - auto* base_ptr_ty = + auto base_ptr_ty = b.ty.pointer(CreateASTTypeFor(ctx, incoming_shape->root.type), incoming_shape->root.address_space); params.Push(b.Param(symbols.base_ptr, base_ptr_ty)); } if (symbols.indices.IsValid()) { // Variant has dynamic indices for this variant, replace it. - auto* dyn_idx_arr_type = DynamicIndexArrayType(*incoming_shape); + auto dyn_idx_arr_type = DynamicIndexArrayType(*incoming_shape); params.Push(b.Param(symbols.indices, dyn_idx_arr_type)); } } else { @@ -850,7 +850,7 @@ struct DirectVariableAccess::State { // Build the variant by cloning the source function. The other clone callbacks will // use clone_state->current_variant and clone_state->current_variant_sig to produce // the variant. - auto* ret_ty = ctx.Clone(fn->Declaration()->return_type); + auto ret_ty = ctx.Clone(fn->Declaration()->return_type); auto body = ctx.Clone(fn->Declaration()->body); auto attrs = ctx.Clone(fn->Declaration()->attributes); auto ret_attrs = ctx.Clone(fn->Declaration()->return_type_attributes); @@ -912,7 +912,7 @@ struct DirectVariableAccess::State { } // Get or create the dynamic indices array. - if (auto* dyn_idx_arr_ty = DynamicIndexArrayType(full_indices)) { + if (auto dyn_idx_arr_ty = DynamicIndexArrayType(full_indices)) { // Build an array of dynamic indices to pass as the replacement for the pointer. utils::Vector dyn_idx_args; if (auto* root_param = chain->root.variable->As()) { @@ -1064,7 +1064,7 @@ struct DirectVariableAccess::State { /// @returns the type alias used to hold the dynamic indices for @p shape, declaring a new alias /// if this is the first call for the given shape. - const ast::TypeName* DynamicIndexArrayType(const AccessShape& shape) { + ast::Type DynamicIndexArrayType(const AccessShape& shape) { auto name = dynamic_index_array_aliases.GetOrCreate(shape, [&] { // Count the number of dynamic indices uint32_t num_dyn_indices = shape.NumDynamicIndices(); @@ -1075,7 +1075,7 @@ struct DirectVariableAccess::State { b.Alias(symbol, b.ty.array(b.ty.u32(), u32(num_dyn_indices))); return symbol; }); - return name.IsValid() ? b.ty(name) : nullptr; + return name.IsValid() ? b.ty(name) : ast::Type{}; } /// @returns a name describing the given shape diff --git a/src/tint/transform/module_scope_var_to_entry_point_param.cc b/src/tint/transform/module_scope_var_to_entry_point_param.cc index 285b95cc51..364087bebf 100644 --- a/src/tint/transform/module_scope_var_to_entry_point_param.cc +++ b/src/tint/transform/module_scope_var_to_entry_point_param.cc @@ -145,7 +145,7 @@ struct ModuleScopeVarToEntryPointParam::State { attributes.Push(ctx.dst->Disable(ast::DisabledValidation::kEntryPointParameter)); attributes.Push(ctx.dst->Disable(ast::DisabledValidation::kIgnoreAddressSpace)); - auto* param_type = store_type(); + auto param_type = store_type(); if (auto* arr = ty->As(); arr && arr->Count()->Is()) { // Wrap runtime-sized arrays in structures, so that we can declare pointers to @@ -230,7 +230,7 @@ struct ModuleScopeVarToEntryPointParam::State { bool& is_pointer) { auto* var_ast = var->Declaration()->As(); auto* ty = var->Type()->UnwrapRef(); - auto* param_type = CreateASTTypeFor(ctx, ty); + auto param_type = CreateASTTypeFor(ctx, ty); auto sc = var->AddressSpace(); switch (sc) { case type::AddressSpace::kPrivate: @@ -450,7 +450,7 @@ struct ModuleScopeVarToEntryPointParam::State { // The parameter is a struct that contains members for each workgroup variable. auto* str = ctx.dst->Structure(ctx.dst->Sym(), std::move(workgroup_parameter_members)); - auto* param_type = + auto param_type = ctx.dst->ty.pointer(ctx.dst->ty.Of(str), type::AddressSpace::kWorkgroup); auto* param = ctx.dst->Param( workgroup_param(), param_type, @@ -463,8 +463,8 @@ struct ModuleScopeVarToEntryPointParam::State { // Pass the variables as pointers to any functions that need them. for (auto* call : calls_to_replace[func_ast]) { - auto* target = ctx.src->AST().Functions().Find(call->target.name->symbol); - auto* target_sem = ctx.src->Sem().Get(target); + auto* call_sem = ctx.src->Sem().Get(call)->Unwrap()->As(); + auto* target_sem = call_sem->Target()->As(); // Add new arguments for any variables that are needed by the callee. // For entry points, pass non-handle types as pointers. diff --git a/src/tint/transform/multiplanar_external_texture.cc b/src/tint/transform/multiplanar_external_texture.cc index 1bbbe223d5..06dfba4735 100644 --- a/src/tint/transform/multiplanar_external_texture.cc +++ b/src/tint/transform/multiplanar_external_texture.cc @@ -34,8 +34,8 @@ namespace { bool ShouldRun(const Program* program) { for (auto* node : program->ASTNodes().Objects()) { - if (auto* ty = node->As()) { - if (program->Sem().Get(ty)) { + if (auto* expr = node->As()) { + if (Is(program->TypeOf(expr))) { return true; } } @@ -263,7 +263,8 @@ struct MultiplanarExternalTexture::State { b.Member("gammaDecodeParams", b.ty("GammaTransferParams")), b.Member("gammaEncodeParams", b.ty("GammaTransferParams")), b.Member("gamutConversionMatrix", b.ty.mat3x3()), - b.Member("coordTransformationMatrix", b.ty.mat3x2())}; + b.Member("coordTransformationMatrix", b.ty.mat3x2()), + }; params_struct_sym = b.Symbols().New("ExternalTextureParams"); diff --git a/src/tint/transform/pad_structs.cc b/src/tint/transform/pad_structs.cc index 7d9e7cd40c..954069cc00 100644 --- a/src/tint/transform/pad_structs.cc +++ b/src/tint/transform/pad_structs.cc @@ -75,7 +75,7 @@ Transform::ApplyResult PadStructs::Apply(const Program* src, const DataMap&, Dat } auto* ty = mem->Type(); - const ast::Type* type = CreateASTTypeFor(ctx, ty); + auto type = CreateASTTypeFor(ctx, ty); new_members.Push(b.Member(name, type)); diff --git a/src/tint/transform/remove_phonies.cc b/src/tint/transform/remove_phonies.cc index 3b0dabd3b7..6131892a2e 100644 --- a/src/tint/transform/remove_phonies.cc +++ b/src/tint/transform/remove_phonies.cc @@ -108,7 +108,7 @@ Transform::ApplyResult RemovePhonies::Apply(const Program* src, const DataMap&, auto name = b.Symbols().New("phony_sink"); utils::Vector params; for (auto* ty : sig) { - auto* ast_ty = CreateASTTypeFor(ctx, ty); + auto ast_ty = CreateASTTypeFor(ctx, ty); params.Push(b.Param("p" + std::to_string(params.Length()), ast_ty)); } b.Func(name, params, b.ty.void_(), {}); diff --git a/src/tint/transform/renamer.cc b/src/tint/transform/renamer.cc index ec8dcee970..f2aea29a07 100644 --- a/src/tint/transform/renamer.cc +++ b/src/tint/transform/renamer.cc @@ -22,6 +22,7 @@ #include "src/tint/sem/call.h" #include "src/tint/sem/member_accessor_expression.h" #include "src/tint/sem/type_conversion.h" +#include "src/tint/sem/type_expression.h" #include "src/tint/sem/type_initializer.h" #include "src/tint/text/unicode.h" @@ -1292,20 +1293,28 @@ Transform::ApplyResult Renamer::Apply(const Program* src, [&](const ast::DiagnosticDirective* diagnostic) { preserved_identifiers.Add(diagnostic->control.rule_name); }, - [&](const ast::TypeName* ty) { preserve_if_builtin_type(ty->name); }, [&](const ast::IdentifierExpression* expr) { - if (src->Sem().Get(expr)) { - preserved_identifiers.Add(expr->identifier); - } + Switch( + src->Sem().Get(expr), // + [&](const sem::BuiltinEnumExpressionBase*) { + preserved_identifiers.Add(expr->identifier); + }, + [&](const sem::TypeExpression*) { + preserve_if_builtin_type(expr->identifier); + }); }, [&](const ast::CallExpression* call) { - if (auto* ident = call->target.name) { - Switch( - src->Sem().Get(call)->UnwrapMaterialize()->As()->Target(), - [&](const sem::Builtin*) { preserved_identifiers.Add(ident); }, - [&](const sem::TypeConversion*) { preserve_if_builtin_type(ident); }, - [&](const sem::TypeInitializer*) { preserve_if_builtin_type(ident); }); - } + Switch( + src->Sem().Get(call)->UnwrapMaterialize()->As()->Target(), + [&](const sem::Builtin*) { + preserved_identifiers.Add(call->target->identifier); + }, + [&](const sem::TypeConversion*) { + preserve_if_builtin_type(call->target->identifier); + }, + [&](const sem::TypeInitializer*) { + preserve_if_builtin_type(call->target->identifier); + }); }); } @@ -1369,7 +1378,7 @@ Transform::ApplyResult Renamer::Apply(const Program* src, if (auto* tmpl_ident = ident->As()) { auto args = ctx.Clone(tmpl_ident->arguments); return ctx.dst->create(ctx.Clone(ident->source), replacement, - std::move(args)); + std::move(args), utils::Empty); } return ctx.dst->create(ctx.Clone(ident->source), replacement); }); diff --git a/src/tint/transform/renamer_test.cc b/src/tint/transform/renamer_test.cc index 982a9a2abe..71cf2a2e71 100644 --- a/src/tint/transform/renamer_test.cc +++ b/src/tint/transform/renamer_test.cc @@ -1667,23 +1667,45 @@ std::string ExpandBuiltinType(std::string_view name) { /// @return all the identifiers parsed as keywords std::unordered_set Keywords() { return { + "array", + "atomic", "bool", "f16", "f32", "i32", + "mat2x2", + "mat2x3", + "mat2x4", + "mat3x2", + "mat3x3", + "mat3x4", + "mat4x2", + "mat4x3", + "mat4x4", + "ptr", "sampler_comparison", "sampler", + "texture_1d", + "texture_2d_array", + "texture_2d", + "texture_3d", + "texture_cube_array", + "texture_cube", "texture_depth_2d_array", "texture_depth_2d", "texture_depth_cube_array", "texture_depth_cube", "texture_depth_multisampled_2d", "texture_external", + "texture_multisampled_2d", "texture_storage_1d", - "texture_storage_2d", "texture_storage_2d_array", + "texture_storage_2d", "texture_storage_3d", "u32", + "vec2", + "vec3", + "vec4", }; } @@ -1802,6 +1824,30 @@ fn tint_symbol() { EXPECT_EQ(expect, str(got)); } +TEST_F(RenamerBuiltinTypeTest, PreserveTypeExpression) { + auto src = R"( +enable f16; + +@fragment +fn f() { + var v : array = array(); +} +)"; + + auto expect = R"( +enable f16; + +@fragment +fn tint_symbol() { + var tint_symbol_1 : array = array(); +} +)"; + + auto got = Run(src); + + EXPECT_EQ(expect, str(got)); +} + TEST_P(RenamerBuiltinTypeTest, RenameShadowedByAlias) { auto expand = [&](const char* source) { auto out = utils::ReplaceAll(source, "$name", GetParam()); diff --git a/src/tint/transform/robustness.cc b/src/tint/transform/robustness.cc index 87403e807a..579d6843d6 100644 --- a/src/tint/transform/robustness.cc +++ b/src/tint/transform/robustness.cc @@ -182,7 +182,7 @@ struct Robustness::State { } return 1u; }; - auto scalar_or_vec_ty = [&](const ast::Type* scalar, uint32_t width) -> const ast::Type* { + auto scalar_or_vec_ty = [&](ast::Type scalar, uint32_t width) { if (width > 1) { return b.ty.vec(scalar, width); } @@ -191,7 +191,7 @@ struct Robustness::State { auto scalar_or_vec = [&](const ast::Expression* scalar, uint32_t width) -> const ast::Expression* { if (width > 1) { - return b.Call(b.ty.vec(nullptr, width), scalar); + return b.Call(b.ty.vec(width), scalar); } return scalar; }; diff --git a/src/tint/transform/spirv_atomic.cc b/src/tint/transform/spirv_atomic.cc index afbc5cb2cc..b3924cc6a5 100644 --- a/src/tint/transform/spirv_atomic.cc +++ b/src/tint/transform/spirv_atomic.cc @@ -131,7 +131,7 @@ struct SpirvAtomic::State { for (size_t i = 0; i < str->members.Length(); i++) { auto* member = str->members[i]; if (forked.atomic_members.count(i)) { - auto* type = AtomicTypeFor(ctx.src->Sem().Get(member)->Type()); + auto type = AtomicTypeFor(ctx.src->Sem().Get(member)->Type()); auto name = ctx.src->Symbols().NameFor(member->name->symbol); members.Push(b.Member(name, type, ctx.Clone(member->attributes))); } else { @@ -169,7 +169,7 @@ struct SpirvAtomic::State { [&](const sem::VariableUser* user) { auto* v = user->Variable()->Declaration(); if (v->type && atomic_variables.emplace(user->Variable()).second) { - ctx.Replace(v->type, AtomicTypeFor(user->Variable()->Type())); + ctx.Replace(v->type.expr, b.Expr(AtomicTypeFor(user->Variable()->Type()))); } if (auto* ctor = user->Variable()->Initializer()) { atomic_expressions.Add(ctor); @@ -193,13 +193,13 @@ struct SpirvAtomic::State { } } - const ast::Type* AtomicTypeFor(const type::Type* ty) { + ast::Type AtomicTypeFor(const type::Type* ty) { return Switch( ty, // [&](const type::I32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); }, [&](const type::U32*) { return b.ty.atomic(CreateASTTypeFor(ctx, ty)); }, [&](const sem::Struct* str) { return b.ty(Fork(str->Declaration()).name); }, - [&](const type::Array* arr) -> const ast::Type* { + [&](const type::Array* arr) { if (arr->Count()->Is()) { return b.ty.array(AtomicTypeFor(arr->ElemType())); } @@ -221,7 +221,7 @@ struct SpirvAtomic::State { [&](Default) { TINT_ICE(Transform, b.Diagnostics()) << "unhandled type: " << ty->FriendlyName(ctx.src->Symbols()); - return nullptr; + return ast::Type{}; }); } diff --git a/src/tint/transform/std140.cc b/src/tint/transform/std140.cc index 825685e54f..4c487d0590 100644 --- a/src/tint/transform/std140.cc +++ b/src/tint/transform/std140.cc @@ -308,7 +308,7 @@ struct Std140::State { continue; // Next member } - } else if (auto* std140_ty = Std140Type(member->Type())) { + } else if (auto std140_ty = Std140Type(member->Type())) { // Member is of a type that requires forking for std140-layout fork_std140 = true; auto attrs = ctx.Clone(member->Declaration()->attributes); @@ -352,8 +352,8 @@ struct Std140::State { if (auto* var = global->As()) { if (var->declared_address_space == type::AddressSpace::kUniform) { auto* v = sem.Get(var); - if (auto* std140_ty = Std140Type(v->Type()->UnwrapRef())) { - ctx.Replace(global->type, std140_ty); + if (auto std140_ty = Std140Type(v->Type()->UnwrapRef())) { + ctx.Replace(global->type.expr, b.Expr(std140_ty)); std140_uniforms.Add(v); } } @@ -400,16 +400,16 @@ struct Std140::State { /// If the semantic type is not split for std140-layout, then nullptr is returned. /// @note will construct new std140 structures to hold decomposed matrices, populating /// #std140_mats. - const ast::Type* Std140Type(const type::Type* ty) { + ast::Type Std140Type(const type::Type* ty) { return Switch( ty, // - [&](const sem::Struct* str) -> const ast::Type* { + [&](const sem::Struct* str) { if (auto std140 = std140_structs.Find(str)) { return b.ty(*std140); } - return nullptr; + return ast::Type{}; }, - [&](const type::Matrix* mat) -> const ast::Type* { + [&](const type::Matrix* mat) { if (MatrixNeedsDecomposing(mat)) { auto std140_mat = std140_mats.GetOrCreate(mat, [&] { auto name = b.Symbols().New("mat" + std::to_string(mat->columns()) + "x" + @@ -426,10 +426,10 @@ struct Std140::State { }); return b.ty(std140_mat.name); } - return nullptr; + return ast::Type{}; }, - [&](const type::Array* arr) -> const ast::Type* { - if (auto* std140 = Std140Type(arr->ElemType())) { + [&](const type::Array* arr) { + if (auto std140 = Std140Type(arr->ElemType())) { utils::Vector attrs; if (!arr->IsStrideImplicit()) { attrs.Push(b.create(arr->Stride())); @@ -444,10 +444,9 @@ struct Std140::State { << "unexpected non-constant array count"; count = 1; } - return b.create(std140, b.Expr(u32(count.value())), - std::move(attrs)); + return b.ty.array(std140, b.Expr(u32(count.value())), std::move(attrs)); } - return nullptr; + return ast::Type{}; }); } @@ -483,7 +482,7 @@ struct Std140::State { // Build the member const auto col_name = name_prefix + std::to_string(i); - const auto* col_ty = CreateASTTypeFor(ctx, mat->ColumnType()); + const auto col_ty = CreateASTTypeFor(ctx, mat->ColumnType()); const auto* col_member = b.Member(col_name, col_ty, std::move(attributes)); // Record the member for std140_mat_members out.Push(col_member); @@ -702,7 +701,7 @@ struct Std140::State { for (auto* member : str->Members()) { if (auto col_members = std140_mat_members.Find(member)) { // std140 decomposed matrix. Reassemble. - auto* mat_ty = CreateASTTypeFor(ctx, member->Type()); + auto mat_ty = CreateASTTypeFor(ctx, member->Type()); auto mat_args = utils::Transform(*col_members, [&](const ast::StructMember* m) { return b.MemberAccessor(param, m->name->symbol); @@ -723,7 +722,7 @@ struct Std140::State { if (TINT_LIKELY(std140_mat)) { utils::Vector args; // std140 decomposed matrix. Reassemble. - auto* mat_ty = CreateASTTypeFor(ctx, mat); + auto mat_ty = CreateASTTypeFor(ctx, mat); auto mat_args = utils::Transform(std140_mat->columns, [&](Symbol name) { return b.MemberAccessor(param, name); }); @@ -764,7 +763,7 @@ struct Std140::State { }); // Generate the function - auto* ret_ty = CreateASTTypeFor(ctx, ty); + auto ret_ty = CreateASTTypeFor(ctx, ty); auto fn_sym = b.Symbols().New("conv_" + ConvertSuffix(ty)); b.Func(fn_sym, utils::Vector{param}, ret_ty, std::move(stmts)); return fn_sym; @@ -1046,7 +1045,7 @@ struct Std140::State { stmts.Push(b.Return(expr)); // Build the function - auto* ret_ty = CreateASTTypeFor(ctx, ty); + auto ret_ty = CreateASTTypeFor(ctx, ty); auto fn_sym = b.Symbols().New(name); b.Func(fn_sym, std::move(dynamic_index_params), ret_ty, std::move(stmts)); return fn_sym; diff --git a/src/tint/transform/substitute_override.cc b/src/tint/transform/substitute_override.cc index f5a859bb8a..2d6b99585a 100644 --- a/src/tint/transform/substitute_override.cc +++ b/src/tint/transform/substitute_override.cc @@ -64,7 +64,7 @@ Transform::ApplyResult SubstituteOverride::Apply(const Program* src, auto source = ctx.Clone(w->source); auto sym = ctx.Clone(w->name->symbol); - auto* ty = ctx.Clone(w->type); + ast::Type ty = w->type ? ctx.Clone(w->type) : ast::Type{}; // No replacement provided, just clone the override node as a const. auto iter = data->map.find(sem->OverrideId()); diff --git a/src/tint/transform/texture_1d_to_2d.cc b/src/tint/transform/texture_1d_to_2d.cc index 84d480aae7..d1caaab0b0 100644 --- a/src/tint/transform/texture_1d_to_2d.cc +++ b/src/tint/transform/texture_1d_to_2d.cc @@ -19,6 +19,7 @@ #include "src/tint/program_builder.h" #include "src/tint/sem/function.h" #include "src/tint/sem/statement.h" +#include "src/tint/sem/type_expression.h" #include "src/tint/type/texture_dimension.h" TINT_INSTANTIATE_TYPEINFO(tint::transform::Texture1DTo2D); @@ -46,7 +47,7 @@ bool ShouldRun(const Program* program) { } for (auto* var : program->AST().GlobalVariables()) { if (Switch( - program->Sem().Get(var->type), + program->Sem().Get(var)->Type()->UnwrapRef(), [&](const type::SampledTexture* tex) { return tex->dim() == type::TextureDimension::k1d; }, @@ -83,8 +84,7 @@ struct Texture1DTo2D::State { return SkipTransform; } - auto create_var = [&](const ast::Variable* v, - const ast::Type* type) -> const ast::Variable* { + auto create_var = [&](const ast::Variable* v, ast::Type type) -> const ast::Variable* { if (v->As()) { return ctx.dst->Param(ctx.Clone(v->name->symbol), type, ctx.Clone(v->attributes)); } else { @@ -94,11 +94,11 @@ struct Texture1DTo2D::State { ctx.ReplaceAll([&](const ast::Variable* v) -> const ast::Variable* { const ast::Variable* r = Switch( - sem.Get(v->type), + sem.Get(v)->Type()->UnwrapRef(), [&](const type::SampledTexture* tex) -> const ast::Variable* { if (tex->dim() == type::TextureDimension::k1d) { - auto* type = ctx.dst->create( - type::TextureDimension::k2d, CreateASTTypeFor(ctx, tex->type())); + auto type = ctx.dst->ty.sampled_texture(type::TextureDimension::k2d, + CreateASTTypeFor(ctx, tex->type())); return create_var(v, type); } else { return nullptr; @@ -106,9 +106,9 @@ struct Texture1DTo2D::State { }, [&](const type::StorageTexture* storage_tex) -> const ast::Variable* { if (storage_tex->dim() == type::TextureDimension::k1d) { - auto* type = ctx.dst->ty.storage_texture(type::TextureDimension::k2d, - storage_tex->texel_format(), - storage_tex->access()); + auto type = ctx.dst->ty.storage_texture(type::TextureDimension::k2d, + storage_tex->texel_format(), + storage_tex->access()); return create_var(v, type); } else { return nullptr; @@ -172,7 +172,7 @@ struct Texture1DTo2D::State { } index++; } - return ctx.dst->Call(ctx.Clone(c->target.name), args); + return ctx.dst->Call(ctx.Clone(c->target), args); }); ctx.Clone(); diff --git a/src/tint/transform/transform.cc b/src/tint/transform/transform.cc index a2ae23794b..cc09e6c908 100644 --- a/src/tint/transform/transform.cc +++ b/src/tint/transform/transform.cc @@ -73,9 +73,9 @@ void Transform::RemoveStatement(CloneContext& ctx, const ast::Statement* stmt) { << "unable to remove statement from parent of type " << sem->TypeInfo().name; } -const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type* ty) { +ast::Type Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type* ty) { if (ty->Is()) { - return nullptr; + return ast::Type{}; } if (ty->Is()) { return ctx.dst->ty.i32(); @@ -93,21 +93,21 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type return ctx.dst->ty.bool_(); } if (auto* m = ty->As()) { - auto* el = CreateASTTypeFor(ctx, m->type()); - return ctx.dst->create(el, m->rows(), m->columns()); + auto el = CreateASTTypeFor(ctx, m->type()); + return ctx.dst->ty.mat(el, m->columns(), m->rows()); } if (auto* v = ty->As()) { - auto* el = CreateASTTypeFor(ctx, v->type()); - return ctx.dst->create(el, v->Width()); + auto el = CreateASTTypeFor(ctx, v->type()); + return ctx.dst->ty.vec(el, v->Width()); } if (auto* a = ty->As()) { - auto* el = CreateASTTypeFor(ctx, a->ElemType()); + auto el = CreateASTTypeFor(ctx, a->ElemType()); utils::Vector attrs; if (!a->IsStrideImplicit()) { attrs.Push(ctx.dst->create(a->Stride())); } if (a->Count()->Is()) { - return ctx.dst->ty.array(el, nullptr, std::move(attrs)); + return ctx.dst->ty.array(el, std::move(attrs)); } if (auto* override = a->Count()->As()) { auto* count = ctx.Clone(override->variable->Declaration()); @@ -144,7 +144,7 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type return CreateASTTypeFor(ctx, s->StoreType()); } if (auto* a = ty->As()) { - return ctx.dst->create(CreateASTTypeFor(ctx, a->Type())); + return ctx.dst->ty.atomic(CreateASTTypeFor(ctx, a->Type())); } if (auto* t = ty->As()) { return ctx.dst->ty.depth_texture(t->dim()); @@ -156,11 +156,10 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type return ctx.dst->ty.external_texture(); } if (auto* t = ty->As()) { - return ctx.dst->create(t->dim(), - CreateASTTypeFor(ctx, t->type())); + return ctx.dst->ty.multisampled_texture(t->dim(), CreateASTTypeFor(ctx, t->type())); } if (auto* t = ty->As()) { - return ctx.dst->create(t->dim(), CreateASTTypeFor(ctx, t->type())); + return ctx.dst->ty.sampled_texture(t->dim(), CreateASTTypeFor(ctx, t->type())); } if (auto* t = ty->As()) { return ctx.dst->ty.storage_texture(t->dim(), t->texel_format(), t->access()); @@ -170,7 +169,7 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type } TINT_UNREACHABLE(Transform, ctx.dst->Diagnostics()) << "Unhandled type: " << ty->TypeInfo().name; - return nullptr; + return ast::Type{}; } } // namespace tint::transform diff --git a/src/tint/transform/transform.h b/src/tint/transform/transform.h index cc2f7828aa..dfb9188662 100644 --- a/src/tint/transform/transform.h +++ b/src/tint/transform/transform.h @@ -189,13 +189,11 @@ class Transform : public Castable { /// @param stmt the statement to remove when the program is cloned static void RemoveStatement(CloneContext& ctx, const ast::Statement* stmt); - /// CreateASTTypeFor constructs new ast::Type nodes that reconstructs the - /// semantic type `ty`. + /// CreateASTTypeFor constructs new ast::Type that reconstructs the semantic type `ty`. /// @param ctx the clone context /// @param ty the semantic type to reconstruct - /// @returns a ast::Type that when resolved, will produce the semantic type - /// `ty`. - static const ast::Type* CreateASTTypeFor(CloneContext& ctx, const type::Type* ty); + /// @returns an ast::Type that when resolved, will produce the semantic type `ty`. + static ast::Type CreateASTTypeFor(CloneContext& ctx, const type::Type* ty); }; } // namespace tint::transform diff --git a/src/tint/transform/transform_test.cc b/src/tint/transform/transform_test.cc index 6d97614e78..f27a990276 100644 --- a/src/tint/transform/transform_test.cc +++ b/src/tint/transform/transform_test.cc @@ -14,6 +14,7 @@ #include +#include "src/tint/ast/test_helper.h" #include "src/tint/clone_context.h" #include "src/tint/program_builder.h" #include "src/tint/transform/transform.h" @@ -31,7 +32,7 @@ struct CreateASTTypeForTest : public testing::Test, public Transform { return SkipTransform; } - const ast::Type* create(std::function create_sem_type) { + ast::Type create(std::function create_sem_type) { ProgramBuilder sem_type_builder; auto* sem_type = create_sem_type(sem_type_builder); Program program(std::move(sem_type_builder)); @@ -39,71 +40,60 @@ struct CreateASTTypeForTest : public testing::Test, public Transform { return CreateASTTypeFor(ctx, sem_type); } - std::string TypeNameOf(const ast::Type* ty) const { - if (auto* type_name = ty->As()) { - return ast_type_builder.Symbols().NameFor(type_name->name->symbol); - } - return ""; - } - ProgramBuilder ast_type_builder; }; TEST_F(CreateASTTypeForTest, Basic) { - EXPECT_EQ(TypeNameOf(create([](ProgramBuilder& b) { return b.create(); })), "i32"); - EXPECT_EQ(TypeNameOf(create([](ProgramBuilder& b) { return b.create(); })), "u32"); - EXPECT_EQ(TypeNameOf(create([](ProgramBuilder& b) { return b.create(); })), "f32"); - EXPECT_EQ(TypeNameOf(create([](ProgramBuilder& b) { return b.create(); })), "bool"); + auto check = [&](ast::Type ty, const char* expect) { + ast::CheckIdentifier(ast_type_builder.Symbols(), ty->identifier, expect); + }; + + check(create([](ProgramBuilder& b) { return b.create(); }), "i32"); + check(create([](ProgramBuilder& b) { return b.create(); }), "u32"); + check(create([](ProgramBuilder& b) { return b.create(); }), "f32"); + check(create([](ProgramBuilder& b) { return b.create(); }), "bool"); EXPECT_EQ(create([](ProgramBuilder& b) { return b.create(); }), nullptr); } TEST_F(CreateASTTypeForTest, Matrix) { - auto* mat = create([](ProgramBuilder& b) { + auto mat = create([](ProgramBuilder& b) { auto* column_type = b.create(b.create(), 2u); return b.create(column_type, 3u); }); - ASSERT_TRUE(mat->Is()); - EXPECT_EQ(TypeNameOf(mat->As()->type), "f32"); - ASSERT_EQ(mat->As()->columns, 3u); - ASSERT_EQ(mat->As()->rows, 2u); + + ast::CheckIdentifier(ast_type_builder.Symbols(), mat, ast::Template("mat3x2", "f32")); } TEST_F(CreateASTTypeForTest, Vector) { - auto* vec = + auto vec = create([](ProgramBuilder& b) { return b.create(b.create(), 2u); }); - ASSERT_TRUE(vec->Is()); - EXPECT_EQ(TypeNameOf(vec->As()->type), "f32"); - ASSERT_EQ(vec->As()->width, 2u); + + ast::CheckIdentifier(ast_type_builder.Symbols(), vec, ast::Template("vec2", "f32")); } TEST_F(CreateASTTypeForTest, ArrayImplicitStride) { - auto* arr = create([](ProgramBuilder& b) { + auto arr = create([](ProgramBuilder& b) { return b.create(b.create(), b.create(2u), 4u, 4u, 32u, 32u); }); - ASSERT_TRUE(arr->Is()); - EXPECT_EQ(TypeNameOf(arr->As()->type), "f32"); - ASSERT_EQ(arr->As()->attributes.Length(), 0u); - auto* size = arr->As()->count->As(); - ASSERT_NE(size, nullptr); - EXPECT_EQ(size->value, 2); + ast::CheckIdentifier(ast_type_builder.Symbols(), arr, ast::Template("array", "f32", 2_u)); + auto* tmpl_attr = arr->identifier->As(); + ASSERT_NE(tmpl_attr, nullptr); + EXPECT_TRUE(tmpl_attr->attributes.IsEmpty()); } TEST_F(CreateASTTypeForTest, ArrayNonImplicitStride) { - auto* arr = create([](ProgramBuilder& b) { + auto arr = create([](ProgramBuilder& b) { return b.create(b.create(), b.create(2u), 4u, 4u, 64u, 32u); }); - ASSERT_TRUE(arr->Is()); - EXPECT_EQ(TypeNameOf(arr->As()->type), "f32"); - ASSERT_EQ(arr->As()->attributes.Length(), 1u); - ASSERT_TRUE(arr->As()->attributes[0]->Is()); - ASSERT_EQ(arr->As()->attributes[0]->As()->stride, 64u); - - auto* size = arr->As()->count->As(); - ASSERT_NE(size, nullptr); - EXPECT_EQ(size->value, 2); + ast::CheckIdentifier(ast_type_builder.Symbols(), arr, ast::Template("array", "f32", 2_u)); + auto* tmpl_attr = arr->identifier->As(); + ASSERT_NE(tmpl_attr, nullptr); + ASSERT_EQ(tmpl_attr->attributes.Length(), 1u); + ASSERT_TRUE(tmpl_attr->attributes[0]->Is()); + ASSERT_EQ(tmpl_attr->attributes[0]->As()->stride, 64u); } // crbug.com/tint/1764 @@ -123,19 +113,18 @@ TEST_F(CreateASTTypeForTest, AliasedArrayWithComplexOverrideLength) { auto* arr_ty = program.Sem().Get(alias); CloneContext ctx(&ast_type_builder, &program, false); - auto* ast_ty = tint::As(CreateASTTypeFor(ctx, arr_ty)); - ASSERT_NE(ast_ty, nullptr); - EXPECT_EQ(ast_type_builder.Symbols().NameFor(ast_ty->name->symbol), "A"); + auto ast_ty = CreateASTTypeFor(ctx, arr_ty); + ast::CheckIdentifier(ast_type_builder.Symbols(), ast_ty, "A"); } TEST_F(CreateASTTypeForTest, Struct) { - auto* str = create([](ProgramBuilder& b) { + auto str = create([](ProgramBuilder& b) { auto* decl = b.Structure("S", {}); return b.create(decl, decl->source, decl->name->symbol, utils::Empty, 4u /* align */, 4u /* size */, 4u /* size_no_padding */); }); - ASSERT_TRUE(str->Is()); - EXPECT_EQ(ast_type_builder.Symbols().NameFor(str->As()->name->symbol), "S"); + + ast::CheckIdentifier(ast_type_builder.Symbols(), str, "S"); } } // namespace diff --git a/src/tint/transform/truncate_interstage_variables.cc b/src/tint/transform/truncate_interstage_variables.cc index cf15a38ad3..b4ae24e2a1 100644 --- a/src/tint/transform/truncate_interstage_variables.cc +++ b/src/tint/transform/truncate_interstage_variables.cc @@ -143,11 +143,12 @@ Transform::ApplyResult TruncateInterstageVariables::Apply(const Program* src, utils::Vector{b.Param("io", ctx.Clone(func_ast->return_type))}, b.ty(new_struct_sym), utils::Vector{ - b.Return(b.Call(b.ty(new_struct_sym), std::move(initializer_exprs)))}); + b.Return(b.Call(new_struct_sym, std::move(initializer_exprs))), + }); return TruncatedStructAndConverter{new_struct_sym, mapping_fn_sym}; }); - ctx.Replace(func_ast->return_type, b.ty(entry.truncated_struct)); + ctx.Replace(func_ast->return_type.expr, b.Expr(entry.truncated_struct)); entry_point_functions_to_truncate_functions.Add(func_sem, entry.truncate_fn); } diff --git a/src/tint/transform/unshadow.cc b/src/tint/transform/unshadow.cc index ac00a39693..8f79544bf6 100644 --- a/src/tint/transform/unshadow.cc +++ b/src/tint/transform/unshadow.cc @@ -56,7 +56,7 @@ struct Unshadow::State { renamed_to.Add(v, symbol); auto source = ctx.Clone(decl->source); - auto* type = ctx.Clone(decl->type); + auto type = decl->type ? ctx.Clone(decl->type) : ast::Type{}; auto* initializer = ctx.Clone(decl->initializer); auto attributes = ctx.Clone(decl->attributes); return Switch( diff --git a/src/tint/transform/vertex_pulling.cc b/src/tint/transform/vertex_pulling.cc index 438ede8b14..11984cdaef 100644 --- a/src/tint/transform/vertex_pulling.cc +++ b/src/tint/transform/vertex_pulling.cc @@ -395,7 +395,7 @@ struct VertexPulling::State { // Convert the fetched scalar/vector if WGSL variable is of `f16` types if (var_dt.base_type == BaseWGSLType::kF16) { // The type of the same element number of base type of target WGSL variable - const ast::Type* loaded_data_target_type; + ast::Type loaded_data_target_type; if (fmt_dt.width == 1) { loaded_data_target_type = b.ty.f16(); } else { @@ -443,8 +443,7 @@ struct VertexPulling::State { } } - const ast::Type* target_ty = CreateASTTypeFor(ctx, var.type); - value = b.Call(target_ty, values); + value = b.Call(CreateASTTypeFor(ctx, var.type), values); } // Assign the value to the WGSL variable @@ -735,7 +734,7 @@ struct VertexPulling::State { uint32_t offset, uint32_t buffer, uint32_t element_stride, - const ast::Type* base_type, + ast::Type base_type, VertexFormat base_format, uint32_t count) { utils::Vector expr_list; @@ -745,7 +744,7 @@ struct VertexPulling::State { expr_list.Push(LoadPrimitive(array_base, primitive_offset, buffer, base_format)); } - return b.Call(b.create(base_type, count), std::move(expr_list)); + return b.Call(b.ty.vec(base_type, count), std::move(expr_list)); } /// Process a non-struct entry point parameter. @@ -757,7 +756,7 @@ struct VertexPulling::State { if (ast::HasAttribute(param->attributes)) { // Create a function-scope variable to replace the parameter. auto func_var_sym = ctx.Clone(param->name->symbol); - auto* func_var_type = ctx.Clone(param->type); + auto func_var_type = ctx.Clone(param->type); auto* func_var = b.Var(func_var_sym, func_var_type); ctx.InsertFront(func->body->statements, b.Decl(func_var)); // Capture mapping from location to the new variable. @@ -856,7 +855,7 @@ struct VertexPulling::State { utils::Vector new_members; for (auto* member : members_to_clone) { auto member_name = ctx.Clone(member->name); - auto* member_type = ctx.Clone(member->type); + auto member_type = ctx.Clone(member->type); auto member_attrs = ctx.Clone(member->attributes); new_members.Push(b.Member(member_name, member_type, std::move(member_attrs))); } @@ -926,7 +925,7 @@ struct VertexPulling::State { // Rewrite the function header with the new parameters. auto func_sym = ctx.Clone(func->name->symbol); - auto* ret_type = ctx.Clone(func->return_type); + 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); diff --git a/src/tint/type/builtin.cc b/src/tint/type/builtin.cc index b400ccbfb4..828bf57b78 100644 --- a/src/tint/type/builtin.cc +++ b/src/tint/type/builtin.cc @@ -28,6 +28,12 @@ namespace tint::type { /// @param str the string to parse /// @returns the parsed enum, or Builtin::kUndefined if the string could not be parsed. Builtin ParseBuiltin(std::string_view str) { + if (str == "array") { + return Builtin::kArray; + } + if (str == "atomic") { + return Builtin::kAtomic; + } if (str == "bool") { return Builtin::kBool; } @@ -40,66 +46,114 @@ Builtin ParseBuiltin(std::string_view str) { if (str == "i32") { return Builtin::kI32; } + if (str == "mat2x2") { + return Builtin::kMat2X2; + } if (str == "mat2x2f") { return Builtin::kMat2X2F; } if (str == "mat2x2h") { return Builtin::kMat2X2H; } + if (str == "mat2x3") { + return Builtin::kMat2X3; + } if (str == "mat2x3f") { return Builtin::kMat2X3F; } if (str == "mat2x3h") { return Builtin::kMat2X3H; } + if (str == "mat2x4") { + return Builtin::kMat2X4; + } if (str == "mat2x4f") { return Builtin::kMat2X4F; } if (str == "mat2x4h") { return Builtin::kMat2X4H; } + if (str == "mat3x2") { + return Builtin::kMat3X2; + } if (str == "mat3x2f") { return Builtin::kMat3X2F; } if (str == "mat3x2h") { return Builtin::kMat3X2H; } + if (str == "mat3x3") { + return Builtin::kMat3X3; + } if (str == "mat3x3f") { return Builtin::kMat3X3F; } if (str == "mat3x3h") { return Builtin::kMat3X3H; } + if (str == "mat3x4") { + return Builtin::kMat3X4; + } if (str == "mat3x4f") { return Builtin::kMat3X4F; } if (str == "mat3x4h") { return Builtin::kMat3X4H; } + if (str == "mat4x2") { + return Builtin::kMat4X2; + } if (str == "mat4x2f") { return Builtin::kMat4X2F; } if (str == "mat4x2h") { return Builtin::kMat4X2H; } + if (str == "mat4x3") { + return Builtin::kMat4X3; + } if (str == "mat4x3f") { return Builtin::kMat4X3F; } if (str == "mat4x3h") { return Builtin::kMat4X3H; } + if (str == "mat4x4") { + return Builtin::kMat4X4; + } if (str == "mat4x4f") { return Builtin::kMat4X4F; } if (str == "mat4x4h") { return Builtin::kMat4X4H; } + if (str == "ptr") { + return Builtin::kPtr; + } if (str == "sampler") { return Builtin::kSampler; } if (str == "sampler_comparison") { return Builtin::kSamplerComparison; } + if (str == "texture_1d") { + return Builtin::kTexture1D; + } + if (str == "texture_2d") { + return Builtin::kTexture2D; + } + if (str == "texture_2d_array") { + return Builtin::kTexture2DArray; + } + if (str == "texture_3d") { + return Builtin::kTexture3D; + } + if (str == "texture_cube") { + return Builtin::kTextureCube; + } + if (str == "texture_cube_array") { + return Builtin::kTextureCubeArray; + } if (str == "texture_depth_2d") { return Builtin::kTextureDepth2D; } @@ -118,6 +172,9 @@ Builtin ParseBuiltin(std::string_view str) { if (str == "texture_external") { return Builtin::kTextureExternal; } + if (str == "texture_multisampled_2d") { + return Builtin::kTextureMultisampled2D; + } if (str == "texture_storage_1d") { return Builtin::kTextureStorage1D; } @@ -133,6 +190,9 @@ Builtin ParseBuiltin(std::string_view str) { if (str == "u32") { return Builtin::kU32; } + if (str == "vec2") { + return Builtin::kVec2; + } if (str == "vec2f") { return Builtin::kVec2F; } @@ -145,6 +205,9 @@ Builtin ParseBuiltin(std::string_view str) { if (str == "vec2u") { return Builtin::kVec2U; } + if (str == "vec3") { + return Builtin::kVec3; + } if (str == "vec3f") { return Builtin::kVec3F; } @@ -157,6 +220,9 @@ Builtin ParseBuiltin(std::string_view str) { if (str == "vec3u") { return Builtin::kVec3U; } + if (str == "vec4") { + return Builtin::kVec4; + } if (str == "vec4f") { return Builtin::kVec4F; } @@ -176,6 +242,10 @@ std::ostream& operator<<(std::ostream& out, Builtin value) { switch (value) { case Builtin::kUndefined: return out << "undefined"; + case Builtin::kArray: + return out << "array"; + case Builtin::kAtomic: + return out << "atomic"; case Builtin::kBool: return out << "bool"; case Builtin::kF16: @@ -184,46 +254,78 @@ std::ostream& operator<<(std::ostream& out, Builtin value) { return out << "f32"; case Builtin::kI32: return out << "i32"; + case Builtin::kMat2X2: + return out << "mat2x2"; case Builtin::kMat2X2F: return out << "mat2x2f"; case Builtin::kMat2X2H: return out << "mat2x2h"; + case Builtin::kMat2X3: + return out << "mat2x3"; case Builtin::kMat2X3F: return out << "mat2x3f"; case Builtin::kMat2X3H: return out << "mat2x3h"; + case Builtin::kMat2X4: + return out << "mat2x4"; case Builtin::kMat2X4F: return out << "mat2x4f"; case Builtin::kMat2X4H: return out << "mat2x4h"; + case Builtin::kMat3X2: + return out << "mat3x2"; case Builtin::kMat3X2F: return out << "mat3x2f"; case Builtin::kMat3X2H: return out << "mat3x2h"; + case Builtin::kMat3X3: + return out << "mat3x3"; case Builtin::kMat3X3F: return out << "mat3x3f"; case Builtin::kMat3X3H: return out << "mat3x3h"; + case Builtin::kMat3X4: + return out << "mat3x4"; case Builtin::kMat3X4F: return out << "mat3x4f"; case Builtin::kMat3X4H: return out << "mat3x4h"; + case Builtin::kMat4X2: + return out << "mat4x2"; case Builtin::kMat4X2F: return out << "mat4x2f"; case Builtin::kMat4X2H: return out << "mat4x2h"; + case Builtin::kMat4X3: + return out << "mat4x3"; case Builtin::kMat4X3F: return out << "mat4x3f"; case Builtin::kMat4X3H: return out << "mat4x3h"; + case Builtin::kMat4X4: + return out << "mat4x4"; case Builtin::kMat4X4F: return out << "mat4x4f"; case Builtin::kMat4X4H: return out << "mat4x4h"; + case Builtin::kPtr: + return out << "ptr"; case Builtin::kSampler: return out << "sampler"; case Builtin::kSamplerComparison: return out << "sampler_comparison"; + case Builtin::kTexture1D: + return out << "texture_1d"; + case Builtin::kTexture2D: + return out << "texture_2d"; + case Builtin::kTexture2DArray: + return out << "texture_2d_array"; + case Builtin::kTexture3D: + return out << "texture_3d"; + case Builtin::kTextureCube: + return out << "texture_cube"; + case Builtin::kTextureCubeArray: + return out << "texture_cube_array"; case Builtin::kTextureDepth2D: return out << "texture_depth_2d"; case Builtin::kTextureDepth2DArray: @@ -236,6 +338,8 @@ std::ostream& operator<<(std::ostream& out, Builtin value) { return out << "texture_depth_multisampled_2d"; case Builtin::kTextureExternal: return out << "texture_external"; + case Builtin::kTextureMultisampled2D: + return out << "texture_multisampled_2d"; case Builtin::kTextureStorage1D: return out << "texture_storage_1d"; case Builtin::kTextureStorage2D: @@ -246,6 +350,8 @@ std::ostream& operator<<(std::ostream& out, Builtin value) { return out << "texture_storage_3d"; case Builtin::kU32: return out << "u32"; + case Builtin::kVec2: + return out << "vec2"; case Builtin::kVec2F: return out << "vec2f"; case Builtin::kVec2H: @@ -254,6 +360,8 @@ std::ostream& operator<<(std::ostream& out, Builtin value) { return out << "vec2i"; case Builtin::kVec2U: return out << "vec2u"; + case Builtin::kVec3: + return out << "vec3"; case Builtin::kVec3F: return out << "vec3f"; case Builtin::kVec3H: @@ -262,6 +370,8 @@ std::ostream& operator<<(std::ostream& out, Builtin value) { return out << "vec3i"; case Builtin::kVec3U: return out << "vec3u"; + case Builtin::kVec4: + return out << "vec4"; case Builtin::kVec4F: return out << "vec4f"; case Builtin::kVec4H: diff --git a/src/tint/type/builtin.h b/src/tint/type/builtin.h index 3b57489ffe..78e63c253b 100644 --- a/src/tint/type/builtin.h +++ b/src/tint/type/builtin.h @@ -30,49 +30,71 @@ namespace tint::type { /// An enumerator of builtin types. enum class Builtin { kUndefined, + kArray, + kAtomic, kBool, kF16, kF32, kI32, + kMat2X2, kMat2X2F, kMat2X2H, + kMat2X3, kMat2X3F, kMat2X3H, + kMat2X4, kMat2X4F, kMat2X4H, + kMat3X2, kMat3X2F, kMat3X2H, + kMat3X3, kMat3X3F, kMat3X3H, + kMat3X4, kMat3X4F, kMat3X4H, + kMat4X2, kMat4X2F, kMat4X2H, + kMat4X3, kMat4X3F, kMat4X3H, + kMat4X4, kMat4X4F, kMat4X4H, + kPtr, kSampler, kSamplerComparison, + kTexture1D, + kTexture2D, + kTexture2DArray, + kTexture3D, + kTextureCube, + kTextureCubeArray, kTextureDepth2D, kTextureDepth2DArray, kTextureDepthCube, kTextureDepthCubeArray, kTextureDepthMultisampled2D, kTextureExternal, + kTextureMultisampled2D, kTextureStorage1D, kTextureStorage2D, kTextureStorage2DArray, kTextureStorage3D, kU32, + kVec2, kVec2F, kVec2H, kVec2I, kVec2U, + kVec3, kVec3F, kVec3H, kVec3I, kVec3U, + kVec4, kVec4F, kVec4H, kVec4I, @@ -90,49 +112,71 @@ std::ostream& operator<<(std::ostream& out, Builtin value); Builtin ParseBuiltin(std::string_view str); constexpr const char* kBuiltinStrings[] = { + "array", + "atomic", "bool", "f16", "f32", "i32", + "mat2x2", "mat2x2f", "mat2x2h", + "mat2x3", "mat2x3f", "mat2x3h", + "mat2x4", "mat2x4f", "mat2x4h", + "mat3x2", "mat3x2f", "mat3x2h", + "mat3x3", "mat3x3f", "mat3x3h", + "mat3x4", "mat3x4f", "mat3x4h", + "mat4x2", "mat4x2f", "mat4x2h", + "mat4x3", "mat4x3f", "mat4x3h", + "mat4x4", "mat4x4f", "mat4x4h", + "ptr", "sampler", "sampler_comparison", + "texture_1d", + "texture_2d", + "texture_2d_array", + "texture_3d", + "texture_cube", + "texture_cube_array", "texture_depth_2d", "texture_depth_2d_array", "texture_depth_cube", "texture_depth_cube_array", "texture_depth_multisampled_2d", "texture_external", + "texture_multisampled_2d", "texture_storage_1d", "texture_storage_2d", "texture_storage_2d_array", "texture_storage_3d", "u32", + "vec2", "vec2f", "vec2h", "vec2i", "vec2u", + "vec3", "vec3f", "vec3h", "vec3i", "vec3u", + "vec4", "vec4f", "vec4h", "vec4i", diff --git a/src/tint/type/builtin_bench.cc b/src/tint/type/builtin_bench.cc index aea57f59f9..f8b86cf8f1 100644 --- a/src/tint/type/builtin_bench.cc +++ b/src/tint/type/builtin_bench.cc @@ -31,335 +31,489 @@ namespace { void BuiltinParser(::benchmark::State& state) { const char* kStrings[] = { - "ccol", - "3", - "bVol", + "arccy", + "3a", + "aVray", + "array", + "arra1", + "qqrJy", + "arrll7y", + "atppmHHc", + "cto", + "abGmi", + "atomic", + "atvmiii", + "atWWm8c", + "xxtomc", + "bXgg", + "Xu", + "b3ol", "bool", - "1ool", - "bqoJ", - "bllo77", - "fppqH", - "", - "Gb", - "f16", - "f1vi", - "f8WW", - "fxx", - "fgg", - "X", - "332", - "f32", - "fE2", - "fPTT", - "dxx2", - "4432", - "iSVV2", + "booE", + "TTPol", + "xxool", + "4416", + "fSVV6", "RR2", + "f16", + "96", + "f1", + "VOR6", + "y3", + "l77rrn2", + "4032", + "f32", + "5", + "u377", + "kk2", + "ii", + "i3XX", + "55399II", "i32", - "92", - "i3", - "VOR2", - "ma2xyf", - "llnarr2772f", - "mat24200", - "mat2x2f", - "a2oof", - "zz2x2f", - "miitppx1", - "mat2xXXh", - "9II5ann2x2h", - "mataSSrHHYh", - "mat2x2h", - "makkh", - "jatgRx", - "mb2x2", + "irSSHHa", + "U", + "jV3", + "ax2", + "t2SGG", + "q2x2", + "mat2x2", + "at2", + "majjx", + "a2xrf", "mat2xjf", - "at2x3f", - "q2x3f", + "mNNw2x28", + "matx2f", + "mat2x2f", + "mrrt2x2f", + "Gat2x2f", + "mat2x2FF", + "at2h", + "marrx2h", + "t2x2h", + "mat2x2h", + "Da2xJJh", + "ma82", + "m11k2", + "matx3", + "maJx3", + "cat2x3", + "mat2x3", + "mat2O3", + "ttKavv2x__", + "5txxx8", + "__qatF3", + "matqx3f", + "33atOx3f", "mat2x3f", - "matNN3f", - "at23vv", - "QQt2x3f", - "maffxr", - "mat2xjh", - "mNNw2x38", - "mat2x3h", - "matx3h", - "mrrt2x3h", - "Gat2x3h", - "mat2x4FF", - "at2f", - "marrx4f", - "mat2x4f", - "t2x4f", - "Da2xJJf", - "ma84", - "m11k4", - "matx4h", - "maJx4h", - "mat2x4h", - "mat2c4h", - "mat2x4O", - "KK_atvvtt4h", - "xx83x2f", - "__qatF2", - "matqx2f", - "mat3x2f", - "33atOx2f", - "mtt63x9oQQ", - "ma3x66f", + "mtt62x9oQQ", + "ma2x66f", "mtOxzz66", - "mat3yy2h", - "ZaHH2Z", - "mat3x2h", - "4WWt3q2h", - "mOO3x2h", - "oatY2h", + "mat2yy3h", + "ZaHH3Z", + "4WWt2q3h", + "mat2x3h", + "mOO2x3h", + "oatY3h", "matx", - "ma3xFf", - "at3x3w", - "mat3x3f", - "fGtxKf", - "matqKx3f", - "matmmxFf", - "at3x3h", - "mt3x3q", - "mat3xbb", - "mat3x3h", - "mi3x3h", - "maOO3xq", - "matTvvx3h", - "maFF3x4f", - "Pa00xQf", - "mPt3x4f", - "mat3x4f", - "ma773xss", - "RRCbb3x4f", - "mXXt3x4f", - "qaCC3xOOh", - "ma3s4L", - "mXt3x4h", - "mat3x4h", - "mat34h", - "qa3O4", - "mat3x22h", - "myzz40XX", + "ma2x4", + "matw4", + "ma2Gf", + "mat2x4", + "qatKKx4", + "mmmt2x4", + "at2x4", + "mt2x4q", + "mat2xbb", + "mi2x4f", + "mat2x4f", + "maOO2xq", + "matTvvx4f", + "maFF2x4f", + "Pa00xQh", + "mPt2x4h", + "ma772xss", + "mat2x4h", + "RRCbb2x4h", + "mXXt2x4h", + "qaCC2xOOh", + "mtsuL", + "mat3xX", + "mat3x", + "mat3x2", + "qqt2", + "mat3x22", + "mzzyt3x", "matVViP", "mannC2f", - "mat4x2f", "atx2AHHq", + "mat3x2f", + "may3x2", + "aOOOZZf", + "Vt12f", + "mff__3x2h", + "qaTMMl4h", + "mNNt3xg", + "mat3x2h", + "uub3XX2h", + "matx2h", + "Qt882h", + "maqx3", + "mat3113", + "Ft3xi22", + "mat3x3", + "m7t3x3", + "NNa323", + "VVat3x3", + "FaWW3w11f", + "mawwx3f", + "Dat3x3f", + "mat3x3f", + "mt3x3K", + "mat31PPhf", + "mat33f", + "mYYt3x3h", + "mttHH3kk", + "mat3rr3h", + "mat3x3h", + "WWas3x3h", + "Yt3x3h", + "mt3qfh", + "vvafu224", + "mt34", + "maY34", + "mat3x4", + "YYa7y3E4", + "Moatd4", + "mt3xMM", + "mat3x55f", + "maN34", + "ma3Ox33", + "mat3x4f", + "m3t3x4f", + "mam3xI", + "mnnt3r4K", + "m3XX", + "LatIx4h", + "at3fh", + "mat3x4h", + "mYtURD4", + "mah3x4h", + "uuIqt3x", + "mat4xH", + "at4Qvv", + "66ate", "mat4x2", - "fatK2f", - "ltgg2h", - "mat4xh", - "NTTtcx4h", + "mat7x", + "m0t55DD2", + "IIaH4x2", + "at4x2", + "rat4x299", + "mGtt41W2f", + "mat4x2f", + "yatx2", + "mt4x2f", + "IIaBB4x2f", + "TTat4x833", + "ddUUnntYYx2h", + "m5CCxxdZ", "mat4x2h", - "ma7ppl2h", - "mNNt4xg", - "uub4XX2h", - "matx3f", - "Qt883f", - "mt9q3f", + "matkkq2h", + "005itpxh", + "maIInnx2h", + "ccaKx", + "mtKK", + "ma664x3", + "mat4x3", + "mKKtPx", + "maxx43", + "matqx3", + "MMayySrxf", + "mat3f", + "tx3f", "mat4x3f", - "m11t4x3f", - "22at4iif", - "at4x377", - "m2t4xNh", - "mVVt4x3h", - "FaWW4w11h", + "ma5F4x3f", + "rra444z3f", + "matWW", + "CatZJXx3h", + "maPPx3h", + "mat4c3h", "mat4x3h", - "mawwx3h", - "Dat4x3h", - "mt4x3K", - "mat41PPhf", - "mat44f", - "mYYt4x4f", + "matPPll6h", + "mat993yy", + "mat4JKKh", + "ma_x4", + "a4K4", + "kVt4xz", + "mat4x4", + "qaSKx4", + "mat44", + "ma4xVV", + "AAatIxUf", + "mbj4f", + "YY444x", "mat4x4f", - "mttHH4kk", - "mat4rr4f", - "WWas4x4f", - "Yt4x4h", - "mt4qfh", - "mav224xuh", + "mao4x4", + "mtx114f", + "mtmxccf", + "aJJ4x4h", + "fCCDD4x4U", + "mgt4x4h", "mat4x4h", - "t4x4h", - "YYat4h", - "may4x4EYY", - "daplMor", - "samMMle", - "sampl55r", - "sampler", - "saNpe", - "sa3Ol33", - "s3mpler", - "Iamplercomparismn", - "sampleKrcompannison", - "samlr_copXXison", - "sampler_comparison", - "samplpLL_comparisI", - "smplerfomparison", - "sYmpURDr_comprison", - "texturh_depth_2d", - "teqtureuIIdep_2d", - "texture_depth_2H", - "texture_depth_2d", - "texre_depth_2Qvv", - "te66ue_depeh_2d", - "textue_d7pOh_2d", - "textureDDde0th_255_array", - "texture_IIepth_Hd_array", - "txture_depth_2d_array", - "texture_depth_2d_array", - "txture_depth_2r_array", - "tlxture_depth_2d_array", - "ttexturGdeth_2d_arrJJy", - "yexture_depth_cbe", - "texturedepth_cube", - "texture_IIeptBB_cube", - "texture_depth_cube", - "textKre_depth_c83TTe", - "texSnnYUUure_depth_cube", - "textuxe_5eptCCdZube", - "texturekkdepth_cube_arraq", - "exture_dppt00iicube5array", - "texIIurenndepth_cube_array", - "texture_depth_cube_array", - "ccextue_depth_cube_aKWa", - "texture_epth_cube_raKK", - "texture_depth_cube_a66ray", - "textEPPeKKdept_multisampled_2", - "texture_depth_mutisampledxx2d", - "texture_depth_qultisampled_2d", - "texture_depth_multisampled_2d", - "textureyydMMptr_mutisampleSS_2d", - "txture_depth_muluisampled2d", - "texSure_ept_mutisampled_2d", - "textu5e_externFFl", - "text44rrr_exterzal", - "texue_eWWtenal", - "texture_external", - "textuXe_ZZxtJJrnal", - "textuPPe_eternal", - "texturc_external", - "tllxture_storage_P6d", - "tex99ure_yytorag_1d", - "textuKKe_storage_1d", - "texture_storage_1d", - "texture__xorage_d", - "yxKur_storage_1d", - "textureVstorkge_1z", - "texKure_Storqge_2d", - "texture_storage_d", - "teture_storage_VVd", - "texture_storage_2d", - "textureIstoraAUe_2d", - "jextre_storaR_2d", - "extue44storYYge_2", - "textre_storage_2d_array", - "tex9ur_stor11ge_d_xxrray", - "tmmxture_storJe_2d_arrcc", - "texture_storage_2d_array", - "tJJxture_storage_2_array", - "DDCCltufe_storaUe_2d_array", - "tegture_storage_2d_array", - "exture_srageCC3d", - "txture_storage_3d", - "textuIe_sto__age_3d", - "texture_storage_3d", - "texttte_PPorage_3d", - "texture_stora3de_3d", - "exture_Ktoragyy_3d", + "CCx4h", + "mat4x66", + "maN4M4h", + "pt", + "KW", + "pzzee", + "ptr", "", - "03nn", - "uCnuu", + "w9", + "4tnn", + "sllDler", + "oamp4er", + "wEaggler", + "sampler", + "gamler", + "spleS", + "aampl", + "sampZcRTr_comparison", + "sampler_88TmparisOn", + "sampler_comparim00n", + "sampler_comparison", + "sampler_Bmomparison", + "Mamper_ppomarison", + "samper_compOOrison", + "teGtGre_1d", + "tex11ureHH1d", + "6exeeur_1FF", + "texture_1d", + "texure_1", + "tKiilure_1d", + "exture_1d", + "99etvIIre_2d", + "texture_d", + "texture_hd", + "texture_2d", + "llxzzure_PPd", + "exue2d", + "tffqqtre_2d", + "texJJre_2dd_arWay", + "teXXzzre_2darray", + "textu2_2d_array", + "texture_2d_array", + "tNyyture_2d_array", + "txture_2d_rOOa", + "textureErduaZPay", + "22lxtredd3ee", + "texVVe93d", + "teture_I1d", + "texture_3d", + "tebture_3d", + "ie7ure3d", + "teotiire_3d", + "entre_cube", + "texturScube", + "tex22r_cube", + "texture_cube", + "teC711recuGe", + "texture8cffbe", + "textue_cue", + "tJJxture_SSube_array", + "texture_9ue_arry", + "TbbJJxture_cube_array", + "texture_cube_array", + "t66ture_cube_aray", + "textur66_cubu_arra", + "textureWubeyarray", + "texture_deth_d", + "texture_epth_2d", + "texture_derth_2d", + "texture_depth_2d", + "tex2ure_depth_2B", + "texture_dpBBh_2d", + "texture_dpth_RRd", + "tLLxture_deptVV0darray", + "textuOOe_dethKK2d_arra", + "textuwe_ggepth_2d_rray", + "texture_depth_2d_array", + "textue_depthLh2d_arpay", + "texture_depEh2diiKrray", + "texture_dept_2d_array", + "textuUUe88dept_cbe", + "texrrure_depvvh_cube", + "texure_wepmmh_ube", + "texture_depth_cube", + "tjture_d44pth_cube", + "texture_depth_cXbe", + "t8xture_depth_cube", + "textre_depth_cubeEEarrvvy", + "tzzture_d9pth_cuie_array", + "teAture_depth_QQube_GGrrJJy", + "texture_depth_cube_array", + "texture_depth_cusse_array", + "texture_Pepth_cKbe_array", + "texture_dppp_cube_attray", + "texture_depth_multisample_2", + "texture_depth_multisamplMMd_2d", + "texJJure_de0th_multisampled_2d", + "texture_depth_multisampled_2d", + "textu8_dpth_mulisampled_2V", + "texture_dhhpth_mKltisggmpled_2d", + "texture_depth_multisampledf2d", + "tex77ure_exQernal", + "tYYxture_externa", + "tektur_exterSal", + "texture_external", + "txturn_ext2rnal", + "txture_FFternal", + "texUPPIre_GGxuernal", + "txtuEEe_mulaisFmpledv2d", + "ddexBBure_mltDDeampled_2d", + "teMture_EEulccisam55led_2", + "texture_multisampled_2d", + "texturemuKKtisample_d", + "texture_multisRmpled_2d", + "texturemulDisampl9d_2d", + "texturestorage_1d", + "textIre_storaa_1d", + "texture_sto77age_1d", + "texture_storage_1d", + "texIure_storage_1d", + "texture_storagedd", + "texture_storae_1d", + "texture_strate_d", + "texture33stoXXcge_2d", + "texturestorage_2E", + "texture_storage_2d", + "textuXXestorage_2d", + "texture_stoBaxxe_2d", + "texte_storWge_2G", + "texture_storage_2d_ar66ay", + "t0xTTr_storave_2d_array", + "kexure_orage_2d_rray", + "texture_storage_2d_array", + "textppre_stoae_2d_array", + "textre_stora11e_d_array", + "textureystorBEgeJ2d_array", + "textqreIImtxrage_3d", + "texture_toFage_3d", + "exture_Ytorage_3d", + "texture_storage_3d", + "heDture_sHHorage_3d", + "texturstorage23H", + "teture_strage_3d", + "u2", + "u2", + "dd32", "u32", - "3Xl", - "pp3o", - "uww", - "veuug", - "vaac", - "TRZcccf", + "uPO", + "ba", + "u02", + "veh2", + "vgY2", + "Oec2", + "vec2", + "eh", + "ppfe2", + "vev", + "vc2zz", + "vaac2", + "Ouuicf", "vec2f", - "vTc2O8", - "vem02f", - "meBB2f", - "Mpp2", - "OOe2h", - "veG2G", + "vGc2f", + "22ecTTf", + "dlc2f", + "vecbh", + "ec2BB", + "IIScXPP", "vec2h", - "11eHH2h", - "veFFe6", - "ve2", - "vKii2l", - "ec2i", - "v992IIv", + "jjec2h", + "cc_c2h", + "zz6xx2h", + "c2", + "4xx2N", + "p0AAei", "vec2i", - "veci", - "vechi", - "vczllPi", - "u", - "vffqq2", - "vJdd2u", + "vey2", + "vbWW0i", + "meMMtti", + "du", + "vvc_", + "VEEc2u", "vec2u", - "vecXX", - "ve22", - "Nyyc2u", - "vO3", - "PEruZ", - "vlc2edd", - "vec3f", - "ec9f", - "ve1II", - "veb3f", - "vi7", - "oec3ii", - "ec3", - "vec3h", - "veci", - "22ec", - "vGc3C", - "ffec38", - "c3i", - "JJecSSi", - "vec3i", - "93i", - "vbbJJ3TT", - "e66i", - "u663u", - "vW3u", - "v3u", - "vec3u", - "vecu", - "rec3u", - "2ec3B", - "vcBBf", - "vRc4f", - "v4LL0", - "vec4f", - "vKOOf", - "vgwcf", - "vLphf", - "eiiEh", - "ec4h", - "UU884", - "vec4h", - "rrecvvh", - "ecmm", - "vec4j", - "vec4X", - "vec48", - "vecvEE", - "vec4i", - "z99ci", - "GGeJJA4i", - "vess4i", - "vPcKu", - "tpc4u", + "vec24", + "VVeX2u", + "veVou", "vec", + "KKc3", + "G", + "vec3", + "ea3", + "OOc", + "G", + "v5c3f", + "99jcfff", + "XXvYY3R", + "vec3f", + "ccf", + "v8XX5", + "ec3", + "ppc3cc", + "vecvh", + "eEE3SS", + "vec3h", + "vec", + "eh", + "ec3ww", + "vecd99i", + "ve99P", + "KKec3", + "vec3i", + "ooMcDD", + "vei", + "vqi", + "veL30", + "vncvv66", + "vrrn3", + "vec3u", + "vxxce", + "NCCOc3u", + "vc3u", + "veca", + "veNNN", + "vec", + "vec4", + "vc", + "vAYS4", + "vec0", + "vecaaf", + "vmm4f", + "ec4f", + "vec4f", + "vE4U", + "veKD4", + "v0t4__", + "cpA", + "ec4h", + "vBBc4h", + "vec4h", + "vbnn99", + "EEcAAh", + "v5c66h", + "vHc4i", + "vecxi", + "vzyn40", + "vec4i", + "ve4i", + "kH4i", + "veci", + "oo4rr", + "JJc4", + "vcCC0", "vec4u", - "MMec4u", - "vJJc40", - "8c", + "xAA99F", + "veccu", + "vec4S", }; for (auto _ : state) { for (auto* str : kStrings) { diff --git a/src/tint/type/builtin_test.cc b/src/tint/type/builtin_test.cc index ebd2cea5d8..345a214917 100644 --- a/src/tint/type/builtin_test.cc +++ b/src/tint/type/builtin_test.cc @@ -43,49 +43,71 @@ inline std::ostream& operator<<(std::ostream& out, Case c) { } static constexpr Case kValidCases[] = { + {"array", Builtin::kArray}, + {"atomic", Builtin::kAtomic}, {"bool", Builtin::kBool}, {"f16", Builtin::kF16}, {"f32", Builtin::kF32}, {"i32", Builtin::kI32}, + {"mat2x2", Builtin::kMat2X2}, {"mat2x2f", Builtin::kMat2X2F}, {"mat2x2h", Builtin::kMat2X2H}, + {"mat2x3", Builtin::kMat2X3}, {"mat2x3f", Builtin::kMat2X3F}, {"mat2x3h", Builtin::kMat2X3H}, + {"mat2x4", Builtin::kMat2X4}, {"mat2x4f", Builtin::kMat2X4F}, {"mat2x4h", Builtin::kMat2X4H}, + {"mat3x2", Builtin::kMat3X2}, {"mat3x2f", Builtin::kMat3X2F}, {"mat3x2h", Builtin::kMat3X2H}, + {"mat3x3", Builtin::kMat3X3}, {"mat3x3f", Builtin::kMat3X3F}, {"mat3x3h", Builtin::kMat3X3H}, + {"mat3x4", Builtin::kMat3X4}, {"mat3x4f", Builtin::kMat3X4F}, {"mat3x4h", Builtin::kMat3X4H}, + {"mat4x2", Builtin::kMat4X2}, {"mat4x2f", Builtin::kMat4X2F}, {"mat4x2h", Builtin::kMat4X2H}, + {"mat4x3", Builtin::kMat4X3}, {"mat4x3f", Builtin::kMat4X3F}, {"mat4x3h", Builtin::kMat4X3H}, + {"mat4x4", Builtin::kMat4X4}, {"mat4x4f", Builtin::kMat4X4F}, {"mat4x4h", Builtin::kMat4X4H}, + {"ptr", Builtin::kPtr}, {"sampler", Builtin::kSampler}, {"sampler_comparison", Builtin::kSamplerComparison}, + {"texture_1d", Builtin::kTexture1D}, + {"texture_2d", Builtin::kTexture2D}, + {"texture_2d_array", Builtin::kTexture2DArray}, + {"texture_3d", Builtin::kTexture3D}, + {"texture_cube", Builtin::kTextureCube}, + {"texture_cube_array", Builtin::kTextureCubeArray}, {"texture_depth_2d", Builtin::kTextureDepth2D}, {"texture_depth_2d_array", Builtin::kTextureDepth2DArray}, {"texture_depth_cube", Builtin::kTextureDepthCube}, {"texture_depth_cube_array", Builtin::kTextureDepthCubeArray}, {"texture_depth_multisampled_2d", Builtin::kTextureDepthMultisampled2D}, {"texture_external", Builtin::kTextureExternal}, + {"texture_multisampled_2d", Builtin::kTextureMultisampled2D}, {"texture_storage_1d", Builtin::kTextureStorage1D}, {"texture_storage_2d", Builtin::kTextureStorage2D}, {"texture_storage_2d_array", Builtin::kTextureStorage2DArray}, {"texture_storage_3d", Builtin::kTextureStorage3D}, {"u32", Builtin::kU32}, + {"vec2", Builtin::kVec2}, {"vec2f", Builtin::kVec2F}, {"vec2h", Builtin::kVec2H}, {"vec2i", Builtin::kVec2I}, {"vec2u", Builtin::kVec2U}, + {"vec3", Builtin::kVec3}, {"vec3f", Builtin::kVec3F}, {"vec3h", Builtin::kVec3H}, {"vec3i", Builtin::kVec3I}, {"vec3u", Builtin::kVec3U}, + {"vec4", Builtin::kVec4}, {"vec4f", Builtin::kVec4F}, {"vec4h", Builtin::kVec4H}, {"vec4i", Builtin::kVec4I}, @@ -93,147 +115,213 @@ static constexpr Case kValidCases[] = { }; static constexpr Case kInvalidCases[] = { - {"ccol", Builtin::kUndefined}, - {"3", Builtin::kUndefined}, - {"bVol", Builtin::kUndefined}, - {"116", Builtin::kUndefined}, - {"qJ6", Builtin::kUndefined}, - {"f17ll", Builtin::kUndefined}, - {"fppqH", Builtin::kUndefined}, - {"", Builtin::kUndefined}, - {"Gb", Builtin::kUndefined}, - {"i3vi", Builtin::kUndefined}, - {"i8WW", Builtin::kUndefined}, - {"ixx", Builtin::kUndefined}, - {"mX2x2gg", Builtin::kUndefined}, - {"a2xXf", Builtin::kUndefined}, - {"mat232f", Builtin::kUndefined}, - {"Eat2x2h", Builtin::kUndefined}, - {"mPTT2x2h", Builtin::kUndefined}, - {"mat2xdxx", Builtin::kUndefined}, - {"m44t2x3f", Builtin::kUndefined}, - {"maSS2xVVf", Builtin::kUndefined}, - {"RatR22f", Builtin::kUndefined}, - {"mF2x9h", Builtin::kUndefined}, - {"matx3h", Builtin::kUndefined}, - {"VOORRH3h", Builtin::kUndefined}, - {"ma2xyf", Builtin::kUndefined}, - {"llnarr2774f", Builtin::kUndefined}, - {"mat24400", Builtin::kUndefined}, - {"a2ooh", Builtin::kUndefined}, - {"zz2x4h", Builtin::kUndefined}, - {"miitppx1", Builtin::kUndefined}, - {"mat3xXXf", Builtin::kUndefined}, - {"9II5ann3x2f", Builtin::kUndefined}, + {"arccy", Builtin::kUndefined}, + {"3a", Builtin::kUndefined}, + {"aVray", Builtin::kUndefined}, + {"1tomic", Builtin::kUndefined}, + {"aoqqic", Builtin::kUndefined}, + {"atomll77", Builtin::kUndefined}, + {"ppqooH", Builtin::kUndefined}, + {"c", Builtin::kUndefined}, + {"bGo", Builtin::kUndefined}, + {"f1vi", Builtin::kUndefined}, + {"f8WW", Builtin::kUndefined}, + {"fxx", Builtin::kUndefined}, + {"fgg", Builtin::kUndefined}, + {"X", Builtin::kUndefined}, + {"332", Builtin::kUndefined}, + {"iE2", Builtin::kUndefined}, + {"iPTT", Builtin::kUndefined}, + {"dxx2", Builtin::kUndefined}, + {"44at2x2", Builtin::kUndefined}, + {"mSSVV2x2", Builtin::kUndefined}, + {"mat2R2", Builtin::kUndefined}, + {"mF2x9f", Builtin::kUndefined}, + {"matx2f", Builtin::kUndefined}, + {"VOORRH2f", Builtin::kUndefined}, + {"ma2xyh", Builtin::kUndefined}, + {"llnarr2772h", Builtin::kUndefined}, + {"mat24200", Builtin::kUndefined}, + {"m2oo", Builtin::kUndefined}, + {"atzz3", Builtin::kUndefined}, + {"1it2xpp", Builtin::kUndefined}, + {"mat2xXXf", Builtin::kUndefined}, + {"9II5ann2x3f", Builtin::kUndefined}, {"mataSSrHHYf", Builtin::kUndefined}, {"makkh", Builtin::kUndefined}, {"jatgRx", Builtin::kUndefined}, - {"mb3x2", Builtin::kUndefined}, - {"mat3xjf", Builtin::kUndefined}, - {"at3x3f", Builtin::kUndefined}, - {"q3x3f", Builtin::kUndefined}, - {"matNN3h", Builtin::kUndefined}, - {"at33vv", Builtin::kUndefined}, - {"QQt3x3h", Builtin::kUndefined}, + {"mb2x3", Builtin::kUndefined}, + {"mat2j4", Builtin::kUndefined}, + {"mt2x4", Builtin::kUndefined}, + {"m2q4", Builtin::kUndefined}, + {"matNN4f", Builtin::kUndefined}, + {"at24vv", Builtin::kUndefined}, + {"QQt2x4f", Builtin::kUndefined}, {"maffxr", Builtin::kUndefined}, - {"mat3xjf", Builtin::kUndefined}, - {"mNNw3x48", Builtin::kUndefined}, - {"matx4h", Builtin::kUndefined}, - {"mrrt3x4h", Builtin::kUndefined}, - {"Gat3x4h", Builtin::kUndefined}, - {"mat4x2FF", Builtin::kUndefined}, - {"at4f", Builtin::kUndefined}, + {"mat2xjh", Builtin::kUndefined}, + {"mNNw2x48", Builtin::kUndefined}, + {"mt3x2", Builtin::kUndefined}, + {"rrat3x2", Builtin::kUndefined}, + {"mGt3x2", Builtin::kUndefined}, + {"mat3x2FF", Builtin::kUndefined}, + {"at3f", Builtin::kUndefined}, {"marrx2f", Builtin::kUndefined}, - {"t4x2h", Builtin::kUndefined}, - {"Da4xJJh", Builtin::kUndefined}, + {"t3x2h", Builtin::kUndefined}, + {"Da3xJJh", Builtin::kUndefined}, {"ma82", Builtin::kUndefined}, - {"m11k3", Builtin::kUndefined}, - {"matx3f", Builtin::kUndefined}, - {"maJx3f", Builtin::kUndefined}, - {"mat4c3h", Builtin::kUndefined}, - {"mat4x3O", Builtin::kUndefined}, - {"KK_atvvtt3h", Builtin::kUndefined}, - {"xx84x4f", Builtin::kUndefined}, - {"__qatF4", Builtin::kUndefined}, - {"matqx4f", Builtin::kUndefined}, - {"33atOx4h", Builtin::kUndefined}, - {"mtt64x9oQQ", Builtin::kUndefined}, - {"ma4x66h", Builtin::kUndefined}, - {"smOlzz66", Builtin::kUndefined}, - {"sampyyer", Builtin::kUndefined}, - {"ZaHHeZ", Builtin::kUndefined}, - {"sWWpleq_compari44on", Builtin::kUndefined}, - {"sampler_compaisoOO", Builtin::kUndefined}, - {"smpeoo_coYparison", Builtin::kUndefined}, - {"eture_dpth_2d", Builtin::kUndefined}, - {"texture_detF_2d", Builtin::kUndefined}, - {"texturedwpth_2d", Builtin::kUndefined}, - {"teKuffe_Gepth_2d_arry", Builtin::kUndefined}, - {"texture_dKKptq_2d_array", Builtin::kUndefined}, - {"texture_depmmh32d_arraF", Builtin::kUndefined}, - {"textur_depth_cube", Builtin::kUndefined}, - {"texure_depqh_cube", Builtin::kUndefined}, - {"texture_debth_cube", Builtin::kUndefined}, - {"txture_deptii_cube_arry", Builtin::kUndefined}, - {"textureqdepth_OOube_arry", Builtin::kUndefined}, - {"texture_deTvvth_cube_array", Builtin::kUndefined}, - {"texture_depth_multiFFampled_2d", Builtin::kUndefined}, - {"textue_depthPmfl00isampled_Qd", Builtin::kUndefined}, - {"textuPe_depth_multisampled_2d", Builtin::kUndefined}, - {"texture_exernss77", Builtin::kUndefined}, - {"texture_bbxternRRl", Builtin::kUndefined}, - {"textureXXexternal", Builtin::kUndefined}, - {"CCextOOre_stoage_qOd", Builtin::kUndefined}, - {"txtsre_sturage_1L", Builtin::kUndefined}, - {"texture_stoXage_1d", Builtin::kUndefined}, + {"1k33", Builtin::kUndefined}, + {"matx3", Builtin::kUndefined}, + {"maJx3", Builtin::kUndefined}, + {"mat3c3f", Builtin::kUndefined}, + {"mat3x3O", Builtin::kUndefined}, + {"KK_atvvtt3f", Builtin::kUndefined}, + {"xx83x3h", Builtin::kUndefined}, + {"__qatF3", Builtin::kUndefined}, + {"matqx3h", Builtin::kUndefined}, + {"ma33x66", Builtin::kUndefined}, + {"mttQQo3x4", Builtin::kUndefined}, + {"mat66x", Builtin::kUndefined}, + {"mtOxzz66", Builtin::kUndefined}, + {"mat3yy4f", Builtin::kUndefined}, + {"ZaHH4Z", Builtin::kUndefined}, + {"4WWt3q4h", Builtin::kUndefined}, + {"mOO3x4h", Builtin::kUndefined}, + {"oatY4h", Builtin::kUndefined}, + {"ax2", Builtin::kUndefined}, + {"ma4x2", Builtin::kUndefined}, + {"matw2", Builtin::kUndefined}, + {"fGtxKf", Builtin::kUndefined}, + {"matqKx2f", Builtin::kUndefined}, + {"matmmxFf", Builtin::kUndefined}, + {"at4x2h", Builtin::kUndefined}, + {"mt4x2q", Builtin::kUndefined}, + {"mat4xbb", Builtin::kUndefined}, + {"it4x3", Builtin::kUndefined}, + {"mOO4xq", Builtin::kUndefined}, + {"mat4Tvv3", Builtin::kUndefined}, + {"maFF4x3f", Builtin::kUndefined}, + {"Pa00xQf", Builtin::kUndefined}, + {"mPt4x3f", Builtin::kUndefined}, + {"ma774xss", Builtin::kUndefined}, + {"RRCbb4x3h", Builtin::kUndefined}, + {"mXXt4x3h", Builtin::kUndefined}, + {"CCt4OOOO", Builtin::kUndefined}, + {"mtsuL", Builtin::kUndefined}, + {"mat4xX", Builtin::kUndefined}, + {"mat44f", Builtin::kUndefined}, + {"qa4O4", Builtin::kUndefined}, + {"mat4x22f", Builtin::kUndefined}, + {"myzz40XX", Builtin::kUndefined}, + {"matVViP", Builtin::kUndefined}, + {"mannC4h", Builtin::kUndefined}, + {"pHAq", Builtin::kUndefined}, + {"tr", Builtin::kUndefined}, + {"Kf", Builtin::kUndefined}, + {"lmgger", Builtin::kUndefined}, + {"samplr", Builtin::kUndefined}, + {"NTTmcl4r", Builtin::kUndefined}, + {"sampler_clmppri77on", Builtin::kUndefined}, + {"samplg_czzmparNNso", Builtin::kUndefined}, + {"smpleuuXXomparibbon", Builtin::kUndefined}, + {"texture_1", Builtin::kUndefined}, + {"t88tueQ1K", Builtin::kUndefined}, + {"texturq9d", Builtin::kUndefined}, + {"text11re_2d", Builtin::kUndefined}, + {"teiiu22eF2d", Builtin::kUndefined}, + {"tex77ur_2d", Builtin::kUndefined}, + {"textNNr2_d_array", Builtin::kUndefined}, + {"textVVre_2d_array", Builtin::kUndefined}, + {"texwure_WWF_11rray", Builtin::kUndefined}, + {"txture_3ww", Builtin::kUndefined}, + {"texturD_3d", Builtin::kUndefined}, + {"teKture_d", Builtin::kUndefined}, + {"11exPPufe_cubh", Builtin::kUndefined}, + {"textue_cube", Builtin::kUndefined}, + {"texture_cubYY", Builtin::kUndefined}, + {"texttr_cube_HHkkVay", Builtin::kUndefined}, + {"texture_crrbe_array", Builtin::kUndefined}, + {"texturesscubeWWaray", Builtin::kUndefined}, + {"texture_deptY_d", Builtin::kUndefined}, + {"teLturq_defh_2d", Builtin::kUndefined}, + {"texvvre_duu22th_2d", Builtin::kUndefined}, + {"texure_deth_2d_array", Builtin::kUndefined}, + {"texturYY_depth_2daray", Builtin::kUndefined}, + {"texturE_77epth_2d_aryYay", Builtin::kUndefined}, + {"Mexdoore_depth_cue", Builtin::kUndefined}, + {"texturedepMMh_cube", Builtin::kUndefined}, + {"texture55depth_cube", Builtin::kUndefined}, + {"textue_depth_cbe_aNray", Builtin::kUndefined}, + {"texture_dpth_c33be_array", Builtin::kUndefined}, + {"texture_depth_cub3_array", Builtin::kUndefined}, + {"texIure_mepth_mulisampled_2d", Builtin::kUndefined}, + {"texture_depthrmKltisampled_2nn", Builtin::kUndefined}, + {"textur_depth_multismXld_2d", Builtin::kUndefined}, + {"texpure_exLLeIna", Builtin::kUndefined}, + {"txture_exfrnal", Builtin::kUndefined}, + {"teUture_extYRRDl", Builtin::kUndefined}, + {"texturehmultisampled_2d", Builtin::kUndefined}, + {"texturqmultsIImuuled_2d", Builtin::kUndefined}, + {"Hexture_multisampled_2d", Builtin::kUndefined}, + {"texQQur_storge_vvd", Builtin::kUndefined}, + {"texeure_66oage_1d", Builtin::kUndefined}, + {"texture_stoage71d", Builtin::kUndefined}, + {"texture_s55or0ge_2DD", Builtin::kUndefined}, + {"teHture_storIIge_2d", Builtin::kUndefined}, {"textue_storage_2d", Builtin::kUndefined}, - {"teuresOorageqq2d", Builtin::kUndefined}, - {"texture_sto22age_2d", Builtin::kUndefined}, - {"exture_syora0e_2d_Xzzrray", Builtin::kUndefined}, - {"texiVVr_storageP2d_array", Builtin::kUndefined}, - {"texturestorage_2nn_arCay", Builtin::kUndefined}, - {"texturHHstorAAe_qqd", Builtin::kUndefined}, - {"textur_storage_3d", Builtin::kUndefined}, - {"texure_sfKorage3d", Builtin::kUndefined}, - {"gg", Builtin::kUndefined}, - {"u3", Builtin::kUndefined}, - {"NT42", Builtin::kUndefined}, - {"ppec7l", Builtin::kUndefined}, - {"zNe2f", Builtin::kUndefined}, - {"uXXb2f", Builtin::kUndefined}, - {"vec2", Builtin::kUndefined}, - {"882K", Builtin::kUndefined}, - {"vq9h", Builtin::kUndefined}, - {"vec211", Builtin::kUndefined}, - {"22ciii", Builtin::kUndefined}, - {"ec77i", Builtin::kUndefined}, - {"NN22u", Builtin::kUndefined}, - {"vVVc2u", Builtin::kUndefined}, - {"WW11w2u", Builtin::kUndefined}, - {"vcwwf", Builtin::kUndefined}, - {"vDc3f", Builtin::kUndefined}, - {"vecK", Builtin::kUndefined}, - {"f11r3PP", Builtin::kUndefined}, - {"ve3h", Builtin::kUndefined}, - {"vec3YY", Builtin::kUndefined}, - {"vkktHH", Builtin::kUndefined}, - {"rrec3i", Builtin::kUndefined}, - {"vWWssi", Builtin::kUndefined}, - {"veYu", Builtin::kUndefined}, - {"eq3f", Builtin::kUndefined}, - {"u22ec3u", Builtin::kUndefined}, - {"c4f", Builtin::kUndefined}, - {"vec4", Builtin::kUndefined}, - {"vYyc47E", Builtin::kUndefined}, - {"veMoh", Builtin::kUndefined}, - {"ve4MM", Builtin::kUndefined}, - {"55ec4h", Builtin::kUndefined}, - {"N4i", Builtin::kUndefined}, - {"ve33i", Builtin::kUndefined}, - {"3ec4i", Builtin::kUndefined}, - {"mecI", Builtin::kUndefined}, - {"vrnK4u", Builtin::kUndefined}, - {"v4", Builtin::kUndefined}, + {"texturestorage_2d_rrray", Builtin::kUndefined}, + {"textule_storage_2d_array", Builtin::kUndefined}, + {"tetture_JJtorage_Gd_arra", Builtin::kUndefined}, + {"yexture_storage3d", Builtin::kUndefined}, + {"texturestorage_3d", Builtin::kUndefined}, + {"texture_IItorBBge_3d", Builtin::kUndefined}, + {"TTK33", Builtin::kUndefined}, + {"nnUYdSS2", Builtin::kUndefined}, + {"x5dZ", Builtin::kUndefined}, + {"veckq", Builtin::kUndefined}, + {"ii500", Builtin::kUndefined}, + {"vecIIn", Builtin::kUndefined}, + {"cceW", Builtin::kUndefined}, + {"cKK", Builtin::kUndefined}, + {"vec66f", Builtin::kUndefined}, + {"vePPK", Builtin::kUndefined}, + {"vexxh", Builtin::kUndefined}, + {"qec2h", Builtin::kUndefined}, + {"veSyMMr", Builtin::kUndefined}, + {"v2u", Builtin::kUndefined}, + {"ec", Builtin::kUndefined}, + {"5eFF2u", Builtin::kUndefined}, + {"rrecz44", Builtin::kUndefined}, + {"vWW", Builtin::kUndefined}, + {"ZJJCcX", Builtin::kUndefined}, + {"vcPP", Builtin::kUndefined}, + {"vec", Builtin::kUndefined}, + {"3Le003f", Builtin::kUndefined}, + {"MMec3RR", Builtin::kUndefined}, + {"vec39K", Builtin::kUndefined}, + {"yyecm", Builtin::kUndefined}, + {"v__cD", Builtin::kUndefined}, + {"vec3U", Builtin::kUndefined}, + {"ze333i", Builtin::kUndefined}, + {"eKti", Builtin::kUndefined}, + {"ve3V", Builtin::kUndefined}, + {"jbR3K", Builtin::kUndefined}, + {"e44344", Builtin::kUndefined}, + {"00u", Builtin::kUndefined}, + {"WK4", Builtin::kUndefined}, + {"m", Builtin::kUndefined}, + {"vJJ", Builtin::kUndefined}, + {"lDDcUfC", Builtin::kUndefined}, + {"vec4g", Builtin::kUndefined}, + {"CCe", Builtin::kUndefined}, + {"ec4h", Builtin::kUndefined}, + {"vIc__h", Builtin::kUndefined}, + {"ePPtt", Builtin::kUndefined}, + {"v3dc4i", Builtin::kUndefined}, + {"vcyyi", Builtin::kUndefined}, + {"u4", Builtin::kUndefined}, + {"v03nnu", Builtin::kUndefined}, + {"Cuuecnv", Builtin::kUndefined}, + {"vX4ll", Builtin::kUndefined}, }; using BuiltinParseTest = testing::TestWithParam; diff --git a/src/tint/type/storage_texture_test.cc b/src/tint/type/storage_texture_test.cc index ad5ad6e952..2ffc0b7b5c 100644 --- a/src/tint/type/storage_texture_test.cc +++ b/src/tint/type/storage_texture_test.cc @@ -96,7 +96,7 @@ TEST_F(StorageTextureTest, FriendlyName) { } TEST_F(StorageTextureTest, F32) { - Type* s = Create(TextureDimension::k2dArray, type::TexelFormat::kRgba32Float, + auto* s = Create(TextureDimension::k2dArray, type::TexelFormat::kRgba32Float, type::Access::kReadWrite); auto program = Build(); @@ -109,7 +109,7 @@ TEST_F(StorageTextureTest, F32) { TEST_F(StorageTextureTest, U32) { auto* subtype = StorageTexture::SubtypeFor(type::TexelFormat::kRg32Uint, Types()); - Type* s = create(TextureDimension::k2dArray, type::TexelFormat::kRg32Uint, + auto* s = create(TextureDimension::k2dArray, type::TexelFormat::kRg32Uint, type::Access::kReadWrite, subtype); auto program = Build(); @@ -122,7 +122,7 @@ TEST_F(StorageTextureTest, U32) { TEST_F(StorageTextureTest, I32) { auto* subtype = StorageTexture::SubtypeFor(type::TexelFormat::kRgba32Sint, Types()); - Type* s = create(TextureDimension::k2dArray, type::TexelFormat::kRgba32Sint, + auto* s = create(TextureDimension::k2dArray, type::TexelFormat::kRgba32Sint, type::Access::kReadWrite, subtype); auto program = Build(); diff --git a/src/tint/type/texture.cc b/src/tint/type/texture.cc index 717d63ae5d..357af56d37 100644 --- a/src/tint/type/texture.cc +++ b/src/tint/type/texture.cc @@ -22,4 +22,36 @@ Texture::Texture(size_t hash, TextureDimension dim) : Base(hash, type::Flags{}), Texture::~Texture() = default; +bool IsTextureArray(type::TextureDimension dim) { + switch (dim) { + case type::TextureDimension::k2dArray: + case type::TextureDimension::kCubeArray: + return true; + case type::TextureDimension::k2d: + case type::TextureDimension::kNone: + case type::TextureDimension::k1d: + case type::TextureDimension::k3d: + case type::TextureDimension::kCube: + return false; + } + return false; +} + +int NumCoordinateAxes(type::TextureDimension dim) { + switch (dim) { + case type::TextureDimension::kNone: + return 0; + case type::TextureDimension::k1d: + return 1; + case type::TextureDimension::k2d: + case type::TextureDimension::k2dArray: + return 2; + case type::TextureDimension::k3d: + case type::TextureDimension::kCube: + case type::TextureDimension::kCubeArray: + return 3; + } + return 0; +} + } // namespace tint::type diff --git a/src/tint/type/texture.h b/src/tint/type/texture.h index 4fab761e9c..e7cbe81e66 100644 --- a/src/tint/type/texture.h +++ b/src/tint/type/texture.h @@ -37,6 +37,24 @@ class Texture : public Castable { TextureDimension const dim_; }; +/// @param dim the type::TextureDimension to query +/// @return true if the given type::TextureDimension is an array texture +bool IsTextureArray(type::TextureDimension dim); + +/// Returns the number of axes in the coordinate used for accessing +/// the texture, where an access is one of: sampling, fetching, load, +/// or store. +/// None -> 0 +/// 1D -> 1 +/// 2D, 2DArray -> 2 +/// 3D, Cube, CubeArray -> 3 +/// Note: To sample a cube texture, the coordinate has 3 dimensions, +/// but textureDimensions on a cube or cube array returns a 2-element +/// size, representing the (x,y) size of each cube face, in texels. +/// @param dim the type::TextureDimension to query +/// @return number of dimensions in a coordinate for the dimensionality +int NumCoordinateAxes(type::TextureDimension dim); + } // namespace tint::type #endif // SRC_TINT_TYPE_TEXTURE_H_ diff --git a/src/tint/writer/append_vector.cc b/src/tint/writer/append_vector.cc index ab18461792..3d38c7faf6 100644 --- a/src/tint/writer/append_vector.cc +++ b/src/tint/writer/append_vector.cc @@ -86,7 +86,7 @@ const sem::Call* AppendVector(ProgramBuilder* b, packed_el_sem_ty = vector_ty; } - const ast::Type* packed_el_ast_ty = Switch( + auto packed_el_ast_ty = Switch( packed_el_sem_ty, // [&](const type::I32*) { return b->ty.i32(); }, [&](const type::U32*) { return b->ty.u32(); }, @@ -95,12 +95,12 @@ const sem::Call* AppendVector(ProgramBuilder* b, [&](Default) { TINT_UNREACHABLE(Writer, b->Diagnostics()) << "unsupported vector element type: " << packed_el_sem_ty->TypeInfo().name; - return nullptr; + return ast::Type{}; }); auto* statement = vector_sem->Stmt(); - auto* packed_ast_ty = b->create(packed_el_ast_ty, packed_size); + auto packed_ast_ty = b->ty.vec(packed_el_ast_ty, packed_size); auto* packed_sem_ty = b->create(packed_el_sem_ty, packed_size); // If the coordinates are already passed in a vector initializer, with only diff --git a/src/tint/writer/append_vector_test.cc b/src/tint/writer/append_vector_test.cc index c8c6428c13..feded0c854 100644 --- a/src/tint/writer/append_vector_test.cc +++ b/src/tint/writer/append_vector_test.cc @@ -13,6 +13,7 @@ // limitations under the License. #include "src/tint/writer/append_vector.h" +#include "src/tint/ast/test_helper.h" #include "src/tint/program_builder.h" #include "src/tint/resolver/resolver.h" #include "src/tint/sem/type_initializer.h" @@ -86,8 +87,7 @@ TEST_F(AppendVectorTest, Vec2i32_u32) { EXPECT_EQ(vec_123->args[1], scalar_2); auto* u32_to_i32 = vec_123->args[2]->As(); ASSERT_NE(u32_to_i32, nullptr); - ASSERT_TRUE(u32_to_i32->target.type->Is()); - EXPECT_EQ(Symbols().NameFor(u32_to_i32->target.type->As()->name->symbol), "i32"); + ast::CheckIdentifier(Symbols(), u32_to_i32->target, "i32"); ASSERT_EQ(u32_to_i32->args.Length(), 1u); EXPECT_EQ(u32_to_i32->args[0], scalar_3); @@ -132,20 +132,14 @@ TEST_F(AppendVectorTest, Vec2i32FromVec2u32_u32) { ASSERT_EQ(vec_123->args.Length(), 2u); auto* v2u32_to_v2i32 = vec_123->args[0]->As(); ASSERT_NE(v2u32_to_v2i32, nullptr); - ASSERT_TRUE(v2u32_to_v2i32->target.type->Is()); - EXPECT_EQ(v2u32_to_v2i32->target.type->As()->width, 2u); - ASSERT_TRUE(v2u32_to_v2i32->target.type->As()->type->Is()); - EXPECT_EQ(Symbols().NameFor(v2u32_to_v2i32->target.type->As() - ->type->As() - ->name->symbol), - "i32"); + + ast::CheckIdentifier(Symbols(), v2u32_to_v2i32->target, ast::Template("vec2", "i32")); EXPECT_EQ(v2u32_to_v2i32->args.Length(), 1u); EXPECT_EQ(v2u32_to_v2i32->args[0], uvec_12); auto* u32_to_i32 = vec_123->args[1]->As(); ASSERT_NE(u32_to_i32, nullptr); - ASSERT_TRUE(u32_to_i32->target.type->Is()); - EXPECT_EQ(Symbols().NameFor(u32_to_i32->target.type->As()->name->symbol), "i32"); + ast::CheckIdentifier(Symbols(), u32_to_i32->target, "i32"); ASSERT_EQ(u32_to_i32->args.Length(), 1u); EXPECT_EQ(u32_to_i32->args[0], scalar_3); @@ -157,6 +151,7 @@ TEST_F(AppendVectorTest, Vec2i32FromVec2u32_u32) { auto* ctor = call->Target()->As(); ASSERT_NE(ctor, nullptr); + ASSERT_TRUE(ctor->ReturnType()->Is()); EXPECT_EQ(ctor->ReturnType()->As()->Width(), 3u); EXPECT_TRUE(ctor->ReturnType()->As()->type()->Is()); @@ -187,8 +182,7 @@ TEST_F(AppendVectorTest, Vec2i32_f32) { EXPECT_EQ(vec_123->args[1], scalar_2); auto* f32_to_i32 = vec_123->args[2]->As(); ASSERT_NE(f32_to_i32, nullptr); - ASSERT_TRUE(f32_to_i32->target.type->Is()); - EXPECT_EQ(Symbols().NameFor(f32_to_i32->target.type->As()->name->symbol), "i32"); + ast::CheckIdentifier(Symbols(), f32_to_i32->target, "i32"); ASSERT_EQ(f32_to_i32->args.Length(), 1u); EXPECT_EQ(f32_to_i32->args[0], scalar_3); @@ -389,8 +383,7 @@ TEST_F(AppendVectorTest, Vec2i32Var_f32Var) { EXPECT_EQ(vec_123->args[0], vec_12); auto* f32_to_i32 = vec_123->args[1]->As(); ASSERT_NE(f32_to_i32, nullptr); - ASSERT_TRUE(f32_to_i32->target.type->Is()); - EXPECT_EQ(Symbols().NameFor(f32_to_i32->target.type->As()->name->symbol), "i32"); + ast::CheckIdentifier(Symbols(), f32_to_i32->target, "i32"); ASSERT_EQ(f32_to_i32->args.Length(), 1u); EXPECT_EQ(f32_to_i32->args[0], scalar_3); diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index cb1850a523..58479234a6 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -706,7 +706,7 @@ bool GeneratorImpl::EmitCall(std::ostream& out, const ast::CallExpression* expr) auto* call = builder_.Sem().Get(expr); return Switch( call->Target(), // - [&](const sem::Function*) { return EmitFunctionCall(out, call); }, + [&](const sem::Function* fn) { return EmitFunctionCall(out, call, fn); }, [&](const sem::Builtin* builtin) { return EmitBuiltinCall(out, call, builtin); }, [&](const sem::TypeConversion* conv) { return EmitTypeConversion(out, call, conv); }, [&](const sem::TypeInitializer* init) { return EmitTypeInitializer(out, call, init); }, @@ -717,15 +717,13 @@ bool GeneratorImpl::EmitCall(std::ostream& out, const ast::CallExpression* expr) }); } -bool GeneratorImpl::EmitFunctionCall(std::ostream& out, const sem::Call* call) { +bool GeneratorImpl::EmitFunctionCall(std::ostream& out, + const sem::Call* call, + const sem::Function* fn) { const auto& args = call->Arguments(); - auto* decl = call->Declaration(); - auto* ident = decl->target.name; + auto* ident = fn->Declaration()->name; - auto name = builder_.Symbols().NameFor(ident->symbol); - auto caller_sym = ident->symbol; - - out << name; + out << builder_.Symbols().NameFor(ident->symbol); ScopedParen sp(out); bool first = true; diff --git a/src/tint/writer/glsl/generator_impl.h b/src/tint/writer/glsl/generator_impl.h index 7a623ed89b..e972b12e3e 100644 --- a/src/tint/writer/glsl/generator_impl.h +++ b/src/tint/writer/glsl/generator_impl.h @@ -150,8 +150,9 @@ class GeneratorImpl : public TextGenerator { /// Handles generating a function call expression /// @param out the output of the expression stream /// @param call the call expression + /// @param fn the function being called /// @returns true if the expression is emitted - bool EmitFunctionCall(std::ostream& out, const sem::Call* call); + bool EmitFunctionCall(std::ostream& out, const sem::Call* call, const sem::Function* fn); /// Handles generating a builtin call expression /// @param out the output of the expression stream /// @param call the call expression diff --git a/src/tint/writer/glsl/generator_impl_member_accessor_test.cc b/src/tint/writer/glsl/generator_impl_member_accessor_test.cc index ebccf27f4c..1023ad0058 100644 --- a/src/tint/writer/glsl/generator_impl_member_accessor_test.cc +++ b/src/tint/writer/glsl/generator_impl_member_accessor_test.cc @@ -23,63 +23,63 @@ namespace { using ::testing::HasSubstr; -using create_type_func_ptr = const ast::Type* (*)(const ProgramBuilder::TypesBuilder& ty); +using create_type_func_ptr = ast::Type (*)(const ProgramBuilder::TypesBuilder& ty); -inline const ast::Type* ty_i32(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_i32(const ProgramBuilder::TypesBuilder& ty) { return ty.i32(); } -inline const ast::Type* ty_u32(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_u32(const ProgramBuilder::TypesBuilder& ty) { return ty.u32(); } -inline const ast::Type* ty_f32(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_f32(const ProgramBuilder::TypesBuilder& ty) { return ty.f32(); } template -inline const ast::Type* ty_vec2(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_vec2(const ProgramBuilder::TypesBuilder& ty) { return ty.vec2(); } template -inline const ast::Type* ty_vec3(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_vec3(const ProgramBuilder::TypesBuilder& ty) { return ty.vec3(); } template -inline const ast::Type* ty_vec4(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_vec4(const ProgramBuilder::TypesBuilder& ty) { return ty.vec4(); } template -inline const ast::Type* ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) { return ty.mat2x2(); } template -inline const ast::Type* ty_mat2x3(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat2x3(const ProgramBuilder::TypesBuilder& ty) { return ty.mat2x3(); } template -inline const ast::Type* ty_mat2x4(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat2x4(const ProgramBuilder::TypesBuilder& ty) { return ty.mat2x4(); } template -inline const ast::Type* ty_mat3x2(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat3x2(const ProgramBuilder::TypesBuilder& ty) { return ty.mat3x2(); } template -inline const ast::Type* ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) { return ty.mat3x3(); } template -inline const ast::Type* ty_mat3x4(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat3x4(const ProgramBuilder::TypesBuilder& ty) { return ty.mat3x4(); } template -inline const ast::Type* ty_mat4x2(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat4x2(const ProgramBuilder::TypesBuilder& ty) { return ty.mat4x2(); } template -inline const ast::Type* ty_mat4x3(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat4x3(const ProgramBuilder::TypesBuilder& ty) { return ty.mat4x3(); } template -inline const ast::Type* ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) { return ty.mat4x4(); } @@ -144,10 +144,7 @@ struct TypeCase { std::string expected; }; inline std::ostream& operator<<(std::ostream& out, TypeCase c) { - ProgramBuilder b; - auto* ty = c.member_type(b.ty); - out << ty->FriendlyName(b.Symbols()); - return out; + return out << c.expected; } using GlslGeneratorImplTest_MemberAccessor_StorageBufferLoad = diff --git a/src/tint/writer/glsl/generator_impl_module_constant_test.cc b/src/tint/writer/glsl/generator_impl_module_constant_test.cc index c5d594f7ab..9f0985df84 100644 --- a/src/tint/writer/glsl/generator_impl_module_constant_test.cc +++ b/src/tint/writer/glsl/generator_impl_module_constant_test.cc @@ -156,7 +156,7 @@ void f() { } TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_vec3_AInt) { - auto* var = GlobalConst("G", Call(ty.vec3(nullptr), 1_a, 2_a, 3_a)); + auto* var = GlobalConst("G", Call(ty.vec3(), 1_a, 2_a, 3_a)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(Let("l", Expr(var))), @@ -176,7 +176,7 @@ void f() { } TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_vec3_AFloat) { - auto* var = GlobalConst("G", Call(ty.vec3(nullptr), 1._a, 2._a, 3._a)); + auto* var = GlobalConst("G", Call(ty.vec3(), 1._a, 2._a, 3._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(Let("l", Expr(var))), @@ -239,7 +239,7 @@ void f() { } TEST_F(GlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_mat2x3_AFloat) { - auto* var = GlobalConst("G", Call(ty.mat(nullptr, 2, 3), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); + auto* var = GlobalConst("G", Call(ty.mat2x3(), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(Let("l", Expr(var))), diff --git a/src/tint/writer/glsl/generator_impl_type_test.cc b/src/tint/writer/glsl/generator_impl_type_test.cc index 5a63fcb0a6..625c7d3067 100644 --- a/src/tint/writer/glsl/generator_impl_type_test.cc +++ b/src/tint/writer/glsl/generator_impl_type_test.cc @@ -33,52 +33,52 @@ namespace { using GlslGeneratorImplTest_Type = TestHelper; TEST_F(GlslGeneratorImplTest_Type, EmitType_Array) { - auto* arr = ty.array(); - GlobalVar("G", arr, type::AddressSpace::kPrivate); + auto arr = ty.array(); + ast::Type ty = GlobalVar("G", arr, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, type::Access::kReadWrite, "ary")) << gen.error(); EXPECT_EQ(out.str(), "bool ary[4]"); } TEST_F(GlslGeneratorImplTest_Type, EmitType_ArrayOfArray) { - auto* arr = ty.array(ty.array(), 5_u); - GlobalVar("G", arr, type::AddressSpace::kPrivate); + auto arr = ty.array(ty.array(), 5_u); + ast::Type ty = GlobalVar("G", arr, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, type::Access::kReadWrite, "ary")) << gen.error(); EXPECT_EQ(out.str(), "bool ary[5][4]"); } TEST_F(GlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) { - auto* arr = ty.array(ty.array(ty.array(), 5_u), 6_u); - GlobalVar("G", arr, type::AddressSpace::kPrivate); + auto arr = ty.array(ty.array(ty.array(), 5_u), 6_u); + ast::Type ty = GlobalVar("G", arr, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, type::Access::kReadWrite, "ary")) << gen.error(); EXPECT_EQ(out.str(), "bool ary[6][5][4]"); } TEST_F(GlslGeneratorImplTest_Type, EmitType_Array_WithoutName) { - auto* arr = ty.array(); - GlobalVar("G", arr, type::AddressSpace::kPrivate); + auto arr = ty.array(); + ast::Type ty = GlobalVar("G", arr, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "bool[4]"); @@ -313,7 +313,7 @@ using GlslDepthTexturesTest = TestParamHelper; TEST_P(GlslDepthTexturesTest, Emit) { auto params = GetParam(); - auto* t = ty.depth_texture(params.dim); + auto t = ty.depth_texture(params.dim); GlobalVar("tex", t, Binding(1_a), Group(2_a)); @@ -341,7 +341,7 @@ INSTANTIATE_TEST_SUITE_P( using GlslDepthMultisampledTexturesTest = TestHelper; TEST_F(GlslDepthMultisampledTexturesTest, Emit) { - auto* t = ty.depth_multisampled_texture(type::TextureDimension::k2d); + auto t = ty.depth_multisampled_texture(type::TextureDimension::k2d); GlobalVar("tex", t, Binding(1_a), Group(2_a)); @@ -373,7 +373,7 @@ using GlslSampledTexturesTest = TestParamHelper; TEST_P(GlslSampledTexturesTest, Emit) { auto params = GetParam(); - const ast::Type* datatype = nullptr; + ast::Type datatype; switch (params.datatype) { case TextureDataType::F32: datatype = ty.f32(); @@ -385,7 +385,7 @@ TEST_P(GlslSampledTexturesTest, Emit) { datatype = ty.i32(); break; } - auto* t = ty.sampled_texture(params.dim, datatype); + ast::Type t = ty.sampled_texture(params.dim, datatype); GlobalVar("tex", t, Binding(1_a), Group(2_a)); @@ -520,7 +520,7 @@ using GlslStorageTexturesTest = TestParamHelper; TEST_P(GlslStorageTexturesTest, Emit) { auto params = GetParam(); - auto* t = ty.storage_texture(params.dim, params.imgfmt, type::Access::kWrite); + auto t = ty.storage_texture(params.dim, params.imgfmt, type::Access::kWrite); GlobalVar("tex", t, Binding(1_a), Group(2_a)); diff --git a/src/tint/writer/glsl/generator_impl_variable_decl_statement_test.cc b/src/tint/writer/glsl/generator_impl_variable_decl_statement_test.cc index 562dabe32d..6511179f6a 100644 --- a/src/tint/writer/glsl/generator_impl_variable_decl_statement_test.cc +++ b/src/tint/writer/glsl/generator_impl_variable_decl_statement_test.cc @@ -194,7 +194,7 @@ void f() { } TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_vec3_AInt) { - auto* C = Const("C", Call(ty.vec3(nullptr), 1_a, 2_a, 3_a)); + auto* C = Const("C", Call(ty.vec3(), 1_a, 2_a, 3_a)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(C), @@ -215,7 +215,7 @@ void f() { } TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_vec3_AFloat) { - auto* C = Const("C", Call(ty.vec3(nullptr), 1._a, 2._a, 3._a)); + auto* C = Const("C", Call(ty.vec3(), 1._a, 2._a, 3._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(C), @@ -281,7 +281,7 @@ void f() { } TEST_F(GlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_mat2x3_AFloat) { - auto* C = Const("C", Call(ty.mat(nullptr, 2, 3), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); + auto* C = Const("C", Call(ty.mat2x3(), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(C), diff --git a/src/tint/writer/hlsl/generator_impl_member_accessor_test.cc b/src/tint/writer/hlsl/generator_impl_member_accessor_test.cc index 94f96a861c..0bd7ae685e 100644 --- a/src/tint/writer/hlsl/generator_impl_member_accessor_test.cc +++ b/src/tint/writer/hlsl/generator_impl_member_accessor_test.cc @@ -23,66 +23,66 @@ using namespace tint::number_suffixes; // NOLINT namespace tint::writer::hlsl { namespace { -using create_type_func_ptr = const ast::Type* (*)(const ProgramBuilder::TypesBuilder& ty); +using create_type_func_ptr = ast::Type (*)(const ProgramBuilder::TypesBuilder& ty); -inline const ast::Type* ty_i32(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_i32(const ProgramBuilder::TypesBuilder& ty) { return ty.i32(); } -inline const ast::Type* ty_u32(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_u32(const ProgramBuilder::TypesBuilder& ty) { return ty.u32(); } -inline const ast::Type* ty_f32(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_f32(const ProgramBuilder::TypesBuilder& ty) { return ty.f32(); } -inline const ast::Type* ty_f16(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_f16(const ProgramBuilder::TypesBuilder& ty) { return ty.f16(); } template -inline const ast::Type* ty_vec2(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_vec2(const ProgramBuilder::TypesBuilder& ty) { return ty.vec2(); } template -inline const ast::Type* ty_vec3(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_vec3(const ProgramBuilder::TypesBuilder& ty) { return ty.vec3(); } template -inline const ast::Type* ty_vec4(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_vec4(const ProgramBuilder::TypesBuilder& ty) { return ty.vec4(); } template -inline const ast::Type* ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat2x2(const ProgramBuilder::TypesBuilder& ty) { return ty.mat2x2(); } template -inline const ast::Type* ty_mat2x3(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat2x3(const ProgramBuilder::TypesBuilder& ty) { return ty.mat2x3(); } template -inline const ast::Type* ty_mat2x4(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat2x4(const ProgramBuilder::TypesBuilder& ty) { return ty.mat2x4(); } template -inline const ast::Type* ty_mat3x2(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat3x2(const ProgramBuilder::TypesBuilder& ty) { return ty.mat3x2(); } template -inline const ast::Type* ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat3x3(const ProgramBuilder::TypesBuilder& ty) { return ty.mat3x3(); } template -inline const ast::Type* ty_mat3x4(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat3x4(const ProgramBuilder::TypesBuilder& ty) { return ty.mat3x4(); } template -inline const ast::Type* ty_mat4x2(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat4x2(const ProgramBuilder::TypesBuilder& ty) { return ty.mat4x2(); } template -inline const ast::Type* ty_mat4x3(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat4x3(const ProgramBuilder::TypesBuilder& ty) { return ty.mat4x3(); } template -inline const ast::Type* ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) { +inline ast::Type ty_mat4x4(const ProgramBuilder::TypesBuilder& ty) { return ty.mat4x4(); } @@ -149,10 +149,7 @@ struct TypeCase { std::string expected; }; inline std::ostream& operator<<(std::ostream& out, TypeCase c) { - ProgramBuilder b; - auto* ty = c.member_type(b.ty); - out << ty->FriendlyName(b.Symbols()); - return out; + return out << c.expected; } using HlslGeneratorImplTest_MemberAccessor_StorageBufferLoad_ConstantOffset = diff --git a/src/tint/writer/hlsl/generator_impl_module_constant_test.cc b/src/tint/writer/hlsl/generator_impl_module_constant_test.cc index 212a5d527e..62f1d8ee43 100644 --- a/src/tint/writer/hlsl/generator_impl_module_constant_test.cc +++ b/src/tint/writer/hlsl/generator_impl_module_constant_test.cc @@ -109,7 +109,7 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_f16) { } TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_vec3_AInt) { - auto* var = GlobalConst("G", Call(ty.vec3(nullptr), 1_a, 2_a, 3_a)); + auto* var = GlobalConst("G", Call(ty.vec3(), 1_a, 2_a, 3_a)); Func("f", utils::Empty, ty.void_(), utils::Vector{Decl(Let("l", Expr(var)))}); GeneratorImpl& gen = Build(); @@ -123,7 +123,7 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_vec3_AInt) { } TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_vec3_AFloat) { - auto* var = GlobalConst("G", Call(ty.vec3(nullptr), 1._a, 2._a, 3._a)); + auto* var = GlobalConst("G", Call(ty.vec3(), 1._a, 2._a, 3._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{Decl(Let("l", Expr(var)))}); GeneratorImpl& gen = Build(); @@ -167,7 +167,7 @@ TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_vec3_f16) { } TEST_F(HlslGeneratorImplTest_ModuleConstant, Emit_GlobalConst_mat2x3_AFloat) { - auto* var = GlobalConst("G", Call(ty.mat(nullptr, 2, 3), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); + auto* var = GlobalConst("G", Call(ty.mat2x3(), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{Decl(Let("l", Expr(var)))}); GeneratorImpl& gen = Build(); diff --git a/src/tint/writer/hlsl/generator_impl_type_test.cc b/src/tint/writer/hlsl/generator_impl_type_test.cc index 9f5d01296f..be5a90057a 100644 --- a/src/tint/writer/hlsl/generator_impl_type_test.cc +++ b/src/tint/writer/hlsl/generator_impl_type_test.cc @@ -33,52 +33,52 @@ namespace { using HlslGeneratorImplTest_Type = TestHelper; TEST_F(HlslGeneratorImplTest_Type, EmitType_Array) { - auto* arr = ty.array(); - GlobalVar("G", arr, type::AddressSpace::kPrivate); + auto arr = ty.array(); + ast::Type ty = GlobalVar("G", arr, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, type::Access::kReadWrite, "ary")) << gen.error(); EXPECT_EQ(out.str(), "bool ary[4]"); } TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArray) { - auto* arr = ty.array(ty.array(), 5_u); - GlobalVar("G", arr, type::AddressSpace::kPrivate); + auto arr = ty.array(ty.array(), 5_u); + ast::Type ty = GlobalVar("G", arr, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, type::Access::kReadWrite, "ary")) << gen.error(); EXPECT_EQ(out.str(), "bool ary[5][4]"); } TEST_F(HlslGeneratorImplTest_Type, EmitType_ArrayOfArrayOfArray) { - auto* arr = ty.array(ty.array(ty.array(), 5_u), 6_u); - GlobalVar("G", arr, type::AddressSpace::kPrivate); + auto arr = ty.array(ty.array(ty.array(), 5_u), 6_u); + ast::Type ty = GlobalVar("G", arr, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, type::Access::kReadWrite, "ary")) << gen.error(); EXPECT_EQ(out.str(), "bool ary[6][5][4]"); } TEST_F(HlslGeneratorImplTest_Type, EmitType_Array_WithoutName) { - auto* arr = ty.array(); - GlobalVar("G", arr, type::AddressSpace::kPrivate); + auto arr = ty.array(); + ast::Type ty = GlobalVar("G", arr, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), type::AddressSpace::kNone, + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(ty), type::AddressSpace::kNone, type::Access::kReadWrite, "")) << gen.error(); EXPECT_EQ(out.str(), "bool[4]"); @@ -307,7 +307,7 @@ using HlslDepthTexturesTest = TestParamHelper; TEST_P(HlslDepthTexturesTest, Emit) { auto params = GetParam(); - auto* t = ty.depth_texture(params.dim); + auto t = ty.depth_texture(params.dim); GlobalVar("tex", t, Binding(1_a), Group(2_a)); @@ -338,7 +338,7 @@ INSTANTIATE_TEST_SUITE_P( using HlslDepthMultisampledTexturesTest = TestHelper; TEST_F(HlslDepthMultisampledTexturesTest, Emit) { - auto* t = ty.depth_multisampled_texture(type::TextureDimension::k2d); + auto t = ty.depth_multisampled_texture(type::TextureDimension::k2d); GlobalVar("tex", t, Binding(1_a), Group(2_a)); @@ -370,7 +370,7 @@ using HlslSampledTexturesTest = TestParamHelper; TEST_P(HlslSampledTexturesTest, Emit) { auto params = GetParam(); - const ast::Type* datatype = nullptr; + ast::Type datatype; switch (params.datatype) { case TextureDataType::F32: datatype = ty.f32(); @@ -382,7 +382,7 @@ TEST_P(HlslSampledTexturesTest, Emit) { datatype = ty.i32(); break; } - auto* t = ty.sampled_texture(params.dim, datatype); + ast::Type t = ty.sampled_texture(params.dim, datatype); GlobalVar("tex", t, Binding(1_a), Group(2_a)); @@ -518,7 +518,7 @@ using HlslStorageTexturesTest = TestParamHelper; TEST_P(HlslStorageTexturesTest, Emit) { auto params = GetParam(); - auto* t = ty.storage_texture(params.dim, params.imgfmt, type::Access::kWrite); + auto t = ty.storage_texture(params.dim, params.imgfmt, type::Access::kWrite); GlobalVar("tex", t, utils::Vector{ diff --git a/src/tint/writer/hlsl/generator_impl_variable_decl_statement_test.cc b/src/tint/writer/hlsl/generator_impl_variable_decl_statement_test.cc index 47a7db3f62..170d993ff5 100644 --- a/src/tint/writer/hlsl/generator_impl_variable_decl_statement_test.cc +++ b/src/tint/writer/hlsl/generator_impl_variable_decl_statement_test.cc @@ -175,7 +175,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_f16) } TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_vec3_AInt) { - auto* C = Const("C", Call(ty.vec3(nullptr), 1_a, 2_a, 3_a)); + auto* C = Const("C", Call(ty.vec3(), 1_a, 2_a, 3_a)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(C), @@ -193,7 +193,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_vec3 } TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_vec3_AFloat) { - auto* C = Const("C", Call(ty.vec3(nullptr), 1._a, 2._a, 3._a)); + auto* C = Const("C", Call(ty.vec3(), 1._a, 2._a, 3._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(C), @@ -249,7 +249,7 @@ TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_vec3 } TEST_F(HlslGeneratorImplTest_VariableDecl, Emit_VariableDeclStatement_Const_mat2x3_AFloat) { - auto* C = Const("C", Call(ty.mat(nullptr, 2, 3), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); + auto* C = Const("C", Call(ty.mat2x3(), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(C), diff --git a/src/tint/writer/msl/generator_impl.cc b/src/tint/writer/msl/generator_impl.cc index 71003218c6..febde27f52 100644 --- a/src/tint/writer/msl/generator_impl.cc +++ b/src/tint/writer/msl/generator_impl.cc @@ -650,9 +650,8 @@ bool GeneratorImpl::EmitCall(std::ostream& out, const ast::CallExpression* expr) bool GeneratorImpl::EmitFunctionCall(std::ostream& out, const sem::Call* call, - const sem::Function*) { - auto* ident = call->Declaration()->target.name; - out << program_->Symbols().NameFor(ident->symbol) << "("; + const sem::Function* fn) { + out << program_->Symbols().NameFor(fn->Declaration()->name->symbol) << "("; bool first = true; for (auto* arg : call->Arguments()) { @@ -2097,7 +2096,6 @@ bool GeneratorImpl::EmitEntryPointFunction(const ast::Function* func) { } return true; }); - if (!ok) { return false; } diff --git a/src/tint/writer/msl/generator_impl_binary_test.cc b/src/tint/writer/msl/generator_impl_binary_test.cc index fc03507b93..4916799235 100644 --- a/src/tint/writer/msl/generator_impl_binary_test.cc +++ b/src/tint/writer/msl/generator_impl_binary_test.cc @@ -32,8 +32,8 @@ TEST_P(MslBinaryTest, Emit) { auto type = [&] { return ((params.op == ast::BinaryOp::kLogicalAnd) || (params.op == ast::BinaryOp::kLogicalOr)) - ? static_cast(ty.bool_()) - : static_cast(ty.u32()); + ? ty.bool_() + : ty.u32(); }; auto* left = Var("left", type()); @@ -74,10 +74,10 @@ using MslBinaryTest_SignedOverflowDefinedBehaviour = TestParamHelper TEST_P(MslBinaryTest_SignedOverflowDefinedBehaviour, Emit) { auto params = GetParam(); - auto* a_type = ty.i32(); - auto* b_type = + auto a_type = ty.i32(); + auto b_type = (params.op == ast::BinaryOp::kShiftLeft || params.op == ast::BinaryOp::kShiftRight) - ? static_cast(ty.u32()) + ? ty.u32() : ty.i32(); auto* a = Var("a", a_type); @@ -107,10 +107,10 @@ using MslBinaryTest_SignedOverflowDefinedBehaviour_Chained = TestParamHelper(ty.u32()) + ? ty.u32() : ty.i32(); auto* a = Var("a", a_type); diff --git a/src/tint/writer/msl/generator_impl_builtin_texture_test.cc b/src/tint/writer/msl/generator_impl_builtin_texture_test.cc index 028f85109d..16688ef91f 100644 --- a/src/tint/writer/msl/generator_impl_builtin_texture_test.cc +++ b/src/tint/writer/msl/generator_impl_builtin_texture_test.cc @@ -276,7 +276,7 @@ TEST_P(MslGeneratorBuiltinTextureTest, Call) { param.BuildTextureVariable(this); param.BuildSamplerVariable(this); - auto* call = Call(Ident(param.function), param.args(this)); + auto* call = Call(param.function, param.args(this)); auto* stmt = CallStmt(call); Func("main", utils::Empty, ty.void_(), utils::Vector{stmt}, diff --git a/src/tint/writer/msl/generator_impl_function_test.cc b/src/tint/writer/msl/generator_impl_function_test.cc index a1e91feb5a..a93d262841 100644 --- a/src/tint/writer/msl/generator_impl_function_test.cc +++ b/src/tint/writer/msl/generator_impl_function_test.cc @@ -179,7 +179,7 @@ TEST_F(MslGeneratorImplTest, Emit_Attribute_EntryPoint_SharedStruct_DifferentSta // @builtin(position) pos : vec4; // }; // fn vert_main() -> Interface { - // return Interface(0.4, 0.6, vec4()); + // return Interface(0.5, 0.25, vec4()); // } // fn frag_main(colors : Interface) { // const r = colors.col1; @@ -194,8 +194,7 @@ TEST_F(MslGeneratorImplTest, Emit_Attribute_EntryPoint_SharedStruct_DifferentSta }); Func("vert_main", utils::Empty, ty.Of(interface_struct), - utils::Vector{Return( - Call(ty.Of(interface_struct), Expr(0.5_f), Expr(0.25_f), Call(ty.vec4())))}, + utils::Vector{Return(Call(ty.Of(interface_struct), 0.5_f, 0.25_f, vec4()))}, utils::Vector{Stage(ast::PipelineStage::kVertex)}); Func("frag_main", utils::Vector{Param("colors", ty.Of(interface_struct))}, ty.void_(), diff --git a/src/tint/writer/msl/generator_impl_module_constant_test.cc b/src/tint/writer/msl/generator_impl_module_constant_test.cc index 6de50d7bcf..e7983647e4 100644 --- a/src/tint/writer/msl/generator_impl_module_constant_test.cc +++ b/src/tint/writer/msl/generator_impl_module_constant_test.cc @@ -133,7 +133,7 @@ void f() { } TEST_F(MslGeneratorImplTest, Emit_GlobalConst_vec3_AInt) { - auto* var = GlobalConst("G", Call(ty.vec3(nullptr), 1_a, 2_a, 3_a)); + auto* var = GlobalConst("G", Call(ty.vec3(), 1_a, 2_a, 3_a)); Func("f", utils::Empty, ty.void_(), utils::Vector{Decl(Let("l", Expr(var)))}); GeneratorImpl& gen = Build(); @@ -151,7 +151,7 @@ void f() { } TEST_F(MslGeneratorImplTest, Emit_GlobalConst_vec3_AFloat) { - auto* var = GlobalConst("G", Call(ty.vec3(nullptr), 1._a, 2._a, 3._a)); + auto* var = GlobalConst("G", Call(ty.vec3(), 1._a, 2._a, 3._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{Decl(Let("l", Expr(var)))}); GeneratorImpl& gen = Build(); @@ -207,7 +207,7 @@ void f() { } TEST_F(MslGeneratorImplTest, Emit_GlobalConst_mat2x3_AFloat) { - auto* var = GlobalConst("G", Call(ty.mat(nullptr, 2, 3), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); + auto* var = GlobalConst("G", Call(ty.mat2x3(), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{Decl(Let("l", Expr(var)))}); GeneratorImpl& gen = Build(); diff --git a/src/tint/writer/msl/generator_impl_sanitizer_test.cc b/src/tint/writer/msl/generator_impl_sanitizer_test.cc index fda5296ef9..3b35e6dfd3 100644 --- a/src/tint/writer/msl/generator_impl_sanitizer_test.cc +++ b/src/tint/writer/msl/generator_impl_sanitizer_test.cc @@ -27,9 +27,7 @@ using namespace tint::number_suffixes; // NOLINT using MslSanitizerTest = TestHelper; TEST_F(MslSanitizerTest, Call_ArrayLength) { - auto* s = Structure("my_struct", utils::Vector{ - Member(0, "a", ty.array()), - }); + auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array())}); GlobalVar("b", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, Binding(1_a), Group(2_a)); @@ -136,9 +134,7 @@ fragment void a_func(const constant tint_symbol* tint_symbol_2 [[buffer(30)]]) { } TEST_F(MslSanitizerTest, Call_ArrayLength_ViaLets) { - auto* s = Structure("my_struct", utils::Vector{ - Member(0, "a", ty.array()), - }); + auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array())}); GlobalVar("b", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, Binding(1_a), Group(2_a)); @@ -195,9 +191,7 @@ fragment void a_func(const constant tint_symbol* tint_symbol_2 [[buffer(30)]]) { } TEST_F(MslSanitizerTest, Call_ArrayLength_ArrayLengthFromUniform) { - auto* s = Structure("my_struct", utils::Vector{ - Member(0, "a", ty.array()), - }); + auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array())}); GlobalVar("b", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, Binding(1_a), Group(0_a)); GlobalVar("c", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, Binding(2_a), @@ -256,9 +250,7 @@ fragment void a_func(const constant tint_symbol* tint_symbol_2 [[buffer(29)]]) { } TEST_F(MslSanitizerTest, Call_ArrayLength_ArrayLengthFromUniformMissingBinding) { - auto* s = Structure("my_struct", utils::Vector{ - Member(0, "a", ty.array()), - }); + auto* s = Structure("my_struct", utils::Vector{Member(0, "a", ty.array())}); GlobalVar("b", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, Binding(1_a), Group(0_a)); GlobalVar("c", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, Binding(2_a), diff --git a/src/tint/writer/msl/generator_impl_type_test.cc b/src/tint/writer/msl/generator_impl_type_test.cc index c116e87751..971d2a6084 100644 --- a/src/tint/writer/msl/generator_impl_type_test.cc +++ b/src/tint/writer/msl/generator_impl_type_test.cc @@ -89,60 +89,60 @@ using uint = unsigned int; using MslGeneratorImplTest = TestHelper; TEST_F(MslGeneratorImplTest, EmitType_Array) { - auto* arr = ty.array(); - GlobalVar("G", arr, type::AddressSpace::kPrivate); + auto arr = ty.array(); + ast::Type type = GlobalVar("G", arr, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), "ary")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(type), "ary")) << gen.error(); EXPECT_EQ(out.str(), "tint_array"); } TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArray) { - auto* a = ty.array(); - auto* b = ty.array(a, 5_u); - GlobalVar("G", b, type::AddressSpace::kPrivate); + auto a = ty.array(); + auto b = ty.array(a, 5_u); + ast::Type type = GlobalVar("G", b, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(b), "ary")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(type), "ary")) << gen.error(); EXPECT_EQ(out.str(), "tint_array, 5>"); } TEST_F(MslGeneratorImplTest, EmitType_ArrayOfArrayOfArray) { - auto* a = ty.array(); - auto* b = ty.array(a, 5_u); - auto* c = ty.array(b, 6_u); - GlobalVar("G", c, type::AddressSpace::kPrivate); + auto a = ty.array(); + auto b = ty.array(a, 5_u); + auto c = ty.array(b, 6_u); + ast::Type type = GlobalVar("G", c, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(c), "ary")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(type), "ary")) << gen.error(); EXPECT_EQ(out.str(), "tint_array, 5>, 6>"); } TEST_F(MslGeneratorImplTest, EmitType_Array_WithoutName) { - auto* arr = ty.array(); - GlobalVar("G", arr, type::AddressSpace::kPrivate); + auto arr = ty.array(); + ast::Type type = GlobalVar("G", arr, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(type), "")) << gen.error(); EXPECT_EQ(out.str(), "tint_array"); } TEST_F(MslGeneratorImplTest, EmitType_RuntimeArray) { - auto* arr = ty.array(); - GlobalVar("G", arr, type::AddressSpace::kPrivate); + auto arr = ty.array(); + ast::Type type = GlobalVar("G", arr, type::AddressSpace::kPrivate)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(arr), "ary")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(type), "ary")) << gen.error(); EXPECT_EQ(out.str(), "tint_array"); } @@ -283,13 +283,14 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_NonComposites) { Member("z", ty.f32()), }); - GlobalVar("G", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, Binding(0_a), - Group(0_a)); + ast::Type type = GlobalVar("G", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, + Binding(0_a), Group(0_a)) + ->type; GeneratorImpl& gen = Build(); TextGenerator::TextBuffer buf; - auto* sem_s = program->TypeOf(s)->As(); + auto* sem_s = program->TypeOf(type)->As(); ASSERT_TRUE(gen.EmitStructType(&buf, sem_s)) << gen.error(); // ALL_FIELDS() calls the macro FIELD(ADDR, TYPE, ARRAY_COUNT, NAME) @@ -391,13 +392,14 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_Structures) { Member("e", ty.f32()), }); - GlobalVar("G", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, Binding(0_a), - Group(0_a)); + ast::Type type = GlobalVar("G", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, + Binding(0_a), Group(0_a)) + ->type; GeneratorImpl& gen = Build(); TextGenerator::TextBuffer buf; - auto* sem_s = program->TypeOf(s)->As(); + auto* sem_s = program->TypeOf(type)->As(); ASSERT_TRUE(gen.EmitStructType(&buf, sem_s)) << gen.error(); // ALL_FIELDS() calls the macro FIELD(ADDR, TYPE, ARRAY_COUNT, NAME) @@ -465,13 +467,13 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_ArrayDefaultStride) { }); // array_x: size(28), align(4) - auto* array_x = ty.array(); + auto array_x = ty.array(); // array_y: size(4096), align(512) - auto* array_y = ty.array(ty.Of(inner), 4_u); + auto array_y = ty.array(ty.Of(inner), 4_u); // array_z: size(4), align(4) - auto* array_z = ty.array(); + auto array_z = ty.array(); auto* s = Structure("S", utils::Vector{ Member("a", ty.i32()), @@ -482,13 +484,14 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_ArrayDefaultStride) { Member("f", array_z), }); - GlobalVar("G", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, Binding(0_a), - Group(0_a)); + ast::Type type = GlobalVar("G", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, + Binding(0_a), Group(0_a)) + ->type; GeneratorImpl& gen = Build(); TextGenerator::TextBuffer buf; - auto* sem_s = program->TypeOf(s)->As(); + auto* sem_s = program->TypeOf(type)->As(); ASSERT_TRUE(gen.EmitStructType(&buf, sem_s)) << gen.error(); // ALL_FIELDS() calls the macro FIELD(ADDR, TYPE, ARRAY_COUNT, NAME) @@ -557,7 +560,7 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_ArrayDefaultStride) { TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_ArrayVec3DefaultStride) { // array: size(64), align(16) - auto* array = ty.array(ty.vec3(), 4_u); + auto array = ty.array(ty.vec3(), 4_u); auto* s = Structure("S", utils::Vector{ Member("a", ty.i32()), @@ -565,13 +568,14 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_Layout_ArrayVec3DefaultStride) { Member("c", ty.i32()), }); - GlobalVar("G", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, Binding(0_a), - Group(0_a)); + ast::Type type = GlobalVar("G", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, + Binding(0_a), Group(0_a)) + ->type; GeneratorImpl& gen = Build(); TextGenerator::TextBuffer buf; - auto* sem_s = program->TypeOf(s)->As(); + auto* sem_s = program->TypeOf(type)->As(); ASSERT_TRUE(gen.EmitStructType(&buf, sem_s)) << gen.error(); // ALL_FIELDS() calls the macro FIELD(ADDR, TYPE, ARRAY_COUNT, NAME) @@ -626,13 +630,14 @@ TEST_F(MslGeneratorImplTest, AttemptTintPadSymbolCollision) { Member("tint_pad_21", ty.f32()), }); - GlobalVar("G", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, Binding(0_a), - Group(0_a)); + ast::Type type = GlobalVar("G", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, + Binding(0_a), Group(0_a)) + ->type; GeneratorImpl& gen = Build(); TextGenerator::TextBuffer buf; - auto* sem_s = program->TypeOf(s)->As(); + auto* sem_s = program->TypeOf(type)->As(); ASSERT_TRUE(gen.EmitStructType(&buf, sem_s)) << gen.error(); EXPECT_EQ(buf.String(), R"(struct S { /* 0x0000 */ int tint_pad_2; @@ -684,13 +689,14 @@ TEST_F(MslGeneratorImplTest, EmitType_Struct_WithAttribute) { Member("b", ty.f32()), }); - GlobalVar("G", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, Binding(0_a), - Group(0_a)); + ast::Type type = GlobalVar("G", ty.Of(s), type::AddressSpace::kStorage, type::Access::kRead, + Binding(0_a), Group(0_a)) + ->type; GeneratorImpl& gen = Build(); TextGenerator::TextBuffer buf; - auto* sem_s = program->TypeOf(s)->As(); + auto* sem_s = program->TypeOf(type)->As(); ASSERT_TRUE(gen.EmitStructType(&buf, sem_s)) << gen.error(); EXPECT_EQ(buf.String(), R"(struct S { /* 0x0000 */ int a; @@ -847,13 +853,13 @@ using MslStorageTexturesTest = TestParamHelper; TEST_P(MslStorageTexturesTest, Emit) { auto params = GetParam(); - auto* s = ty.storage_texture(params.dim, type::TexelFormat::kR32Float, type::Access::kWrite); - GlobalVar("test_var", s, Binding(0_a), Group(0_a)); + auto s = ty.storage_texture(params.dim, type::TexelFormat::kR32Float, type::Access::kWrite); + ast::Type type = GlobalVar("test_var", s, Binding(0_a), Group(0_a))->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, program->TypeOf(s), "")) << gen.error(); + ASSERT_TRUE(gen.EmitType(out, program->TypeOf(type), "")) << gen.error(); EXPECT_EQ(out.str(), params.result); } INSTANTIATE_TEST_SUITE_P( diff --git a/src/tint/writer/msl/generator_impl_variable_decl_statement_test.cc b/src/tint/writer/msl/generator_impl_variable_decl_statement_test.cc index 5631b4db1f..927ae2627d 100644 --- a/src/tint/writer/msl/generator_impl_variable_decl_statement_test.cc +++ b/src/tint/writer/msl/generator_impl_variable_decl_statement_test.cc @@ -175,7 +175,7 @@ void f() { } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_AInt) { - auto* C = Const("C", Call(ty.vec3(nullptr), 1_a, 2_a, 3_a)); + auto* C = Const("C", vec3(1_a, 2_a, 3_a)); Func("f", utils::Empty, ty.void_(), utils::Vector{Decl(C), Decl(Let("l", Expr(C)))}); GeneratorImpl& gen = Build(); @@ -193,7 +193,7 @@ void f() { } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_AFloat) { - auto* C = Const("C", Call(ty.vec3(nullptr), 1._a, 2._a, 3._a)); + auto* C = Const("C", vec3(1._a, 2._a, 3._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{Decl(C), Decl(Let("l", Expr(C)))}); GeneratorImpl& gen = Build(); @@ -249,7 +249,7 @@ void f() { } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const_mat2x3_AFloat) { - auto* C = Const("C", Call(ty.mat(nullptr, 2, 3), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); + auto* C = Const("C", Call(ty.mat2x3(), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{Decl(C), Decl(Let("l", Expr(C)))}); GeneratorImpl& gen = Build(); @@ -305,7 +305,7 @@ void f() { } TEST_F(MslGeneratorImplTest, Emit_VariableDeclStatement_Const_arr_f32) { - auto* C = Const("C", Call(ty.array(), 1_f, 2_f, 3_f)); + auto* C = Const("C", array(1_f, 2_f, 3_f)); Func("f", utils::Empty, ty.void_(), utils::Vector{Decl(C), Decl(Let("l", Expr(C)))}); GeneratorImpl& gen = Build(); diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc index 590004cdca..008cf412b9 100644 --- a/src/tint/writer/spirv/builder.cc +++ b/src/tint/writer/spirv/builder.cc @@ -2243,9 +2243,9 @@ uint32_t Builder::GenerateCallExpression(const ast::CallExpression* expr) { }); } -uint32_t Builder::GenerateFunctionCall(const sem::Call* call, const sem::Function*) { +uint32_t Builder::GenerateFunctionCall(const sem::Call* call, const sem::Function* fn) { auto* expr = call->Declaration(); - auto* ident = expr->target.name; + auto* ident = fn->Declaration()->name; auto type_id = GenerateTypeIfNeeded(call->Type()); if (type_id == 0) { diff --git a/src/tint/writer/spirv/builder_accessor_expression_test.cc b/src/tint/writer/spirv/builder_accessor_expression_test.cc index ccbcad6df3..e6692abbce 100644 --- a/src/tint/writer/spirv/builder_accessor_expression_test.cc +++ b/src/tint/writer/spirv/builder_accessor_expression_test.cc @@ -1384,10 +1384,10 @@ TEST_F(BuilderTest, IndexAccessor_Mixed_ArrayAndMember) { auto* c_type = Structure("C", utils::Vector{Member("baz", ty.vec3())}); auto* b_type = Structure("B", utils::Vector{Member("bar", ty.Of(c_type))}); - auto* b_ary_type = ty.array(ty.Of(b_type), 3_u); + auto b_ary_type = ty.array(ty.Of(b_type), 3_u); auto* a_type = Structure("A", utils::Vector{Member("foo", b_ary_type)}); - auto* a_ary_type = ty.array(ty.Of(a_type), 2_u); + auto a_ary_type = ty.array(ty.Of(a_type), 2_u); auto* var = Var("index", a_ary_type); auto* expr = MemberAccessor( MemberAccessor( diff --git a/src/tint/writer/spirv/builder_builtin_test.cc b/src/tint/writer/spirv/builder_builtin_test.cc index 63c39903c5..0bab161c76 100644 --- a/src/tint/writer/spirv/builder_builtin_test.cc +++ b/src/tint/writer/spirv/builder_builtin_test.cc @@ -41,8 +41,8 @@ inline std::ostream& operator<<(std::ostream& out, BuiltinData data) { // This tests that we do not push OpTypeSampledImage and float_0 type twice. TEST_F(BuiltinBuilderTest, Call_TextureSampleCompare_Twice) { - auto* s = ty.sampler(type::SamplerKind::kComparisonSampler); - auto* t = ty.depth_texture(type::TextureDimension::k2d); + auto s = ty.sampler(type::SamplerKind::kComparisonSampler); + auto t = ty.depth_texture(type::TextureDimension::k2d); auto* tex = GlobalVar("texture", t, Binding(0_a), Group(0_a)); auto* sampler = GlobalVar("sampler", s, Binding(1_a), Group(0_a)); diff --git a/src/tint/writer/spirv/builder_entry_point_test.cc b/src/tint/writer/spirv/builder_entry_point_test.cc index 51995dd4f5..7b55804006 100644 --- a/src/tint/writer/spirv/builder_entry_point_test.cc +++ b/src/tint/writer/spirv/builder_entry_point_test.cc @@ -215,7 +215,7 @@ TEST_F(BuilderTest, EntryPoint_SharedStruct) { Member("pos", ty.vec4(), utils::Vector{Builtin(ast::BuiltinValue::kPosition)}), }); - auto* vert_retval = Call(ty.Of(interface), 42_f, Call(ty.vec4())); + auto* vert_retval = Call(ty.Of(interface), 42_f, vec4()); Func("vert_main", utils::Empty, ty.Of(interface), utils::Vector{Return(vert_retval)}, utils::Vector{ Stage(ast::PipelineStage::kVertex), diff --git a/src/tint/writer/spirv/builder_function_attribute_test.cc b/src/tint/writer/spirv/builder_function_attribute_test.cc index 9bba88fa9d..8776842071 100644 --- a/src/tint/writer/spirv/builder_function_attribute_test.cc +++ b/src/tint/writer/spirv/builder_function_attribute_test.cc @@ -51,15 +51,13 @@ TEST_P(Attribute_StageTest, Emit) { auto params = GetParam(); const ast::Variable* var = nullptr; - const ast::Type* ret_type = nullptr; + ast::Type ret_type; utils::Vector ret_type_attrs; utils::Vector body; if (params.stage == ast::PipelineStage::kVertex) { ret_type = ty.vec4(); ret_type_attrs.Push(Builtin(ast::BuiltinValue::kPosition)); body.Push(Return(Call(ty.vec4()))); - } else { - ret_type = ty.void_(); } utils::Vector deco_list{Stage(params.stage)}; diff --git a/src/tint/writer/spirv/builder_global_variable_test.cc b/src/tint/writer/spirv/builder_global_variable_test.cc index c74def592d..a246cbd657 100644 --- a/src/tint/writer/spirv/builder_global_variable_test.cc +++ b/src/tint/writer/spirv/builder_global_variable_test.cc @@ -150,7 +150,7 @@ TEST_F(BuilderTest, GlobalConst_Vec_AInt_Initializer) { // const c = vec3(1, 2, 3); // var v = c; - auto* c = GlobalConst("c", Call(ty.vec3(nullptr), 1_a, 2_a, 3_a)); + auto* c = GlobalConst("c", Call(ty.vec3(), 1_a, 2_a, 3_a)); GlobalVar("v", type::AddressSpace::kPrivate, Expr(c)); spirv::Builder& b = SanitizeAndBuild(); @@ -179,7 +179,7 @@ TEST_F(BuilderTest, GlobalConst_Vec_AFloat_Initializer) { // const c = vec3(1.0, 2.0, 3.0); // var v = c; - auto* c = GlobalConst("c", Call(ty.vec3(nullptr), 1._a, 2._a, 3._a)); + auto* c = GlobalConst("c", Call(ty.vec3(), 1._a, 2._a, 3._a)); GlobalVar("v", type::AddressSpace::kPrivate, Expr(c)); spirv::Builder& b = SanitizeAndBuild(); @@ -472,8 +472,8 @@ OpName %9 "unused_entry_point" TEST_F(BuilderTest, GlobalVar_TextureStorageWriteOnly) { // var a : texture_storage_2d; - auto* type = ty.storage_texture(type::TextureDimension::k2d, type::TexelFormat::kR32Uint, - type::Access::kWrite); + auto type = ty.storage_texture(type::TextureDimension::k2d, type::TexelFormat::kR32Uint, + type::Access::kWrite); auto* var_a = GlobalVar("a", type, Binding(0_a), Group(0_a)); @@ -493,10 +493,10 @@ OpDecorate %1 DescriptorSet 0 } TEST_F(BuilderTest, GlobalVar_WorkgroupWithZeroInit) { - auto* type_scalar = ty.i32(); + auto type_scalar = ty.i32(); auto* var_scalar = GlobalVar("a", type_scalar, type::AddressSpace::kWorkgroup); - auto* type_array = ty.array(); + auto type_array = ty.array(); auto* var_array = GlobalVar("b", type_array, type::AddressSpace::kWorkgroup); auto* type_struct = Structure("C", utils::Vector{ diff --git a/src/tint/writer/spirv/builder_type_test.cc b/src/tint/writer/spirv/builder_type_test.cc index 81c51a2d40..ad13e96675 100644 --- a/src/tint/writer/spirv/builder_type_test.cc +++ b/src/tint/writer/spirv/builder_type_test.cc @@ -27,14 +27,15 @@ namespace { using BuilderTest_Type = TestHelper; TEST_F(BuilderTest_Type, GenerateRuntimeArray) { - auto* ary = ty.array(ty.i32()); + auto ary = ty.array(ty.i32()); auto* str = Structure("S", utils::Vector{Member("x", ary)}); GlobalVar("a", ty.Of(str), type::AddressSpace::kStorage, type::Access::kRead, Binding(0_a), Group(0_a)); + ast::Type type = str->members[0]->type; spirv::Builder& b = Build(); - auto id = b.GenerateTypeIfNeeded(program->TypeOf(ary)); + auto id = b.GenerateTypeIfNeeded(program->TypeOf(type)); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(1u, id); @@ -44,15 +45,16 @@ TEST_F(BuilderTest_Type, GenerateRuntimeArray) { } TEST_F(BuilderTest_Type, ReturnsGeneratedRuntimeArray) { - auto* ary = ty.array(ty.i32()); + auto ary = ty.array(ty.i32()); auto* str = Structure("S", utils::Vector{Member("x", ary)}); GlobalVar("a", ty.Of(str), type::AddressSpace::kStorage, type::Access::kRead, Binding(0_a), Group(0_a)); + ast::Type type = str->members[0]->type; spirv::Builder& b = Build(); - EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ary)), 1u); - EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ary)), 1u); + EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(type)), 1u); + EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(type)), 1u); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 @@ -61,12 +63,12 @@ TEST_F(BuilderTest_Type, ReturnsGeneratedRuntimeArray) { } TEST_F(BuilderTest_Type, GenerateArray) { - auto* ary = ty.array(); - GlobalVar("a", ary, type::AddressSpace::kPrivate); + auto ary = ty.array(); + ast::Type type = GlobalVar("a", ary, type::AddressSpace::kPrivate)->type; spirv::Builder& b = Build(); - auto id = b.GenerateTypeIfNeeded(program->TypeOf(ary)); + auto id = b.GenerateTypeIfNeeded(program->TypeOf(type)); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(1u, id); @@ -78,12 +80,12 @@ TEST_F(BuilderTest_Type, GenerateArray) { } TEST_F(BuilderTest_Type, GenerateArray_WithStride) { - auto* ary = ty.array(utils::Vector{Stride(16)}); - GlobalVar("a", ary, type::AddressSpace::kPrivate); + auto ary = ty.array(utils::Vector{Stride(16)}); + ast::Type ty = GlobalVar("a", ary, type::AddressSpace::kPrivate)->type; spirv::Builder& b = Build(); - auto id = b.GenerateTypeIfNeeded(program->TypeOf(ary)); + auto id = b.GenerateTypeIfNeeded(program->TypeOf(ty)); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(1u, id); @@ -98,13 +100,13 @@ TEST_F(BuilderTest_Type, GenerateArray_WithStride) { } TEST_F(BuilderTest_Type, ReturnsGeneratedArray) { - auto* ary = ty.array(); - GlobalVar("a", ary, type::AddressSpace::kPrivate); + auto ary = ty.array(); + ast::Type ty = GlobalVar("a", ary, type::AddressSpace::kPrivate)->type; spirv::Builder& b = Build(); - EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ary)), 1u); - EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ary)), 1u); + EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u); + EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 @@ -438,13 +440,13 @@ OpMemberDecorate %1 5 MatrixStride 8 TEST_F(BuilderTest_Type, GenerateStruct_DecoratedMembers_ArraysOfMatrix) { Enable(ast::Extension::kF16); - auto* arr_mat2x2_f32 = ty.array(ty.mat2x2(), 1_u); // Singly nested array - auto* arr_mat2x2_f16 = ty.array(ty.mat2x2(), 1_u); // Singly nested array - auto* arr_arr_mat2x3_f32 = + auto arr_mat2x2_f32 = ty.array(ty.mat2x2(), 1_u); // Singly nested array + auto arr_mat2x2_f16 = ty.array(ty.mat2x2(), 1_u); // Singly nested array + ast::Type arr_arr_mat2x3_f32 = ty.array(ty.array(ty.mat2x3(), 1_u), 2_u); // Doubly nested array - auto* arr_arr_mat2x3_f16 = + ast::Type arr_arr_mat2x3_f16 = ty.array(ty.array(ty.mat2x3(), 1_u), 2_u); // Doubly nested array - auto* rtarr_mat4x4 = ty.array(ty.mat4x4()); // Runtime array + auto rtarr_mat4x4 = ty.array(ty.mat4x4()); // Runtime array auto* s = Structure( "S", utils::Vector{ @@ -860,14 +862,14 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_CubeArray) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_1d) { - auto* s = ty.storage_texture(type::TextureDimension::k1d, type::TexelFormat::kR32Float, - type::Access::kWrite); + auto s = ty.storage_texture(type::TextureDimension::k1d, type::TexelFormat::kR32Float, + type::Access::kWrite); - GlobalVar("test_var", s, Binding(0_a), Group(0_a)); + ast::Type ty = GlobalVar("test_var", s, Binding(0_a), Group(0_a))->type; spirv::Builder& b = Build(); - EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u); + EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 1D 0 0 0 2 R32f @@ -875,14 +877,14 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_1d) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { - auto* s = ty.storage_texture(type::TextureDimension::k2d, type::TexelFormat::kR32Float, - type::Access::kWrite); + auto s = ty.storage_texture(type::TextureDimension::k2d, type::TexelFormat::kR32Float, + type::Access::kWrite); - GlobalVar("test_var", s, Binding(0_a), Group(0_a)); + ast::Type ty = GlobalVar("test_var", s, Binding(0_a), Group(0_a))->type; spirv::Builder& b = Build(); - EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u); + EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 2D 0 0 0 2 R32f @@ -890,14 +892,14 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2d) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { - auto* s = ty.storage_texture(type::TextureDimension::k2dArray, type::TexelFormat::kR32Float, - type::Access::kWrite); + auto s = ty.storage_texture(type::TextureDimension::k2dArray, type::TexelFormat::kR32Float, + type::Access::kWrite); - GlobalVar("test_var", s, Binding(0_a), Group(0_a)); + ast::Type ty = GlobalVar("test_var", s, Binding(0_a), Group(0_a))->type; spirv::Builder& b = Build(); - EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u); + EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 2D 0 1 0 2 R32f @@ -905,14 +907,14 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_2dArray) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { - auto* s = ty.storage_texture(type::TextureDimension::k3d, type::TexelFormat::kR32Float, - type::Access::kWrite); + auto s = ty.storage_texture(type::TextureDimension::k3d, type::TexelFormat::kR32Float, + type::Access::kWrite); - GlobalVar("test_var", s, Binding(0_a), Group(0_a)); + ast::Type ty = GlobalVar("test_var", s, Binding(0_a), Group(0_a))->type; spirv::Builder& b = Build(); - EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u); + EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 3D 0 0 0 2 R32f @@ -920,14 +922,14 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_3d) { } TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeFloat_Format_r32float) { - auto* s = ty.storage_texture(type::TextureDimension::k2d, type::TexelFormat::kR32Float, - type::Access::kWrite); + auto s = ty.storage_texture(type::TextureDimension::k2d, type::TexelFormat::kR32Float, + type::Access::kWrite); - GlobalVar("test_var", s, Binding(0_a), Group(0_a)); + ast::Type ty = GlobalVar("test_var", s, Binding(0_a), Group(0_a))->type; spirv::Builder& b = Build(); - EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u); + EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 2D 0 0 0 2 R32f @@ -935,14 +937,14 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeFloat_Format_r32floa } TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeSint_Format_r32sint) { - auto* s = ty.storage_texture(type::TextureDimension::k2d, type::TexelFormat::kR32Sint, - type::Access::kWrite); + auto s = ty.storage_texture(type::TextureDimension::k2d, type::TexelFormat::kR32Sint, + type::Access::kWrite); - GlobalVar("test_var", s, Binding(0_a), Group(0_a)); + ast::Type ty = GlobalVar("test_var", s, Binding(0_a), Group(0_a))->type; spirv::Builder& b = Build(); - EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u); + EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 %1 = OpTypeImage %2 2D 0 0 0 2 R32i @@ -950,14 +952,14 @@ TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeSint_Format_r32sint) } TEST_F(BuilderTest_Type, StorageTexture_Generate_SampledTypeUint_Format_r32uint) { - auto* s = ty.storage_texture(type::TextureDimension::k2d, type::TexelFormat::kR32Uint, - type::Access::kWrite); + auto s = ty.storage_texture(type::TextureDimension::k2d, type::TexelFormat::kR32Uint, + type::Access::kWrite); - GlobalVar("test_var", s, Binding(0_a), Group(0_a)); + ast::Type ty = GlobalVar("test_var", s, Binding(0_a), Group(0_a))->type; spirv::Builder& b = Build(); - EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(s)), 1u); + EXPECT_EQ(b.GenerateTypeIfNeeded(program->TypeOf(ty)), 1u); ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0 %1 = OpTypeImage %2 2D 0 0 0 2 R32ui diff --git a/src/tint/writer/text_generator.h b/src/tint/writer/text_generator.h index 248809a7db..1c22522908 100644 --- a/src/tint/writer/text_generator.h +++ b/src/tint/writer/text_generator.h @@ -196,10 +196,6 @@ class TextGenerator { /// @param expr the expression const type::Type* TypeOf(const ast::Expression* expr) const { return builder_.TypeOf(expr); } - /// @returns the resolved type of the ast::Type `type` - /// @param type the type - const type::Type* TypeOf(const ast::Type* type) const { return builder_.TypeOf(type); } - /// @returns the resolved type of the ast::TypeDecl `type_decl` /// @param type_decl the type const type::Type* TypeOf(const ast::TypeDecl* type_decl) const { diff --git a/src/tint/writer/wgsl/generator_impl.cc b/src/tint/writer/wgsl/generator_impl.cc index 19345d090b..10bd9d8549 100644 --- a/src/tint/writer/wgsl/generator_impl.cc +++ b/src/tint/writer/wgsl/generator_impl.cc @@ -17,8 +17,6 @@ #include #include "src/tint/ast/alias.h" -#include "src/tint/ast/array.h" -#include "src/tint/ast/atomic.h" #include "src/tint/ast/bool_literal_expression.h" #include "src/tint/ast/call_statement.h" #include "src/tint/ast/float_literal_expression.h" @@ -26,19 +24,13 @@ #include "src/tint/ast/internal_attribute.h" #include "src/tint/ast/interpolate_attribute.h" #include "src/tint/ast/invariant_attribute.h" -#include "src/tint/ast/matrix.h" #include "src/tint/ast/module.h" -#include "src/tint/ast/multisampled_texture.h" -#include "src/tint/ast/pointer.h" -#include "src/tint/ast/sampled_texture.h" #include "src/tint/ast/stage_attribute.h" #include "src/tint/ast/stride_attribute.h" #include "src/tint/ast/struct_member_align_attribute.h" #include "src/tint/ast/struct_member_offset_attribute.h" #include "src/tint/ast/struct_member_size_attribute.h" -#include "src/tint/ast/type_name.h" #include "src/tint/ast/variable_decl_statement.h" -#include "src/tint/ast/vector.h" #include "src/tint/ast/workgroup_attribute.h" #include "src/tint/sem/struct.h" #include "src/tint/sem/switch_statement.h" @@ -118,7 +110,7 @@ bool GeneratorImpl::EmitTypeDecl(const ast::TypeDecl* ty) { [&](const ast::Alias* alias) { // auto out = line(); out << "alias " << program_->Symbols().NameFor(alias->name->symbol) << " = "; - if (!EmitType(out, alias->type)) { + if (!EmitExpression(out, alias->type)) { return false; } out << ";"; @@ -215,7 +207,7 @@ bool GeneratorImpl::EmitMemberAccessor(std::ostream& out, bool GeneratorImpl::EmitBitcast(std::ostream& out, const ast::BitcastExpression* expr) { out << "bitcast<"; - if (!EmitType(out, expr->type)) { + if (!EmitExpression(out, expr->type)) { return false; } @@ -229,14 +221,7 @@ bool GeneratorImpl::EmitBitcast(std::ostream& out, const ast::BitcastExpression* } bool GeneratorImpl::EmitCall(std::ostream& out, const ast::CallExpression* expr) { - if (expr->target.name) { - out << program_->Symbols().NameFor(expr->target.name->symbol); - } else if (TINT_LIKELY(expr->target.type)) { - if (!EmitType(out, expr->target.type)) { - return false; - } - } else { - TINT_ICE(Writer, diagnostics_) << "CallExpression target had neither a name or type"; + if (!EmitExpression(out, expr->target)) { return false; } out << "("; @@ -293,9 +278,12 @@ bool GeneratorImpl::EmitIdentifier(std::ostream& out, const ast::IdentifierExpre } bool GeneratorImpl::EmitIdentifier(std::ostream& out, const ast::Identifier* ident) { - out << program_->Symbols().NameFor(ident->symbol); if (auto* tmpl_ident = ident->As()) { - out << "<"; + if (!tmpl_ident->attributes.IsEmpty()) { + EmitAttributes(out, tmpl_ident->attributes); + out << " "; + } + out << program_->Symbols().NameFor(ident->symbol) << "<"; TINT_DEFER(out << ">"); for (auto* expr : tmpl_ident->arguments) { if (expr != tmpl_ident->arguments.Front()) { @@ -305,6 +293,8 @@ bool GeneratorImpl::EmitIdentifier(std::ostream& out, const ast::Identifier* ide return false; } } + } else { + out << program_->Symbols().NameFor(ident->symbol); } return true; } @@ -335,7 +325,7 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { out << program_->Symbols().NameFor(v->name->symbol) << " : "; - if (!EmitType(out, v->type)) { + if (!EmitExpression(out, v->type)) { return false; } } @@ -352,7 +342,7 @@ bool GeneratorImpl::EmitFunction(const ast::Function* func) { out << " "; } - if (!EmitType(out, func->return_type)) { + if (!EmitExpression(out, func->return_type)) { return false; } } @@ -404,152 +394,6 @@ bool GeneratorImpl::EmitAccess(std::ostream& out, const type::Access access) { return false; } -bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) { - return Switch( - ty, - [&](const ast::Array* ary) { - for (auto* attr : ary->attributes) { - if (auto* stride = attr->As()) { - out << "@stride(" << stride->stride << ") "; - } - } - - out << "array"; - if (ary->type) { - out << "<"; - TINT_DEFER(out << ">"); - - if (!EmitType(out, ary->type)) { - return false; - } - - if (!ary->IsRuntimeArray()) { - out << ", "; - if (!EmitExpression(out, ary->count)) { - return false; - } - } - } - return true; - }, - [&](const ast::Matrix* mat) { - out << "mat" << mat->columns << "x" << mat->rows; - if (auto* el_ty = mat->type) { - out << "<"; - if (!EmitType(out, el_ty)) { - return false; - } - out << ">"; - } - return true; - }, - [&](const ast::Pointer* ptr) { - out << "ptr<" << ptr->address_space << ", "; - if (!EmitType(out, ptr->type)) { - return false; - } - if (ptr->access != type::Access::kUndefined) { - out << ", "; - if (!EmitAccess(out, ptr->access)) { - return false; - } - } - out << ">"; - return true; - }, - [&](const ast::Atomic* atomic) { - out << "atomic<"; - if (!EmitType(out, atomic->type)) { - return false; - } - out << ">"; - return true; - }, - [&](const ast::Texture* texture) { - out << "texture_"; - bool ok = Switch( - texture, - [&](const ast::SampledTexture*) { // - /* nothing to emit */ - return true; - }, - [&](const ast::MultisampledTexture*) { // - out << "multisampled_"; - return true; - }, - [&](Default) { // - diagnostics_.add_error(diag::System::Writer, "unknown texture type"); - return false; - }); - if (!ok) { - return false; - } - - switch (texture->dim) { - case type::TextureDimension::k1d: - out << "1d"; - break; - case type::TextureDimension::k2d: - out << "2d"; - break; - case type::TextureDimension::k2dArray: - out << "2d_array"; - break; - case type::TextureDimension::k3d: - out << "3d"; - break; - case type::TextureDimension::kCube: - out << "cube"; - break; - case type::TextureDimension::kCubeArray: - out << "cube_array"; - break; - default: - diagnostics_.add_error(diag::System::Writer, "unknown texture dimension"); - return false; - } - - return Switch( - texture, - [&](const ast::SampledTexture* sampled) { // - out << "<"; - if (!EmitType(out, sampled->type)) { - return false; - } - out << ">"; - return true; - }, - [&](const ast::MultisampledTexture* ms) { // - out << "<"; - if (!EmitType(out, ms->type)) { - return false; - } - out << ">"; - return true; - }, - [&](Default) { // - return true; - }); - }, - [&](const ast::Vector* vec) { - out << "vec" << vec->width; - if (auto* el_ty = vec->type) { - out << "<"; - if (!EmitType(out, el_ty)) { - return false; - } - out << ">"; - } - return true; - }, - [&](const ast::TypeName* tn) { return EmitIdentifier(out, tn->name); }, - [&](Default) { - diagnostics_.add_error(diag::System::Writer, - "unknown type in EmitType: " + std::string(ty->TypeInfo().name)); - return false; - }); -} - bool GeneratorImpl::EmitStructType(const ast::Struct* str) { if (str->attributes.Length()) { if (!EmitAttributes(line(), str->attributes)) { @@ -606,7 +450,7 @@ bool GeneratorImpl::EmitStructType(const ast::Struct* str) { auto out = line(); out << program_->Symbols().NameFor(mem->name->symbol) << " : "; - if (!EmitType(out, mem->type)) { + if (!EmitExpression(out, mem->type)) { return false; } out << ","; @@ -665,9 +509,9 @@ bool GeneratorImpl::EmitVariable(std::ostream& out, const ast::Variable* v) { out << " " << program_->Symbols().NameFor(v->name->symbol); - if (auto* ty = v->type) { + if (auto ty = v->type) { out << " : "; - if (!EmitType(out, ty)) { + if (!EmitExpression(out, ty)) { return false; } } diff --git a/src/tint/writer/wgsl/generator_impl.h b/src/tint/writer/wgsl/generator_impl.h index cf5d270318..56c0dfb75d 100644 --- a/src/tint/writer/wgsl/generator_impl.h +++ b/src/tint/writer/wgsl/generator_impl.h @@ -53,7 +53,7 @@ class GeneratorImpl : public TextGenerator { bool Generate(); /// Handles generating a diagnostic control - /// @param out the output of the expression stream + /// @param out the output stream /// @param diagnostic the diagnostic control node /// @returns true if the diagnostic control was emitted bool EmitDiagnosticControl(std::ostream& out, const ast::DiagnosticControl& diagnostic); @@ -66,7 +66,7 @@ class GeneratorImpl : public TextGenerator { /// @returns true if the declared type was emitted bool EmitTypeDecl(const ast::TypeDecl* ty); /// Handles an index accessor expression - /// @param out the output of the expression stream + /// @param out the output stream /// @param expr the expression to emit /// @returns true if the index accessor was emitted bool EmitIndexAccessor(std::ostream& out, const ast::IndexAccessorExpression* expr); @@ -75,17 +75,17 @@ class GeneratorImpl : public TextGenerator { /// @returns true if the statement was emitted successfully bool EmitAssign(const ast::AssignmentStatement* stmt); /// Handles generating a binary expression - /// @param out the output of the expression stream + /// @param out the output stream /// @param expr the binary expression /// @returns true if the expression was emitted, false otherwise bool EmitBinary(std::ostream& out, const ast::BinaryExpression* expr); /// Handles generating a binary operator - /// @param out the output of the expression stream + /// @param out the output stream /// @param op the binary operator /// @returns true if the operator was emitted, false otherwise bool EmitBinaryOp(std::ostream& out, const ast::BinaryOp op); /// Handles generating a bitcast expression - /// @param out the output of the expression stream + /// @param out the output stream /// @param expr the bitcast expression /// @returns true if the bitcast was emitted bool EmitBitcast(std::ostream& out, const ast::BitcastExpression* expr); @@ -107,7 +107,7 @@ class GeneratorImpl : public TextGenerator { /// @returns true if the statement was emitted successfully bool EmitBreakIf(const ast::BreakIfStatement* stmt); /// Handles generating a call expression - /// @param out the output of the expression stream + /// @param out the output stream /// @param expr the call expression /// @returns true if the call expression is emitted bool EmitCall(std::ostream& out, const ast::CallExpression* expr); @@ -120,7 +120,7 @@ class GeneratorImpl : public TextGenerator { /// @returns true if the statement was emitted successfully bool EmitCompoundAssign(const ast::CompoundAssignmentStatement* stmt); /// Handles generating a literal expression - /// @param out the output of the expression stream + /// @param out the output stream /// @param expr the literal expression expression /// @returns true if the literal expression is emitted bool EmitLiteral(std::ostream& out, const ast::LiteralExpression* expr); @@ -129,7 +129,7 @@ class GeneratorImpl : public TextGenerator { /// @returns true if the statement was emitted successfully bool EmitContinue(const ast::ContinueStatement* stmt); /// Handles generate an Expression - /// @param out the output of the expression stream + /// @param out the output stream /// @param expr the expression /// @returns true if the expression was emitted bool EmitExpression(std::ostream& out, const ast::Expression* expr); @@ -138,7 +138,7 @@ class GeneratorImpl : public TextGenerator { /// @returns true if the function was emitted bool EmitFunction(const ast::Function* func); /// Handles generating an identifier expression - /// @param out the output of the expression stream + /// @param out the output stream /// @param expr the identifier expression /// @returns true if the identifier was emitted bool EmitIdentifier(std::ostream& out, const ast::IdentifierExpression* expr); @@ -172,7 +172,7 @@ class GeneratorImpl : public TextGenerator { /// @returns true if the statement was emtited bool EmitWhile(const ast::WhileStatement* stmt); /// Handles a member accessor expression - /// @param out the output of the expression stream + /// @param out the output stream /// @param expr the member accessor expression /// @returns true if the member accessor was emitted bool EmitMemberAccessor(std::ostream& out, const ast::MemberAccessorExpression* expr); @@ -200,37 +200,32 @@ class GeneratorImpl : public TextGenerator { /// @param stmt the statement to emit /// @returns true if the statement was emitted bool EmitSwitch(const ast::SwitchStatement* stmt); - /// Handles generating type - /// @param out the output of the expression stream - /// @param type the type to generate - /// @returns true if the type is emitted - bool EmitType(std::ostream& out, const ast::Type* type); /// Handles generating a struct declaration /// @param str the struct /// @returns true if the struct is emitted bool EmitStructType(const ast::Struct* str); /// Handles emitting an image format - /// @param out the output of the expression stream + /// @param out the output stream /// @param fmt the format to generate /// @returns true if the format is emitted bool EmitImageFormat(std::ostream& out, const type::TexelFormat fmt); /// Handles emitting an access control - /// @param out the output of the expression stream + /// @param out the output stream /// @param access the access to generate /// @returns true if the access is emitted bool EmitAccess(std::ostream& out, const type::Access access); /// Handles a unary op expression - /// @param out the output of the expression stream + /// @param out the output stream /// @param expr the expression to emit /// @returns true if the expression was emitted bool EmitUnaryOp(std::ostream& out, const ast::UnaryOpExpression* expr); /// Handles generating a variable - /// @param out the output of the expression stream + /// @param out the output stream /// @param var the variable to generate /// @returns true if the variable was emitted bool EmitVariable(std::ostream& out, const ast::Variable* var); /// Handles generating a attribute list - /// @param out the output of the expression stream + /// @param out the output stream /// @param attrs the attribute list /// @returns true if the attributes were emitted bool EmitAttributes(std::ostream& out, utils::VectorRef attrs); diff --git a/src/tint/writer/wgsl/generator_impl_binary_test.cc b/src/tint/writer/wgsl/generator_impl_binary_test.cc index 8368ad83ed..2770e5ce16 100644 --- a/src/tint/writer/wgsl/generator_impl_binary_test.cc +++ b/src/tint/writer/wgsl/generator_impl_binary_test.cc @@ -29,7 +29,7 @@ using WgslBinaryTest = TestParamHelper; TEST_P(WgslBinaryTest, Emit) { auto params = GetParam(); - auto op_ty = [&]() -> const ast::Type* { + auto op_ty = [&]() { if (params.op == ast::BinaryOp::kLogicalAnd || params.op == ast::BinaryOp::kLogicalOr) { return ty.bool_(); } else { diff --git a/src/tint/writer/wgsl/generator_impl_function_test.cc b/src/tint/writer/wgsl/generator_impl_function_test.cc index 6550b6a64e..42e0184f99 100644 --- a/src/tint/writer/wgsl/generator_impl_function_test.cc +++ b/src/tint/writer/wgsl/generator_impl_function_test.cc @@ -109,7 +109,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Function_WithAttribute_WorkgroupSize_WithIden } TEST_F(WgslGeneratorImplTest, Emit_Function_EntryPoint_Parameters) { - auto* vec4 = ty.vec4(); + auto vec4 = ty.vec4(); auto* coord = Param("coord", vec4, utils::Vector{ Builtin(ast::BuiltinValue::kPosition), diff --git a/src/tint/writer/wgsl/generator_impl_global_decl_test.cc b/src/tint/writer/wgsl/generator_impl_global_decl_test.cc index 294b2d6442..5654ebecb4 100644 --- a/src/tint/writer/wgsl/generator_impl_global_decl_test.cc +++ b/src/tint/writer/wgsl/generator_impl_global_decl_test.cc @@ -117,7 +117,7 @@ TEST_F(WgslGeneratorImplTest, Emit_Global_Sampler) { } TEST_F(WgslGeneratorImplTest, Emit_Global_Texture) { - auto* st = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); + auto st = ty.sampled_texture(type::TextureDimension::k1d, ty.f32()); GlobalVar("t", st, Group(0_a), Binding(0_a)); GeneratorImpl& gen = Build(); diff --git a/src/tint/writer/wgsl/generator_impl_initializer_test.cc b/src/tint/writer/wgsl/generator_impl_initializer_test.cc index 9bc62c1be6..87dddca778 100644 --- a/src/tint/writer/wgsl/generator_impl_initializer_test.cc +++ b/src/tint/writer/wgsl/generator_impl_initializer_test.cc @@ -175,8 +175,8 @@ TEST_F(WgslGeneratorImplTest, EmitInitializer_Type_Array) { } TEST_F(WgslGeneratorImplTest, EmitInitializer_Type_ImplicitArray) { - WrapInFunction(Call(ty.array(nullptr, nullptr), vec3(1_f, 2_f, 3_f), - vec3(4_f, 5_f, 6_f), vec3(7_f, 8_f, 9_f))); + WrapInFunction(Call(ty.array(), vec3(1_f, 2_f, 3_f), vec3(4_f, 5_f, 6_f), + vec3(7_f, 8_f, 9_f))); GeneratorImpl& gen = Build(); diff --git a/src/tint/writer/wgsl/generator_impl_type_test.cc b/src/tint/writer/wgsl/generator_impl_type_test.cc index ee798b8fbb..bad1440c1a 100644 --- a/src/tint/writer/wgsl/generator_impl_type_test.cc +++ b/src/tint/writer/wgsl/generator_impl_type_test.cc @@ -27,138 +27,129 @@ using WgslGeneratorImplTest = TestHelper; TEST_F(WgslGeneratorImplTest, EmitType_Alias) { auto* alias = Alias("alias", ty.f32()); - auto* alias_ty = ty.Of(alias); - WrapInFunction(Var("make_reachable", alias_ty)); + auto type = Alias("make_type_reachable", ty.Of(alias))->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, alias_ty)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "alias"); } TEST_F(WgslGeneratorImplTest, EmitType_Array) { - auto* arr = ty.array(); - Alias("make_type_reachable", arr); + auto type = Alias("make_type_reachable", ty.array())->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, arr)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "array"); } TEST_F(WgslGeneratorImplTest, EmitType_Array_Attribute) { - auto* a = ty.array(ty.bool_(), 4_u, utils::Vector{Stride(16)}); - Alias("make_type_reachable", a); + auto type = + Alias("make_type_reachable", ty.array(ty.bool_(), 4_u, utils::Vector{Stride(16)}))->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, a)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "@stride(16) array"); } TEST_F(WgslGeneratorImplTest, EmitType_RuntimeArray) { - auto* a = ty.array(ty.bool_()); - Alias("make_type_reachable", a); + auto type = Alias("make_type_reachable", ty.array(ty.bool_()))->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, a)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "array"); } TEST_F(WgslGeneratorImplTest, EmitType_Bool) { - auto* bool_ = ty.bool_(); - Alias("make_type_reachable", bool_); + auto type = Alias("make_type_reachable", ty.bool_())->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, bool_)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "bool"); } TEST_F(WgslGeneratorImplTest, EmitType_F32) { - auto* f32 = ty.f32(); - Alias("make_type_reachable", f32); + auto type = Alias("make_type_reachable", ty.f32())->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, f32)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "f32"); } TEST_F(WgslGeneratorImplTest, EmitType_F16) { Enable(ast::Extension::kF16); - auto* f16 = ty.f16(); - Alias("make_type_reachable", f16); + auto type = Alias("make_type_reachable", ty.f16())->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, f16)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "f16"); } TEST_F(WgslGeneratorImplTest, EmitType_I32) { - auto* i32 = ty.i32(); - Alias("make_type_reachable", i32); + auto type = Alias("make_type_reachable", ty.i32())->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, i32)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "i32"); } TEST_F(WgslGeneratorImplTest, EmitType_Matrix_F32) { - auto* mat2x3 = ty.mat2x3(); - Alias("make_type_reachable", mat2x3); + auto type = Alias("make_type_reachable", ty.mat2x3())->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, mat2x3)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "mat2x3"); } TEST_F(WgslGeneratorImplTest, EmitType_Matrix_F16) { Enable(ast::Extension::kF16); - auto* mat2x3 = ty.mat2x3(); - Alias("make_type_reachable", mat2x3); + auto type = Alias("make_type_reachable", ty.mat2x3())->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, mat2x3)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "mat2x3"); } TEST_F(WgslGeneratorImplTest, EmitType_Pointer) { - auto* p = ty.pointer(type::AddressSpace::kWorkgroup); - Alias("make_type_reachable", p); + auto type = Alias("make_type_reachable", ty.pointer(type::AddressSpace::kWorkgroup))->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, p)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "ptr"); } TEST_F(WgslGeneratorImplTest, EmitType_PointerAccessMode) { - auto* p = ty.pointer(type::AddressSpace::kStorage, type::Access::kReadWrite); - Alias("make_type_reachable", p); + auto type = Alias("make_type_reachable", + ty.pointer(type::AddressSpace::kStorage, type::Access::kReadWrite)) + ->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, p)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "ptr"); } @@ -167,13 +158,12 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct) { Member("a", ty.i32()), Member("b", ty.f32()), }); - auto* s_ty = ty.Of(s); - WrapInFunction(Var("make_reachable", s_ty)); + auto type = Alias("make_reachable", ty.Of(s))->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, s_ty)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "S"); } @@ -295,37 +285,34 @@ TEST_F(WgslGeneratorImplTest, EmitType_Struct_WithEntryPointAttributes) { } TEST_F(WgslGeneratorImplTest, EmitType_U32) { - auto* u32 = ty.u32(); - Alias("make_type_reachable", u32); + auto type = Alias("make_type_reachable", ty.u32())->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, u32)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "u32"); } TEST_F(WgslGeneratorImplTest, EmitType_Vector_F32) { - auto* vec3 = ty.vec3(); - Alias("make_type_reachable", vec3); + auto type = Alias("make_type_reachable", ty.vec3())->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, vec3)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "vec3"); } TEST_F(WgslGeneratorImplTest, EmitType_Vector_F16) { Enable(ast::Extension::kF16); - auto* vec3 = ty.vec3(); - Alias("make_type_reachable", vec3); + auto type = Alias("make_type_reachable", ty.vec3())->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, vec3)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "vec3"); } @@ -342,13 +329,12 @@ using WgslGenerator_DepthTextureTest = TestParamHelper; TEST_P(WgslGenerator_DepthTextureTest, EmitType_DepthTexture) { auto param = GetParam(); - auto* d = ty.depth_texture(param.dim); - Alias("make_type_reachable", d); + auto type = Alias("make_type_reachable", ty.depth_texture(param.dim))->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, d)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), param.name); } INSTANTIATE_TEST_SUITE_P( @@ -363,39 +349,39 @@ using WgslGenerator_SampledTextureTest = TestParamHelper; TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_F32) { auto param = GetParam(); - auto* t = ty.sampled_texture(param.dim, ty.f32()); - Alias("make_type_reachable", t); + auto t = ty.sampled_texture(param.dim, ty.f32()); + auto type = Alias("make_type_reachable", t)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, t)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), std::string(param.name) + ""); } TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_I32) { auto param = GetParam(); - auto* t = ty.sampled_texture(param.dim, ty.i32()); - Alias("make_type_reachable", t); + auto t = ty.sampled_texture(param.dim, ty.i32()); + auto type = Alias("make_type_reachable", t)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, t)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), std::string(param.name) + ""); } TEST_P(WgslGenerator_SampledTextureTest, EmitType_SampledTexture_U32) { auto param = GetParam(); - auto* t = ty.sampled_texture(param.dim, ty.u32()); - Alias("make_type_reachable", t); + auto t = ty.sampled_texture(param.dim, ty.u32()); + auto type = Alias("make_type_reachable", t)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, t)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), std::string(param.name) + ""); } INSTANTIATE_TEST_SUITE_P( @@ -412,39 +398,39 @@ using WgslGenerator_MultiampledTextureTest = TestParamHelper; TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_F32) { auto param = GetParam(); - auto* t = ty.multisampled_texture(param.dim, ty.f32()); - Alias("make_type_reachable", t); + auto t = ty.multisampled_texture(param.dim, ty.f32()); + auto type = Alias("make_type_reachable", t)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, t)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), std::string(param.name) + ""); } TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_I32) { auto param = GetParam(); - auto* t = ty.multisampled_texture(param.dim, ty.i32()); - Alias("make_type_reachable", t); + auto t = ty.multisampled_texture(param.dim, ty.i32()); + auto type = Alias("make_type_reachable", t)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, t)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), std::string(param.name) + ""); } TEST_P(WgslGenerator_MultiampledTextureTest, EmitType_MultisampledTexture_U32) { auto param = GetParam(); - auto* t = ty.multisampled_texture(param.dim, ty.u32()); - Alias("make_type_reachable", t); + auto t = ty.multisampled_texture(param.dim, ty.u32()); + auto type = Alias("make_type_reachable", t)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, t)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), std::string(param.name) + ""); } INSTANTIATE_TEST_SUITE_P(WgslGeneratorImplTest, @@ -466,13 +452,13 @@ using WgslGenerator_StorageTextureTest = TestParamHelper; TEST_P(WgslGenerator_StorageTextureTest, EmitType_StorageTexture) { auto param = GetParam(); - auto* t = ty.storage_texture(param.dim, param.fmt, param.access); - GlobalVar("g", t, Binding(1_a), Group(2_a)); + auto s = ty.storage_texture(param.dim, param.fmt, param.access); + auto type = GlobalVar("g", s, Binding(1_a), Group(2_a))->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, t)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), param.name); } INSTANTIATE_TEST_SUITE_P( @@ -528,24 +514,24 @@ INSTANTIATE_TEST_SUITE_P( ImageFormatData{type::TexelFormat::kRgba32Float, "rgba32float"})); TEST_F(WgslGeneratorImplTest, EmitType_Sampler) { - auto* sampler = ty.sampler(type::SamplerKind::kSampler); - Alias("make_type_reachable", sampler); + auto sampler = ty.sampler(type::SamplerKind::kSampler); + auto type = Alias("make_type_reachable", sampler)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, sampler)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "sampler"); } TEST_F(WgslGeneratorImplTest, EmitType_SamplerComparison) { - auto* sampler = ty.sampler(type::SamplerKind::kComparisonSampler); - Alias("make_type_reachable", sampler); + auto sampler = ty.sampler(type::SamplerKind::kComparisonSampler); + auto type = Alias("make_type_reachable", sampler)->type; GeneratorImpl& gen = Build(); std::stringstream out; - ASSERT_TRUE(gen.EmitType(out, sampler)) << gen.error(); + ASSERT_TRUE(gen.EmitExpression(out, type)) << gen.error(); EXPECT_EQ(out.str(), "sampler_comparison"); } diff --git a/src/tint/writer/wgsl/generator_impl_variable_decl_statement_test.cc b/src/tint/writer/wgsl/generator_impl_variable_decl_statement_test.cc index 51b8683f94..bf684201ac 100644 --- a/src/tint/writer/wgsl/generator_impl_variable_decl_statement_test.cc +++ b/src/tint/writer/wgsl/generator_impl_variable_decl_statement_test.cc @@ -169,7 +169,7 @@ fn f() { } TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_AInt) { - auto* C = Const("C", Call(ty.vec3(nullptr), 1_a, 2_a, 3_a)); + auto* C = Const("C", Call(ty.vec3(), 1_a, 2_a, 3_a)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(C), @@ -188,7 +188,7 @@ TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_AInt) { } TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_vec3_AFloat) { - auto* C = Const("C", Call(ty.vec3(nullptr), 1._a, 2._a, 3._a)); + auto* C = Const("C", Call(ty.vec3(), 1._a, 2._a, 3._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(C), @@ -249,7 +249,7 @@ fn f() { } TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_mat2x3_AFloat) { - auto* C = Const("C", Call(ty.mat(nullptr, 2, 3), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); + auto* C = Const("C", Call(ty.mat2x3(), 1._a, 2._a, 3._a, 4._a, 5._a, 6._a)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(C), @@ -310,7 +310,7 @@ fn f() { } TEST_F(WgslGeneratorImplTest, Emit_VariableDeclStatement_Const_arr_f32) { - auto* C = Const("C", Call(ty.array(), 1_f, 2_f, 3_f)); + auto* C = Const("C", array(1_f, 2_f, 3_f)); Func("f", utils::Empty, ty.void_(), utils::Vector{ Decl(C), diff --git a/test/tint/array/assign_to_storage_var.wgsl.expected.dxc.hlsl b/test/tint/array/assign_to_storage_var.wgsl.expected.dxc.hlsl index 8529fd082c..2ce38dc55b 100644 --- a/test/tint/array/assign_to_storage_var.wgsl.expected.dxc.hlsl +++ b/test/tint/array/assign_to_storage_var.wgsl.expected.dxc.hlsl @@ -28,10 +28,10 @@ S ret_struct_arr() { } void tint_symbol_3(RWByteAddressBuffer buffer, uint offset, int4 value[4]) { - int4 array[4] = value; + int4 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - buffer.Store4((offset + (i * 16u)), asuint(array[i])); + buffer.Store4((offset + (i * 16u)), asuint(array_1[i])); } } } @@ -60,28 +60,28 @@ tint_symbol_7_ret tint_symbol_7(RWByteAddressBuffer buffer, uint offset) { } void tint_symbol_11(RWByteAddressBuffer buffer, uint offset, int value[2]) { - int array_3[2] = value; + int array_4[2] = value; { for(uint i_3 = 0u; (i_3 < 2u); i_3 = (i_3 + 1u)) { - buffer.Store((offset + (i_3 * 4u)), asuint(array_3[i_3])); + buffer.Store((offset + (i_3 * 4u)), asuint(array_4[i_3])); } } } void tint_symbol_10(RWByteAddressBuffer buffer, uint offset, int value[3][2]) { - int array_2[3][2] = value; + int array_3[3][2] = value; { for(uint i_4 = 0u; (i_4 < 3u); i_4 = (i_4 + 1u)) { - tint_symbol_11(buffer, (offset + (i_4 * 8u)), array_2[i_4]); + tint_symbol_11(buffer, (offset + (i_4 * 8u)), array_3[i_4]); } } } void tint_symbol_9(RWByteAddressBuffer buffer, uint offset, int value[4][3][2]) { - int array_1[4][3][2] = value; + int array_2[4][3][2] = value; { for(uint i_5 = 0u; (i_5 < 4u); i_5 = (i_5 + 1u)) { - tint_symbol_10(buffer, (offset + (i_5 * 24u)), array_1[i_5]); + tint_symbol_10(buffer, (offset + (i_5 * 24u)), array_2[i_5]); } } } diff --git a/test/tint/array/assign_to_storage_var.wgsl.expected.fxc.hlsl b/test/tint/array/assign_to_storage_var.wgsl.expected.fxc.hlsl index 8529fd082c..2ce38dc55b 100644 --- a/test/tint/array/assign_to_storage_var.wgsl.expected.fxc.hlsl +++ b/test/tint/array/assign_to_storage_var.wgsl.expected.fxc.hlsl @@ -28,10 +28,10 @@ S ret_struct_arr() { } void tint_symbol_3(RWByteAddressBuffer buffer, uint offset, int4 value[4]) { - int4 array[4] = value; + int4 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - buffer.Store4((offset + (i * 16u)), asuint(array[i])); + buffer.Store4((offset + (i * 16u)), asuint(array_1[i])); } } } @@ -60,28 +60,28 @@ tint_symbol_7_ret tint_symbol_7(RWByteAddressBuffer buffer, uint offset) { } void tint_symbol_11(RWByteAddressBuffer buffer, uint offset, int value[2]) { - int array_3[2] = value; + int array_4[2] = value; { for(uint i_3 = 0u; (i_3 < 2u); i_3 = (i_3 + 1u)) { - buffer.Store((offset + (i_3 * 4u)), asuint(array_3[i_3])); + buffer.Store((offset + (i_3 * 4u)), asuint(array_4[i_3])); } } } void tint_symbol_10(RWByteAddressBuffer buffer, uint offset, int value[3][2]) { - int array_2[3][2] = value; + int array_3[3][2] = value; { for(uint i_4 = 0u; (i_4 < 3u); i_4 = (i_4 + 1u)) { - tint_symbol_11(buffer, (offset + (i_4 * 8u)), array_2[i_4]); + tint_symbol_11(buffer, (offset + (i_4 * 8u)), array_3[i_4]); } } } void tint_symbol_9(RWByteAddressBuffer buffer, uint offset, int value[4][3][2]) { - int array_1[4][3][2] = value; + int array_2[4][3][2] = value; { for(uint i_5 = 0u; (i_5 < 4u); i_5 = (i_5 + 1u)) { - tint_symbol_10(buffer, (offset + (i_5 * 24u)), array_1[i_5]); + tint_symbol_10(buffer, (offset + (i_5 * 24u)), array_2[i_5]); } } } diff --git a/test/tint/array/strides.spvasm.expected.dxc.hlsl b/test/tint/array/strides.spvasm.expected.dxc.hlsl index ddd8ded450..72a5a23c65 100644 --- a/test/tint/array/strides.spvasm.expected.dxc.hlsl +++ b/test/tint/array/strides.spvasm.expected.dxc.hlsl @@ -55,19 +55,19 @@ void tint_symbol_10(RWByteAddressBuffer buffer, uint offset, strided_arr value) } void tint_symbol_9(RWByteAddressBuffer buffer, uint offset, strided_arr value[2]) { - strided_arr array_2[2] = value; + strided_arr array_3[2] = value; { for(uint i_3 = 0u; (i_3 < 2u); i_3 = (i_3 + 1u)) { - tint_symbol_10(buffer, (offset + (i_3 * 8u)), array_2[i_3]); + tint_symbol_10(buffer, (offset + (i_3 * 8u)), array_3[i_3]); } } } void tint_symbol_8(RWByteAddressBuffer buffer, uint offset, strided_arr value[3][2]) { - strided_arr array_1[3][2] = value; + strided_arr array_2[3][2] = value; { for(uint i_4 = 0u; (i_4 < 3u); i_4 = (i_4 + 1u)) { - tint_symbol_9(buffer, (offset + (i_4 * 16u)), array_1[i_4]); + tint_symbol_9(buffer, (offset + (i_4 * 16u)), array_2[i_4]); } } } @@ -77,10 +77,10 @@ void tint_symbol_7(RWByteAddressBuffer buffer, uint offset, strided_arr_1 value) } void tint_symbol_6(RWByteAddressBuffer buffer, uint offset, strided_arr_1 value[4]) { - strided_arr_1 array[4] = value; + strided_arr_1 array_1[4] = value; { for(uint i_5 = 0u; (i_5 < 4u); i_5 = (i_5 + 1u)) { - tint_symbol_7(buffer, (offset + (i_5 * 128u)), array[i_5]); + tint_symbol_7(buffer, (offset + (i_5 * 128u)), array_1[i_5]); } } } diff --git a/test/tint/array/strides.spvasm.expected.fxc.hlsl b/test/tint/array/strides.spvasm.expected.fxc.hlsl index ddd8ded450..72a5a23c65 100644 --- a/test/tint/array/strides.spvasm.expected.fxc.hlsl +++ b/test/tint/array/strides.spvasm.expected.fxc.hlsl @@ -55,19 +55,19 @@ void tint_symbol_10(RWByteAddressBuffer buffer, uint offset, strided_arr value) } void tint_symbol_9(RWByteAddressBuffer buffer, uint offset, strided_arr value[2]) { - strided_arr array_2[2] = value; + strided_arr array_3[2] = value; { for(uint i_3 = 0u; (i_3 < 2u); i_3 = (i_3 + 1u)) { - tint_symbol_10(buffer, (offset + (i_3 * 8u)), array_2[i_3]); + tint_symbol_10(buffer, (offset + (i_3 * 8u)), array_3[i_3]); } } } void tint_symbol_8(RWByteAddressBuffer buffer, uint offset, strided_arr value[3][2]) { - strided_arr array_1[3][2] = value; + strided_arr array_2[3][2] = value; { for(uint i_4 = 0u; (i_4 < 3u); i_4 = (i_4 + 1u)) { - tint_symbol_9(buffer, (offset + (i_4 * 16u)), array_1[i_4]); + tint_symbol_9(buffer, (offset + (i_4 * 16u)), array_2[i_4]); } } } @@ -77,10 +77,10 @@ void tint_symbol_7(RWByteAddressBuffer buffer, uint offset, strided_arr_1 value) } void tint_symbol_6(RWByteAddressBuffer buffer, uint offset, strided_arr_1 value[4]) { - strided_arr_1 array[4] = value; + strided_arr_1 array_1[4] = value; { for(uint i_5 = 0u; (i_5 < 4u); i_5 = (i_5 + 1u)) { - tint_symbol_7(buffer, (offset + (i_5 * 128u)), array[i_5]); + tint_symbol_7(buffer, (offset + (i_5 * 128u)), array_1[i_5]); } } } diff --git a/test/tint/buffer/storage/dynamic_index/write.wgsl.expected.dxc.hlsl b/test/tint/buffer/storage/dynamic_index/write.wgsl.expected.dxc.hlsl index 4bcc56db81..508e26972c 100644 --- a/test/tint/buffer/storage/dynamic_index/write.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/storage/dynamic_index/write.wgsl.expected.dxc.hlsl @@ -59,10 +59,10 @@ void tint_symbol_22(RWByteAddressBuffer buffer, uint offset, float4x4 value) { } void tint_symbol_23(RWByteAddressBuffer buffer, uint offset, float3 value[2]) { - float3 array[2] = value; + float3 array_1[2] = value; { for(uint i = 0u; (i < 2u); i = (i + 1u)) { - buffer.Store3((offset + (i * 16u)), asuint(array[i])); + buffer.Store3((offset + (i * 16u)), asuint(array_1[i])); } } } diff --git a/test/tint/buffer/storage/dynamic_index/write.wgsl.expected.fxc.hlsl b/test/tint/buffer/storage/dynamic_index/write.wgsl.expected.fxc.hlsl index 4bcc56db81..508e26972c 100644 --- a/test/tint/buffer/storage/dynamic_index/write.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/storage/dynamic_index/write.wgsl.expected.fxc.hlsl @@ -59,10 +59,10 @@ void tint_symbol_22(RWByteAddressBuffer buffer, uint offset, float4x4 value) { } void tint_symbol_23(RWByteAddressBuffer buffer, uint offset, float3 value[2]) { - float3 array[2] = value; + float3 array_1[2] = value; { for(uint i = 0u; (i < 2u); i = (i + 1u)) { - buffer.Store3((offset + (i * 16u)), asuint(array[i])); + buffer.Store3((offset + (i * 16u)), asuint(array_1[i])); } } } diff --git a/test/tint/buffer/storage/dynamic_index/write_f16.wgsl.expected.dxc.hlsl b/test/tint/buffer/storage/dynamic_index/write_f16.wgsl.expected.dxc.hlsl index fe9d9f0144..26888190c4 100644 --- a/test/tint/buffer/storage/dynamic_index/write_f16.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/storage/dynamic_index/write_f16.wgsl.expected.dxc.hlsl @@ -113,19 +113,19 @@ void tint_symbol_35(RWByteAddressBuffer buffer, uint offset, matrix value[2]) { - matrix array_1[2] = value; + matrix array_2[2] = value; { for(uint i_1 = 0u; (i_1 < 2u); i_1 = (i_1 + 1u)) { - tint_symbol_33(buffer, (offset + (i_1 * 16u)), array_1[i_1]); + tint_symbol_33(buffer, (offset + (i_1 * 16u)), array_2[i_1]); } } } diff --git a/test/tint/buffer/storage/static_index/write.wgsl.expected.dxc.hlsl b/test/tint/buffer/storage/static_index/write.wgsl.expected.dxc.hlsl index 1fcb36233d..9bf75ff89e 100644 --- a/test/tint/buffer/storage/static_index/write.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/storage/static_index/write.wgsl.expected.dxc.hlsl @@ -60,10 +60,10 @@ void tint_symbol_20(RWByteAddressBuffer buffer, uint offset, float4x4 value) { } void tint_symbol_21(RWByteAddressBuffer buffer, uint offset, float3 value[2]) { - float3 array[2] = value; + float3 array_1[2] = value; { for(uint i = 0u; (i < 2u); i = (i + 1u)) { - buffer.Store3((offset + (i * 16u)), asuint(array[i])); + buffer.Store3((offset + (i * 16u)), asuint(array_1[i])); } } } @@ -74,10 +74,10 @@ void tint_symbol_22(RWByteAddressBuffer buffer, uint offset, Inner value) { } void tint_symbol_23(RWByteAddressBuffer buffer, uint offset, Inner value[4]) { - Inner array_1[4] = value; + Inner array_2[4] = value; { for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) { - tint_symbol_22(buffer, (offset + (i_1 * 8u)), array_1[i_1]); + tint_symbol_22(buffer, (offset + (i_1 * 8u)), array_2[i_1]); } } } diff --git a/test/tint/buffer/storage/static_index/write.wgsl.expected.fxc.hlsl b/test/tint/buffer/storage/static_index/write.wgsl.expected.fxc.hlsl index 1fcb36233d..9bf75ff89e 100644 --- a/test/tint/buffer/storage/static_index/write.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/storage/static_index/write.wgsl.expected.fxc.hlsl @@ -60,10 +60,10 @@ void tint_symbol_20(RWByteAddressBuffer buffer, uint offset, float4x4 value) { } void tint_symbol_21(RWByteAddressBuffer buffer, uint offset, float3 value[2]) { - float3 array[2] = value; + float3 array_1[2] = value; { for(uint i = 0u; (i < 2u); i = (i + 1u)) { - buffer.Store3((offset + (i * 16u)), asuint(array[i])); + buffer.Store3((offset + (i * 16u)), asuint(array_1[i])); } } } @@ -74,10 +74,10 @@ void tint_symbol_22(RWByteAddressBuffer buffer, uint offset, Inner value) { } void tint_symbol_23(RWByteAddressBuffer buffer, uint offset, Inner value[4]) { - Inner array_1[4] = value; + Inner array_2[4] = value; { for(uint i_1 = 0u; (i_1 < 4u); i_1 = (i_1 + 1u)) { - tint_symbol_22(buffer, (offset + (i_1 * 8u)), array_1[i_1]); + tint_symbol_22(buffer, (offset + (i_1 * 8u)), array_2[i_1]); } } } diff --git a/test/tint/buffer/storage/static_index/write_f16.wgsl.expected.dxc.hlsl b/test/tint/buffer/storage/static_index/write_f16.wgsl.expected.dxc.hlsl index 526b6f5a07..121700ab9c 100644 --- a/test/tint/buffer/storage/static_index/write_f16.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/storage/static_index/write_f16.wgsl.expected.dxc.hlsl @@ -115,19 +115,19 @@ void tint_symbol_33(RWByteAddressBuffer buffer, uint offset, matrix value[2]) { - matrix array_1[2] = value; + matrix array_2[2] = value; { for(uint i_1 = 0u; (i_1 < 2u); i_1 = (i_1 + 1u)) { - tint_symbol_31(buffer, (offset + (i_1 * 16u)), array_1[i_1]); + tint_symbol_31(buffer, (offset + (i_1 * 16u)), array_2[i_1]); } } } @@ -139,10 +139,10 @@ void tint_symbol_36(RWByteAddressBuffer buffer, uint offset, Inner value) { } void tint_symbol_37(RWByteAddressBuffer buffer, uint offset, Inner value[4]) { - Inner array_2[4] = value; + Inner array_3[4] = value; { for(uint i_2 = 0u; (i_2 < 4u); i_2 = (i_2 + 1u)) { - tint_symbol_36(buffer, (offset + (i_2 * 12u)), array_2[i_2]); + tint_symbol_36(buffer, (offset + (i_2 * 12u)), array_3[i_2]); } } } diff --git a/test/tint/buffer/storage/types/array4_f16.wgsl.expected.dxc.hlsl b/test/tint/buffer/storage/types/array4_f16.wgsl.expected.dxc.hlsl index 15fa0aba77..ac93313fa8 100644 --- a/test/tint/buffer/storage/types/array4_f16.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/storage/types/array4_f16.wgsl.expected.dxc.hlsl @@ -2,10 +2,10 @@ ByteAddressBuffer tint_symbol : register(t0, space0); RWByteAddressBuffer tint_symbol_1 : register(u1, space0); void tint_symbol_2(RWByteAddressBuffer buffer, uint offset, float16_t value[4]) { - float16_t array[4] = value; + float16_t array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - buffer.Store((offset + (i * 2u)), array[i]); + buffer.Store((offset + (i * 2u)), array_1[i]); } } } diff --git a/test/tint/buffer/storage/types/array4_f32.wgsl.expected.dxc.hlsl b/test/tint/buffer/storage/types/array4_f32.wgsl.expected.dxc.hlsl index efaf35eedf..b1f25b27ae 100644 --- a/test/tint/buffer/storage/types/array4_f32.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/storage/types/array4_f32.wgsl.expected.dxc.hlsl @@ -2,10 +2,10 @@ ByteAddressBuffer tint_symbol : register(t0, space0); RWByteAddressBuffer tint_symbol_1 : register(u1, space0); void tint_symbol_2(RWByteAddressBuffer buffer, uint offset, float value[4]) { - float array[4] = value; + float array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - buffer.Store((offset + (i * 4u)), asuint(array[i])); + buffer.Store((offset + (i * 4u)), asuint(array_1[i])); } } } diff --git a/test/tint/buffer/storage/types/array4_f32.wgsl.expected.fxc.hlsl b/test/tint/buffer/storage/types/array4_f32.wgsl.expected.fxc.hlsl index efaf35eedf..b1f25b27ae 100644 --- a/test/tint/buffer/storage/types/array4_f32.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/storage/types/array4_f32.wgsl.expected.fxc.hlsl @@ -2,10 +2,10 @@ ByteAddressBuffer tint_symbol : register(t0, space0); RWByteAddressBuffer tint_symbol_1 : register(u1, space0); void tint_symbol_2(RWByteAddressBuffer buffer, uint offset, float value[4]) { - float array[4] = value; + float array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - buffer.Store((offset + (i * 4u)), asuint(array[i])); + buffer.Store((offset + (i * 4u)), asuint(array_1[i])); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat2x2_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat2x2_f32/to_storage.wgsl.expected.dxc.hlsl index b5a37741a5..280d978dbc 100644 --- a/test/tint/buffer/uniform/std140/array/mat2x2_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat2x2_f32/to_storage.wgsl.expected.dxc.hlsl @@ -9,10 +9,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float2x2 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float2x2 value[4]) { - float2x2 array[4] = value; + float2x2 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 16u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 16u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat2x2_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/array/mat2x2_f32/to_storage.wgsl.expected.fxc.hlsl index b5a37741a5..280d978dbc 100644 --- a/test/tint/buffer/uniform/std140/array/mat2x2_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat2x2_f32/to_storage.wgsl.expected.fxc.hlsl @@ -9,10 +9,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float2x2 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float2x2 value[4]) { - float2x2 array[4] = value; + float2x2 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 16u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 16u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat2x3_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat2x3_f16/to_storage.wgsl.expected.dxc.hlsl index 26f9723fad..b40659430e 100644 --- a/test/tint/buffer/uniform/std140/array/mat2x3_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat2x3_f16/to_storage.wgsl.expected.dxc.hlsl @@ -9,10 +9,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, matrix value[4]) { - matrix array[4] = value; + matrix array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 16u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 16u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat2x3_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat2x3_f32/to_storage.wgsl.expected.dxc.hlsl index 9d1bbf8049..93021a5d2c 100644 --- a/test/tint/buffer/uniform/std140/array/mat2x3_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat2x3_f32/to_storage.wgsl.expected.dxc.hlsl @@ -9,10 +9,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float2x3 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float2x3 value[4]) { - float2x3 array[4] = value; + float2x3 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 32u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 32u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat2x3_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/array/mat2x3_f32/to_storage.wgsl.expected.fxc.hlsl index 9d1bbf8049..93021a5d2c 100644 --- a/test/tint/buffer/uniform/std140/array/mat2x3_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat2x3_f32/to_storage.wgsl.expected.fxc.hlsl @@ -9,10 +9,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float2x3 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float2x3 value[4]) { - float2x3 array[4] = value; + float2x3 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 32u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 32u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat2x4_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat2x4_f16/to_storage.wgsl.expected.dxc.hlsl index d519b2e436..28c564e519 100644 --- a/test/tint/buffer/uniform/std140/array/mat2x4_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat2x4_f16/to_storage.wgsl.expected.dxc.hlsl @@ -9,10 +9,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, matrix value[4]) { - matrix array[4] = value; + matrix array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 16u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 16u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat2x4_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat2x4_f32/to_storage.wgsl.expected.dxc.hlsl index 747c20ae2d..5b44d2d99b 100644 --- a/test/tint/buffer/uniform/std140/array/mat2x4_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat2x4_f32/to_storage.wgsl.expected.dxc.hlsl @@ -9,10 +9,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float2x4 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float2x4 value[4]) { - float2x4 array[4] = value; + float2x4 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 32u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 32u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat2x4_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/array/mat2x4_f32/to_storage.wgsl.expected.fxc.hlsl index 747c20ae2d..5b44d2d99b 100644 --- a/test/tint/buffer/uniform/std140/array/mat2x4_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat2x4_f32/to_storage.wgsl.expected.fxc.hlsl @@ -9,10 +9,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float2x4 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float2x4 value[4]) { - float2x4 array[4] = value; + float2x4 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 32u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 32u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat3x3_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat3x3_f32/to_storage.wgsl.expected.dxc.hlsl index 6dc59a86d7..563ec2e0ec 100644 --- a/test/tint/buffer/uniform/std140/array/mat3x3_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat3x3_f32/to_storage.wgsl.expected.dxc.hlsl @@ -10,10 +10,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float3x3 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float3x3 value[4]) { - float3x3 array[4] = value; + float3x3 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 48u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 48u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat3x3_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/array/mat3x3_f32/to_storage.wgsl.expected.fxc.hlsl index 6dc59a86d7..563ec2e0ec 100644 --- a/test/tint/buffer/uniform/std140/array/mat3x3_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat3x3_f32/to_storage.wgsl.expected.fxc.hlsl @@ -10,10 +10,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float3x3 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float3x3 value[4]) { - float3x3 array[4] = value; + float3x3 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 48u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 48u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat3x4_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat3x4_f32/to_storage.wgsl.expected.dxc.hlsl index b82dc9ca1a..b6ecb13051 100644 --- a/test/tint/buffer/uniform/std140/array/mat3x4_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat3x4_f32/to_storage.wgsl.expected.dxc.hlsl @@ -10,10 +10,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float3x4 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float3x4 value[4]) { - float3x4 array[4] = value; + float3x4 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 48u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 48u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat3x4_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/array/mat3x4_f32/to_storage.wgsl.expected.fxc.hlsl index b82dc9ca1a..b6ecb13051 100644 --- a/test/tint/buffer/uniform/std140/array/mat3x4_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat3x4_f32/to_storage.wgsl.expected.fxc.hlsl @@ -10,10 +10,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float3x4 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float3x4 value[4]) { - float3x4 array[4] = value; + float3x4 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 48u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 48u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat4x2_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat4x2_f16/to_storage.wgsl.expected.dxc.hlsl index 80971337f8..45800241b2 100644 --- a/test/tint/buffer/uniform/std140/array/mat4x2_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat4x2_f16/to_storage.wgsl.expected.dxc.hlsl @@ -11,10 +11,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, matrix value[4]) { - matrix array[4] = value; + matrix array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 16u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 16u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat4x2_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat4x2_f32/to_storage.wgsl.expected.dxc.hlsl index f264391c32..22f1ffe707 100644 --- a/test/tint/buffer/uniform/std140/array/mat4x2_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat4x2_f32/to_storage.wgsl.expected.dxc.hlsl @@ -11,10 +11,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float4x2 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float4x2 value[4]) { - float4x2 array[4] = value; + float4x2 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 32u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 32u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat4x2_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/array/mat4x2_f32/to_storage.wgsl.expected.fxc.hlsl index f264391c32..22f1ffe707 100644 --- a/test/tint/buffer/uniform/std140/array/mat4x2_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat4x2_f32/to_storage.wgsl.expected.fxc.hlsl @@ -11,10 +11,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float4x2 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float4x2 value[4]) { - float4x2 array[4] = value; + float4x2 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 32u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 32u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat4x3_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat4x3_f16/to_storage.wgsl.expected.dxc.hlsl index a101585ef1..8039a70956 100644 --- a/test/tint/buffer/uniform/std140/array/mat4x3_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat4x3_f16/to_storage.wgsl.expected.dxc.hlsl @@ -11,10 +11,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, matrix value[4]) { - matrix array[4] = value; + matrix array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 32u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 32u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat4x3_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat4x3_f32/to_storage.wgsl.expected.dxc.hlsl index befc57d54c..6d83315c41 100644 --- a/test/tint/buffer/uniform/std140/array/mat4x3_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat4x3_f32/to_storage.wgsl.expected.dxc.hlsl @@ -11,10 +11,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float4x3 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float4x3 value[4]) { - float4x3 array[4] = value; + float4x3 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 64u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 64u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat4x3_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/array/mat4x3_f32/to_storage.wgsl.expected.fxc.hlsl index befc57d54c..6d83315c41 100644 --- a/test/tint/buffer/uniform/std140/array/mat4x3_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat4x3_f32/to_storage.wgsl.expected.fxc.hlsl @@ -11,10 +11,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float4x3 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float4x3 value[4]) { - float4x3 array[4] = value; + float4x3 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 64u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 64u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat4x4_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat4x4_f16/to_storage.wgsl.expected.dxc.hlsl index 8a3aa03585..9e8d1ecf2c 100644 --- a/test/tint/buffer/uniform/std140/array/mat4x4_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat4x4_f16/to_storage.wgsl.expected.dxc.hlsl @@ -11,10 +11,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, matrix value[4]) { - matrix array[4] = value; + matrix array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 32u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 32u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat4x4_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/array/mat4x4_f32/to_storage.wgsl.expected.dxc.hlsl index 9fd79777e5..fce48272e7 100644 --- a/test/tint/buffer/uniform/std140/array/mat4x4_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat4x4_f32/to_storage.wgsl.expected.dxc.hlsl @@ -11,10 +11,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float4x4 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float4x4 value[4]) { - float4x4 array[4] = value; + float4x4 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 64u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 64u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/array/mat4x4_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/array/mat4x4_f32/to_storage.wgsl.expected.fxc.hlsl index 9fd79777e5..fce48272e7 100644 --- a/test/tint/buffer/uniform/std140/array/mat4x4_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/array/mat4x4_f32/to_storage.wgsl.expected.fxc.hlsl @@ -11,10 +11,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, float4x4 value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, float4x4 value[4]) { - float4x4 array[4] = value; + float4x4 array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 64u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 64u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat2x2_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat2x2_f16/to_storage.wgsl.expected.dxc.hlsl index e217232c01..c2951f1842 100644 --- a/test/tint/buffer/uniform/std140/struct/mat2x2_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat2x2_f16/to_storage.wgsl.expected.dxc.hlsl @@ -21,10 +21,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat2x2_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat2x2_f32/to_storage.wgsl.expected.dxc.hlsl index bfcca34d99..de4e9791ec 100644 --- a/test/tint/buffer/uniform/std140/struct/mat2x2_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat2x2_f32/to_storage.wgsl.expected.dxc.hlsl @@ -21,10 +21,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat2x2_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat2x2_f32/to_storage.wgsl.expected.fxc.hlsl index bfcca34d99..de4e9791ec 100644 --- a/test/tint/buffer/uniform/std140/struct/mat2x2_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat2x2_f32/to_storage.wgsl.expected.fxc.hlsl @@ -21,10 +21,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat2x3_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat2x3_f16/to_storage.wgsl.expected.dxc.hlsl index ba15d731c4..6f680d2cf8 100644 --- a/test/tint/buffer/uniform/std140/struct/mat2x3_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat2x3_f16/to_storage.wgsl.expected.dxc.hlsl @@ -21,10 +21,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat2x3_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat2x3_f32/to_storage.wgsl.expected.dxc.hlsl index 89eabee2d3..257e965d0c 100644 --- a/test/tint/buffer/uniform/std140/struct/mat2x3_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat2x3_f32/to_storage.wgsl.expected.dxc.hlsl @@ -21,10 +21,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat2x3_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat2x3_f32/to_storage.wgsl.expected.fxc.hlsl index 89eabee2d3..257e965d0c 100644 --- a/test/tint/buffer/uniform/std140/struct/mat2x3_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat2x3_f32/to_storage.wgsl.expected.fxc.hlsl @@ -21,10 +21,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat2x4_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat2x4_f16/to_storage.wgsl.expected.dxc.hlsl index 10a3807a1d..daa5fd7f84 100644 --- a/test/tint/buffer/uniform/std140/struct/mat2x4_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat2x4_f16/to_storage.wgsl.expected.dxc.hlsl @@ -21,10 +21,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat2x4_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat2x4_f32/to_storage.wgsl.expected.dxc.hlsl index 21467135bb..425d179cf6 100644 --- a/test/tint/buffer/uniform/std140/struct/mat2x4_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat2x4_f32/to_storage.wgsl.expected.dxc.hlsl @@ -21,10 +21,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat2x4_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat2x4_f32/to_storage.wgsl.expected.fxc.hlsl index 21467135bb..425d179cf6 100644 --- a/test/tint/buffer/uniform/std140/struct/mat2x4_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat2x4_f32/to_storage.wgsl.expected.fxc.hlsl @@ -21,10 +21,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat3x2_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat3x2_f16/to_storage.wgsl.expected.dxc.hlsl index 0a5e75f0cc..2a909739b2 100644 --- a/test/tint/buffer/uniform/std140/struct/mat3x2_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat3x2_f16/to_storage.wgsl.expected.dxc.hlsl @@ -22,10 +22,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat3x2_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat3x2_f32/to_storage.wgsl.expected.dxc.hlsl index 2869d033da..50eb6e728d 100644 --- a/test/tint/buffer/uniform/std140/struct/mat3x2_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat3x2_f32/to_storage.wgsl.expected.dxc.hlsl @@ -22,10 +22,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat3x2_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat3x2_f32/to_storage.wgsl.expected.fxc.hlsl index 2869d033da..50eb6e728d 100644 --- a/test/tint/buffer/uniform/std140/struct/mat3x2_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat3x2_f32/to_storage.wgsl.expected.fxc.hlsl @@ -22,10 +22,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat3x3_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat3x3_f16/to_storage.wgsl.expected.dxc.hlsl index 403b78d739..35a1a179b1 100644 --- a/test/tint/buffer/uniform/std140/struct/mat3x3_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat3x3_f16/to_storage.wgsl.expected.dxc.hlsl @@ -22,10 +22,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat3x3_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat3x3_f32/to_storage.wgsl.expected.dxc.hlsl index 51fb0e8fa2..c27c39378e 100644 --- a/test/tint/buffer/uniform/std140/struct/mat3x3_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat3x3_f32/to_storage.wgsl.expected.dxc.hlsl @@ -22,10 +22,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat3x3_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat3x3_f32/to_storage.wgsl.expected.fxc.hlsl index 51fb0e8fa2..c27c39378e 100644 --- a/test/tint/buffer/uniform/std140/struct/mat3x3_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat3x3_f32/to_storage.wgsl.expected.fxc.hlsl @@ -22,10 +22,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat3x4_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat3x4_f16/to_storage.wgsl.expected.dxc.hlsl index c236690c81..994f4fc3ef 100644 --- a/test/tint/buffer/uniform/std140/struct/mat3x4_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat3x4_f16/to_storage.wgsl.expected.dxc.hlsl @@ -22,10 +22,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat3x4_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat3x4_f32/to_storage.wgsl.expected.dxc.hlsl index 629f8ff0e6..ce77d82e50 100644 --- a/test/tint/buffer/uniform/std140/struct/mat3x4_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat3x4_f32/to_storage.wgsl.expected.dxc.hlsl @@ -22,10 +22,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat3x4_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat3x4_f32/to_storage.wgsl.expected.fxc.hlsl index 629f8ff0e6..ce77d82e50 100644 --- a/test/tint/buffer/uniform/std140/struct/mat3x4_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat3x4_f32/to_storage.wgsl.expected.fxc.hlsl @@ -22,10 +22,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat4x2_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat4x2_f16/to_storage.wgsl.expected.dxc.hlsl index 180ae47b9f..651a533813 100644 --- a/test/tint/buffer/uniform/std140/struct/mat4x2_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat4x2_f16/to_storage.wgsl.expected.dxc.hlsl @@ -23,10 +23,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat4x2_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat4x2_f32/to_storage.wgsl.expected.dxc.hlsl index 5dc514f78a..bfc91abd51 100644 --- a/test/tint/buffer/uniform/std140/struct/mat4x2_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat4x2_f32/to_storage.wgsl.expected.dxc.hlsl @@ -23,10 +23,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat4x2_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat4x2_f32/to_storage.wgsl.expected.fxc.hlsl index 5dc514f78a..bfc91abd51 100644 --- a/test/tint/buffer/uniform/std140/struct/mat4x2_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat4x2_f32/to_storage.wgsl.expected.fxc.hlsl @@ -23,10 +23,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat4x3_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat4x3_f16/to_storage.wgsl.expected.dxc.hlsl index 5b9dfa8302..f4e10acd33 100644 --- a/test/tint/buffer/uniform/std140/struct/mat4x3_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat4x3_f16/to_storage.wgsl.expected.dxc.hlsl @@ -23,10 +23,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat4x3_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat4x3_f32/to_storage.wgsl.expected.dxc.hlsl index f910578696..9f86bd8f27 100644 --- a/test/tint/buffer/uniform/std140/struct/mat4x3_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat4x3_f32/to_storage.wgsl.expected.dxc.hlsl @@ -23,10 +23,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 192u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 192u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat4x3_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat4x3_f32/to_storage.wgsl.expected.fxc.hlsl index f910578696..9f86bd8f27 100644 --- a/test/tint/buffer/uniform/std140/struct/mat4x3_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat4x3_f32/to_storage.wgsl.expected.fxc.hlsl @@ -23,10 +23,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 192u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 192u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat4x4_f16/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat4x4_f16/to_storage.wgsl.expected.dxc.hlsl index 212b921a6a..4ec616b615 100644 --- a/test/tint/buffer/uniform/std140/struct/mat4x4_f16/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat4x4_f16/to_storage.wgsl.expected.dxc.hlsl @@ -23,10 +23,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 128u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 128u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat4x4_f32/to_storage.wgsl.expected.dxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat4x4_f32/to_storage.wgsl.expected.dxc.hlsl index cc210072be..9f194ab201 100644 --- a/test/tint/buffer/uniform/std140/struct/mat4x4_f32/to_storage.wgsl.expected.dxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat4x4_f32/to_storage.wgsl.expected.dxc.hlsl @@ -23,10 +23,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 192u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 192u)), array_1[i]); } } } diff --git a/test/tint/buffer/uniform/std140/struct/mat4x4_f32/to_storage.wgsl.expected.fxc.hlsl b/test/tint/buffer/uniform/std140/struct/mat4x4_f32/to_storage.wgsl.expected.fxc.hlsl index cc210072be..9f194ab201 100644 --- a/test/tint/buffer/uniform/std140/struct/mat4x4_f32/to_storage.wgsl.expected.fxc.hlsl +++ b/test/tint/buffer/uniform/std140/struct/mat4x4_f32/to_storage.wgsl.expected.fxc.hlsl @@ -23,10 +23,10 @@ void tint_symbol_1(RWByteAddressBuffer buffer, uint offset, S value) { } void tint_symbol(RWByteAddressBuffer buffer, uint offset, S value[4]) { - S array[4] = value; + S array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - tint_symbol_1(buffer, (offset + (i * 192u)), array[i]); + tint_symbol_1(buffer, (offset + (i * 192u)), array_1[i]); } } } diff --git a/test/tint/layout/storage/mat2x2/stride/16.spvasm.expected.dxc.hlsl b/test/tint/layout/storage/mat2x2/stride/16.spvasm.expected.dxc.hlsl index dd1dcb6a87..0c201315da 100644 --- a/test/tint/layout/storage/mat2x2/stride/16.spvasm.expected.dxc.hlsl +++ b/test/tint/layout/storage/mat2x2/stride/16.spvasm.expected.dxc.hlsl @@ -37,10 +37,10 @@ void tint_symbol_5(RWByteAddressBuffer buffer, uint offset, strided_arr value) { } void tint_symbol_4(RWByteAddressBuffer buffer, uint offset, strided_arr value[2]) { - strided_arr array[2] = value; + strided_arr array_1[2] = value; { for(uint i_1 = 0u; (i_1 < 2u); i_1 = (i_1 + 1u)) { - tint_symbol_5(buffer, (offset + (i_1 * 16u)), array[i_1]); + tint_symbol_5(buffer, (offset + (i_1 * 16u)), array_1[i_1]); } } } diff --git a/test/tint/layout/storage/mat2x2/stride/16.spvasm.expected.fxc.hlsl b/test/tint/layout/storage/mat2x2/stride/16.spvasm.expected.fxc.hlsl index dd1dcb6a87..0c201315da 100644 --- a/test/tint/layout/storage/mat2x2/stride/16.spvasm.expected.fxc.hlsl +++ b/test/tint/layout/storage/mat2x2/stride/16.spvasm.expected.fxc.hlsl @@ -37,10 +37,10 @@ void tint_symbol_5(RWByteAddressBuffer buffer, uint offset, strided_arr value) { } void tint_symbol_4(RWByteAddressBuffer buffer, uint offset, strided_arr value[2]) { - strided_arr array[2] = value; + strided_arr array_1[2] = value; { for(uint i_1 = 0u; (i_1 < 2u); i_1 = (i_1 + 1u)) { - tint_symbol_5(buffer, (offset + (i_1 * 16u)), array[i_1]); + tint_symbol_5(buffer, (offset + (i_1 * 16u)), array_1[i_1]); } } } diff --git a/test/tint/ptr_ref/store/param/storage/array_in_struct.wgsl.expected.dxc.hlsl b/test/tint/ptr_ref/store/param/storage/array_in_struct.wgsl.expected.dxc.hlsl index 30148d53d9..517d789014 100644 --- a/test/tint/ptr_ref/store/param/storage/array_in_struct.wgsl.expected.dxc.hlsl +++ b/test/tint/ptr_ref/store/param/storage/array_in_struct.wgsl.expected.dxc.hlsl @@ -1,10 +1,10 @@ RWByteAddressBuffer S : register(u0, space0); void tint_symbol(RWByteAddressBuffer buffer, uint offset, int value[4]) { - int array[4] = value; + int array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - buffer.Store((offset + (i * 4u)), asuint(array[i])); + buffer.Store((offset + (i * 4u)), asuint(array_1[i])); } } } diff --git a/test/tint/ptr_ref/store/param/storage/array_in_struct.wgsl.expected.fxc.hlsl b/test/tint/ptr_ref/store/param/storage/array_in_struct.wgsl.expected.fxc.hlsl index 30148d53d9..517d789014 100644 --- a/test/tint/ptr_ref/store/param/storage/array_in_struct.wgsl.expected.fxc.hlsl +++ b/test/tint/ptr_ref/store/param/storage/array_in_struct.wgsl.expected.fxc.hlsl @@ -1,10 +1,10 @@ RWByteAddressBuffer S : register(u0, space0); void tint_symbol(RWByteAddressBuffer buffer, uint offset, int value[4]) { - int array[4] = value; + int array_1[4] = value; { for(uint i = 0u; (i < 4u); i = (i + 1u)) { - buffer.Store((offset + (i * 4u)), asuint(array[i])); + buffer.Store((offset + (i * 4u)), asuint(array_1[i])); } } }