diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index 574b275579..ba10dfeb75 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -247,7 +247,6 @@ libtint_source_set("libtint_syntax_tree_src") { "ast/binding_attribute.h", "ast/bitcast_expression.h", "ast/block_statement.h", - "ast/bool.h", "ast/bool_literal_expression.h", "ast/break_if_statement.h", "ast/break_statement.h", @@ -272,13 +271,10 @@ libtint_source_set("libtint_syntax_tree_src") { "ast/expression.h", "ast/extension.h", "ast/external_texture.h", - "ast/f16.h", - "ast/f32.h", "ast/float_literal_expression.h", "ast/for_loop_statement.h", "ast/function.h", "ast/group_attribute.h", - "ast/i32.h", "ast/id_attribute.h", "ast/identifier.h", "ast/identifier_expression.h", @@ -323,7 +319,6 @@ libtint_source_set("libtint_syntax_tree_src") { "ast/type.h", "ast/type_decl.h", "ast/type_name.h", - "ast/u32.h", "ast/unary_op.h", "ast/unary_op_expression.h", "ast/var.h", @@ -567,8 +562,6 @@ libtint_source_set("libtint_ast_src") { "ast/bitcast_expression.h", "ast/block_statement.cc", "ast/block_statement.h", - "ast/bool.cc", - "ast/bool.h", "ast/bool_literal_expression.cc", "ast/bool_literal_expression.h", "ast/break_if_statement.cc", @@ -617,10 +610,6 @@ libtint_source_set("libtint_ast_src") { "ast/extension.h", "ast/external_texture.cc", "ast/external_texture.h", - "ast/f16.cc", - "ast/f16.h", - "ast/f32.cc", - "ast/f32.h", "ast/float_literal_expression.cc", "ast/float_literal_expression.h", "ast/for_loop_statement.cc", @@ -629,8 +618,6 @@ libtint_source_set("libtint_ast_src") { "ast/function.h", "ast/group_attribute.cc", "ast/group_attribute.h", - "ast/i32.cc", - "ast/i32.h", "ast/id_attribute.cc", "ast/id_attribute.h", "ast/identifier.cc", @@ -717,8 +704,6 @@ libtint_source_set("libtint_ast_src") { "ast/type_decl.h", "ast/type_name.cc", "ast/type_name.h", - "ast/u32.cc", - "ast/u32.h", "ast/unary_op.cc", "ast/unary_op.h", "ast/unary_op_expression.cc", @@ -1317,7 +1302,6 @@ if (tint_build_unittests) { "ast/bitcast_expression_test.cc", "ast/block_statement_test.cc", "ast/bool_literal_expression_test.cc", - "ast/bool_test.cc", "ast/break_if_statement_test.cc", "ast/break_statement_test.cc", "ast/builtin_attribute_test.cc", @@ -1338,13 +1322,10 @@ if (tint_build_unittests) { "ast/enable_test.cc", "ast/extension_test.cc", "ast/external_texture_test.cc", - "ast/f16_test.cc", - "ast/f32_test.cc", "ast/float_literal_expression_test.cc", "ast/for_loop_statement_test.cc", "ast/function_test.cc", "ast/group_attribute_test.cc", - "ast/i32_test.cc", "ast/id_attribute_test.cc", "ast/identifier_expression_test.cc", "ast/identifier_test.cc", @@ -1380,7 +1361,6 @@ if (tint_build_unittests) { "ast/texture_test.cc", "ast/traverse_expressions_test.cc", "ast/type_name_test.cc", - "ast/u32_test.cc", "ast/unary_op_expression_test.cc", "ast/variable_decl_statement_test.cc", "ast/variable_test.cc", diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 473e0ee590..56f81d5dcc 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -102,8 +102,6 @@ list(APPEND TINT_LIB_SRCS ast/block_statement.h ast/bool_literal_expression.cc ast/bool_literal_expression.h - ast/bool.cc - ast/bool.h ast/break_if_statement.cc ast/break_if_statement.h ast/break_statement.cc @@ -146,10 +144,6 @@ list(APPEND TINT_LIB_SRCS ast/expression.h ast/external_texture.cc ast/external_texture.h - ast/f16.cc - ast/f16.h - ast/f32.cc - ast/f32.h ast/float_literal_expression.cc ast/float_literal_expression.h ast/for_loop_statement.cc @@ -158,8 +152,6 @@ list(APPEND TINT_LIB_SRCS ast/function.h ast/group_attribute.cc ast/group_attribute.h - ast/i32.cc - ast/i32.h ast/id_attribute.cc ast/id_attribute.h ast/identifier.cc @@ -244,8 +236,6 @@ list(APPEND TINT_LIB_SRCS ast/type_name.h ast/type.cc ast/type.h - ast/u32.cc - ast/u32.h ast/unary_op_expression.cc ast/unary_op_expression.h ast/unary_op.cc @@ -834,7 +824,6 @@ if(TINT_BUILD_TESTS) ast/bitcast_expression_test.cc ast/block_statement_test.cc ast/bool_literal_expression_test.cc - ast/bool_test.cc ast/break_if_statement_test.cc ast/break_statement_test.cc ast/builtin_attribute_test.cc @@ -855,13 +844,10 @@ if(TINT_BUILD_TESTS) ast/discard_statement_test.cc ast/enable_test.cc ast/external_texture_test.cc - ast/f16_test.cc - ast/f32_test.cc ast/float_literal_expression_test.cc ast/for_loop_statement_test.cc ast/function_test.cc ast/group_attribute_test.cc - ast/i32_test.cc ast/id_attribute_test.cc ast/identifier_test.cc ast/identifier_expression_test.cc @@ -896,7 +882,6 @@ if(TINT_BUILD_TESTS) ast/texture_test.cc ast/traverse_expressions_test.cc ast/type_name_test.cc - ast/u32_test.cc ast/unary_op_expression_test.cc ast/variable_decl_statement_test.cc ast/variable_test.cc diff --git a/src/tint/ast/alias_test.cc b/src/tint/ast/alias_test.cc index faedff7a99..d2fa755081 100644 --- a/src/tint/ast/alias_test.cc +++ b/src/tint/ast/alias_test.cc @@ -14,16 +14,12 @@ #include "src/tint/ast/alias.h" #include "src/tint/ast/array.h" -#include "src/tint/ast/bool.h" -#include "src/tint/ast/f32.h" -#include "src/tint/ast/i32.h" #include "src/tint/ast/matrix.h" #include "src/tint/ast/pointer.h" #include "src/tint/ast/sampler.h" #include "src/tint/ast/struct.h" #include "src/tint/ast/test_helper.h" #include "src/tint/ast/texture.h" -#include "src/tint/ast/u32.h" #include "src/tint/ast/vector.h" #include "src/tint/type/access.h" @@ -33,9 +29,9 @@ namespace { using AstAliasTest = TestHelper; TEST_F(AstAliasTest, Create) { - auto* u32 = create(); + auto* u32 = ty.u32(); auto* a = Alias("a_type", u32); - EXPECT_EQ(a->name->symbol, Symbol(1, ID())); + EXPECT_EQ(Symbols().NameFor(a->name->symbol), "a_type"); EXPECT_EQ(a->type, u32); } diff --git a/src/tint/ast/array_test.cc b/src/tint/ast/array_test.cc index e2ce77b9d5..eb5eddc5b1 100644 --- a/src/tint/ast/array_test.cc +++ b/src/tint/ast/array_test.cc @@ -24,19 +24,19 @@ namespace { using AstArrayTest = TestHelper; TEST_F(AstArrayTest, CreateSizedArray) { - auto* u32 = create(); auto* count = Expr(3_u); - auto* arr = create(u32, count, utils::Empty); - EXPECT_EQ(arr->type, u32); + 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* u32 = create(); - auto* arr = create(u32, nullptr, utils::Empty); - EXPECT_EQ(arr->type, u32); + 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()); @@ -51,26 +51,22 @@ TEST_F(AstArrayTest, CreateInferredTypeArray) { } TEST_F(AstArrayTest, FriendlyName_RuntimeSized) { - auto* i32 = create(); - auto* arr = create(i32, nullptr, utils::Empty); + auto* arr = create(ty.i32(), nullptr, utils::Empty); EXPECT_EQ(arr->FriendlyName(Symbols()), "array"); } TEST_F(AstArrayTest, FriendlyName_LiteralSized) { - auto* i32 = create(); - auto* arr = create(i32, Expr(5_u), utils::Empty); + auto* arr = create(ty.i32(), Expr(5_u), utils::Empty); EXPECT_EQ(arr->FriendlyName(Symbols()), "array"); } TEST_F(AstArrayTest, FriendlyName_ConstantSized) { - auto* i32 = create(); - auto* arr = create(i32, Expr("size"), utils::Empty); + auto* arr = create(ty.i32(), Expr("size"), utils::Empty); EXPECT_EQ(arr->FriendlyName(Symbols()), "array"); } TEST_F(AstArrayTest, FriendlyName_WithStride) { - auto* i32 = create(); - auto* arr = create(i32, Expr(5_u), utils::Vector{create(32u)}); + auto* arr = create(ty.i32(), Expr(5_u), utils::Vector{create(32u)}); EXPECT_EQ(arr->FriendlyName(Symbols()), "@stride(32) array"); } diff --git a/src/tint/ast/atomic_test.cc b/src/tint/ast/atomic_test.cc index 2b0ada948c..abb906e87e 100644 --- a/src/tint/ast/atomic_test.cc +++ b/src/tint/ast/atomic_test.cc @@ -14,7 +14,6 @@ #include "src/tint/ast/atomic.h" -#include "src/tint/ast/i32.h" #include "src/tint/ast/test_helper.h" namespace tint::ast { @@ -23,13 +22,14 @@ namespace { using AstAtomicTest = TestHelper; TEST_F(AstAtomicTest, Creation) { - auto* i32 = create(); + auto* i32 = ty.i32(); auto* p = create(i32); - EXPECT_EQ(p->type, i32); + ASSERT_TRUE(p->type->Is()); + EXPECT_EQ(Symbols().NameFor(p->type->As()->name->symbol), "i32"); } TEST_F(AstAtomicTest, FriendlyName) { - auto* i32 = create(); + auto* i32 = ty.i32(); auto* p = create(i32); EXPECT_EQ(p->FriendlyName(Symbols()), "atomic"); } diff --git a/src/tint/ast/bitcast_expression_test.cc b/src/tint/ast/bitcast_expression_test.cc index 7478456897..1a446f3856 100644 --- a/src/tint/ast/bitcast_expression_test.cc +++ b/src/tint/ast/bitcast_expression_test.cc @@ -26,7 +26,8 @@ TEST_F(BitcastExpressionTest, Create) { auto* expr = Expr("expr"); auto* exp = create(ty.f32(), expr); - EXPECT_TRUE(exp->type->Is()); + ASSERT_TRUE(exp->type->Is()); + EXPECT_EQ(Symbols().NameFor(exp->type->As()->name->symbol), "f32"); ASSERT_EQ(exp->expr, expr); } diff --git a/src/tint/ast/bool.cc b/src/tint/ast/bool.cc deleted file mode 100644 index 9b326eb044..0000000000 --- a/src/tint/ast/bool.cc +++ /dev/null @@ -1,38 +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/bool.h" - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::Bool); - -namespace tint::ast { - -Bool::Bool(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} - -Bool::Bool(Bool&&) = default; - -Bool::~Bool() = default; - -std::string Bool::FriendlyName(const SymbolTable&) const { - return "bool"; -} - -const Bool* Bool::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source); - return ctx->dst->create(src); -} - -} // namespace tint::ast diff --git a/src/tint/ast/bool.h b/src/tint/ast/bool.h deleted file mode 100644 index d61e49d6af..0000000000 --- a/src/tint/ast/bool.h +++ /dev/null @@ -1,55 +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_BOOL_H_ -#define SRC_TINT_AST_BOOL_H_ - -#include - -#include "src/tint/ast/type.h" - -// X11 likes to #define Bool leading to confusing error messages. -// If its defined, undefine it. -#ifdef Bool -#undef Bool -#endif - -namespace tint::ast { - -/// A boolean type -class Bool 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 - Bool(ProgramID pid, NodeID nid, const Source& src); - /// Move constructor - Bool(Bool&&); - ~Bool() 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 Bool* Clone(CloneContext* ctx) const override; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_BOOL_H_ diff --git a/src/tint/ast/bool_test.cc b/src/tint/ast/bool_test.cc deleted file mode 100644 index d3842b93ca..0000000000 --- a/src/tint/ast/bool_test.cc +++ /dev/null @@ -1,30 +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/bool.h" - -#include "src/tint/ast/test_helper.h" - -namespace tint::ast { -namespace { - -using AstBoolTest = TestHelper; - -TEST_F(AstBoolTest, FriendlyName) { - auto* b = create(); - EXPECT_EQ(b->FriendlyName(Symbols()), "bool"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/f16.cc b/src/tint/ast/f16.cc deleted file mode 100644 index dd3e48e67a..0000000000 --- a/src/tint/ast/f16.cc +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2022 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/f16.h" - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::F16); - -namespace tint::ast { - -F16::F16(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} - -F16::F16(F16&&) = default; - -F16::~F16() = default; - -std::string F16::FriendlyName(const SymbolTable&) const { - return "f16"; -} - -const F16* F16::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source); - return ctx->dst->create(src); -} - -} // namespace tint::ast diff --git a/src/tint/ast/f16.h b/src/tint/ast/f16.h deleted file mode 100644 index bae6291356..0000000000 --- a/src/tint/ast/f16.h +++ /dev/null @@ -1,49 +0,0 @@ -// Copyright 2022 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_F16_H_ -#define SRC_TINT_AST_F16_H_ - -#include - -#include "src/tint/ast/type.h" - -namespace tint::ast { - -/// A float 16 type -class F16 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 - F16(ProgramID pid, NodeID nid, const Source& src); - /// Move constructor - F16(F16&&); - ~F16() 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 F16* Clone(CloneContext* ctx) const override; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_F16_H_ diff --git a/src/tint/ast/f16_test.cc b/src/tint/ast/f16_test.cc deleted file mode 100644 index 48ab284f55..0000000000 --- a/src/tint/ast/f16_test.cc +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2022 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/f16.h" - -#include "src/tint/ast/test_helper.h" - -namespace tint::ast { -namespace { - -using AstF16Test = TestHelper; - -TEST_F(AstF16Test, FriendlyName) { - auto* f = create(); - EXPECT_EQ(f->FriendlyName(Symbols()), "f16"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/f32.cc b/src/tint/ast/f32.cc deleted file mode 100644 index 0ae354ad00..0000000000 --- a/src/tint/ast/f32.cc +++ /dev/null @@ -1,38 +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/f32.h" - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::F32); - -namespace tint::ast { - -F32::F32(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} - -F32::F32(F32&&) = default; - -F32::~F32() = default; - -std::string F32::FriendlyName(const SymbolTable&) const { - return "f32"; -} - -const F32* F32::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source); - return ctx->dst->create(src); -} - -} // namespace tint::ast diff --git a/src/tint/ast/f32.h b/src/tint/ast/f32.h deleted file mode 100644 index 5176c45e3d..0000000000 --- a/src/tint/ast/f32.h +++ /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. - -#ifndef SRC_TINT_AST_F32_H_ -#define SRC_TINT_AST_F32_H_ - -#include - -#include "src/tint/ast/type.h" - -namespace tint::ast { - -/// A float 32 type -class F32 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 - F32(ProgramID pid, NodeID nid, const Source& src); - /// Move constructor - F32(F32&&); - ~F32() 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 F32* Clone(CloneContext* ctx) const override; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_F32_H_ diff --git a/src/tint/ast/f32_test.cc b/src/tint/ast/f32_test.cc deleted file mode 100644 index 793289fff8..0000000000 --- a/src/tint/ast/f32_test.cc +++ /dev/null @@ -1,30 +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/f32.h" - -#include "src/tint/ast/test_helper.h" - -namespace tint::ast { -namespace { - -using AstF32Test = TestHelper; - -TEST_F(AstF32Test, FriendlyName) { - auto* f = create(); - EXPECT_EQ(f->FriendlyName(Symbols()), "f32"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/i32.cc b/src/tint/ast/i32.cc deleted file mode 100644 index ffdf30dedf..0000000000 --- a/src/tint/ast/i32.cc +++ /dev/null @@ -1,38 +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/i32.h" - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::I32); - -namespace tint::ast { - -I32::I32(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} - -I32::I32(I32&&) = default; - -I32::~I32() = default; - -std::string I32::FriendlyName(const SymbolTable&) const { - return "i32"; -} - -const I32* I32::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source); - return ctx->dst->create(src); -} - -} // namespace tint::ast diff --git a/src/tint/ast/i32.h b/src/tint/ast/i32.h deleted file mode 100644 index d2c951c3f0..0000000000 --- a/src/tint/ast/i32.h +++ /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. - -#ifndef SRC_TINT_AST_I32_H_ -#define SRC_TINT_AST_I32_H_ - -#include - -#include "src/tint/ast/type.h" - -namespace tint::ast { - -/// A signed int 32 type. -class I32 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 - I32(ProgramID pid, NodeID nid, const Source& src); - /// Move constructor - I32(I32&&); - ~I32() 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 I32* Clone(CloneContext* ctx) const override; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_I32_H_ diff --git a/src/tint/ast/i32_test.cc b/src/tint/ast/i32_test.cc deleted file mode 100644 index ee220cb91a..0000000000 --- a/src/tint/ast/i32_test.cc +++ /dev/null @@ -1,30 +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/i32.h" - -#include "src/tint/ast/test_helper.h" - -namespace tint::ast { -namespace { - -using AstI32Test = TestHelper; - -TEST_F(AstI32Test, FriendlyName) { - auto* i = create(); - EXPECT_EQ(i->FriendlyName(Symbols()), "i32"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/matrix_test.cc b/src/tint/ast/matrix_test.cc index ff47494a74..5d582946bb 100644 --- a/src/tint/ast/matrix_test.cc +++ b/src/tint/ast/matrix_test.cc @@ -15,15 +15,11 @@ #include "src/tint/ast/matrix.h" #include "src/tint/ast/alias.h" #include "src/tint/ast/array.h" -#include "src/tint/ast/bool.h" -#include "src/tint/ast/f32.h" -#include "src/tint/ast/i32.h" #include "src/tint/ast/pointer.h" #include "src/tint/ast/sampler.h" #include "src/tint/ast/struct.h" #include "src/tint/ast/test_helper.h" #include "src/tint/ast/texture.h" -#include "src/tint/ast/u32.h" #include "src/tint/ast/vector.h" #include "src/tint/type/access.h" @@ -33,16 +29,15 @@ namespace { using AstMatrixTest = TestHelper; TEST_F(AstMatrixTest, Creation) { - auto* i32 = create(); - auto* m = create(i32, 2u, 4u); - EXPECT_EQ(m->type, i32); + 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* i32 = create(); - auto* m = create(i32, 3u, 2u); + auto* m = create(ty.i32(), 3u, 2u); EXPECT_EQ(m->FriendlyName(Symbols()), "mat2x3"); } diff --git a/src/tint/ast/multisampled_texture_test.cc b/src/tint/ast/multisampled_texture_test.cc index 8cb3b00b52..1bf018749d 100644 --- a/src/tint/ast/multisampled_texture_test.cc +++ b/src/tint/ast/multisampled_texture_test.cc @@ -16,10 +16,7 @@ #include "src/tint/ast/alias.h" #include "src/tint/ast/array.h" -#include "src/tint/ast/bool.h" #include "src/tint/ast/depth_texture.h" -#include "src/tint/ast/f32.h" -#include "src/tint/ast/i32.h" #include "src/tint/ast/matrix.h" #include "src/tint/ast/pointer.h" #include "src/tint/ast/sampled_texture.h" @@ -28,7 +25,6 @@ #include "src/tint/ast/struct.h" #include "src/tint/ast/test_helper.h" #include "src/tint/ast/texture.h" -#include "src/tint/ast/u32.h" #include "src/tint/ast/vector.h" #include "src/tint/type/access.h" @@ -38,29 +34,26 @@ namespace { using AstMultisampledTextureTest = TestHelper; TEST_F(AstMultisampledTextureTest, IsTexture) { - auto* f32 = create(); - Texture* ty = create(type::TextureDimension::kCube, f32); - EXPECT_FALSE(ty->Is()); - EXPECT_TRUE(ty->Is()); - EXPECT_FALSE(ty->Is()); - EXPECT_FALSE(ty->Is()); + Texture* t = create(type::TextureDimension::kCube, ty.f32()); + EXPECT_FALSE(t->Is()); + EXPECT_TRUE(t->Is()); + EXPECT_FALSE(t->Is()); + EXPECT_FALSE(t->Is()); } TEST_F(AstMultisampledTextureTest, Dim) { - auto* f32 = create(); - auto* s = create(type::TextureDimension::k3d, f32); + auto* s = create(type::TextureDimension::k3d, ty.f32()); EXPECT_EQ(s->dim, type::TextureDimension::k3d); } TEST_F(AstMultisampledTextureTest, Type) { - auto* f32 = create(); - auto* s = create(type::TextureDimension::k3d, f32); - EXPECT_EQ(s->type, f32); + 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* f32 = create(); - auto* s = create(type::TextureDimension::k3d, f32); + auto* s = create(type::TextureDimension::k3d, ty.f32()); EXPECT_EQ(s->FriendlyName(Symbols()), "texture_multisampled_3d"); } diff --git a/src/tint/ast/pointer_test.cc b/src/tint/ast/pointer_test.cc index 648d76797a..ad2ff157d2 100644 --- a/src/tint/ast/pointer_test.cc +++ b/src/tint/ast/pointer_test.cc @@ -14,7 +14,6 @@ #include "src/tint/ast/pointer.h" -#include "src/tint/ast/i32.h" #include "src/tint/ast/test_helper.h" namespace tint::ast { @@ -23,22 +22,20 @@ namespace { using AstPointerTest = TestHelper; TEST_F(AstPointerTest, Creation) { - auto* i32 = create(); - auto* p = create(i32, type::AddressSpace::kStorage, type::Access::kRead); - EXPECT_EQ(p->type, i32); + 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* i32 = create(); - auto* p = create(i32, type::AddressSpace::kWorkgroup, type::Access::kUndefined); + auto* p = create(ty.i32(), type::AddressSpace::kWorkgroup, type::Access::kUndefined); EXPECT_EQ(p->FriendlyName(Symbols()), "ptr"); } TEST_F(AstPointerTest, FriendlyNameWithAccess) { - auto* i32 = create(); - auto* p = create(i32, type::AddressSpace::kStorage, type::Access::kReadWrite); + auto* p = create(ty.i32(), type::AddressSpace::kStorage, type::Access::kReadWrite); EXPECT_EQ(p->FriendlyName(Symbols()), "ptr"); } diff --git a/src/tint/ast/sampled_texture_test.cc b/src/tint/ast/sampled_texture_test.cc index 4b42da7e8b..f377d68c23 100644 --- a/src/tint/ast/sampled_texture_test.cc +++ b/src/tint/ast/sampled_texture_test.cc @@ -14,7 +14,6 @@ #include "src/tint/ast/sampled_texture.h" -#include "src/tint/ast/f32.h" #include "src/tint/ast/test_helper.h" namespace tint::ast { @@ -23,28 +22,25 @@ namespace { using AstSampledTextureTest = TestHelper; TEST_F(AstSampledTextureTest, IsTexture) { - auto* f32 = create(); - Texture* ty = create(type::TextureDimension::kCube, f32); - EXPECT_FALSE(ty->Is()); - EXPECT_TRUE(ty->Is()); - EXPECT_FALSE(ty->Is()); + Texture* t = create(type::TextureDimension::kCube, ty.f32()); + EXPECT_FALSE(t->Is()); + EXPECT_TRUE(t->Is()); + EXPECT_FALSE(t->Is()); } TEST_F(AstSampledTextureTest, Dim) { - auto* f32 = create(); - auto* s = create(type::TextureDimension::k3d, f32); + auto* s = create(type::TextureDimension::k3d, ty.f32()); EXPECT_EQ(s->dim, type::TextureDimension::k3d); } TEST_F(AstSampledTextureTest, Type) { - auto* f32 = create(); - auto* s = create(type::TextureDimension::k3d, f32); - EXPECT_EQ(s->type, f32); + 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* f32 = create(); - auto* s = create(type::TextureDimension::k3d, f32); + auto* s = create(type::TextureDimension::k3d, ty.f32()); EXPECT_EQ(s->FriendlyName(Symbols()), "texture_3d"); } diff --git a/src/tint/ast/storage_texture.cc b/src/tint/ast/storage_texture.cc index d10733083e..cb2cee7cf7 100644 --- a/src/tint/ast/storage_texture.cc +++ b/src/tint/ast/storage_texture.cc @@ -14,9 +14,6 @@ #include "src/tint/ast/storage_texture.h" -#include "src/tint/ast/f32.h" -#include "src/tint/ast/i32.h" -#include "src/tint/ast/u32.h" #include "src/tint/program_builder.h" TINT_INSTANTIATE_TYPEINFO(tint::ast::StorageTexture); @@ -49,14 +46,14 @@ const StorageTexture* StorageTexture::Clone(CloneContext* ctx) const { return ctx->dst->create(src, dim, format, ty, access); } -Type* StorageTexture::SubtypeFor(type::TexelFormat format, ProgramBuilder& builder) { +const Type* StorageTexture::SubtypeFor(type::TexelFormat format, ProgramBuilder& builder) { switch (format) { case type::TexelFormat::kR32Uint: case type::TexelFormat::kRgba8Uint: case type::TexelFormat::kRg32Uint: case type::TexelFormat::kRgba16Uint: case type::TexelFormat::kRgba32Uint: { - return builder.create(); + return builder.ty.u32(); } case type::TexelFormat::kR32Sint: @@ -64,7 +61,7 @@ Type* StorageTexture::SubtypeFor(type::TexelFormat format, ProgramBuilder& build case type::TexelFormat::kRg32Sint: case type::TexelFormat::kRgba16Sint: case type::TexelFormat::kRgba32Sint: { - return builder.create(); + return builder.ty.i32(); } case type::TexelFormat::kBgra8Unorm: @@ -74,7 +71,7 @@ Type* StorageTexture::SubtypeFor(type::TexelFormat format, ProgramBuilder& build case type::TexelFormat::kRg32Float: case type::TexelFormat::kRgba16Float: case type::TexelFormat::kRgba32Float: { - return builder.create(); + return builder.ty.f32(); } case type::TexelFormat::kUndefined: diff --git a/src/tint/ast/storage_texture.h b/src/tint/ast/storage_texture.h index 0f602a04b7..646bca0524 100644 --- a/src/tint/ast/storage_texture.h +++ b/src/tint/ast/storage_texture.h @@ -59,8 +59,8 @@ class StorageTexture final : public Castable { /// @param format the storage texture image format /// @param builder the ProgramBuilder used to build the returned type - /// @returns the storage texture subtype for the given type::TexelFormat - static Type* SubtypeFor(type::TexelFormat format, ProgramBuilder& builder); + /// @returns the storage texture subtype for the given TexelFormat + static const Type* SubtypeFor(type::TexelFormat format, ProgramBuilder& builder); /// The image format const type::TexelFormat format; diff --git a/src/tint/ast/storage_texture_test.cc b/src/tint/ast/storage_texture_test.cc index 8bfd293029..1183fd9996 100644 --- a/src/tint/ast/storage_texture_test.cc +++ b/src/tint/ast/storage_texture_test.cc @@ -59,7 +59,9 @@ TEST_F(AstStorageTextureTest, F32) { ASSERT_TRUE(s->Is()); ASSERT_TRUE(s->Is()); - EXPECT_TRUE(s->As()->type->Is()); + ASSERT_TRUE(s->As()->type->Is()); + EXPECT_EQ(Symbols().NameFor(s->As()->type->As()->name->symbol), + "f32"); } TEST_F(AstStorageTextureTest, U32) { @@ -69,7 +71,9 @@ TEST_F(AstStorageTextureTest, U32) { ASSERT_TRUE(s->Is()); ASSERT_TRUE(s->Is()); - EXPECT_TRUE(s->As()->type->Is()); + ASSERT_TRUE(s->As()->type->Is()); + EXPECT_EQ(Symbols().NameFor(s->As()->type->As()->name->symbol), + "u32"); } TEST_F(AstStorageTextureTest, I32) { @@ -79,7 +83,9 @@ TEST_F(AstStorageTextureTest, I32) { ASSERT_TRUE(s->Is()); ASSERT_TRUE(s->Is()); - EXPECT_TRUE(s->As()->type->Is()); + ASSERT_TRUE(s->As()->type->Is()); + EXPECT_EQ(Symbols().NameFor(s->As()->type->As()->name->symbol), + "i32"); } } // namespace diff --git a/src/tint/ast/struct_member_test.cc b/src/tint/ast/struct_member_test.cc index 056d1906c1..d67b379b4c 100644 --- a/src/tint/ast/struct_member_test.cc +++ b/src/tint/ast/struct_member_test.cc @@ -23,8 +23,9 @@ using StructMemberTest = TestHelper; TEST_F(StructMemberTest, Creation) { auto* st = Member("a", ty.i32(), utils::Vector{MemberSize(4_a)}); - EXPECT_EQ(st->name->symbol, Symbol(1, ID())); - EXPECT_TRUE(st->type->Is()); + EXPECT_EQ(Symbols().NameFor(st->name->symbol), "a"); + ASSERT_TRUE(st->type->Is()); + EXPECT_EQ(Symbols().NameFor(st->type->As()->name->symbol), "i32"); EXPECT_EQ(st->attributes.Length(), 1u); EXPECT_TRUE(st->attributes[0]->Is()); EXPECT_EQ(st->source.range.begin.line, 0u); @@ -36,8 +37,9 @@ 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(st->name->symbol, Symbol(1, ID())); - EXPECT_TRUE(st->type->Is()); + EXPECT_EQ(Symbols().NameFor(st->name->symbol), "a"); + ASSERT_TRUE(st->type->Is()); + EXPECT_EQ(Symbols().NameFor(st->type->As()->name->symbol), "i32"); EXPECT_EQ(st->attributes.Length(), 0u); EXPECT_EQ(st->source.range.begin.line, 27u); EXPECT_EQ(st->source.range.begin.column, 4u); diff --git a/src/tint/ast/struct_test.cc b/src/tint/ast/struct_test.cc index b1f7293f72..ac73b035ad 100644 --- a/src/tint/ast/struct_test.cc +++ b/src/tint/ast/struct_test.cc @@ -16,15 +16,11 @@ #include "gtest/gtest-spi.h" #include "src/tint/ast/alias.h" #include "src/tint/ast/array.h" -#include "src/tint/ast/bool.h" -#include "src/tint/ast/f32.h" -#include "src/tint/ast/i32.h" #include "src/tint/ast/matrix.h" #include "src/tint/ast/pointer.h" #include "src/tint/ast/sampler.h" #include "src/tint/ast/test_helper.h" #include "src/tint/ast/texture.h" -#include "src/tint/ast/u32.h" #include "src/tint/ast/vector.h" #include "src/tint/transform/add_block_attribute.h" diff --git a/src/tint/ast/texture_test.cc b/src/tint/ast/texture_test.cc index cad2884007..9c1996311e 100644 --- a/src/tint/ast/texture_test.cc +++ b/src/tint/ast/texture_test.cc @@ -16,15 +16,11 @@ #include "src/tint/ast/alias.h" #include "src/tint/ast/array.h" -#include "src/tint/ast/bool.h" -#include "src/tint/ast/f32.h" -#include "src/tint/ast/i32.h" #include "src/tint/ast/matrix.h" #include "src/tint/ast/pointer.h" #include "src/tint/ast/sampler.h" #include "src/tint/ast/struct.h" #include "src/tint/ast/test_helper.h" -#include "src/tint/ast/u32.h" #include "src/tint/ast/vector.h" namespace tint::ast { diff --git a/src/tint/ast/type.cc b/src/tint/ast/type.cc index 768493f90a..cc6c4d8367 100644 --- a/src/tint/ast/type.cc +++ b/src/tint/ast/type.cc @@ -15,14 +15,10 @@ #include "src/tint/ast/type.h" #include "src/tint/ast/alias.h" -#include "src/tint/ast/bool.h" -#include "src/tint/ast/f32.h" -#include "src/tint/ast/i32.h" #include "src/tint/ast/matrix.h" #include "src/tint/ast/pointer.h" #include "src/tint/ast/sampler.h" #include "src/tint/ast/texture.h" -#include "src/tint/ast/u32.h" #include "src/tint/ast/vector.h" #include "src/tint/symbol_table.h" diff --git a/src/tint/ast/u32.cc b/src/tint/ast/u32.cc deleted file mode 100644 index c99dc4f284..0000000000 --- a/src/tint/ast/u32.cc +++ /dev/null @@ -1,38 +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/u32.h" - -#include "src/tint/program_builder.h" - -TINT_INSTANTIATE_TYPEINFO(tint::ast::U32); - -namespace tint::ast { - -U32::U32(ProgramID pid, NodeID nid, const Source& src) : Base(pid, nid, src) {} - -U32::~U32() = default; - -U32::U32(U32&&) = default; - -std::string U32::FriendlyName(const SymbolTable&) const { - return "u32"; -} - -const U32* U32::Clone(CloneContext* ctx) const { - auto src = ctx->Clone(source); - return ctx->dst->create(src); -} - -} // namespace tint::ast diff --git a/src/tint/ast/u32.h b/src/tint/ast/u32.h deleted file mode 100644 index 9237278de3..0000000000 --- a/src/tint/ast/u32.h +++ /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. - -#ifndef SRC_TINT_AST_U32_H_ -#define SRC_TINT_AST_U32_H_ - -#include - -#include "src/tint/ast/type.h" - -namespace tint::ast { - -/// A unsigned int 32 type. -class U32 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 - U32(ProgramID pid, NodeID nid, const Source& src); - /// Move constructor - U32(U32&&); - ~U32() 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 U32* Clone(CloneContext* ctx) const override; -}; - -} // namespace tint::ast - -#endif // SRC_TINT_AST_U32_H_ diff --git a/src/tint/ast/u32_test.cc b/src/tint/ast/u32_test.cc deleted file mode 100644 index a3a380b329..0000000000 --- a/src/tint/ast/u32_test.cc +++ /dev/null @@ -1,30 +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/u32.h" - -#include "src/tint/ast/test_helper.h" - -namespace tint::ast { -namespace { - -using AstU32Test = TestHelper; - -TEST_F(AstU32Test, FriendlyName) { - auto* u = create(); - EXPECT_EQ(u->FriendlyName(Symbols()), "u32"); -} - -} // namespace -} // namespace tint::ast diff --git a/src/tint/ast/variable_test.cc b/src/tint/ast/variable_test.cc index 05474c8f2b..29dc75452f 100644 --- a/src/tint/ast/variable_test.cc +++ b/src/tint/ast/variable_test.cc @@ -27,9 +27,10 @@ using VariableTest = TestHelper; TEST_F(VariableTest, Creation) { auto* v = Var("my_var", ty.i32(), type::AddressSpace::kFunction); - EXPECT_EQ(v->name->symbol, Symbol(1, ID())); + EXPECT_EQ(Symbols().NameFor(v->name->symbol), "my_var"); EXPECT_EQ(v->declared_address_space, type::AddressSpace::kFunction); - EXPECT_TRUE(v->type->Is()); + ASSERT_TRUE(v->type->Is()); + EXPECT_EQ(Symbols().NameFor(v->type->As()->name->symbol), "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); @@ -40,9 +41,10 @@ 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(v->name->symbol, Symbol(1, ID())); + EXPECT_EQ(Symbols().NameFor(v->name->symbol), "i"); EXPECT_EQ(v->declared_address_space, type::AddressSpace::kPrivate); - EXPECT_TRUE(v->type->Is()); + ASSERT_TRUE(v->type->Is()); + EXPECT_EQ(Symbols().NameFor(v->type->As()->name->symbol), "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); @@ -53,9 +55,10 @@ 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(v->name->symbol, Symbol(1, ID())); + EXPECT_EQ(Symbols().NameFor(v->name->symbol), "a_var"); EXPECT_EQ(v->declared_address_space, type::AddressSpace::kWorkgroup); - EXPECT_TRUE(v->type->Is()); + ASSERT_TRUE(v->type->Is()); + EXPECT_EQ(Symbols().NameFor(v->type->As()->name->symbol), "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_test.cc b/src/tint/ast/vector_test.cc index da2ad1f3de..81a00757dc 100644 --- a/src/tint/ast/vector_test.cc +++ b/src/tint/ast/vector_test.cc @@ -14,7 +14,6 @@ #include "src/tint/ast/vector.h" -#include "src/tint/ast/i32.h" #include "src/tint/ast/test_helper.h" namespace tint::ast { @@ -23,15 +22,14 @@ namespace { using AstVectorTest = TestHelper; TEST_F(AstVectorTest, Creation) { - auto* i32 = create(); - auto* v = create(i32, 2u); - EXPECT_EQ(v->type, i32); + 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* f32 = create(); - auto* v = create(f32, 3u); + auto* v = create(ty.f32(), 3u); EXPECT_EQ(v->FriendlyName(Symbols()), "vec3"); } diff --git a/src/tint/intrinsics.def b/src/tint/intrinsics.def index a5ed0c6922..d1b8cb3215 100644 --- a/src/tint/intrinsics.def +++ b/src/tint/intrinsics.def @@ -129,6 +129,12 @@ enum interpolation_sampling { } enum builtin_type { + // https://www.w3.org/TR/WGSL/#scalar-types + bool + f16 + f32 + i32 + u32 // https://www.w3.org/TR/WGSL/#matrix-types mat2x2f mat2x2h diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index 228be2ded1..116c5a9a74 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -28,7 +28,6 @@ #include "src/tint/ast/binary_expression.h" #include "src/tint/ast/binding_attribute.h" #include "src/tint/ast/bitcast_expression.h" -#include "src/tint/ast/bool.h" #include "src/tint/ast/bool_literal_expression.h" #include "src/tint/ast/break_if_statement.h" #include "src/tint/ast/break_statement.h" @@ -49,11 +48,8 @@ #include "src/tint/ast/enable.h" #include "src/tint/ast/extension.h" #include "src/tint/ast/external_texture.h" -#include "src/tint/ast/f16.h" -#include "src/tint/ast/f32.h" #include "src/tint/ast/float_literal_expression.h" #include "src/tint/ast/for_loop_statement.h" -#include "src/tint/ast/i32.h" #include "src/tint/ast/id_attribute.h" #include "src/tint/ast/identifier.h" #include "src/tint/ast/if_statement.h" @@ -84,7 +80,6 @@ #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/u32.h" #include "src/tint/ast/unary_op_expression.h" #include "src/tint/ast/var.h" #include "src/tint/ast/variable_decl_statement.h" @@ -569,50 +564,40 @@ class ProgramBuilder { /// @returns nullptr ast::Type const ast::Type* void_() const { return nullptr; } - /// @returns a boolean type - const ast::Bool* bool_() const { return builder->create(); } + /// @returns a 'bool' typename + const ast::TypeName* bool_() const { return (*this)("bool"); } /// @param source the Source of the node - /// @returns a boolean type - const ast::Bool* bool_(const Source& source) const { - return builder->create(source); - } + /// @returns a 'bool' typename + const ast::TypeName* bool_(const Source& source) const { return (*this)(source, "bool"); } - /// @returns a f16 type - const ast::F16* f16() const { return builder->create(); } + /// @returns a 'f16' typename + const ast::TypeName* f16() const { return (*this)("f16"); } /// @param source the Source of the node - /// @returns a f16 type - const ast::F16* f16(const Source& source) const { - return builder->create(source); - } + /// @returns a 'f16' typename + const ast::TypeName* f16(const Source& source) const { return (*this)(source, "f16"); } - /// @returns a f32 type - const ast::F32* f32() const { return builder->create(); } + /// @returns a 'f32' typename + const ast::TypeName* f32() const { return (*this)("f32"); } /// @param source the Source of the node - /// @returns a f32 type - const ast::F32* f32(const Source& source) const { - return builder->create(source); - } + /// @returns a 'f32' typename + const ast::TypeName* f32(const Source& source) const { return (*this)(source, "f32"); } - /// @returns a i32 type - const ast::I32* i32() const { return builder->create(); } + /// @returns a 'i32' typename + const ast::TypeName* i32() const { return (*this)("i32"); } /// @param source the Source of the node - /// @returns a i32 type - const ast::I32* i32(const Source& source) const { - return builder->create(source); - } + /// @returns a 'i32' typename + const ast::TypeName* i32(const Source& source) const { return (*this)(source, "i32"); } - /// @returns a u32 type - const ast::U32* u32() const { return builder->create(); } + /// @returns a 'u32' typename + const ast::TypeName* u32() const { return (*this)("u32"); } /// @param source the Source of the node - /// @returns a u32 type - const ast::U32* u32(const Source& source) const { - return builder->create(source); - } + /// @returns a 'u32' typename + const ast::TypeName* u32(const Source& source) const { return (*this)(source, "u32"); } /// @param type vector subtype /// @param n vector width in elements diff --git a/src/tint/reader/wgsl/parser_impl_callable_test.cc b/src/tint/reader/wgsl/parser_impl_callable_test.cc index f47dde0848..408a36f783 100644 --- a/src/tint/reader/wgsl/parser_impl_callable_test.cc +++ b/src/tint/reader/wgsl/parser_impl_callable_test.cc @@ -64,17 +64,6 @@ TEST_F(ParserImplTest, Callable_MatPrefix) { EXPECT_EQ(m->rows, 2u); } -TEST_F(ParserImplTest, Callable_TypeDecl_F32) { - auto p = parser("f32"); - auto t = p->callable(); - ASSERT_TRUE(p->peek_is(Token::Type::kEOF)); - EXPECT_TRUE(t.matched); - EXPECT_FALSE(t.errored); - ASSERT_FALSE(p->has_error()) << p->error(); - ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t.value->Is()); -} - TEST_F(ParserImplTest, Callable_TypeDecl_Array) { auto p = parser("array"); auto t = p->callable(); @@ -87,7 +76,9 @@ TEST_F(ParserImplTest, Callable_TypeDecl_Array) { auto* a = t.value->As(); EXPECT_FALSE(a->IsRuntimeArray()); - EXPECT_TRUE(a->type->Is()); + + 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); @@ -107,7 +98,9 @@ TEST_F(ParserImplTest, Callable_TypeDecl_Array_Runtime) { auto* a = t.value->As(); EXPECT_TRUE(a->IsRuntimeArray()); - EXPECT_TRUE(a->type->Is()); + + ASSERT_TRUE(a->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); ASSERT_EQ(a->count, nullptr); } @@ -123,7 +116,10 @@ TEST_F(ParserImplTest, Callable_TypeDecl_VecPrefix) { ASSERT_TRUE(t.value->Is()); auto* v = t.value->As(); - EXPECT_TRUE(v->type->Is()); + + ASSERT_TRUE(v->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As()->name->symbol), "f32"); + EXPECT_EQ(v->width, 3u); } @@ -138,7 +134,10 @@ TEST_F(ParserImplTest, Callable_TypeDecl_MatPrefix) { ASSERT_TRUE(t.value->Is()); auto* m = t.value->As(); - EXPECT_TRUE(m->type->Is()); + + 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); } 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 415cfa10ca..dad9b5564c 100644 --- a/src/tint/reader/wgsl/parser_impl_function_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_function_decl_test.cc @@ -239,7 +239,11 @@ TEST_F(ParserImplTest, FunctionDecl_ReturnTypeAttributeList) { EXPECT_EQ(f->name->symbol, p->builder().Symbols().Get("main")); ASSERT_NE(f->return_type, nullptr); - EXPECT_TRUE(f->return_type->Is()); + + ASSERT_TRUE(f->return_type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(f->return_type->As()->name->symbol), + "f32"); + ASSERT_EQ(f->params.Length(), 0u); auto& attributes = f->attributes; 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 6837e1f6bf..7007c98dd9 100644 --- a/src/tint/reader/wgsl/parser_impl_function_header_test.cc +++ b/src/tint/reader/wgsl/parser_impl_function_header_test.cc @@ -52,7 +52,9 @@ TEST_F(ParserImplTest, FunctionHeader_AttributeReturnType) { EXPECT_EQ(f->name, "main"); EXPECT_EQ(f->params.Length(), 0u); - EXPECT_TRUE(f->return_type->Is()); + ASSERT_TRUE(f->return_type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(f->return_type->As()->name->symbol), + "f32"); ASSERT_EQ(f->return_type_attributes.Length(), 1u); auto* loc = f->return_type_attributes[0]->As(); @@ -71,7 +73,9 @@ TEST_F(ParserImplTest, FunctionHeader_InvariantReturnType) { EXPECT_EQ(f->name, "main"); EXPECT_EQ(f->params.Length(), 0u); - EXPECT_TRUE(f->return_type->Is()); + ASSERT_TRUE(f->return_type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(f->return_type->As()->name->symbol), + "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 a86ba691bd..7bb7a6fe63 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 @@ -44,7 +44,8 @@ TEST_F(ParserImplTest, GlobalConstDecl) { EXPECT_EQ(c->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(c->type, nullptr); - EXPECT_TRUE(c->type->Is()); + ASSERT_TRUE(c->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(c->type->As()->name->symbol), "f32"); EXPECT_EQ(c->source.range.begin.line, 1u); EXPECT_EQ(c->source.range.begin.column, 7u); @@ -120,7 +121,9 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithId) { EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(override->type, nullptr); - EXPECT_TRUE(override->type->Is()); + ASSERT_TRUE(override->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(override->type->As()->name->symbol), + "f32"); EXPECT_EQ(override->source.range.begin.line, 1u); EXPECT_EQ(override->source.range.begin.column, 17u); @@ -150,7 +153,9 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithId_TrailingComma) { EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(override->type, nullptr); - EXPECT_TRUE(override->type->Is()); + ASSERT_TRUE(override->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(override->type->As()->name->symbol), + "f32"); EXPECT_EQ(override->source.range.begin.line, 1u); EXPECT_EQ(override->source.range.begin.column, 18u); @@ -180,7 +185,9 @@ TEST_F(ParserImplTest, GlobalOverrideDecl_WithoutId) { EXPECT_EQ(override->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(override->type, nullptr); - EXPECT_TRUE(override->type->Is()); + ASSERT_TRUE(override->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(override->type->As()->name->symbol), + "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_variable_decl_test.cc b/src/tint/reader/wgsl/parser_impl_global_variable_decl_test.cc index b00c9c56e5..867e7004de 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 @@ -30,7 +30,10 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithoutInitializer) { ASSERT_NE(var, nullptr); EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a")); - EXPECT_TRUE(var->type->Is()); + + ASSERT_TRUE(var->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(var->type->As()->name->symbol), "f32"); + EXPECT_EQ(var->declared_address_space, type::AddressSpace::kPrivate); EXPECT_EQ(var->source.range.begin.line, 1u); @@ -54,7 +57,10 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithInitializer) { ASSERT_NE(var, nullptr); EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a")); - EXPECT_TRUE(var->type->Is()); + + ASSERT_TRUE(var->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(var->type->As()->name->symbol), "f32"); + EXPECT_EQ(var->declared_address_space, type::AddressSpace::kPrivate); EXPECT_EQ(var->source.range.begin.line, 1u); @@ -80,7 +86,10 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute) { EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(var->type, nullptr); - EXPECT_TRUE(var->type->Is()); + + ASSERT_TRUE(var->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(var->type->As()->name->symbol), "f32"); + EXPECT_EQ(var->declared_address_space, type::AddressSpace::kUniform); EXPECT_EQ(var->source.range.begin.line, 1u); @@ -111,7 +120,10 @@ TEST_F(ParserImplTest, GlobalVariableDecl_WithAttribute_MulitpleGroups) { EXPECT_EQ(var->name->symbol, p->builder().Symbols().Get("a")); ASSERT_NE(var->type, nullptr); - EXPECT_TRUE(var->type->Is()); + + ASSERT_TRUE(var->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(var->type->As()->name->symbol), "f32"); + EXPECT_EQ(var->declared_address_space, type::AddressSpace::kUniform); EXPECT_EQ(var->source.range.begin.line, 1u); 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 7479935ba6..14d23631fb 100644 --- a/src/tint/reader/wgsl/parser_impl_param_list_test.cc +++ b/src/tint/reader/wgsl/parser_impl_param_list_test.cc @@ -26,7 +26,9 @@ TEST_F(ParserImplTest, ParamList_Single) { EXPECT_EQ(e.value.Length(), 1u); EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("a")); - EXPECT_TRUE(e.value[0]->type->Is()); + ASSERT_TRUE(e.value[0]->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(e.value[0]->type->As()->name->symbol), + "i32"); EXPECT_TRUE(e.value[0]->Is()); ASSERT_EQ(e.value[0]->source.range.begin.line, 1u); @@ -44,7 +46,9 @@ TEST_F(ParserImplTest, ParamList_Multiple) { EXPECT_EQ(e.value.Length(), 3u); EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("a")); - EXPECT_TRUE(e.value[0]->type->Is()); + ASSERT_TRUE(e.value[0]->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(e.value[0]->type->As()->name->symbol), + "i32"); EXPECT_TRUE(e.value[0]->Is()); ASSERT_EQ(e.value[0]->source.range.begin.line, 1u); @@ -53,7 +57,9 @@ 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")); - EXPECT_TRUE(e.value[1]->type->Is()); + ASSERT_TRUE(e.value[1]->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(e.value[1]->type->As()->name->symbol), + "f32"); EXPECT_TRUE(e.value[1]->Is()); ASSERT_EQ(e.value[1]->source.range.begin.line, 1u); @@ -63,7 +69,10 @@ TEST_F(ParserImplTest, ParamList_Multiple) { 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()); + 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); EXPECT_TRUE(e.value[2]->Is()); @@ -99,7 +108,10 @@ TEST_F(ParserImplTest, ParamList_Attributes) { EXPECT_EQ(e.value[0]->name->symbol, p->builder().Symbols().Get("coord")); ASSERT_TRUE(e.value[0]->type->Is()); - EXPECT_TRUE(e.value[0]->type->As()->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); EXPECT_TRUE(e.value[0]->Is()); auto attrs_0 = e.value[0]->attributes; @@ -113,7 +125,9 @@ 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")); - EXPECT_TRUE(e.value[1]->type->Is()); + ASSERT_TRUE(e.value[1]->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(e.value[1]->type->As()->name->symbol), + "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 1ced9dd083..517a7b697b 100644 --- a/src/tint/reader/wgsl/parser_impl_primary_expression_test.cc +++ b/src/tint/reader/wgsl/parser_impl_primary_expression_test.cc @@ -238,9 +238,11 @@ TEST_F(ParserImplTest, PrimaryExpression_Cast) { ASSERT_TRUE(e->Is()); auto* call = e->As(); - ASSERT_TRUE(call->target.type->Is()); - ASSERT_EQ(call->args.Length(), 1u); + auto* type_name = As(call->target.type); + ASSERT_NE(type_name, nullptr); + EXPECT_EQ(p->builder().Symbols().NameFor(type_name->name->symbol), "f32"); + ASSERT_EQ(call->args.Length(), 1u); ASSERT_TRUE(call->args[0]->Is()); } @@ -255,7 +257,10 @@ TEST_F(ParserImplTest, PrimaryExpression_Bitcast) { ASSERT_TRUE(e->Is()); auto* c = e->As(); - ASSERT_TRUE(c->type->Is()); + + ASSERT_TRUE(c->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(c->type->As()->name->symbol), "f32"); + ASSERT_TRUE(c->expr->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 6ed719238c..1ae5adf061 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 @@ -29,7 +29,8 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses) { const auto* mem = m.value[0]; EXPECT_EQ(mem->name->symbol, builder.Symbols().Get("a")); - EXPECT_TRUE(mem->type->Is()); + ASSERT_TRUE(mem->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(mem->type->As()->name->symbol), "i32"); EXPECT_EQ(mem->attributes.Length(), 0u); } @@ -45,7 +46,8 @@ TEST_F(ParserImplTest, StructBodyDecl_Parses_TrailingComma) { const auto* mem = m.value[0]; EXPECT_EQ(mem->name->symbol, builder.Symbols().Get("a")); - EXPECT_TRUE(mem->type->Is()); + ASSERT_TRUE(mem->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(mem->type->As()->name->symbol), "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 221190eb17..09f25b85fb 100644 --- a/src/tint/reader/wgsl/parser_impl_struct_member_test.cc +++ b/src/tint/reader/wgsl/parser_impl_struct_member_test.cc @@ -28,7 +28,8 @@ TEST_F(ParserImplTest, StructMember_Parses) { ASSERT_NE(m.value, nullptr); EXPECT_EQ(m->name->symbol, builder.Symbols().Get("a")); - EXPECT_TRUE(m->type->Is()); + ASSERT_TRUE(m->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As()->name->symbol), "i32"); EXPECT_EQ(m->attributes.Length(), 0u); EXPECT_EQ(m->source.range, (Source::Range{{1u, 1u}, {1u, 2u}})); @@ -46,7 +47,8 @@ TEST_F(ParserImplTest, StructMember_ParsesWithAlignAttribute) { ASSERT_NE(m.value, nullptr); EXPECT_EQ(m->name->symbol, builder.Symbols().Get("a")); - EXPECT_TRUE(m->type->Is()); + ASSERT_TRUE(m->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As()->name->symbol), "i32"); EXPECT_EQ(m->attributes.Length(), 1u); EXPECT_TRUE(m->attributes[0]->Is()); @@ -71,7 +73,8 @@ TEST_F(ParserImplTest, StructMember_ParsesWithSizeAttribute) { ASSERT_NE(m.value, nullptr); EXPECT_EQ(m->name->symbol, builder.Symbols().Get("a")); - EXPECT_TRUE(m->type->Is()); + ASSERT_TRUE(m->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As()->name->symbol), "i32"); EXPECT_EQ(m->attributes.Length(), 1u); ASSERT_TRUE(m->attributes[0]->Is()); auto* s = m->attributes[0]->As(); @@ -95,7 +98,8 @@ TEST_F(ParserImplTest, StructMember_ParsesWithMultipleattributes) { ASSERT_NE(m.value, nullptr); EXPECT_EQ(m->name->symbol, builder.Symbols().Get("a")); - EXPECT_TRUE(m->type->Is()); + ASSERT_TRUE(m->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(m->type->As()->name->symbol), "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_test_helper.h b/src/tint/reader/wgsl/parser_impl_test_helper.h index 1b140399fe..e30fa15994 100644 --- a/src/tint/reader/wgsl/parser_impl_test_helper.h +++ b/src/tint/reader/wgsl/parser_impl_test_helper.h @@ -26,7 +26,7 @@ namespace tint::reader::wgsl { /// WGSL Parser test class -class ParserImplTest : public testing::Test, public ProgramBuilder { +class ParserImplTest : public testing::Test { public: /// Constructor ParserImplTest(); 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 7b051d3274..636e539732 100644 --- a/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc +++ b/src/tint/reader/wgsl/parser_impl_texture_sampler_test.cc @@ -74,9 +74,11 @@ 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->Is()); - ASSERT_TRUE(t->As()->type->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}})); } @@ -88,9 +90,11 @@ 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->Is()); - ASSERT_TRUE(t->As()->type->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}})); } @@ -102,9 +106,10 @@ TEST_F(ParserImplTest, TextureSamplerTypes_SampledTexture_U32) { EXPECT_TRUE(t.matched); EXPECT_FALSE(t.errored); ASSERT_NE(t.value, nullptr); - ASSERT_TRUE(t->Is()); ASSERT_TRUE(t->Is()); - ASSERT_TRUE(t->As()->type->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}})); } @@ -146,9 +151,11 @@ 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->Is()); - ASSERT_TRUE(t->As()->type->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}})); } 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 f6b0860dc1..de85b2ca88 100644 --- a/src/tint/reader/wgsl/parser_impl_type_alias_test.cc +++ b/src/tint/reader/wgsl/parser_impl_type_alias_test.cc @@ -27,8 +27,9 @@ TEST_F(ParserImplTest, TypeDecl_ParsesType) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t->Is()); auto* alias = t->As(); - ASSERT_TRUE(alias->type->Is()); - + ASSERT_TRUE(alias->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(alias->type->As()->name->symbol), + "i32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 13u}})); } @@ -62,7 +63,9 @@ TEST_F(ParserImplTest, TypeDecl_Unicode_Parses_Ident) { ASSERT_TRUE(t.value->Is()); auto* alias = t.value->As(); EXPECT_EQ(p->builder().Symbols().NameFor(alias->name->symbol), ident); - EXPECT_TRUE(alias->type->Is()); + ASSERT_TRUE(alias->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(alias->type->As()->name->symbol), + "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 4d9fb9eafd..373f9b7d7e 100644 --- a/src/tint/reader/wgsl/parser_impl_type_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_type_decl_test.cc @@ -51,7 +51,8 @@ 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()); + ASSERT_TRUE(t.value->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "bool"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 5u}})); } @@ -62,7 +63,8 @@ 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()); + ASSERT_TRUE(t.value->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "f16"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -73,7 +75,8 @@ 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()); + ASSERT_TRUE(t.value->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "f32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -84,7 +87,8 @@ 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()); + ASSERT_TRUE(t.value->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "i32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -95,7 +99,8 @@ 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()); + ASSERT_TRUE(t.value->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "u32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -175,7 +180,8 @@ TEST_F(ParserImplTest, TypeDecl_Ptr) { ASSERT_TRUE(t.value->Is()); auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type->Is()); + 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); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); } @@ -190,7 +196,8 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_WithAccess) { ASSERT_TRUE(t.value->Is()); auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type->Is()); + 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); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25u}})); @@ -211,7 +218,8 @@ TEST_F(ParserImplTest, TypeDecl_Ptr_ToVec) { auto* vec = ptr->type->As(); ASSERT_EQ(vec->width, 2u); - ASSERT_TRUE(vec->type->Is()); + 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}})); } @@ -342,7 +350,9 @@ TEST_F(ParserImplTest, TypeDecl_Atomic) { ASSERT_TRUE(t.value->Is()); auto* atomic = t.value->As(); - ASSERT_TRUE(atomic->type->Is()); + ASSERT_TRUE(atomic->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(atomic->type->As()->name->symbol), + "f32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 12u}})); } @@ -360,7 +370,8 @@ TEST_F(ParserImplTest, TypeDecl_Atomic_ToVec) { auto* vec = atomic->type->As(); ASSERT_EQ(vec->width, 2u); - ASSERT_TRUE(vec->type->Is()); + 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, 18u}})); } @@ -405,7 +416,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_AbstractIntLiteralSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); + 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}})); @@ -426,7 +438,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_SintLiteralSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); + 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}})); @@ -447,7 +460,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_UintLiteralSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); + 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}})); @@ -467,7 +481,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_ConstantSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); + 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}})); @@ -487,7 +502,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_ExpressionSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); + ASSERT_TRUE(a->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); EXPECT_EQ(a->attributes.Length(), 0u); ASSERT_TRUE(a->count->Is()); @@ -514,7 +530,8 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime) { auto* a = t.value->As(); ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); + ASSERT_TRUE(a->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "u32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 11u}})); } @@ -531,7 +548,10 @@ TEST_F(ParserImplTest, TypeDecl_Array_Runtime_Vec) { ASSERT_TRUE(a->IsRuntimeArray()); ASSERT_TRUE(a->type->Is()); EXPECT_EQ(a->type->As()->width, 4u); - EXPECT_TRUE(a->type->As()->type->Is()); + ASSERT_TRUE(a->type->As()->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor( + a->type->As()->type->As()->name->symbol), + "u32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); } @@ -683,7 +703,11 @@ TEST_F(ParserImplTest, TypeDecl_Texture) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t.value->Is()); ASSERT_TRUE(t.value->Is()); - ASSERT_TRUE(t.value->As()->type->Is()); + ASSERT_TRUE(t.value->As()->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor( + t.value->As()->type->As()->name->symbol), + "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 0c9eb6e24f..f3cec74732 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 @@ -46,7 +46,8 @@ 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()); + ASSERT_TRUE(t.value->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "bool"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 5u}})); } @@ -56,7 +57,8 @@ 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()); + ASSERT_TRUE(t.value->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "f16"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -66,7 +68,8 @@ 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()); + ASSERT_TRUE(t.value->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "f32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -76,7 +79,8 @@ 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()); + ASSERT_TRUE(t.value->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "i32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -86,7 +90,8 @@ 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()); + ASSERT_TRUE(t.value->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(t.value->As()->name->symbol), "u32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 4u}})); } @@ -166,7 +171,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr) { ASSERT_TRUE(t.value->Is()); auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type->Is()); + 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); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 19u}})); } @@ -181,7 +187,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_WithAccess) { ASSERT_TRUE(t.value->Is()); auto* ptr = t.value->As(); - ASSERT_TRUE(ptr->type->Is()); + 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); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 25u}})); @@ -202,7 +209,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Ptr_ToVec) { auto* vec = ptr->type->As(); ASSERT_EQ(vec->width, 2u); - ASSERT_TRUE(vec->type->Is()); + 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}})); } @@ -333,7 +341,9 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Atomic) { ASSERT_TRUE(t.value->Is()); auto* atomic = t.value->As(); - ASSERT_TRUE(atomic->type->Is()); + ASSERT_TRUE(atomic->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(atomic->type->As()->name->symbol), + "f32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 12u}})); } @@ -351,7 +361,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Atomic_ToVec) { auto* vec = atomic->type->As(); ASSERT_EQ(vec->width, 2u); - ASSERT_TRUE(vec->type->Is()); + 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, 18u}})); } @@ -396,7 +407,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_AbstractIntLiteralSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); + 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}})); @@ -417,7 +429,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_SintLiteralSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); + 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}})); @@ -438,7 +451,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_UintLiteralSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); + 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}})); @@ -458,7 +472,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_ConstantSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); + 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}})); @@ -478,7 +493,8 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_ExpressionSize) { auto* a = t.value->As(); ASSERT_FALSE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); + ASSERT_TRUE(a->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "f32"); EXPECT_EQ(a->attributes.Length(), 0u); ASSERT_TRUE(a->count->Is()); @@ -505,7 +521,9 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_Runtime) { auto* a = t.value->As(); ASSERT_TRUE(a->IsRuntimeArray()); - ASSERT_TRUE(a->type->Is()); + + ASSERT_TRUE(a->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(a->type->As()->name->symbol), "u32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 11u}})); } @@ -522,7 +540,10 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Array_Runtime_Vec) { ASSERT_TRUE(a->IsRuntimeArray()); ASSERT_TRUE(a->type->Is()); EXPECT_EQ(a->type->As()->width, 4u); - EXPECT_TRUE(a->type->As()->type->Is()); + ASSERT_TRUE(a->type->As()->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor( + a->type->As()->type->As()->name->symbol), + "u32"); EXPECT_EQ(t.value->source.range, (Source::Range{{1u, 1u}, {1u, 17u}})); } @@ -675,7 +696,10 @@ TEST_F(ParserImplTest, TypeDeclWithoutIdent_Texture) { ASSERT_NE(t.value, nullptr); ASSERT_TRUE(t.value->Is()); ASSERT_TRUE(t.value->Is()); - ASSERT_TRUE(t.value->As()->type->Is()); + ASSERT_TRUE(t.value->As()->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor( + t.value->As()->type->As()->name->symbol), + "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 7e2920304b..13f900541f 100644 --- a/src/tint/reader/wgsl/parser_impl_variable_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_variable_decl_test.cc @@ -24,7 +24,9 @@ TEST_F(ParserImplTest, VariableDecl_Parses) { EXPECT_FALSE(v.errored); EXPECT_EQ(v->name, "my_var"); EXPECT_NE(v->type, nullptr); - EXPECT_TRUE(v->type->Is()); + + ASSERT_TRUE(v->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As()->name->symbol), "f32"); EXPECT_EQ(v->source.range, (Source::Range{{1u, 5u}, {1u, 11u}})); EXPECT_EQ(v->type->source.range, (Source::Range{{1u, 14u}, {1u, 17u}})); @@ -43,7 +45,9 @@ TEST_F(ParserImplTest, VariableDecl_Unicode_Parses) { EXPECT_FALSE(v.errored); EXPECT_EQ(v->name, ident); EXPECT_NE(v->type, nullptr); - EXPECT_TRUE(v->type->Is()); + + ASSERT_TRUE(v->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As()->name->symbol), "f32"); EXPECT_EQ(v->source.range, (Source::Range{{1u, 5u}, {1u, 48u}})); EXPECT_EQ(v->type->source.range, (Source::Range{{1u, 51u}, {1u, 54u}})); @@ -79,7 +83,10 @@ TEST_F(ParserImplTest, VariableDecl_WithAddressSpace) { EXPECT_FALSE(v.errored); EXPECT_FALSE(p->has_error()); EXPECT_EQ(v->name, "my_var"); - EXPECT_TRUE(v->type->Is()); + + ASSERT_TRUE(v->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As()->name->symbol), "f32"); + EXPECT_EQ(v->address_space, type::AddressSpace::kPrivate); EXPECT_EQ(v->source.range.begin.line, 1u); @@ -95,7 +102,10 @@ TEST_F(ParserImplTest, VariableDecl_WithPushConstant) { EXPECT_FALSE(v.errored); EXPECT_FALSE(p->has_error()); EXPECT_EQ(v->name, "my_var"); - EXPECT_TRUE(v->type->Is()); + + ASSERT_TRUE(v->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(v->type->As()->name->symbol), "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 57bcf19798..373eb75df1 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 @@ -24,7 +24,8 @@ 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()); + ASSERT_TRUE(decl->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(decl->type->As()->name->symbol), "f32"); EXPECT_EQ(decl->source.range, (Source::Range{{1u, 1u}, {1u, 7u}})); EXPECT_EQ(decl->type->source.range, (Source::Range{{1u, 10u}, {1u, 13u}})); @@ -37,7 +38,8 @@ 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()); + ASSERT_TRUE(decl->type->Is()); + EXPECT_EQ(p->builder().Symbols().NameFor(decl->type->As()->name->symbol), "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/resolver/dependency_graph.cc b/src/tint/resolver/dependency_graph.cc index 61bb760ac7..d9c3038216 100644 --- a/src/tint/resolver/dependency_graph.cc +++ b/src/tint/resolver/dependency_graph.cc @@ -23,7 +23,6 @@ #include "src/tint/ast/assignment_statement.h" #include "src/tint/ast/atomic.h" #include "src/tint/ast/block_statement.h" -#include "src/tint/ast/bool.h" #include "src/tint/ast/break_if_statement.h" #include "src/tint/ast/break_statement.h" #include "src/tint/ast/call_statement.h" @@ -35,10 +34,7 @@ #include "src/tint/ast/diagnostic_attribute.h" #include "src/tint/ast/discard_statement.h" #include "src/tint/ast/external_texture.h" -#include "src/tint/ast/f16.h" -#include "src/tint/ast/f32.h" #include "src/tint/ast/for_loop_statement.h" -#include "src/tint/ast/i32.h" #include "src/tint/ast/id_attribute.h" #include "src/tint/ast/identifier.h" #include "src/tint/ast/if_statement.h" @@ -66,7 +62,6 @@ #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/u32.h" #include "src/tint/ast/var.h" #include "src/tint/ast/variable_decl_statement.h" #include "src/tint/ast/vector.h" @@ -407,10 +402,12 @@ class DependencyScanner { [&](const ast::MultisampledTexture* tex) { // TraverseType(tex->type); }, + [&](const ast::StorageTexture* tex) { // + TraverseType(tex->type); + }, [&](Default) { - if (!ty->IsAnyOf()) { + if (!ty->IsAnyOf()) { UnhandledNode(diagnostics_, ty); } }); diff --git a/src/tint/resolver/dependency_graph_test.cc b/src/tint/resolver/dependency_graph_test.cc index 2953ade020..7a98b2f40e 100644 --- a/src/tint/resolver/dependency_graph_test.cc +++ b/src/tint/resolver/dependency_graph_test.cc @@ -1264,11 +1264,13 @@ TEST_P(ResolverDependencyGraphResolveToBuiltinType, Resolve) { TEST_P(ResolverDependencyGraphResolveToBuiltinType, ShadowedByGlobalVar) { const auto use = std::get<0>(GetParam()); - const auto name = std::get<1>(GetParam()); + const std::string name = std::get<1>(GetParam()); const auto symbol = Symbols().New(name); + auto* decl = + GlobalVar(symbol, name == "i32" ? ty.u32() : ty.i32(), type::AddressSpace::kPrivate); + SymbolTestHelper helper(this); - auto* decl = helper.Add(SymbolDeclKind::GlobalVar, symbol); auto* ident = helper.Add(use, symbol); helper.Build(); @@ -1279,11 +1281,14 @@ TEST_P(ResolverDependencyGraphResolveToBuiltinType, ShadowedByGlobalVar) { TEST_P(ResolverDependencyGraphResolveToBuiltinType, ShadowedByStruct) { const auto use = std::get<0>(GetParam()); - const auto name = std::get<1>(GetParam()); + const std::string name = std::get<1>(GetParam()); const auto symbol = Symbols().New(name); + auto* decl = Structure(symbol, utils::Vector{ + Member("m", name == "i32" ? ty.u32() : ty.i32()), + }); + SymbolTestHelper helper(this); - auto* decl = helper.Add(SymbolDeclKind::Struct, symbol); auto* ident = helper.Add(use, symbol); helper.Build(); @@ -1734,7 +1739,7 @@ TEST_F(ResolverDependencyGraphTraversalTest, SymbolsReached) { GlobalVar(Sym(), ty.external_texture()); GlobalVar(Sym(), ty.multisampled_texture(type::TextureDimension::k2d, T)); GlobalVar(Sym(), ty.storage_texture(type::TextureDimension::k2d, type::TexelFormat::kR32Float, - type::Access::kRead)); // + type::Access::kRead)); GlobalVar(Sym(), ty.sampler(type::SamplerKind::kSampler)); GlobalVar(Sym(), ty.i32(), utils::Vector{Binding(V), Group(V)}); diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 047757c22b..538d1513ce 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -227,13 +227,6 @@ type::Type* Resolver::Type(const ast::Type* ty) { Mark(ty); auto* s = Switch( ty, // - [&](const ast::Bool*) { return builder_->create(); }, - [&](const ast::I32*) { return builder_->create(); }, - [&](const ast::U32*) { return builder_->create(); }, - [&](const ast::F16* t) -> type::F16* { - return validator_.CheckF16Enabled(t->source) ? builder_->create() : nullptr; - }, - [&](const ast::F32*) { return builder_->create(); }, [&](const ast::Vector* t) -> type::Vector* { if (!t->type) { AddError("missing vector element type", t->source.End()); @@ -2447,88 +2440,91 @@ sem::Call* Resolver::BuiltinCall(const ast::CallExpression* expr, type::Type* Resolver::BuiltinType(type::Builtin builtin_ty, const ast::Identifier* ident) const { auto& b = *builder_; - auto vec_f32 = [&](uint32_t n) { return b.create(b.create(), n); }; - auto vec_f16 = [&](uint32_t n) { return b.create(b.create(), n); }; + + auto f32 = [&] { return b.create(); }; + auto i32 = [&] { return b.create(); }; + auto u32 = [&] { return b.create(); }; + 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; + }; switch (builtin_ty) { + case type::Builtin::kBool: + return b.create(); + case type::Builtin::kI32: + return i32(); + case type::Builtin::kU32: + return u32(); + case type::Builtin::kF16: + return f16(); + case type::Builtin::kF32: + return b.create(); case type::Builtin::kMat2X2F: - return b.create(vec_f32(2u), 2u); + return mat(f32(), 2u, 2u); case type::Builtin::kMat2X3F: - return b.create(vec_f32(3u), 2u); + return mat(f32(), 2u, 3u); case type::Builtin::kMat2X4F: - return b.create(vec_f32(4u), 2u); + return mat(f32(), 2u, 4u); case type::Builtin::kMat3X2F: - return b.create(vec_f32(2u), 3u); + return mat(f32(), 3u, 2u); case type::Builtin::kMat3X3F: - return b.create(vec_f32(3u), 3u); + return mat(f32(), 3u, 3u); case type::Builtin::kMat3X4F: - return b.create(vec_f32(4u), 3u); + return mat(f32(), 3u, 4u); case type::Builtin::kMat4X2F: - return b.create(vec_f32(2u), 4u); + return mat(f32(), 4u, 2u); case type::Builtin::kMat4X3F: - return b.create(vec_f32(3u), 4u); + return mat(f32(), 4u, 3u); case type::Builtin::kMat4X4F: - return b.create(vec_f32(4u), 4u); + return mat(f32(), 4u, 4u); case type::Builtin::kMat2X2H: - return validator_.CheckF16Enabled(ident->source) - ? b.create(vec_f16(2u), 2u) - : nullptr; + return mat(f16(), 2u, 2u); case type::Builtin::kMat2X3H: - return validator_.CheckF16Enabled(ident->source) - ? b.create(vec_f16(3u), 2u) - : nullptr; + return mat(f16(), 2u, 3u); case type::Builtin::kMat2X4H: - return validator_.CheckF16Enabled(ident->source) - ? b.create(vec_f16(4u), 2u) - : nullptr; + return mat(f16(), 2u, 4u); case type::Builtin::kMat3X2H: - return validator_.CheckF16Enabled(ident->source) - ? b.create(vec_f16(2u), 3u) - : nullptr; + return mat(f16(), 3u, 2u); case type::Builtin::kMat3X3H: - return validator_.CheckF16Enabled(ident->source) - ? b.create(vec_f16(3u), 3u) - : nullptr; + return mat(f16(), 3u, 3u); case type::Builtin::kMat3X4H: - return validator_.CheckF16Enabled(ident->source) - ? b.create(vec_f16(4u), 3u) - : nullptr; + return mat(f16(), 3u, 4u); case type::Builtin::kMat4X2H: - return validator_.CheckF16Enabled(ident->source) - ? b.create(vec_f16(2u), 4u) - : nullptr; + return mat(f16(), 4u, 2u); case type::Builtin::kMat4X3H: - return validator_.CheckF16Enabled(ident->source) - ? b.create(vec_f16(3u), 4u) - : nullptr; + return mat(f16(), 4u, 3u); case type::Builtin::kMat4X4H: - return validator_.CheckF16Enabled(ident->source) - ? b.create(vec_f16(4u), 4u) - : nullptr; + return mat(f16(), 4u, 4u); case type::Builtin::kVec2F: - return vec_f32(2u); + return vec(f32(), 2u); case type::Builtin::kVec3F: - return vec_f32(3u); + return vec(f32(), 3u); case type::Builtin::kVec4F: - return vec_f32(4u); + return vec(f32(), 4u); case type::Builtin::kVec2H: - return validator_.CheckF16Enabled(ident->source) ? vec_f16(2u) : nullptr; + return vec(f16(), 2u); case type::Builtin::kVec3H: - return validator_.CheckF16Enabled(ident->source) ? vec_f16(3u) : nullptr; + return vec(f16(), 3u); case type::Builtin::kVec4H: - return validator_.CheckF16Enabled(ident->source) ? vec_f16(4u) : nullptr; + return vec(f16(), 4u); case type::Builtin::kVec2I: - return b.create(b.create(), 2u); + return vec(i32(), 2u); case type::Builtin::kVec3I: - return b.create(b.create(), 3u); + return vec(i32(), 3u); case type::Builtin::kVec4I: - return b.create(b.create(), 4u); + return vec(i32(), 4u); case type::Builtin::kVec2U: - return b.create(b.create(), 2u); + return vec(u32(), 2u); case type::Builtin::kVec3U: - return b.create(b.create(), 3u); + return vec(u32(), 3u); case type::Builtin::kVec4U: - return b.create(b.create(), 4u); + return vec(u32(), 4u); case type::Builtin::kUndefined: break; } diff --git a/src/tint/transform/combine_samplers.cc b/src/tint/transform/combine_samplers.cc index 284496ab21..c3593efdda 100644 --- a/src/tint/transform/combine_samplers.cc +++ b/src/tint/transform/combine_samplers.cc @@ -143,7 +143,7 @@ struct CombineSamplers::State { 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->create()); + return ctx.dst->create(depth->dim(), ctx.dst->ty.f32()); } else { return CreateASTTypeFor(ctx, texture_type); } diff --git a/src/tint/transform/transform.cc b/src/tint/transform/transform.cc index 78b5373b75..ebf72aaa41 100644 --- a/src/tint/transform/transform.cc +++ b/src/tint/transform/transform.cc @@ -78,19 +78,19 @@ const ast::Type* Transform::CreateASTTypeFor(CloneContext& ctx, const type::Type return nullptr; } if (ty->Is()) { - return ctx.dst->create(); + return ctx.dst->ty.i32(); } if (ty->Is()) { - return ctx.dst->create(); + return ctx.dst->ty.u32(); } if (ty->Is()) { - return ctx.dst->create(); + return ctx.dst->ty.f16(); } if (ty->Is()) { - return ctx.dst->create(); + return ctx.dst->ty.f32(); } if (ty->Is()) { - return ctx.dst->create(); + return ctx.dst->ty.bool_(); } if (auto* m = ty->As()) { auto* el = CreateASTTypeFor(ctx, m->type()); diff --git a/src/tint/transform/transform_test.cc b/src/tint/transform/transform_test.cc index 66be7c6afc..6d97614e78 100644 --- a/src/tint/transform/transform_test.cc +++ b/src/tint/transform/transform_test.cc @@ -12,9 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/tint/transform/transform.h" +#include + #include "src/tint/clone_context.h" #include "src/tint/program_builder.h" +#include "src/tint/transform/transform.h" #include "gtest/gtest.h" @@ -37,14 +39,21 @@ 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_TRUE(create([](ProgramBuilder& b) { return b.create(); })->Is()); - EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create(); })->Is()); - EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create(); })->Is()); - EXPECT_TRUE(create([](ProgramBuilder& b) { return b.create(); })->Is()); + 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"); EXPECT_EQ(create([](ProgramBuilder& b) { return b.create(); }), nullptr); } @@ -54,7 +63,7 @@ TEST_F(CreateASTTypeForTest, Matrix) { return b.create(column_type, 3u); }); ASSERT_TRUE(mat->Is()); - ASSERT_TRUE(mat->As()->type->Is()); + EXPECT_EQ(TypeNameOf(mat->As()->type), "f32"); ASSERT_EQ(mat->As()->columns, 3u); ASSERT_EQ(mat->As()->rows, 2u); } @@ -63,7 +72,7 @@ TEST_F(CreateASTTypeForTest, Vector) { auto* vec = create([](ProgramBuilder& b) { return b.create(b.create(), 2u); }); ASSERT_TRUE(vec->Is()); - ASSERT_TRUE(vec->As()->type->Is()); + EXPECT_EQ(TypeNameOf(vec->As()->type), "f32"); ASSERT_EQ(vec->As()->width, 2u); } @@ -73,7 +82,7 @@ TEST_F(CreateASTTypeForTest, ArrayImplicitStride) { 4u, 4u, 32u, 32u); }); ASSERT_TRUE(arr->Is()); - ASSERT_TRUE(arr->As()->type->Is()); + EXPECT_EQ(TypeNameOf(arr->As()->type), "f32"); ASSERT_EQ(arr->As()->attributes.Length(), 0u); auto* size = arr->As()->count->As(); @@ -87,7 +96,7 @@ TEST_F(CreateASTTypeForTest, ArrayNonImplicitStride) { 4u, 4u, 64u, 32u); }); ASSERT_TRUE(arr->Is()); - ASSERT_TRUE(arr->As()->type->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); diff --git a/src/tint/type/builtin.cc b/src/tint/type/builtin.cc index 40c7c4c963..30409ca882 100644 --- a/src/tint/type/builtin.cc +++ b/src/tint/type/builtin.cc @@ -28,6 +28,18 @@ 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 == "bool") { + return Builtin::kBool; + } + if (str == "f16") { + return Builtin::kF16; + } + if (str == "f32") { + return Builtin::kF32; + } + if (str == "i32") { + return Builtin::kI32; + } if (str == "mat2x2f") { return Builtin::kMat2X2F; } @@ -82,6 +94,9 @@ Builtin ParseBuiltin(std::string_view str) { if (str == "mat4x4h") { return Builtin::kMat4X4H; } + if (str == "u32") { + return Builtin::kU32; + } if (str == "vec2f") { return Builtin::kVec2F; } @@ -125,6 +140,14 @@ std::ostream& operator<<(std::ostream& out, Builtin value) { switch (value) { case Builtin::kUndefined: return out << "undefined"; + case Builtin::kBool: + return out << "bool"; + case Builtin::kF16: + return out << "f16"; + case Builtin::kF32: + return out << "f32"; + case Builtin::kI32: + return out << "i32"; case Builtin::kMat2X2F: return out << "mat2x2f"; case Builtin::kMat2X2H: @@ -161,6 +184,8 @@ std::ostream& operator<<(std::ostream& out, Builtin value) { return out << "mat4x4f"; case Builtin::kMat4X4H: return out << "mat4x4h"; + case Builtin::kU32: + return out << "u32"; case Builtin::kVec2F: return out << "vec2f"; case Builtin::kVec2H: diff --git a/src/tint/type/builtin.h b/src/tint/type/builtin.h index f9d89f7617..df3e9da7f5 100644 --- a/src/tint/type/builtin.h +++ b/src/tint/type/builtin.h @@ -30,6 +30,10 @@ namespace tint::type { /// An enumerator of builtin types. enum class Builtin { kUndefined, + kBool, + kF16, + kF32, + kI32, kMat2X2F, kMat2X2H, kMat2X3F, @@ -48,6 +52,7 @@ enum class Builtin { kMat4X3H, kMat4X4F, kMat4X4H, + kU32, kVec2F, kVec2H, kVec2I, @@ -73,10 +78,11 @@ std::ostream& operator<<(std::ostream& out, Builtin value); Builtin ParseBuiltin(std::string_view str); constexpr const char* kBuiltinStrings[] = { - "mat2x2f", "mat2x2h", "mat2x3f", "mat2x3h", "mat2x4f", "mat2x4h", "mat3x2f", "mat3x2h", - "mat3x3f", "mat3x3h", "mat3x4f", "mat3x4h", "mat4x2f", "mat4x2h", "mat4x3f", "mat4x3h", - "mat4x4f", "mat4x4h", "vec2f", "vec2h", "vec2i", "vec2u", "vec3f", "vec3h", - "vec3i", "vec3u", "vec4f", "vec4h", "vec4i", "vec4u", + "bool", "f16", "f32", "i32", "mat2x2f", "mat2x2h", "mat2x3f", + "mat2x3h", "mat2x4f", "mat2x4h", "mat3x2f", "mat3x2h", "mat3x3f", "mat3x3h", + "mat3x4f", "mat3x4h", "mat4x2f", "mat4x2h", "mat4x3f", "mat4x3h", "mat4x4f", + "mat4x4h", "u32", "vec2f", "vec2h", "vec2i", "vec2u", "vec3f", + "vec3h", "vec3i", "vec3u", "vec4f", "vec4h", "vec4i", "vec4u", }; } // namespace tint::type diff --git a/src/tint/type/builtin_bench.cc b/src/tint/type/builtin_bench.cc index 9661d285b9..d515e5df9a 100644 --- a/src/tint/type/builtin_bench.cc +++ b/src/tint/type/builtin_bench.cc @@ -31,41 +31,47 @@ namespace { void BuiltinParser(::benchmark::State& state) { std::array kStrings{ - "at2x2cc", "l23f", "matVx2f", "mat2x2f", "mat212f", "mqtJx2f", - "mat2x27ll", "ppqqt22HH", "macv", "bt2xGh", "mat2x2h", "mat2iivh", - "8WWt2x2h", "mxx2x2h", "mX2x3gg", "a2xXf", "mat233f", "mat2x3f", - "Eat2x3f", "mPTT2x3f", "mat2xdxx", "m44t2x3h", "maSS2xVVh", "RatR22h", - "mat2x3h", "mF2x9h", "matx3h", "VOORRH3h", "ma2xyf", "llnarr2774f", - "mat24400", "mat2x4f", "a2oof", "zz2x4f", "miitppx1", "mat2xXXh", - "9II5ann2x4h", "mataSSrHHYh", "mat2x4h", "makkh", "jatgRx", "mb2x4", - "mat3xjf", "at3x2f", "q3x2f", "mat3x2f", "matNN2f", "at32vv", - "QQt3x2f", "maffxr", "mat3xjh", "mNNw3x28", "mat3x2h", "matx2h", - "mrrt3x2h", "Gat3x2h", "mat3x3FF", "at3f", "marrx3f", "mat3x3f", - "t3x3f", "Da3xJJf", "ma83", "m11k3", "matx3h", "maJx3h", - "mat3x3h", "mat3c3h", "mat3x3O", "KK_atvvtt3h", "xx83x4f", "__qatF4", - "matqx4f", "mat3x4f", "33atOx4f", "mtt63x9oQQ", "ma3x66f", "mtOxzz66", - "mat3yy4h", "ZaHH4Z", "mat3x4h", "4WWt3q4h", "mOO3x4h", "oatY4h", - "matx", "ma4xFf", "at4x2w", "mat4x2f", "fGtxKf", "matqKx2f", - "matmmxFf", "at4x2h", "mt4x2q", "mat4xbb", "mat4x2h", "mi4x2h", - "maOO4xq", "matTvvx2h", "maFF4x3f", "Pa00xQf", "mPt4x3f", "mat4x3f", - "ma774xss", "RRCbb4x3f", "mXXt4x3f", "qaCC4xOOh", "ma4s3L", "mXt4x3h", - "mat4x3h", "mat43h", "qa4O3", "mat4x22h", "myzz40XX", "matVViP", - "mannC4f", "mat4x4f", "atx4AHHq", "mat4x4", "fatK4f", "ltgg4h", - "mat4xh", "NTTtcx4h", "mat4x4h", "ma7ppl4h", "mNNt4xg", "uub4XX4h", - "vec2", "882K", "vq9f", "vec2f", "vec211", "22ciif", - "ec77f", "NN22h", "vVVc2h", "WW11w2h", "vec2h", "vcwwh", - "vDc2h", "vecK", "f11r2PP", "ve2i", "vec2YY", "vec2i", - "vkktHH", "rrec2i", "vWWssi", "veYu", "eq2f", "u22ec2u", - "vec2u", "c2u", "vec2", "vYyc27E", "veMof", "ve3MM", - "55ec3f", "vec3f", "N3f", "ve33f", "3ec3f", "mecI", - "vrnK3h", "v3", "vec3h", "ILLch", "ecf", "UecRY", - "vechi", "qeIIu", "Hec3i", "vec3i", "eQQvv", "e66i", - "7Wc3", "ve055DD", "IIec3u", "vec3", "vec3u", "rec3", - "lec3u", "GeJ3u", "ey4f", "vc4f", "IIeBB4f", "vec4f", - "TTec338", "veUUSS4nnd", "vZx5CC", "kkec4q", "v005ih", "vnIIc4h", - "vec4h", "cceW", "cKK", "vec66h", "vePPK", "vexxi", - "qec4i", "vec4i", "veSyMMr", "v4u", "ec", "5eFF4u", - "rrecz44", "vWW", "vec4u", "XJecCZZ", "vePP4", "vec4c", + "ccol", "3", "bVol", "bool", "1ool", "bqoJ", + "bllo77", "fppqH", "", "Gb", "f16", "f1vi", + "f8WW", "fxx", "fgg", "X", "332", "f32", + "fE2", "fPTT", "dxx2", "4432", "iSVV2", "RR2", + "i32", "92", "i3", "VOR2", "ma2xyf", "llnarr2772f", + "mat24200", "mat2x2f", "a2oof", "zz2x2f", "miitppx1", "mat2xXXh", + "9II5ann2x2h", "mataSSrHHYh", "mat2x2h", "makkh", "jatgRx", "mb2x2", + "mat2xjf", "at2x3f", "q2x3f", "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", "mtOxzz66", + "mat3yy2h", "ZaHH2Z", "mat3x2h", "4WWt3q2h", "mOO3x2h", "oatY2h", + "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", "matVViP", + "mannC2f", "mat4x2f", "atx2AHHq", "mat4x2", "fatK2f", "ltgg2h", + "mat4xh", "NTTtcx4h", "mat4x2h", "ma7ppl2h", "mNNt4xg", "uub4XX2h", + "matx3f", "Qt883f", "mt9q3f", "mat4x3f", "m11t4x3f", "22at4iif", + "at4x377", "m2t4xNh", "mVVt4x3h", "FaWW4w11h", "mat4x3h", "mawwx3h", + "Dat4x3h", "mt4x3K", "mat41PPhf", "mat44f", "mYYt4x4f", "mat4x4f", + "mttHH4kk", "mat4rr4f", "WWas4x4f", "Yt4x4h", "mt4qfh", "mav224xuh", + "mat4x4h", "t4x4h", "YYat4h", "may4x4EYY", "Mo2", "uMM", + "u552", "u32", "N", "333", "u33", "mecI", + "vrnK2f", "v2", "vec2f", "ILLcf", "ecf", "UecRY", + "vechh", "qeIIu", "Hec2h", "vec2h", "eQQvv", "e66h", + "7Wc2", "ve055DD", "IIec2i", "vec2", "vec2i", "rec2", + "lec2i", "GeJ2i", "ey2u", "vc2u", "IIeBB2u", "vec2u", + "TTec338", "veUUSS2nnd", "vZx5CC", "kkec3q", "v005if", "vnIIc3f", + "vec3f", "cceW", "cKK", "vec66f", "vePPK", "vexxh", + "qec3h", "vec3h", "veSyMMr", "v3u", "ec", "5eFF3i", + "rrecz44", "vWW", "vec3i", "XJecCZZ", "vePP3", "vec3c", + "ve6ll3u", "vcyy99", "Jec3KK", "vec3u", "_ex3", "Ky3", + "zek3u", "veKSf", "vc4f", "ec4VV", "vec4f", "IAAc4f", + "jbR", "veY4", "ec4h", "vc911", "mmcch", "vec4h", + "vJJch", "lDDcUfC", "vec4g", "CCe", "ec4i", "vIc__i", + "vec4i", "ePPtt", "v3dc4i", "vcyyi", "u4", "v03nnu", + "Cuuecnv", "vec4u", "vX4ll", "vocppu", "vwwc4", }; for (auto _ : state) { for (auto& str : kStrings) { diff --git a/src/tint/type/builtin_test.cc b/src/tint/type/builtin_test.cc index 4e405ddcbf..5ef9a17cdf 100644 --- a/src/tint/type/builtin_test.cc +++ b/src/tint/type/builtin_test.cc @@ -43,64 +43,74 @@ inline std::ostream& operator<<(std::ostream& out, Case c) { } static constexpr Case kValidCases[] = { - {"mat2x2f", Builtin::kMat2X2F}, {"mat2x2h", Builtin::kMat2X2H}, {"mat2x3f", Builtin::kMat2X3F}, - {"mat2x3h", Builtin::kMat2X3H}, {"mat2x4f", Builtin::kMat2X4F}, {"mat2x4h", Builtin::kMat2X4H}, - {"mat3x2f", Builtin::kMat3X2F}, {"mat3x2h", Builtin::kMat3X2H}, {"mat3x3f", Builtin::kMat3X3F}, - {"mat3x3h", Builtin::kMat3X3H}, {"mat3x4f", Builtin::kMat3X4F}, {"mat3x4h", Builtin::kMat3X4H}, - {"mat4x2f", Builtin::kMat4X2F}, {"mat4x2h", Builtin::kMat4X2H}, {"mat4x3f", Builtin::kMat4X3F}, - {"mat4x3h", Builtin::kMat4X3H}, {"mat4x4f", Builtin::kMat4X4F}, {"mat4x4h", Builtin::kMat4X4H}, - {"vec2f", Builtin::kVec2F}, {"vec2h", Builtin::kVec2H}, {"vec2i", Builtin::kVec2I}, - {"vec2u", Builtin::kVec2U}, {"vec3f", Builtin::kVec3F}, {"vec3h", Builtin::kVec3H}, - {"vec3i", Builtin::kVec3I}, {"vec3u", Builtin::kVec3U}, {"vec4f", Builtin::kVec4F}, - {"vec4h", Builtin::kVec4H}, {"vec4i", Builtin::kVec4I}, {"vec4u", Builtin::kVec4U}, + {"bool", Builtin::kBool}, {"f16", Builtin::kF16}, {"f32", Builtin::kF32}, + {"i32", Builtin::kI32}, {"mat2x2f", Builtin::kMat2X2F}, {"mat2x2h", Builtin::kMat2X2H}, + {"mat2x3f", Builtin::kMat2X3F}, {"mat2x3h", Builtin::kMat2X3H}, {"mat2x4f", Builtin::kMat2X4F}, + {"mat2x4h", Builtin::kMat2X4H}, {"mat3x2f", Builtin::kMat3X2F}, {"mat3x2h", Builtin::kMat3X2H}, + {"mat3x3f", Builtin::kMat3X3F}, {"mat3x3h", Builtin::kMat3X3H}, {"mat3x4f", Builtin::kMat3X4F}, + {"mat3x4h", Builtin::kMat3X4H}, {"mat4x2f", Builtin::kMat4X2F}, {"mat4x2h", Builtin::kMat4X2H}, + {"mat4x3f", Builtin::kMat4X3F}, {"mat4x3h", Builtin::kMat4X3H}, {"mat4x4f", Builtin::kMat4X4F}, + {"mat4x4h", Builtin::kMat4X4H}, {"u32", Builtin::kU32}, {"vec2f", Builtin::kVec2F}, + {"vec2h", Builtin::kVec2H}, {"vec2i", Builtin::kVec2I}, {"vec2u", Builtin::kVec2U}, + {"vec3f", Builtin::kVec3F}, {"vec3h", Builtin::kVec3H}, {"vec3i", Builtin::kVec3I}, + {"vec3u", Builtin::kVec3U}, {"vec4f", Builtin::kVec4F}, {"vec4h", Builtin::kVec4H}, + {"vec4i", Builtin::kVec4I}, {"vec4u", Builtin::kVec4U}, }; static constexpr Case kInvalidCases[] = { - {"at2x2cc", Builtin::kUndefined}, {"l23f", Builtin::kUndefined}, - {"matVx2f", Builtin::kUndefined}, {"mat212h", Builtin::kUndefined}, - {"mqtJx2h", Builtin::kUndefined}, {"mat2x27ll", Builtin::kUndefined}, - {"ppqqt23HH", Builtin::kUndefined}, {"macv", Builtin::kUndefined}, - {"bt2xGf", Builtin::kUndefined}, {"mat2iivh", Builtin::kUndefined}, - {"8WWt2x3h", Builtin::kUndefined}, {"mxx2x3h", Builtin::kUndefined}, - {"mX2x4gg", Builtin::kUndefined}, {"a2xXf", Builtin::kUndefined}, - {"mat234f", Builtin::kUndefined}, {"Eat2x4h", Builtin::kUndefined}, - {"mPTT2x4h", Builtin::kUndefined}, {"mat2xdxx", Builtin::kUndefined}, - {"m44t3x2f", Builtin::kUndefined}, {"maSS3xVVf", Builtin::kUndefined}, - {"RatR22f", Builtin::kUndefined}, {"mF3x9h", Builtin::kUndefined}, - {"matx2h", Builtin::kUndefined}, {"VOORRH2h", Builtin::kUndefined}, - {"ma3xyf", Builtin::kUndefined}, {"llnarr3773f", Builtin::kUndefined}, - {"mat34300", Builtin::kUndefined}, {"a3ooh", Builtin::kUndefined}, - {"zz3x3h", Builtin::kUndefined}, {"miitppx1", Builtin::kUndefined}, - {"mat3xXXf", Builtin::kUndefined}, {"9II5ann3x4f", Builtin::kUndefined}, + {"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}, {"mataSSrHHYf", Builtin::kUndefined}, {"makkh", Builtin::kUndefined}, - {"jatgRx", Builtin::kUndefined}, {"mb3x4", Builtin::kUndefined}, - {"mat4xjf", Builtin::kUndefined}, {"at4x2f", Builtin::kUndefined}, - {"q4x2f", Builtin::kUndefined}, {"matNN2h", Builtin::kUndefined}, - {"at42vv", Builtin::kUndefined}, {"QQt4x2h", Builtin::kUndefined}, - {"maffxr", Builtin::kUndefined}, {"mat4xjf", Builtin::kUndefined}, - {"mNNw4x38", Builtin::kUndefined}, {"matx3h", Builtin::kUndefined}, - {"mrrt4x3h", Builtin::kUndefined}, {"Gat4x3h", Builtin::kUndefined}, - {"mat4x4FF", Builtin::kUndefined}, {"at4f", Builtin::kUndefined}, - {"marrx4f", Builtin::kUndefined}, {"t4x4h", Builtin::kUndefined}, - {"Da4xJJh", Builtin::kUndefined}, {"ma84", Builtin::kUndefined}, - {"e2k", Builtin::kUndefined}, {"vecf", Builtin::kUndefined}, - {"Jecf", Builtin::kUndefined}, {"ec2h", Builtin::kUndefined}, - {"_KKttcH", Builtin::kUndefined}, {"vexxh", Builtin::kUndefined}, - {"__qcF", Builtin::kUndefined}, {"vc2qq", Builtin::kUndefined}, - {"33e62i", Builtin::kUndefined}, {"6QQott2u", Builtin::kUndefined}, - {"v6c2u", Builtin::kUndefined}, {"zzc2O6", Builtin::kUndefined}, - {"vyyc3f", Builtin::kUndefined}, {"vcZZ", Builtin::kUndefined}, - {"ecWq4f", Builtin::kUndefined}, {"vOO3h", Builtin::kUndefined}, - {"oYe3", Builtin::kUndefined}, {"v3", Builtin::kUndefined}, - {"Fe3i", Builtin::kUndefined}, {"vwci", Builtin::kUndefined}, - {"vefi", Builtin::kUndefined}, {"KKeq3u", Builtin::kUndefined}, - {"vFmm3u", Builtin::kUndefined}, {"vecu", Builtin::kUndefined}, - {"qc4f", Builtin::kUndefined}, {"vecbb", Builtin::kUndefined}, - {"iic4", Builtin::kUndefined}, {"vqOOh", Builtin::kUndefined}, - {"vevvTTh", Builtin::kUndefined}, {"veFF4h", Builtin::kUndefined}, - {"00PfQ", Builtin::kUndefined}, {"vec4P", Builtin::kUndefined}, - {"vec77s", Builtin::kUndefined}, {"vecbbCu", Builtin::kUndefined}, - {"vecXXu", Builtin::kUndefined}, {"CCOOec4", 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}, + {"maffxr", Builtin::kUndefined}, {"mat3xjf", Builtin::kUndefined}, + {"mNNw3x48", Builtin::kUndefined}, {"matx4h", Builtin::kUndefined}, + {"mrrt3x4h", Builtin::kUndefined}, {"Gat3x4h", Builtin::kUndefined}, + {"mat4x2FF", Builtin::kUndefined}, {"at4f", Builtin::kUndefined}, + {"marrx2f", Builtin::kUndefined}, {"t4x2h", Builtin::kUndefined}, + {"Da4xJJh", 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}, + {"zzO6", Builtin::kUndefined}, {"uyy2", Builtin::kUndefined}, + {"HZ", Builtin::kUndefined}, {"ecWq4f", Builtin::kUndefined}, + {"vOO2f", Builtin::kUndefined}, {"oYe2", Builtin::kUndefined}, + {"v2", Builtin::kUndefined}, {"Fe2h", Builtin::kUndefined}, + {"vwch", Builtin::kUndefined}, {"vefi", Builtin::kUndefined}, + {"KKeq2i", Builtin::kUndefined}, {"vFmm2i", Builtin::kUndefined}, + {"vecu", Builtin::kUndefined}, {"qc2u", Builtin::kUndefined}, + {"vecbb", Builtin::kUndefined}, {"iic3", Builtin::kUndefined}, + {"vqOOf", Builtin::kUndefined}, {"vevvTTf", Builtin::kUndefined}, + {"veFF3h", Builtin::kUndefined}, {"00PfQ", Builtin::kUndefined}, + {"vec3P", Builtin::kUndefined}, {"vec77s", Builtin::kUndefined}, + {"vecbbCi", Builtin::kUndefined}, {"vecXXi", Builtin::kUndefined}, + {"CCOOec3", Builtin::kUndefined}, {"vs3u", Builtin::kUndefined}, + {"Xec3u", Builtin::kUndefined}, {"ve4f", Builtin::kUndefined}, + {"qq4", Builtin::kUndefined}, {"vec422", Builtin::kUndefined}, + {"vezzXy", Builtin::kUndefined}, {"ieVVP", Builtin::kUndefined}, + {"venCh", Builtin::kUndefined}, {"vHc4Aq", Builtin::kUndefined}, + {"ve4i", Builtin::kUndefined}, {"vefK", Builtin::kUndefined}, + {"vgg4", Builtin::kUndefined}, {"vecu", Builtin::kUndefined}, + {"4TNc4u", Builtin::kUndefined}, }; using BuiltinParseTest = testing::TestWithParam; diff --git a/src/tint/writer/append_vector.cc b/src/tint/writer/append_vector.cc index 899e81a03a..ab18461792 100644 --- a/src/tint/writer/append_vector.cc +++ b/src/tint/writer/append_vector.cc @@ -86,19 +86,17 @@ const sem::Call* AppendVector(ProgramBuilder* b, packed_el_sem_ty = vector_ty; } - const ast::Type* packed_el_ast_ty = nullptr; - if (packed_el_sem_ty->Is()) { - packed_el_ast_ty = b->create(); - } else if (packed_el_sem_ty->Is()) { - packed_el_ast_ty = b->create(); - } else if (packed_el_sem_ty->Is()) { - packed_el_ast_ty = b->create(); - } else if (packed_el_sem_ty->Is()) { - packed_el_ast_ty = b->create(); - } else { - TINT_UNREACHABLE(Writer, b->Diagnostics()) - << "unsupported vector element type: " << packed_el_sem_ty->TypeInfo().name; - } + const ast::Type* packed_el_ast_ty = Switch( + packed_el_sem_ty, // + [&](const type::I32*) { return b->ty.i32(); }, + [&](const type::U32*) { return b->ty.u32(); }, + [&](const type::F32*) { return b->ty.f32(); }, + [&](const type::Bool*) { return b->ty.bool_(); }, + [&](Default) { + TINT_UNREACHABLE(Writer, b->Diagnostics()) + << "unsupported vector element type: " << packed_el_sem_ty->TypeInfo().name; + return nullptr; + }); auto* statement = vector_sem->Stmt(); diff --git a/src/tint/writer/append_vector_test.cc b/src/tint/writer/append_vector_test.cc index c030db4cb3..c8c6428c13 100644 --- a/src/tint/writer/append_vector_test.cc +++ b/src/tint/writer/append_vector_test.cc @@ -86,7 +86,9 @@ 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); - EXPECT_TRUE(u32_to_i32->target.type->Is()); + ASSERT_TRUE(u32_to_i32->target.type->Is()); + EXPECT_EQ(Symbols().NameFor(u32_to_i32->target.type->As()->name->symbol), "i32"); + ASSERT_EQ(u32_to_i32->args.Length(), 1u); EXPECT_EQ(u32_to_i32->args[0], scalar_3); @@ -132,13 +134,18 @@ TEST_F(AppendVectorTest, Vec2i32FromVec2u32_u32) { ASSERT_NE(v2u32_to_v2i32, nullptr); ASSERT_TRUE(v2u32_to_v2i32->target.type->Is()); EXPECT_EQ(v2u32_to_v2i32->target.type->As()->width, 2u); - EXPECT_TRUE(v2u32_to_v2i32->target.type->As()->type->Is()); + 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"); 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); - EXPECT_TRUE(u32_to_i32->target.type->Is()); + ASSERT_TRUE(u32_to_i32->target.type->Is()); + EXPECT_EQ(Symbols().NameFor(u32_to_i32->target.type->As()->name->symbol), "i32"); ASSERT_EQ(u32_to_i32->args.Length(), 1u); EXPECT_EQ(u32_to_i32->args[0], scalar_3); @@ -180,7 +187,8 @@ 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); - EXPECT_TRUE(f32_to_i32->target.type->Is()); + ASSERT_TRUE(f32_to_i32->target.type->Is()); + EXPECT_EQ(Symbols().NameFor(f32_to_i32->target.type->As()->name->symbol), "i32"); ASSERT_EQ(f32_to_i32->args.Length(), 1u); EXPECT_EQ(f32_to_i32->args[0], scalar_3); @@ -381,7 +389,8 @@ 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); - EXPECT_TRUE(f32_to_i32->target.type->Is()); + ASSERT_TRUE(f32_to_i32->target.type->Is()); + EXPECT_EQ(Symbols().NameFor(f32_to_i32->target.type->As()->name->symbol), "i32"); ASSERT_EQ(f32_to_i32->args.Length(), 1u); EXPECT_EQ(f32_to_i32->args[0], scalar_3); diff --git a/src/tint/writer/wgsl/generator_impl.cc b/src/tint/writer/wgsl/generator_impl.cc index 16523dc4f8..5c76c8655b 100644 --- a/src/tint/writer/wgsl/generator_impl.cc +++ b/src/tint/writer/wgsl/generator_impl.cc @@ -19,14 +19,11 @@ #include "src/tint/ast/alias.h" #include "src/tint/ast/array.h" #include "src/tint/ast/atomic.h" -#include "src/tint/ast/bool.h" #include "src/tint/ast/bool_literal_expression.h" #include "src/tint/ast/call_statement.h" #include "src/tint/ast/depth_texture.h" #include "src/tint/ast/external_texture.h" -#include "src/tint/ast/f32.h" #include "src/tint/ast/float_literal_expression.h" -#include "src/tint/ast/i32.h" #include "src/tint/ast/id_attribute.h" #include "src/tint/ast/internal_attribute.h" #include "src/tint/ast/interpolate_attribute.h" @@ -43,7 +40,6 @@ #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/u32.h" #include "src/tint/ast/variable_decl_statement.h" #include "src/tint/ast/vector.h" #include "src/tint/ast/workgroup_attribute.h" @@ -423,22 +419,6 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) { } return true; }, - [&](const ast::Bool*) { - out << "bool"; - return true; - }, - [&](const ast::F32*) { - out << "f32"; - return true; - }, - [&](const ast::F16*) { - out << "f16"; - return true; - }, - [&](const ast::I32*) { - out << "i32"; - return true; - }, [&](const ast::Matrix* mat) { out << "mat" << mat->columns << "x" << mat->rows; if (auto* el_ty = mat->type) { @@ -574,10 +554,6 @@ bool GeneratorImpl::EmitType(std::ostream& out, const ast::Type* ty) { return true; }); }, - [&](const ast::U32*) { - out << "u32"; - return true; - }, [&](const ast::Vector* vec) { out << "vec" << vec->width; if (auto* el_ty = vec->type) {