diff --git a/docs/tint/ir.md b/docs/tint/ir.md index b65154b535..fb58952776 100644 --- a/docs/tint/ir.md +++ b/docs/tint/ir.md @@ -20,7 +20,7 @@ This round-trip ability provides a few features: The IR helps with the complexity of the AST transforms by limiting the representations seen in the IR form. For example, instead of `for`, `while` and `loop` constructs there is a single `loop` construct. -`alias` and `static_assert` nodes are not emitted into IR. Dead code is +`alias` and `const_assert` nodes are not emitted into IR. Dead code is eliminated during the IR construction. As the IR can convert into AST, we could potentially simplify the @@ -48,7 +48,7 @@ greatly simplifies the number of things to consider in the IR. For instance: * No `alias` nodes -* No `static_assert` nodes +* No `const_assert` nodes * All loops become `while` loops * `if` statements may all become `if/else` diff --git a/docs/tint/origin-trial-changes.md b/docs/tint/origin-trial-changes.md index a4f1cbc658..e989cabd16 100644 --- a/docs/tint/origin-trial-changes.md +++ b/docs/tint/origin-trial-changes.md @@ -5,6 +5,7 @@ ## Deprecated Features * The keyword to alias a type has been renamed from `type` to `alias`. [tint:1812](crbug.com/tint/1812) +* `static_assert` has been renamed to `const_assert`. [tint:1807](crbug.com/tint/1807) ## Changes for M110 diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index 9a14d8a12b..5a11615251 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -224,6 +224,8 @@ libtint_source_set("libtint_core_all_src") { "ast/compound_assignment_statement.h", "ast/const.cc", "ast/const.h", + "ast/const_assert.cc", + "ast/const_assert.h", "ast/continue_statement.cc", "ast/continue_statement.h", "ast/depth_multisampled_texture.cc", @@ -315,8 +317,6 @@ libtint_source_set("libtint_core_all_src") { "ast/stage_attribute.h", "ast/statement.cc", "ast/statement.h", - "ast/static_assert.cc", - "ast/static_assert.h", "ast/storage_texture.cc", "ast/storage_texture.h", "ast/stride_attribute.cc", @@ -1179,6 +1179,7 @@ if (tint_build_unittests) { "ast/case_selector_test.cc", "ast/case_statement_test.cc", "ast/compound_assignment_statement_test.cc", + "ast/const_assert_test.cc", "ast/continue_statement_test.cc", "ast/diagnostic_control_test.cc", "ast/discard_statement_test.cc", @@ -1213,7 +1214,6 @@ if (tint_build_unittests) { "ast/sampled_texture_test.cc", "ast/sampler_test.cc", "ast/stage_attribute_test.cc", - "ast/static_assert_test.cc", "ast/storage_texture_test.cc", "ast/stride_attribute_test.cc", "ast/struct_member_align_attribute_test.cc", @@ -1272,6 +1272,7 @@ if (tint_build_unittests) { "resolver/call_validation_test.cc", "resolver/compound_assignment_validation_test.cc", "resolver/compound_statement_test.cc", + "resolver/const_assert_test.cc", "resolver/const_eval_binary_op_test.cc", "resolver/const_eval_bitcast_test.cc", "resolver/const_eval_builtin_test.cc", @@ -1304,7 +1305,6 @@ if (tint_build_unittests) { "resolver/resolver_test_helper.h", "resolver/root_identifier_test.cc", "resolver/side_effects_test.cc", - "resolver/static_assert_test.cc", "resolver/struct_address_space_use_test.cc", "resolver/struct_layout_test.cc", "resolver/struct_pipeline_stage_use_test.cc", @@ -1526,6 +1526,7 @@ if (tint_build_unittests) { "writer/spirv/builder_builtin_test.cc", "writer/spirv/builder_builtin_texture_test.cc", "writer/spirv/builder_call_test.cc", + "writer/spirv/builder_const_assert_test.cc", "writer/spirv/builder_discard_test.cc", "writer/spirv/builder_entry_point_test.cc", "writer/spirv/builder_format_conversion_test.cc", @@ -1539,7 +1540,6 @@ if (tint_build_unittests) { "writer/spirv/builder_literal_test.cc", "writer/spirv/builder_loop_test.cc", "writer/spirv/builder_return_test.cc", - "writer/spirv/builder_static_assert_test.cc", "writer/spirv/builder_switch_test.cc", "writer/spirv/builder_test.cc", "writer/spirv/builder_type_test.cc", @@ -1654,6 +1654,7 @@ if (tint_build_unittests) { "writer/wgsl/generator_impl_call_test.cc", "writer/wgsl/generator_impl_case_test.cc", "writer/wgsl/generator_impl_cast_test.cc", + "writer/wgsl/generator_impl_const_assert_test.cc", "writer/wgsl/generator_impl_continue_test.cc", "writer/wgsl/generator_impl_discard_test.cc", "writer/wgsl/generator_impl_enable_test.cc", @@ -1666,7 +1667,6 @@ if (tint_build_unittests) { "writer/wgsl/generator_impl_loop_test.cc", "writer/wgsl/generator_impl_member_accessor_test.cc", "writer/wgsl/generator_impl_return_test.cc", - "writer/wgsl/generator_impl_static_assert_test.cc", "writer/wgsl/generator_impl_switch_test.cc", "writer/wgsl/generator_impl_test.cc", "writer/wgsl/generator_impl_type_test.cc", @@ -1695,6 +1695,7 @@ if (tint_build_unittests) { "writer/msl/generator_impl_call_test.cc", "writer/msl/generator_impl_case_test.cc", "writer/msl/generator_impl_cast_test.cc", + "writer/msl/generator_impl_const_assert_test.cc", "writer/msl/generator_impl_continue_test.cc", "writer/msl/generator_impl_discard_test.cc", "writer/msl/generator_impl_function_test.cc", @@ -1707,7 +1708,6 @@ if (tint_build_unittests) { "writer/msl/generator_impl_module_constant_test.cc", "writer/msl/generator_impl_return_test.cc", "writer/msl/generator_impl_sanitizer_test.cc", - "writer/msl/generator_impl_static_assert_test.cc", "writer/msl/generator_impl_switch_test.cc", "writer/msl/generator_impl_test.cc", "writer/msl/generator_impl_type_test.cc", @@ -1735,6 +1735,7 @@ if (tint_build_unittests) { "writer/hlsl/generator_impl_call_test.cc", "writer/hlsl/generator_impl_case_test.cc", "writer/hlsl/generator_impl_cast_test.cc", + "writer/hlsl/generator_impl_const_assert_test.cc", "writer/hlsl/generator_impl_continue_test.cc", "writer/hlsl/generator_impl_discard_test.cc", "writer/hlsl/generator_impl_function_test.cc", @@ -1747,7 +1748,6 @@ if (tint_build_unittests) { "writer/hlsl/generator_impl_module_constant_test.cc", "writer/hlsl/generator_impl_return_test.cc", "writer/hlsl/generator_impl_sanitizer_test.cc", - "writer/hlsl/generator_impl_static_assert_test.cc", "writer/hlsl/generator_impl_switch_test.cc", "writer/hlsl/generator_impl_test.cc", "writer/hlsl/generator_impl_type_test.cc", diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 438ab859c8..8e824c9aa4 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -119,6 +119,8 @@ list(APPEND TINT_LIB_SRCS ast/compound_assignment_statement.h ast/const.cc ast/const.h + ast/const_assert.cc + ast/const_assert.h ast/continue_statement.cc ast/continue_statement.h ast/depth_multisampled_texture.cc @@ -206,8 +208,6 @@ list(APPEND TINT_LIB_SRCS ast/stage_attribute.h ast/statement.cc ast/statement.h - ast/static_assert.cc - ast/static_assert.h ast/storage_texture.cc ast/storage_texture.h ast/stride_attribute.cc @@ -829,6 +829,7 @@ if(TINT_BUILD_TESTS) ast/case_selector_test.cc ast/case_statement_test.cc ast/compound_assignment_statement_test.cc + ast/const_assert_test.cc ast/continue_statement_test.cc ast/depth_multisampled_texture_test.cc ast/depth_texture_test.cc @@ -863,7 +864,6 @@ if(TINT_BUILD_TESTS) ast/sampled_texture_test.cc ast/sampler_test.cc ast/stage_attribute_test.cc - ast/static_assert_test.cc ast/storage_texture_test.cc ast/stride_attribute_test.cc ast/struct_member_align_attribute_test.cc @@ -910,6 +910,7 @@ if(TINT_BUILD_TESTS) resolver/call_validation_test.cc resolver/compound_assignment_validation_test.cc resolver/compound_statement_test.cc + resolver/const_assert_test.cc resolver/const_eval_binary_op_test.cc resolver/const_eval_bitcast_test.cc resolver/const_eval_builtin_test.cc @@ -941,7 +942,6 @@ if(TINT_BUILD_TESTS) resolver/resolver_test_helper.h resolver/resolver_test.cc resolver/side_effects_test.cc - resolver/static_assert_test.cc resolver/root_identifier_test.cc resolver/address_space_layout_validation_test.cc resolver/address_space_validation_test.cc @@ -1164,7 +1164,7 @@ if(TINT_BUILD_TESTS) writer/spirv/builder_builtin_test.cc writer/spirv/builder_builtin_texture_test.cc writer/spirv/builder_call_test.cc - writer/spirv/builder_initializer_expression_test.cc + writer/spirv/builder_const_assert_test.cc writer/spirv/builder_discard_test.cc writer/spirv/builder_entry_point_test.cc writer/spirv/builder_format_conversion_test.cc @@ -1174,10 +1174,10 @@ if(TINT_BUILD_TESTS) writer/spirv/builder_global_variable_test.cc writer/spirv/builder_ident_expression_test.cc writer/spirv/builder_if_test.cc + writer/spirv/builder_initializer_expression_test.cc writer/spirv/builder_literal_test.cc writer/spirv/builder_loop_test.cc writer/spirv/builder_return_test.cc - writer/spirv/builder_static_assert_test.cc writer/spirv/builder_switch_test.cc writer/spirv/builder_test.cc writer/spirv/builder_type_test.cc @@ -1204,7 +1204,7 @@ if(TINT_BUILD_TESTS) writer/wgsl/generator_impl_call_test.cc writer/wgsl/generator_impl_case_test.cc writer/wgsl/generator_impl_cast_test.cc - writer/wgsl/generator_impl_initializer_test.cc + writer/wgsl/generator_impl_const_assert_test.cc writer/wgsl/generator_impl_continue_test.cc writer/wgsl/generator_impl_discard_test.cc writer/wgsl/generator_impl_enable_test.cc @@ -1212,11 +1212,11 @@ if(TINT_BUILD_TESTS) writer/wgsl/generator_impl_global_decl_test.cc writer/wgsl/generator_impl_identifier_test.cc writer/wgsl/generator_impl_if_test.cc + writer/wgsl/generator_impl_initializer_test.cc writer/wgsl/generator_impl_loop_test.cc writer/wgsl/generator_impl_literal_test.cc writer/wgsl/generator_impl_member_accessor_test.cc writer/wgsl/generator_impl_return_test.cc - writer/wgsl/generator_impl_static_assert_test.cc writer/wgsl/generator_impl_switch_test.cc writer/wgsl/generator_impl_type_test.cc writer/wgsl/generator_impl_unary_op_test.cc @@ -1298,19 +1298,19 @@ if(TINT_BUILD_TESTS) writer/msl/generator_impl_call_test.cc writer/msl/generator_impl_case_test.cc writer/msl/generator_impl_cast_test.cc - writer/msl/generator_impl_initializer_test.cc + writer/msl/generator_impl_const_assert_test.cc writer/msl/generator_impl_continue_test.cc writer/msl/generator_impl_discard_test.cc writer/msl/generator_impl_function_test.cc writer/msl/generator_impl_identifier_test.cc writer/msl/generator_impl_if_test.cc + writer/msl/generator_impl_initializer_test.cc writer/msl/generator_impl_import_test.cc writer/msl/generator_impl_loop_test.cc writer/msl/generator_impl_member_accessor_test.cc writer/msl/generator_impl_module_constant_test.cc writer/msl/generator_impl_return_test.cc writer/msl/generator_impl_sanitizer_test.cc - writer/msl/generator_impl_static_assert_test.cc writer/msl/generator_impl_switch_test.cc writer/msl/generator_impl_test.cc writer/msl/generator_impl_type_test.cc @@ -1370,19 +1370,19 @@ if(TINT_BUILD_TESTS) writer/hlsl/generator_impl_call_test.cc writer/hlsl/generator_impl_case_test.cc writer/hlsl/generator_impl_cast_test.cc - writer/hlsl/generator_impl_initializer_test.cc + writer/hlsl/generator_impl_const_assert_test.cc writer/hlsl/generator_impl_continue_test.cc writer/hlsl/generator_impl_discard_test.cc writer/hlsl/generator_impl_function_test.cc writer/hlsl/generator_impl_identifier_test.cc writer/hlsl/generator_impl_if_test.cc + writer/hlsl/generator_impl_initializer_test.cc writer/hlsl/generator_impl_import_test.cc writer/hlsl/generator_impl_loop_test.cc writer/hlsl/generator_impl_member_accessor_test.cc writer/hlsl/generator_impl_module_constant_test.cc writer/hlsl/generator_impl_return_test.cc writer/hlsl/generator_impl_sanitizer_test.cc - writer/hlsl/generator_impl_static_assert_test.cc writer/hlsl/generator_impl_switch_test.cc writer/hlsl/generator_impl_test.cc writer/hlsl/generator_impl_type_test.cc diff --git a/src/tint/ast/static_assert.cc b/src/tint/ast/const_assert.cc similarity index 70% rename from src/tint/ast/static_assert.cc rename to src/tint/ast/const_assert.cc index 0609194b88..5f9978d08c 100644 --- a/src/tint/ast/static_assert.cc +++ b/src/tint/ast/const_assert.cc @@ -12,29 +12,29 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/tint/ast/static_assert.h" +#include "src/tint/ast/const_assert.h" #include "src/tint/program_builder.h" -TINT_INSTANTIATE_TYPEINFO(tint::ast::StaticAssert); +TINT_INSTANTIATE_TYPEINFO(tint::ast::ConstAssert); namespace tint::ast { -StaticAssert::StaticAssert(ProgramID pid, NodeID nid, const Source& src, const Expression* cond) +ConstAssert::ConstAssert(ProgramID pid, NodeID nid, const Source& src, const Expression* cond) : Base(pid, nid, src), condition(cond) { TINT_ASSERT(AST, cond); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, cond, program_id); } -StaticAssert::StaticAssert(StaticAssert&&) = default; +ConstAssert::ConstAssert(ConstAssert&&) = default; -StaticAssert::~StaticAssert() = default; +ConstAssert::~ConstAssert() = default; -const StaticAssert* StaticAssert::Clone(CloneContext* ctx) const { +const ConstAssert* ConstAssert::Clone(CloneContext* ctx) const { // Clone arguments outside of create() call to have deterministic ordering auto src = ctx->Clone(source); auto* cond = ctx->Clone(condition); - return ctx->dst->create(src, cond); + return ctx->dst->create(src, cond); } } // namespace tint::ast diff --git a/src/tint/ast/static_assert.h b/src/tint/ast/const_assert.h similarity index 73% rename from src/tint/ast/static_assert.h rename to src/tint/ast/const_assert.h index f42ad0707b..8f0aae5f11 100644 --- a/src/tint/ast/static_assert.h +++ b/src/tint/ast/const_assert.h @@ -12,34 +12,34 @@ // See the License for the specific language governing permissions and // limitations under the License. -#ifndef SRC_TINT_AST_STATIC_ASSERT_H_ -#define SRC_TINT_AST_STATIC_ASSERT_H_ +#ifndef SRC_TINT_AST_CONST_ASSERT_H_ +#define SRC_TINT_AST_CONST_ASSERT_H_ #include "src/tint/ast/statement.h" #include "src/tint/ast/variable.h" namespace tint::ast { -/// A `static_assert` statement -class StaticAssert final : public Castable { +/// A `const_assert` statement +class ConstAssert final : public Castable { public: /// Constructor /// @param pid the identifier of the program that owns this node /// @param nid the unique node identifier /// @param source the variable statement source /// @param condition the assertion condition - StaticAssert(ProgramID pid, NodeID nid, const Source& source, const Expression* condition); + ConstAssert(ProgramID pid, NodeID nid, const Source& source, const Expression* condition); /// Move constructor - StaticAssert(StaticAssert&&); + ConstAssert(ConstAssert&&); /// Destructor - ~StaticAssert() override; + ~ConstAssert() override; /// Clones this node and all transitive child nodes using the `CloneContext` `ctx`. /// @param ctx the clone context /// @return the newly cloned node - const StaticAssert* Clone(CloneContext* ctx) const override; + const ConstAssert* Clone(CloneContext* ctx) const override; /// The assertion condition const Expression* const condition; @@ -47,4 +47,4 @@ class StaticAssert final : public Castable { } // namespace tint::ast -#endif // SRC_TINT_AST_STATIC_ASSERT_H_ +#endif // SRC_TINT_AST_CONST_ASSERT_H_ diff --git a/src/tint/ast/static_assert_test.cc b/src/tint/ast/const_assert_test.cc similarity index 68% rename from src/tint/ast/static_assert_test.cc rename to src/tint/ast/const_assert_test.cc index 48bee48141..ec938b7329 100644 --- a/src/tint/ast/static_assert_test.cc +++ b/src/tint/ast/const_assert_test.cc @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "src/tint/ast/static_assert.h" +#include "src/tint/ast/const_assert.h" #include "gtest/gtest-spi.h" #include "src/tint/ast/test_helper.h" @@ -20,44 +20,44 @@ namespace tint::ast { namespace { -using StaticAssertTest = TestHelper; +using ConstAssertTest = TestHelper; -TEST_F(StaticAssertTest, Creation) { +TEST_F(ConstAssertTest, Creation) { auto* cond = Expr(true); - auto* stmt = StaticAssert(cond); + auto* stmt = ConstAssert(cond); EXPECT_EQ(stmt->condition, cond); } -TEST_F(StaticAssertTest, Creation_WithSource) { +TEST_F(ConstAssertTest, Creation_WithSource) { auto* cond = Expr(true); - auto* stmt = StaticAssert(Source{{20, 2}}, cond); + auto* stmt = ConstAssert(Source{{20, 2}}, cond); auto src = stmt->source; EXPECT_EQ(src.range.begin.line, 20u); EXPECT_EQ(src.range.begin.column, 2u); } -TEST_F(StaticAssertTest, IsStaticAssert) { +TEST_F(ConstAssertTest, IsConstAssert) { auto* cond = Expr(true); - auto* stmt = StaticAssert(cond); - EXPECT_TRUE(stmt->Is()); + auto* stmt = ConstAssert(cond); + EXPECT_TRUE(stmt->Is()); } -TEST_F(StaticAssertTest, Assert_Null_Condition) { +TEST_F(ConstAssertTest, Assert_Null_Condition) { EXPECT_FATAL_FAILURE( { ProgramBuilder b; - b.StaticAssert(nullptr); + b.ConstAssert(nullptr); }, "internal compiler error"); } -TEST_F(StaticAssertTest, Assert_DifferentProgramID_Condition) { +TEST_F(ConstAssertTest, Assert_DifferentProgramID_Condition) { EXPECT_FATAL_FAILURE( { ProgramBuilder b1; ProgramBuilder b2; - b1.StaticAssert(b2.Expr(i32(123))); + b1.ConstAssert(b2.Expr(i32(123))); }, "internal compiler error"); } diff --git a/src/tint/ast/module.cc b/src/tint/ast/module.cc index 50039960e1..ad6850516e 100644 --- a/src/tint/ast/module.cc +++ b/src/tint/ast/module.cc @@ -75,9 +75,9 @@ void Module::BinGlobalDeclaration(const tint::ast::Node* decl, diag::List& diags TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, enable, program_id); enables_.Push(enable); }, - [&](const StaticAssert* assertion) { + [&](const ConstAssert* assertion) { TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, assertion, program_id); - static_asserts_.Push(assertion); + const_asserts_.Push(assertion); }, [&](Default) { TINT_ICE(AST, diags) << "Unknown global declaration type"; }); } @@ -96,10 +96,10 @@ void Module::AddGlobalVariable(const ast::Variable* var) { global_declarations_.Push(var); } -void Module::AddStaticAssert(const StaticAssert* assertion) { +void Module::AddConstAssert(const ConstAssert* assertion) { TINT_ASSERT(AST, assertion); TINT_ASSERT_PROGRAM_IDS_EQUAL_IF_VALID(AST, assertion, program_id); - static_asserts_.Push(assertion); + const_asserts_.Push(assertion); global_declarations_.Push(assertion); } diff --git a/src/tint/ast/module.h b/src/tint/ast/module.h index 2818cb827e..7e43756e2e 100644 --- a/src/tint/ast/module.h +++ b/src/tint/ast/module.h @@ -17,9 +17,9 @@ #include +#include "src/tint/ast/const_assert.h" #include "src/tint/ast/enable.h" #include "src/tint/ast/function.h" -#include "src/tint/ast/static_assert.h" #include "src/tint/ast/type.h" #include "src/tint/utils/vector.h" @@ -99,12 +99,12 @@ class Module final : public Castable { /// @returns the extension set for the module const auto& Enables() const { return enables_; } - /// Add a global static assertion to the module - /// @param assertion the static assert to add - void AddStaticAssert(const StaticAssert* assertion); + /// Add a global const assertion to the module + /// @param assertion the const assert to add + void AddConstAssert(const ConstAssert* assertion); - /// @returns the list of global static assertions - const auto& StaticAsserts() const { return static_asserts_; } + /// @returns the list of global const assertions + const auto& ConstAsserts() const { return const_asserts_; } /// Adds a type declaration to the module /// @param decl the type declaration to add @@ -147,7 +147,7 @@ class Module final : public Castable { FunctionList functions_; utils::Vector global_variables_; utils::Vector enables_; - utils::Vector static_asserts_; + utils::Vector const_asserts_; }; } // namespace tint::ast diff --git a/src/tint/ir/builder_impl.cc b/src/tint/ir/builder_impl.cc index 0bcaf241ef..2a8ed06e9a 100644 --- a/src/tint/ir/builder_impl.cc +++ b/src/tint/ir/builder_impl.cc @@ -21,6 +21,7 @@ #include "src/tint/ast/bool_literal_expression.h" #include "src/tint/ast/break_if_statement.h" #include "src/tint/ast/break_statement.h" +#include "src/tint/ast/const_assert.h" #include "src/tint/ast/continue_statement.h" #include "src/tint/ast/float_literal_expression.h" #include "src/tint/ast/for_loop_statement.h" @@ -33,7 +34,6 @@ #include "src/tint/ast/override.h" #include "src/tint/ast/return_statement.h" #include "src/tint/ast/statement.h" -#include "src/tint/ast/static_assert.h" #include "src/tint/ast/struct.h" #include "src/tint/ast/struct_member_align_attribute.h" #include "src/tint/ast/struct_member_size_attribute.h" @@ -155,7 +155,7 @@ ResultType BuilderImpl::Build() { // TODO(dsinclair): Implement? I think these need to be passed along so further stages // know what is enabled. // }, - [&](const ast::StaticAssert*) { + [&](const ast::ConstAssert*) { // Evaluated by the resolver, drop from the IR. return true; }, @@ -253,7 +253,7 @@ bool BuilderImpl::EmitStatement(const ast::Statement* stmt) { [&](const ast::ReturnStatement* r) { return EmitReturn(r); }, [&](const ast::SwitchStatement* s) { return EmitSwitch(s); }, [&](const ast::VariableDeclStatement* v) { return EmitVariable(v->variable); }, - [&](const ast::StaticAssert*) { + [&](const ast::ConstAssert*) { return true; // Not emitted }, [&](Default) { diff --git a/src/tint/program_builder.h b/src/tint/program_builder.h index 4e760de40e..2d50c36cf0 100644 --- a/src/tint/program_builder.h +++ b/src/tint/program_builder.h @@ -37,6 +37,7 @@ #include "src/tint/ast/case_statement.h" #include "src/tint/ast/compound_assignment_statement.h" #include "src/tint/ast/const.h" +#include "src/tint/ast/const_assert.h" #include "src/tint/ast/continue_statement.h" #include "src/tint/ast/depth_multisampled_texture.h" #include "src/tint/ast/depth_texture.h" @@ -72,7 +73,6 @@ #include "src/tint/ast/sampled_texture.h" #include "src/tint/ast/sampler.h" #include "src/tint/ast/stage_attribute.h" -#include "src/tint/ast/static_assert.h" #include "src/tint/ast/storage_texture.h" #include "src/tint/ast/stride_attribute.h" #include "src/tint/ast/struct_member_align_attribute.h" @@ -1926,38 +1926,38 @@ class ProgramBuilder { /// @param source the source information /// @param condition the assertion condition - /// @returns a new `ast::StaticAssert`, which is automatically registered as a global statement + /// @returns a new `ast::ConstAssert`, which is automatically registered as a global statement /// with the ast::Module. template - const ast::StaticAssert* GlobalStaticAssert(const Source& source, EXPR&& condition) { - auto* sa = StaticAssert(source, std::forward(condition)); - AST().AddStaticAssert(sa); + const ast::ConstAssert* GlobalConstAssert(const Source& source, EXPR&& condition) { + auto* sa = ConstAssert(source, std::forward(condition)); + AST().AddConstAssert(sa); return sa; } /// @param condition the assertion condition - /// @returns a new `ast::StaticAssert`, which is automatically registered as a global statement + /// @returns a new `ast::ConstAssert`, which is automatically registered as a global statement /// with the ast::Module. template > - const ast::StaticAssert* GlobalStaticAssert(EXPR&& condition) { - auto* sa = StaticAssert(std::forward(condition)); - AST().AddStaticAssert(sa); + const ast::ConstAssert* GlobalConstAssert(EXPR&& condition) { + auto* sa = ConstAssert(std::forward(condition)); + AST().AddConstAssert(sa); return sa; } /// @param source the source information /// @param condition the assertion condition - /// @returns a new `ast::StaticAssert` with the given assertion condition + /// @returns a new `ast::ConstAssert` with the given assertion condition template - const ast::StaticAssert* StaticAssert(const Source& source, EXPR&& condition) { - return create(source, Expr(std::forward(condition))); + const ast::ConstAssert* ConstAssert(const Source& source, EXPR&& condition) { + return create(source, Expr(std::forward(condition))); } /// @param condition the assertion condition - /// @returns a new `ast::StaticAssert` with the given assertion condition + /// @returns a new `ast::ConstAssert` with the given assertion condition template > - const ast::StaticAssert* StaticAssert(EXPR&& condition) { - return create(Expr(std::forward(condition))); + const ast::ConstAssert* ConstAssert(EXPR&& condition) { + return create(Expr(std::forward(condition))); } /// @param source the source information diff --git a/src/tint/reader/wgsl/lexer.cc b/src/tint/reader/wgsl/lexer.cc index 1513555653..722058c8d0 100644 --- a/src/tint/reader/wgsl/lexer.cc +++ b/src/tint/reader/wgsl/lexer.cc @@ -1139,6 +1139,9 @@ Token Lexer::check_keyword(const Source& source, std::string_view str) { if (str == "const") { return {Token::Type::kConst, source, "const"}; } + if (str == "const_assert") { + return {Token::Type::kConstAssert, source, "const_assert"}; + } if (str == "continue") { return {Token::Type::kContinue, source, "continue"}; } diff --git a/src/tint/reader/wgsl/lexer_test.cc b/src/tint/reader/wgsl/lexer_test.cc index c7ab809b6b..a3768881c8 100644 --- a/src/tint/reader/wgsl/lexer_test.cc +++ b/src/tint/reader/wgsl/lexer_test.cc @@ -1064,6 +1064,7 @@ INSTANTIATE_TEST_SUITE_P( TokenData{"break", Token::Type::kBreak}, TokenData{"case", Token::Type::kCase}, TokenData{"const", Token::Type::kConst}, + TokenData{"const_assert", Token::Type::kConstAssert}, TokenData{"continue", Token::Type::kContinue}, TokenData{"continuing", Token::Type::kContinuing}, TokenData{"default", Token::Type::kDefault}, diff --git a/src/tint/reader/wgsl/parser_impl.cc b/src/tint/reader/wgsl/parser_impl.cc index 7b303d17dd..b2dfcbcd44 100644 --- a/src/tint/reader/wgsl/parser_impl.cc +++ b/src/tint/reader/wgsl/parser_impl.cc @@ -427,7 +427,7 @@ Maybe ParserImpl::enable_directive() { // | type_alias_decl SEMICOLON // | struct_decl // | function_decl -// | static_assert_statement SEMICOLON +// | const_assert_statement SEMICOLON Maybe ParserImpl::global_decl() { if (match(Token::Type::kSemicolon) || match(Token::Type::kEOF)) { return kSuccess; @@ -486,13 +486,13 @@ Maybe ParserImpl::global_decl() { return kSuccess; } - auto assertion = static_assert_statement(); + auto assertion = const_assert_statement(); if (assertion.errored) { return Failure::kErrored; } if (assertion.matched) { - builder_.AST().AddStaticAssert(assertion.value); - if (!expect("static assertion declaration", Token::Type::kSemicolon)) { + builder_.AST().AddConstAssert(assertion.value); + if (!expect("const assertion declaration", Token::Type::kSemicolon)) { return Failure::kErrored; } return kSuccess; @@ -1455,11 +1455,15 @@ Expect ParserImpl::expect_struct_member() { decl->type, std::move(attrs.value)); } -// static_assert_statement +// const_assert_statement // : STATIC_ASSERT expression -Maybe ParserImpl::static_assert_statement() { +Maybe ParserImpl::const_assert_statement() { Source start; - if (!match(Token::Type::kStaticAssert, &start)) { + if (match(Token::Type::kConstAssert, &start)) { + // matched + } else if (match(Token::Type::kStaticAssert, &start)) { + deprecated(start, "'static_assert' has been renamed to 'const_assert'"); + } else { return Failure::kNoMatch; } @@ -1472,7 +1476,7 @@ Maybe ParserImpl::static_assert_statement() { } Source source = make_source_range_from(start); - return create(source, condition.value); + return create(source, condition.value); } // function_decl @@ -1786,7 +1790,7 @@ Maybe ParserImpl::statement() { // | continue_statement SEMICOLON // | DISCARD SEMICOLON // | variable_updating_statement SEMICOLON -// | static_assert_statement SEMICOLON +// | const_assert_statement SEMICOLON Maybe ParserImpl::non_block_statement() { auto stmt = [&]() -> Maybe { auto ret_stmt = return_statement(); @@ -1843,7 +1847,7 @@ Maybe ParserImpl::non_block_statement() { return assign.value; } - auto stmt_static_assert = static_assert_statement(); + auto stmt_static_assert = const_assert_statement(); if (stmt_static_assert.errored) { return Failure::kErrored; } diff --git a/src/tint/reader/wgsl/parser_impl.h b/src/tint/reader/wgsl/parser_impl.h index 4ef19bbba9..84238072a7 100644 --- a/src/tint/reader/wgsl/parser_impl.h +++ b/src/tint/reader/wgsl/parser_impl.h @@ -505,9 +505,9 @@ class ParserImpl { /// @param use a description of what was being parsed if an error was raised /// @returns returns the texel format or kNone if none matched. Expect expect_texel_format(std::string_view use); - /// Parses a `static_assert_statement` grammar element - /// @returns returns the static assert, if it matched. - Maybe static_assert_statement(); + /// Parses a `const_assert_statement` grammar element + /// @returns returns the const assert, if it matched. + Maybe const_assert_statement(); /// Parses a `function_header` grammar element /// @returns the parsed function header Maybe function_header(); diff --git a/src/tint/reader/wgsl/parser_impl_error_msg_test.cc b/src/tint/reader/wgsl/parser_impl_error_msg_test.cc index 322425231f..c93604e293 100644 --- a/src/tint/reader/wgsl/parser_impl_error_msg_test.cc +++ b/src/tint/reader/wgsl/parser_impl_error_msg_test.cc @@ -311,46 +311,130 @@ fn f() { for (var i : i32 = 0; i < 8; i=i+1) { )"); } -TEST_F(ParserImplErrorTest, FunctionDeclStaticAssertMissingCondThenEOF) { - EXPECT("fn f() { static_assert }", R"(test.wgsl:1:24 error: unable to parse condition expression -fn f() { static_assert } - ^ -)"); -} - -TEST_F(ParserImplErrorTest, FunctionDeclStaticAssertMissingCondThenSemicolon) { - EXPECT("fn f() { static_assert; }", - R"(test.wgsl:1:23 error: unable to parse condition expression -fn f() { static_assert; } +TEST_F(ParserImplErrorTest, FunctionDeclConstAssertMissingCondThenEOF) { + EXPECT("fn f() { const_assert }", R"(test.wgsl:1:23 error: unable to parse condition expression +fn f() { const_assert } ^ )"); } -TEST_F(ParserImplErrorTest, FunctionDeclStaticAssertMissingCondThenLet) { - EXPECT("fn f() { static_assert\nlet x = 0; }", +TEST_F(ParserImplErrorTest, FunctionDeclConstAssertMissingCondThenSemicolon) { + EXPECT("fn f() { const_assert; }", + R"(test.wgsl:1:22 error: unable to parse condition expression +fn f() { const_assert; } + ^ +)"); +} + +TEST_F(ParserImplErrorTest, FunctionDeclConstAssertMissingCondThenLet) { + EXPECT("fn f() { const_assert\nlet x = 0; }", R"(test.wgsl:2:1 error: unable to parse condition expression let x = 0; } ^^^ )"); } -TEST_F(ParserImplErrorTest, FunctionDeclStaticAssertMissingLParen) { - EXPECT("fn f() { static_assert true);", R"(test.wgsl:1:28 error: expected ';' for statement +TEST_F(ParserImplErrorTest, FunctionDeclConstAssertMissingLParen) { + EXPECT("fn f() { const_assert true);", R"(test.wgsl:1:27 error: expected ';' for statement +fn f() { const_assert true); + ^ +)"); +} + +TEST_F(ParserImplErrorTest, FunctionDeclConstAssertMissingRParen) { + EXPECT("fn f() { const_assert (true;", R"(test.wgsl:1:28 error: expected ')' +fn f() { const_assert (true; + ^ +)"); +} + +TEST_F(ParserImplErrorTest, FunctionDeclConstAssertMissingSemicolon) { + EXPECT("fn f() { const_assert true }", + R"(test.wgsl:1:28 error: expected ';' for statement +fn f() { const_assert true } + ^ +)"); +} + +// TODO(crbug.com/tint/1807) +TEST_F(ParserImplErrorTest, DEPRECATED_FunctionDeclStaticAssertMissingCondThenEOF) { + EXPECT( + "fn f() { static_assert }", + R"(test.wgsl:1:10 warning: use of deprecated language feature: 'static_assert' has been renamed to 'const_assert' +fn f() { static_assert } + ^^^^^^^^^^^^^ + +test.wgsl:1:24 error: unable to parse condition expression +fn f() { static_assert } + ^ +)"); +} + +// TODO(crbug.com/tint/1807) +TEST_F(ParserImplErrorTest, DEPRECATED_FunctionDeclStaticAssertMissingCondThenSemicolon) { + EXPECT( + "fn f() { static_assert; }", + R"(test.wgsl:1:10 warning: use of deprecated language feature: 'static_assert' has been renamed to 'const_assert' +fn f() { static_assert; } + ^^^^^^^^^^^^^ + +test.wgsl:1:23 error: unable to parse condition expression +fn f() { static_assert; } + ^ +)"); +} + +// TODO(crbug.com/tint/1807) +TEST_F(ParserImplErrorTest, DEPRECATED_FunctionDeclStaticAssertMissingCondThenLet) { + EXPECT( + "fn f() { static_assert\nlet x = 0; }", + R"(test.wgsl:1:10 warning: use of deprecated language feature: 'static_assert' has been renamed to 'const_assert' +fn f() { static_assert + ^^^^^^^^^^^^^ + +test.wgsl:2:1 error: unable to parse condition expression +let x = 0; } +^^^ +)"); +} + +// TODO(crbug.com/tint/1807) +TEST_F(ParserImplErrorTest, DEPRECATED_FunctionDeclStaticAssertMissingLParen) { + EXPECT( + "fn f() { static_assert true);", + R"(test.wgsl:1:10 warning: use of deprecated language feature: 'static_assert' has been renamed to 'const_assert' +fn f() { static_assert true); + ^^^^^^^^^^^^^ + +test.wgsl:1:28 error: expected ';' for statement fn f() { static_assert true); ^ )"); } -TEST_F(ParserImplErrorTest, FunctionDeclStaticAssertMissingRParen) { - EXPECT("fn f() { static_assert (true;", R"(test.wgsl:1:29 error: expected ')' +// TODO(crbug.com/tint/1807) +TEST_F(ParserImplErrorTest, DEPRECATED_FunctionDeclStaticAssertMissingRParen) { + EXPECT( + "fn f() { static_assert (true;", + R"(test.wgsl:1:10 warning: use of deprecated language feature: 'static_assert' has been renamed to 'const_assert' +fn f() { static_assert (true; + ^^^^^^^^^^^^^ + +test.wgsl:1:29 error: expected ')' fn f() { static_assert (true; ^ )"); } -TEST_F(ParserImplErrorTest, FunctionDeclStaticAssertMissingSemicolon) { - EXPECT("fn f() { static_assert true }", - R"(test.wgsl:1:29 error: expected ';' for statement +// TODO(crbug.com/tint/1807) +TEST_F(ParserImplErrorTest, DEPRECATED_FunctionDeclStaticAssertMissingSemicolon) { + EXPECT( + "fn f() { static_assert true }", + R"(test.wgsl:1:10 warning: use of deprecated language feature: 'static_assert' has been renamed to 'const_assert' +fn f() { static_assert true } + ^^^^^^^^^^^^^ + +test.wgsl:1:29 error: expected ';' for statement fn f() { static_assert true } ^ )"); @@ -622,46 +706,124 @@ var x : texture_multisampled_2d<1>; )"); } -TEST_F(ParserImplErrorTest, GlobalDeclStaticAssertMissingCondThenEOF) { - EXPECT("static_assert", R"(test.wgsl:1:14 error: unable to parse condition expression -static_assert - ^ +TEST_F(ParserImplErrorTest, GlobalDeclConstAssertMissingCondThenEOF) { + EXPECT("const_assert", R"(test.wgsl:1:13 error: unable to parse condition expression +const_assert + ^ )"); } -TEST_F(ParserImplErrorTest, GlobalDeclStaticAssertMissingCondThenSemicolon) { - EXPECT("static_assert;", R"(test.wgsl:1:14 error: unable to parse condition expression -static_assert; - ^ +TEST_F(ParserImplErrorTest, GlobalDeclConstAssertMissingCondThenSemicolon) { + EXPECT("const_assert;", R"(test.wgsl:1:13 error: unable to parse condition expression +const_assert; + ^ )"); } -TEST_F(ParserImplErrorTest, GlobalDeclStaticAssertMissingCondThenAlias) { - EXPECT("static_assert\ntype T = i32;", +TEST_F(ParserImplErrorTest, GlobalDeclConstAssertMissingCondThenAlias) { + EXPECT("const_assert\ntype T = i32;", R"(test.wgsl:2:1 error: unable to parse condition expression type T = i32; ^^^^ )"); } -TEST_F(ParserImplErrorTest, GlobalDeclStaticAssertMissingLParen) { - EXPECT("static_assert true);", - R"(test.wgsl:1:19 error: expected ';' for static assertion declaration +TEST_F(ParserImplErrorTest, GlobalDeclConstAssertMissingLParen) { + EXPECT("const_assert true);", + R"(test.wgsl:1:18 error: expected ';' for const assertion declaration +const_assert true); + ^ +)"); +} + +TEST_F(ParserImplErrorTest, GlobalDeclConstAssertMissingRParen) { + EXPECT("const_assert (true;", R"(test.wgsl:1:19 error: expected ')' +const_assert (true; + ^ +)"); +} + +TEST_F(ParserImplErrorTest, GlobalDeclConstAssertMissingSemicolon) { + EXPECT("const_assert true const_assert true;", + R"(test.wgsl:1:19 error: expected ';' for const assertion declaration +const_assert true const_assert true; + ^^^^^^^^^^^^ +)"); +} + +// TODO(crbug.com/tint/1807): DEPRECATED +TEST_F(ParserImplErrorTest, DEPRECATED_GlobalDeclStaticAssertMissingCondThenEOF) { + EXPECT("const_assert", R"(test.wgsl:1:13 error: unable to parse condition expression +const_assert + ^ +)"); +} + +// TODO(crbug.com/tint/1807): DEPRECATED +TEST_F(ParserImplErrorTest, DEPRECATED_GlobalDeclStaticAssertMissingCondThenSemicolon) { + EXPECT( + "static_assert;", + R"(test.wgsl:1:1 warning: use of deprecated language feature: 'static_assert' has been renamed to 'const_assert' +static_assert; +^^^^^^^^^^^^^ + +test.wgsl:1:14 error: unable to parse condition expression +static_assert; + ^ +)"); +} + +// TODO(crbug.com/tint/1807): DEPRECATED +TEST_F(ParserImplErrorTest, DEPRECATED_GlobalDeclStaticAssertMissingCondThenAlias) { + EXPECT( + "static_assert\ntype T = i32;", + R"(test.wgsl:1:1 warning: use of deprecated language feature: 'static_assert' has been renamed to 'const_assert' +static_assert +^^^^^^^^^^^^^ + +test.wgsl:2:1 error: unable to parse condition expression +type T = i32; +^^^^ +)"); +} + +// TODO(crbug.com/tint/1807): DEPRECATED +TEST_F(ParserImplErrorTest, DEPRECATED_GlobalDeclStaticAssertMissingLParen) { + EXPECT( + "static_assert true);", + R"(test.wgsl:1:1 warning: use of deprecated language feature: 'static_assert' has been renamed to 'const_assert' +static_assert true); +^^^^^^^^^^^^^ + +test.wgsl:1:19 error: expected ';' for const assertion declaration static_assert true); ^ )"); } -TEST_F(ParserImplErrorTest, GlobalDeclStaticAssertMissingRParen) { - EXPECT("static_assert (true;", R"(test.wgsl:1:20 error: expected ')' +// TODO(crbug.com/tint/1807): DEPRECATED +TEST_F(ParserImplErrorTest, DEPRECATED_GlobalDeclStaticAssertMissingRParen) { + EXPECT( + "static_assert (true;", + R"(test.wgsl:1:1 warning: use of deprecated language feature: 'static_assert' has been renamed to 'const_assert' +static_assert (true; +^^^^^^^^^^^^^ + +test.wgsl:1:20 error: expected ')' static_assert (true; ^ )"); } -TEST_F(ParserImplErrorTest, GlobalDeclStaticAssertMissingSemicolon) { - EXPECT("static_assert true static_assert true;", - R"(test.wgsl:1:20 error: expected ';' for static assertion declaration +// TODO(crbug.com/tint/1807): DEPRECATED +TEST_F(ParserImplErrorTest, DEPRECATED_GlobalDeclStaticAssertMissingSemicolon) { + EXPECT( + "static_assert true static_assert true;", + R"(test.wgsl:1:1 warning: use of deprecated language feature: 'static_assert' has been renamed to 'const_assert' +static_assert true static_assert true; +^^^^^^^^^^^^^ + +test.wgsl:1:20 error: expected ';' for const assertion declaration static_assert true static_assert true; ^^^^^^^^^^^^^ )"); diff --git a/src/tint/reader/wgsl/parser_impl_global_decl_test.cc b/src/tint/reader/wgsl/parser_impl_global_decl_test.cc index d6d32e0ac6..c79af0df1b 100644 --- a/src/tint/reader/wgsl/parser_impl_global_decl_test.cc +++ b/src/tint/reader/wgsl/parser_impl_global_decl_test.cc @@ -257,14 +257,57 @@ TEST_F(ParserImplTest, GlobalDecl_Struct_UnexpectedAttribute) { EXPECT_EQ(p->error(), "1:2: unexpected attributes"); } -TEST_F(ParserImplTest, GlobalDecl_StaticAssert_WithParen) { +TEST_F(ParserImplTest, GlobalDecl_ConstAssert_WithParen) { + auto p = parser("const_assert(true);"); + p->global_decl(); + ASSERT_FALSE(p->has_error()) << p->error(); + + auto program = p->program(); + ASSERT_EQ(program.AST().ConstAsserts().Length(), 1u); + auto* sa = program.AST().ConstAsserts()[0]; + EXPECT_EQ(sa->source.range.begin.line, 1u); + EXPECT_EQ(sa->source.range.begin.column, 1u); + EXPECT_EQ(sa->source.range.end.line, 1u); + EXPECT_EQ(sa->source.range.end.column, 19u); + + EXPECT_TRUE(sa->condition->Is()); + EXPECT_EQ(sa->condition->source.range.begin.line, 1u); + EXPECT_EQ(sa->condition->source.range.begin.column, 14u); + EXPECT_EQ(sa->condition->source.range.end.line, 1u); + EXPECT_EQ(sa->condition->source.range.end.column, 18u); +} + +TEST_F(ParserImplTest, GlobalDecl_ConstAssert_WithoutParen) { + auto p = parser("const_assert true;"); + p->global_decl(); + ASSERT_FALSE(p->has_error()) << p->error(); + + auto program = p->program(); + ASSERT_EQ(program.AST().ConstAsserts().Length(), 1u); + auto* sa = program.AST().ConstAsserts()[0]; + EXPECT_TRUE(sa->condition->Is()); + + EXPECT_EQ(sa->source.range.begin.line, 1u); + EXPECT_EQ(sa->source.range.begin.column, 1u); + EXPECT_EQ(sa->source.range.end.line, 1u); + EXPECT_EQ(sa->source.range.end.column, 19u); + + EXPECT_TRUE(sa->condition->Is()); + EXPECT_EQ(sa->condition->source.range.begin.line, 1u); + EXPECT_EQ(sa->condition->source.range.begin.column, 15u); + EXPECT_EQ(sa->condition->source.range.end.line, 1u); + EXPECT_EQ(sa->condition->source.range.end.column, 19u); +} + +// TODO(crbug.com/tint/1807) +TEST_F(ParserImplTest, DEPRECATED_GlobalDecl_StaticAssert_WithParen) { auto p = parser("static_assert(true);"); p->global_decl(); ASSERT_FALSE(p->has_error()) << p->error(); auto program = p->program(); - ASSERT_EQ(program.AST().StaticAsserts().Length(), 1u); - auto* sa = program.AST().StaticAsserts()[0]; + ASSERT_EQ(program.AST().ConstAsserts().Length(), 1u); + auto* sa = program.AST().ConstAsserts()[0]; EXPECT_EQ(sa->source.range.begin.line, 1u); EXPECT_EQ(sa->source.range.begin.column, 1u); EXPECT_EQ(sa->source.range.end.line, 1u); @@ -277,14 +320,15 @@ TEST_F(ParserImplTest, GlobalDecl_StaticAssert_WithParen) { EXPECT_EQ(sa->condition->source.range.end.column, 19u); } -TEST_F(ParserImplTest, GlobalDecl_StaticAssert_WithoutParen) { +// TODO(crbug.com/tint/1807) +TEST_F(ParserImplTest, DEPRECATED_GlobalDecl_StaticAssert_WithoutParen) { auto p = parser("static_assert true;"); p->global_decl(); ASSERT_FALSE(p->has_error()) << p->error(); auto program = p->program(); - ASSERT_EQ(program.AST().StaticAsserts().Length(), 1u); - auto* sa = program.AST().StaticAsserts()[0]; + ASSERT_EQ(program.AST().ConstAsserts().Length(), 1u); + auto* sa = program.AST().ConstAsserts()[0]; EXPECT_TRUE(sa->condition->Is()); EXPECT_EQ(sa->source.range.begin.line, 1u); diff --git a/src/tint/reader/wgsl/parser_impl_statement_test.cc b/src/tint/reader/wgsl/parser_impl_statement_test.cc index f78e94400f..f21a4e7567 100644 --- a/src/tint/reader/wgsl/parser_impl_statement_test.cc +++ b/src/tint/reader/wgsl/parser_impl_statement_test.cc @@ -272,14 +272,57 @@ TEST_F(ParserImplTest, Statement_Body_Invalid) { EXPECT_EQ(p->error(), "1:3: expected '}'"); } -TEST_F(ParserImplTest, Statement_StaticAssert_WithParen) { +TEST_F(ParserImplTest, Statement_ConstAssert_WithParen) { + auto p = parser("const_assert(true);"); + auto e = p->statement(); + ASSERT_FALSE(p->has_error()) << p->error(); + EXPECT_TRUE(e.matched); + EXPECT_FALSE(e.errored); + + auto* sa = As(e.value); + ASSERT_NE(sa, nullptr); + EXPECT_EQ(sa->source.range.begin.line, 1u); + EXPECT_EQ(sa->source.range.begin.column, 1u); + EXPECT_EQ(sa->source.range.end.line, 1u); + EXPECT_EQ(sa->source.range.end.column, 19u); + + EXPECT_TRUE(sa->condition->Is()); + EXPECT_EQ(sa->condition->source.range.begin.line, 1u); + EXPECT_EQ(sa->condition->source.range.begin.column, 14u); + EXPECT_EQ(sa->condition->source.range.end.line, 1u); + EXPECT_EQ(sa->condition->source.range.end.column, 18u); +} + +TEST_F(ParserImplTest, Statement_ConstAssert_WithoutParen) { + auto p = parser("const_assert true;"); + auto e = p->statement(); + ASSERT_FALSE(p->has_error()) << p->error(); + EXPECT_TRUE(e.matched); + EXPECT_FALSE(e.errored); + + auto* sa = As(e.value); + ASSERT_NE(sa, nullptr); + EXPECT_EQ(sa->source.range.begin.line, 1u); + EXPECT_EQ(sa->source.range.begin.column, 1u); + EXPECT_EQ(sa->source.range.end.line, 1u); + EXPECT_EQ(sa->source.range.end.column, 19u); + + EXPECT_TRUE(sa->condition->Is()); + EXPECT_EQ(sa->condition->source.range.begin.line, 1u); + EXPECT_EQ(sa->condition->source.range.begin.column, 15u); + EXPECT_EQ(sa->condition->source.range.end.line, 1u); + EXPECT_EQ(sa->condition->source.range.end.column, 19u); +} + +// TODO(crbug.com/tint/1807) +TEST_F(ParserImplTest, DEPRECATED_Statement_StaticAssert_WithParen) { auto p = parser("static_assert(true);"); auto e = p->statement(); ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - auto* sa = As(e.value); + auto* sa = As(e.value); ASSERT_NE(sa, nullptr); EXPECT_EQ(sa->source.range.begin.line, 1u); EXPECT_EQ(sa->source.range.begin.column, 1u); @@ -293,14 +336,15 @@ TEST_F(ParserImplTest, Statement_StaticAssert_WithParen) { EXPECT_EQ(sa->condition->source.range.end.column, 19u); } -TEST_F(ParserImplTest, Statement_StaticAssert_WithoutParen) { +// TODO(crbug.com/tint/1807) +TEST_F(ParserImplTest, DEPRECATED_Statement_StaticAssert_WithoutParen) { auto p = parser("static_assert true;"); auto e = p->statement(); ASSERT_FALSE(p->has_error()) << p->error(); EXPECT_TRUE(e.matched); EXPECT_FALSE(e.errored); - auto* sa = As(e.value); + auto* sa = As(e.value); ASSERT_NE(sa, nullptr); EXPECT_EQ(sa->source.range.begin.line, 1u); EXPECT_EQ(sa->source.range.begin.column, 1u); diff --git a/src/tint/reader/wgsl/token.cc b/src/tint/reader/wgsl/token.cc index 290cc1e3c3..c85bbf0a43 100644 --- a/src/tint/reader/wgsl/token.cc +++ b/src/tint/reader/wgsl/token.cc @@ -151,6 +151,8 @@ std::string_view Token::TypeToName(Type type) { return "case"; case Token::Type::kConst: return "const"; + case Token::Type::kConstAssert: + return "const_assert"; case Token::Type::kContinue: return "continue"; case Token::Type::kContinuing: diff --git a/src/tint/reader/wgsl/token.h b/src/tint/reader/wgsl/token.h index ed00ba13c3..1aeab04748 100644 --- a/src/tint/reader/wgsl/token.h +++ b/src/tint/reader/wgsl/token.h @@ -161,6 +161,8 @@ class Token { kCase, /// A 'const' kConst, + /// A 'const_assert' + kConstAssert, /// A 'continue' kContinue, /// A 'continuing' diff --git a/src/tint/resolver/alias_analysis_test.cc b/src/tint/resolver/alias_analysis_test.cc index db78d64b83..66d503367d 100644 --- a/src/tint/resolver/alias_analysis_test.cc +++ b/src/tint/resolver/alias_analysis_test.cc @@ -36,7 +36,7 @@ struct ResolverAliasAnalysisTest : public resolver::TestHelper, public testing:: // } struct TwoPointerConfig { type::AddressSpace address_space; // The address space for the pointers. - bool aliased; // Whether the pointers alias or not. + bool aliased; // Whether the pointers alias or not. }; class TwoPointers : public ResolverTestWithParam { protected: diff --git a/src/tint/resolver/const_assert_test.cc b/src/tint/resolver/const_assert_test.cc new file mode 100644 index 0000000000..fb08b8bfd1 --- /dev/null +++ b/src/tint/resolver/const_assert_test.cc @@ -0,0 +1,107 @@ +// 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/resolver/resolver.h" + +#include "gmock/gmock.h" +#include "src/tint/resolver/resolver_test_helper.h" + +using namespace tint::number_suffixes; // NOLINT + +namespace tint::resolver { +namespace { + +using ResolverConstAssertTest = ResolverTest; + +TEST_F(ResolverConstAssertTest, Global_True_Pass) { + GlobalConstAssert(true); + ASSERT_TRUE(r()->Resolve()) << r()->error(); +} + +TEST_F(ResolverConstAssertTest, Global_False_Fail) { + GlobalConstAssert(Source{{12, 34}}, false); + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), "12:34 error: const assertion failed"); +} + +TEST_F(ResolverConstAssertTest, Global_Const_Pass) { + GlobalConst("C", ty.bool_(), Expr(true)); + GlobalConstAssert("C"); + ASSERT_TRUE(r()->Resolve()) << r()->error(); +} + +TEST_F(ResolverConstAssertTest, Global_Const_Fail) { + GlobalConst("C", ty.bool_(), Expr(false)); + GlobalConstAssert(Source{{12, 34}}, "C"); + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), "12:34 error: const assertion failed"); +} + +TEST_F(ResolverConstAssertTest, Global_LessThan_Pass) { + GlobalConstAssert(LessThan(2_i, 3_i)); + ASSERT_TRUE(r()->Resolve()) << r()->error(); +} + +TEST_F(ResolverConstAssertTest, Global_LessThan_Fail) { + GlobalConstAssert(Source{{12, 34}}, LessThan(4_i, 3_i)); + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), "12:34 error: const assertion failed"); +} + +TEST_F(ResolverConstAssertTest, Local_True_Pass) { + WrapInFunction(ConstAssert(true)); + ASSERT_TRUE(r()->Resolve()) << r()->error(); +} + +TEST_F(ResolverConstAssertTest, Local_False_Fail) { + WrapInFunction(ConstAssert(Source{{12, 34}}, false)); + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), "12:34 error: const assertion failed"); +} + +TEST_F(ResolverConstAssertTest, Local_Const_Pass) { + GlobalConst("C", ty.bool_(), Expr(true)); + WrapInFunction(ConstAssert("C")); + ASSERT_TRUE(r()->Resolve()) << r()->error(); +} + +TEST_F(ResolverConstAssertTest, Local_Const_Fail) { + GlobalConst("C", ty.bool_(), Expr(false)); + WrapInFunction(ConstAssert(Source{{12, 34}}, "C")); + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), "12:34 error: const assertion failed"); +} + +TEST_F(ResolverConstAssertTest, Local_NonConst) { + GlobalVar("V", ty.bool_(), Expr(true), type::AddressSpace::kPrivate); + WrapInFunction(ConstAssert(Expr(Source{{12, 34}}, "V"))); + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), + "12:34 error: const assertion requires a const-expression, but expression is a " + "runtime-expression"); +} + +TEST_F(ResolverConstAssertTest, Local_LessThan_Pass) { + WrapInFunction(ConstAssert(LessThan(2_i, 3_i))); + ASSERT_TRUE(r()->Resolve()) << r()->error(); +} + +TEST_F(ResolverConstAssertTest, Local_LessThan_Fail) { + WrapInFunction(ConstAssert(Source{{12, 34}}, LessThan(4_i, 3_i))); + EXPECT_FALSE(r()->Resolve()); + EXPECT_EQ(r()->error(), "12:34 error: const assertion failed"); +} + +} // namespace +} // namespace tint::resolver diff --git a/src/tint/resolver/dependency_graph.cc b/src/tint/resolver/dependency_graph.cc index 4047ce5f1f..17fcb47132 100644 --- a/src/tint/resolver/dependency_graph.cc +++ b/src/tint/resolver/dependency_graph.cc @@ -207,7 +207,7 @@ class DependencyScanner { [&](const ast::Enable*) { // Enable directives do not effect the dependency graph. }, - [&](const ast::StaticAssert* assertion) { TraverseExpression(assertion->condition); }, + [&](const ast::ConstAssert* assertion) { TraverseExpression(assertion->condition); }, [&](Default) { UnhandledNode(diagnostics_, global->node); }); } @@ -319,7 +319,7 @@ class DependencyScanner { TraverseExpression(w->condition); TraverseStatement(w->body); }, - [&](const ast::StaticAssert* assertion) { TraverseExpression(assertion->condition); }, + [&](const ast::ConstAssert* assertion) { TraverseExpression(assertion->condition); }, [&](Default) { if (TINT_UNLIKELY((!stmt->IsAnyOf()))) { @@ -556,7 +556,7 @@ struct DependencyAnalysis { [&](const ast::Function* func) { return func->symbol; }, [&](const ast::Variable* var) { return var->symbol; }, [&](const ast::Enable*) { return Symbol(); }, - [&](const ast::StaticAssert*) { return Symbol(); }, + [&](const ast::ConstAssert*) { return Symbol(); }, [&](Default) { UnhandledNode(diagnostics_, node); return Symbol{}; @@ -575,12 +575,12 @@ struct DependencyAnalysis { /// declaration std::string KindOf(const ast::Node* node) { return Switch( - node, // - [&](const ast::Struct*) { return "struct"; }, // - [&](const ast::Alias*) { return "alias"; }, // - [&](const ast::Function*) { return "function"; }, // - [&](const ast::Variable* v) { return v->Kind(); }, // - [&](const ast::StaticAssert*) { return "static_assert"; }, // + node, // + [&](const ast::Struct*) { return "struct"; }, // + [&](const ast::Alias*) { return "alias"; }, // + [&](const ast::Function*) { return "function"; }, // + [&](const ast::Variable* v) { return v->Kind(); }, // + [&](const ast::ConstAssert*) { return "const_assert"; }, // [&](Default) { UnhandledNode(diagnostics_, node); return ""; diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 3f306b594e..59e36bbd6b 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -155,7 +155,7 @@ bool Resolver::ResolveInternal() { [&](const ast::TypeDecl* td) { return TypeDecl(td); }, [&](const ast::Function* func) { return Function(func); }, [&](const ast::Variable* var) { return GlobalVariable(var); }, - [&](const ast::StaticAssert* sa) { return StaticAssert(sa); }, + [&](const ast::ConstAssert* ca) { return ConstAssert(ca); }, [&](Default) { TINT_UNREACHABLE(Resolver, diagnostics_) << "unhandled global declaration: " << decl->TypeInfo().name; @@ -936,8 +936,8 @@ sem::GlobalVariable* Resolver::GlobalVariable(const ast::Variable* v) { return sem; } -sem::Statement* Resolver::StaticAssert(const ast::StaticAssert* assertion) { - ExprEvalStageConstraint constraint{sem::EvaluationStage::kConstant, "static assertion"}; +sem::Statement* Resolver::ConstAssert(const ast::ConstAssert* assertion) { + ExprEvalStageConstraint constraint{sem::EvaluationStage::kConstant, "const assertion"}; TINT_SCOPED_ASSIGNMENT(expr_eval_stage_constraint_, constraint); auto* expr = Expression(assertion->condition); if (!expr) { @@ -946,12 +946,12 @@ sem::Statement* Resolver::StaticAssert(const ast::StaticAssert* assertion) { auto* cond = expr->ConstantValue(); if (auto* ty = cond->Type(); !ty->Is()) { AddError( - "static assertion condition must be a bool, got '" + builder_->FriendlyName(ty) + "'", + "const assertion condition must be a bool, got '" + builder_->FriendlyName(ty) + "'", assertion->condition->source); return nullptr; } if (!cond->ValueAs()) { - AddError("static assertion failed", assertion->source); + AddError("const assertion failed", assertion->source); return nullptr; } auto* sem = @@ -1258,7 +1258,7 @@ sem::Statement* Resolver::Statement(const ast::Statement* stmt) { [&](const ast::IncrementDecrementStatement* i) { return IncrementDecrementStatement(i); }, [&](const ast::ReturnStatement* r) { return ReturnStatement(r); }, [&](const ast::VariableDeclStatement* v) { return VariableDeclStatement(v); }, - [&](const ast::StaticAssert* sa) { return StaticAssert(sa); }, + [&](const ast::ConstAssert* sa) { return ConstAssert(sa); }, // Error cases [&](const ast::CaseStatement*) { diff --git a/src/tint/resolver/resolver.h b/src/tint/resolver/resolver.h index 38d08c020e..87998854a9 100644 --- a/src/tint/resolver/resolver.h +++ b/src/tint/resolver/resolver.h @@ -230,6 +230,7 @@ class Resolver { sem::CaseStatement* CaseStatement(const ast::CaseStatement*, const type::Type*); sem::Statement* CompoundAssignmentStatement(const ast::CompoundAssignmentStatement*); sem::Statement* ContinueStatement(const ast::ContinueStatement*); + sem::Statement* ConstAssert(const ast::ConstAssert*); sem::Statement* DiscardStatement(const ast::DiscardStatement*); sem::ForLoopStatement* ForLoopStatement(const ast::ForLoopStatement*); sem::WhileStatement* WhileStatement(const ast::WhileStatement*); @@ -240,7 +241,6 @@ class Resolver { sem::LoopStatement* LoopStatement(const ast::LoopStatement*); sem::Statement* ReturnStatement(const ast::ReturnStatement*); sem::Statement* Statement(const ast::Statement*); - sem::Statement* StaticAssert(const ast::StaticAssert*); sem::SwitchStatement* SwitchStatement(const ast::SwitchStatement* s); sem::Statement* VariableDeclStatement(const ast::VariableDeclStatement*); bool Statements(utils::VectorRef); diff --git a/src/tint/resolver/static_assert_test.cc b/src/tint/resolver/static_assert_test.cc deleted file mode 100644 index 3915dcd4fa..0000000000 --- a/src/tint/resolver/static_assert_test.cc +++ /dev/null @@ -1,107 +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/resolver/resolver.h" - -#include "gmock/gmock.h" -#include "src/tint/resolver/resolver_test_helper.h" - -using namespace tint::number_suffixes; // NOLINT - -namespace tint::resolver { -namespace { - -using ResolverStaticAssertTest = ResolverTest; - -TEST_F(ResolverStaticAssertTest, Global_True_Pass) { - GlobalStaticAssert(true); - ASSERT_TRUE(r()->Resolve()) << r()->error(); -} - -TEST_F(ResolverStaticAssertTest, Global_False_Fail) { - GlobalStaticAssert(Source{{12, 34}}, false); - EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: static assertion failed"); -} - -TEST_F(ResolverStaticAssertTest, Global_Const_Pass) { - GlobalConst("C", ty.bool_(), Expr(true)); - GlobalStaticAssert("C"); - ASSERT_TRUE(r()->Resolve()) << r()->error(); -} - -TEST_F(ResolverStaticAssertTest, Global_Const_Fail) { - GlobalConst("C", ty.bool_(), Expr(false)); - GlobalStaticAssert(Source{{12, 34}}, "C"); - EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: static assertion failed"); -} - -TEST_F(ResolverStaticAssertTest, Global_LessThan_Pass) { - GlobalStaticAssert(LessThan(2_i, 3_i)); - ASSERT_TRUE(r()->Resolve()) << r()->error(); -} - -TEST_F(ResolverStaticAssertTest, Global_LessThan_Fail) { - GlobalStaticAssert(Source{{12, 34}}, LessThan(4_i, 3_i)); - EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: static assertion failed"); -} - -TEST_F(ResolverStaticAssertTest, Local_True_Pass) { - WrapInFunction(StaticAssert(true)); - ASSERT_TRUE(r()->Resolve()) << r()->error(); -} - -TEST_F(ResolverStaticAssertTest, Local_False_Fail) { - WrapInFunction(StaticAssert(Source{{12, 34}}, false)); - EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: static assertion failed"); -} - -TEST_F(ResolverStaticAssertTest, Local_Const_Pass) { - GlobalConst("C", ty.bool_(), Expr(true)); - WrapInFunction(StaticAssert("C")); - ASSERT_TRUE(r()->Resolve()) << r()->error(); -} - -TEST_F(ResolverStaticAssertTest, Local_Const_Fail) { - GlobalConst("C", ty.bool_(), Expr(false)); - WrapInFunction(StaticAssert(Source{{12, 34}}, "C")); - EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: static assertion failed"); -} - -TEST_F(ResolverStaticAssertTest, Local_NonConst) { - GlobalVar("V", ty.bool_(), Expr(true), type::AddressSpace::kPrivate); - WrapInFunction(StaticAssert(Expr(Source{{12, 34}}, "V"))); - EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), - "12:34 error: static assertion requires a const-expression, but expression is a " - "runtime-expression"); -} - -TEST_F(ResolverStaticAssertTest, Local_LessThan_Pass) { - WrapInFunction(StaticAssert(LessThan(2_i, 3_i))); - ASSERT_TRUE(r()->Resolve()) << r()->error(); -} - -TEST_F(ResolverStaticAssertTest, Local_LessThan_Fail) { - WrapInFunction(StaticAssert(Source{{12, 34}}, LessThan(4_i, 3_i))); - EXPECT_FALSE(r()->Resolve()); - EXPECT_EQ(r()->error(), "12:34 error: static assertion failed"); -} - -} // namespace -} // namespace tint::resolver diff --git a/src/tint/resolver/uniformity.cc b/src/tint/resolver/uniformity.cc index 7b297e17db..77297b2f71 100644 --- a/src/tint/resolver/uniformity.cc +++ b/src/tint/resolver/uniformity.cc @@ -1067,7 +1067,7 @@ class UniformityGraph { return cf; }, - [&](const ast::StaticAssert*) { + [&](const ast::ConstAssert*) { return cf; // No impact on uniformity }, diff --git a/src/tint/transform/decompose_memory_access.cc b/src/tint/transform/decompose_memory_access.cc index cbef564edf..abb78b2f78 100644 --- a/src/tint/transform/decompose_memory_access.cc +++ b/src/tint/transform/decompose_memory_access.cc @@ -111,8 +111,8 @@ struct OffsetBinOp : Offset { struct LoadStoreKey { type::AddressSpace const address_space; // buffer address space type::Access const access; // buffer access - type::Type const* buf_ty = nullptr; // buffer type - type::Type const* el_ty = nullptr; // element type + type::Type const* buf_ty = nullptr; // buffer type + type::Type const* el_ty = nullptr; // element type bool operator==(const LoadStoreKey& rhs) const { return address_space == rhs.address_space && access == rhs.access && buf_ty == rhs.buf_ty && el_ty == rhs.el_ty; diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 8bd4033174..5b1020948b 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -250,7 +250,7 @@ bool GeneratorImpl::Generate() { auto* mod = builder_.Sem().Module(); for (auto* decl : mod->DependencyOrderedDeclarations()) { - if (decl->IsAnyOf()) { + if (decl->IsAnyOf()) { continue; // These are not emitted. } @@ -2796,7 +2796,7 @@ bool GeneratorImpl::EmitStatement(const ast::Statement* stmt) { return false; }); }, - [&](const ast::StaticAssert*) { + [&](const ast::ConstAssert*) { return true; // Not emitted }, [&](Default) { diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc index 82237dbd34..69c19f15d9 100644 --- a/src/tint/writer/hlsl/generator_impl.cc +++ b/src/tint/writer/hlsl/generator_impl.cc @@ -310,7 +310,7 @@ bool GeneratorImpl::Generate() { auto* mod = builder_.Sem().Module(); for (auto* decl : mod->DependencyOrderedDeclarations()) { - if (decl->IsAnyOf()) { + if (decl->IsAnyOf()) { continue; // These are not emitted. } @@ -3842,7 +3842,7 @@ bool GeneratorImpl::EmitStatement(const ast::Statement* stmt) { return false; }); }, - [&](const ast::StaticAssert*) { + [&](const ast::ConstAssert*) { return true; // Not emitted }, [&](Default) { // diff --git a/src/tint/writer/hlsl/generator_impl_static_assert_test.cc b/src/tint/writer/hlsl/generator_impl_const_assert_test.cc similarity index 78% rename from src/tint/writer/hlsl/generator_impl_static_assert_test.cc rename to src/tint/writer/hlsl/generator_impl_const_assert_test.cc index 8ae5dd8b00..eac90c6228 100644 --- a/src/tint/writer/hlsl/generator_impl_static_assert_test.cc +++ b/src/tint/writer/hlsl/generator_impl_const_assert_test.cc @@ -21,23 +21,23 @@ namespace { using HlslGeneratorImplTest = TestHelper; -TEST_F(HlslGeneratorImplTest, Emit_GlobalStaticAssert) { - GlobalStaticAssert(true); +TEST_F(HlslGeneratorImplTest, Emit_GlobalConstAssert) { + GlobalConstAssert(true); GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.Generate()) << gen.error(); - // static asserts are not emitted + // const asserts are not emitted EXPECT_EQ(gen.result(), ""); } -TEST_F(HlslGeneratorImplTest, Emit_FunctionStaticAssert) { - Func("f", utils::Empty, ty.void_(), utils::Vector{StaticAssert(true)}); +TEST_F(HlslGeneratorImplTest, Emit_FunctionConstAssert) { + Func("f", utils::Empty, ty.void_(), utils::Vector{ConstAssert(true)}); GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.Generate()) << gen.error(); - // static asserts are not emitted + // const asserts are not emitted EXPECT_EQ(gen.result(), R"(void f() { } )"); diff --git a/src/tint/writer/msl/generator_impl.cc b/src/tint/writer/msl/generator_impl.cc index 251483e1d1..bff14a293c 100644 --- a/src/tint/writer/msl/generator_impl.cc +++ b/src/tint/writer/msl/generator_impl.cc @@ -317,7 +317,7 @@ bool GeneratorImpl::Generate() { // Do nothing for enabling extension in MSL return true; }, - [&](const ast::StaticAssert*) { + [&](const ast::ConstAssert*) { return true; // Not emitted }, [&](Default) { @@ -2469,7 +2469,7 @@ bool GeneratorImpl::EmitStatement(const ast::Statement* stmt) { return false; }); }, - [&](const ast::StaticAssert*) { + [&](const ast::ConstAssert*) { return true; // Not emitted }, [&](Default) { diff --git a/src/tint/writer/msl/generator_impl_static_assert_test.cc b/src/tint/writer/msl/generator_impl_const_assert_test.cc similarity index 79% rename from src/tint/writer/msl/generator_impl_static_assert_test.cc rename to src/tint/writer/msl/generator_impl_const_assert_test.cc index 5b8ca3fd94..a9850ebc25 100644 --- a/src/tint/writer/msl/generator_impl_static_assert_test.cc +++ b/src/tint/writer/msl/generator_impl_const_assert_test.cc @@ -21,26 +21,26 @@ namespace { using MslGeneratorImplTest = TestHelper; -TEST_F(MslGeneratorImplTest, Emit_GlobalStaticAssert) { - GlobalStaticAssert(true); +TEST_F(MslGeneratorImplTest, Emit_GlobalConstAssert) { + GlobalConstAssert(true); GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.Generate()) << gen.error(); - // static asserts are not emitted + // const asserts are not emitted EXPECT_EQ(gen.result(), R"(#include using namespace metal; )"); } -TEST_F(MslGeneratorImplTest, Emit_FunctionStaticAssert) { - Func("f", utils::Empty, ty.void_(), utils::Vector{StaticAssert(true)}); +TEST_F(MslGeneratorImplTest, Emit_FunctionConstAssert) { + Func("f", utils::Empty, ty.void_(), utils::Vector{ConstAssert(true)}); GeneratorImpl& gen = Build(); ASSERT_TRUE(gen.Generate()) << gen.error(); - // static asserts are not emitted + // const asserts are not emitted EXPECT_EQ(gen.result(), R"(#include using namespace metal; diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc index 9df433b3bc..39297ae939 100644 --- a/src/tint/writer/spirv/builder.cc +++ b/src/tint/writer/spirv/builder.cc @@ -3614,7 +3614,7 @@ bool Builder::GenerateStatement(const ast::Statement* stmt) { [&](const ast::ReturnStatement* r) { return GenerateReturnStatement(r); }, [&](const ast::SwitchStatement* s) { return GenerateSwitchStatement(s); }, [&](const ast::VariableDeclStatement* v) { return GenerateVariableDeclStatement(v); }, - [&](const ast::StaticAssert*) { + [&](const ast::ConstAssert*) { return true; // Not emitted }, [&](Default) { diff --git a/src/tint/writer/spirv/builder_static_assert_test.cc b/src/tint/writer/spirv/builder_const_assert_test.cc similarity index 82% rename from src/tint/writer/spirv/builder_static_assert_test.cc rename to src/tint/writer/spirv/builder_const_assert_test.cc index 6e5092d9fa..bca6deb533 100644 --- a/src/tint/writer/spirv/builder_static_assert_test.cc +++ b/src/tint/writer/spirv/builder_const_assert_test.cc @@ -22,26 +22,26 @@ namespace { using BuilderTest = TestHelper; -TEST_F(BuilderTest, GlobalStaticAssert) { - GlobalStaticAssert(true); +TEST_F(BuilderTest, GlobalConstAssert) { + GlobalConstAssert(true); spirv::Builder& b = Build(); ASSERT_TRUE(b.Build()) << b.error(); - // static asserts are not emitted + // const asserts are not emitted EXPECT_EQ(DumpInstructions(b.types()), ""); EXPECT_EQ(b.functions().size(), 0u); } -TEST_F(BuilderTest, FunctionStaticAssert) { - Func("f", utils::Empty, ty.void_(), utils::Vector{StaticAssert(true)}); +TEST_F(BuilderTest, FunctionConstAssert) { + Func("f", utils::Empty, ty.void_(), utils::Vector{ConstAssert(true)}); spirv::Builder& b = Build(); ASSERT_TRUE(b.Build()) << b.error(); - // static asserts are not emitted + // const asserts are not emitted EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid %1 = OpTypeFunction %2 )"); diff --git a/src/tint/writer/wgsl/generator_impl.cc b/src/tint/writer/wgsl/generator_impl.cc index 2a722724a8..d83ad4a735 100644 --- a/src/tint/writer/wgsl/generator_impl.cc +++ b/src/tint/writer/wgsl/generator_impl.cc @@ -82,7 +82,7 @@ bool GeneratorImpl::Generate() { [&](const ast::TypeDecl* td) { return EmitTypeDecl(td); }, [&](const ast::Function* func) { return EmitFunction(func); }, [&](const ast::Variable* var) { return EmitVariable(line(), var); }, - [&](const ast::StaticAssert* sa) { return EmitStaticAssert(sa); }, + [&](const ast::ConstAssert* ca) { return EmitConstAssert(ca); }, [&](Default) { TINT_UNREACHABLE(Writer, diagnostics_); return false; @@ -992,7 +992,7 @@ bool GeneratorImpl::EmitStatement(const ast::Statement* stmt) { [&](const ast::ForLoopStatement* l) { return EmitForLoop(l); }, [&](const ast::WhileStatement* l) { return EmitWhile(l); }, [&](const ast::ReturnStatement* r) { return EmitReturn(r); }, - [&](const ast::StaticAssert* s) { return EmitStaticAssert(s); }, + [&](const ast::ConstAssert* c) { return EmitConstAssert(c); }, [&](const ast::SwitchStatement* s) { return EmitSwitch(s); }, [&](const ast::VariableDeclStatement* v) { return EmitVariable(line(), v->variable); }, [&](Default) { @@ -1299,7 +1299,7 @@ bool GeneratorImpl::EmitReturn(const ast::ReturnStatement* stmt) { return true; } -bool GeneratorImpl::EmitStaticAssert(const ast::StaticAssert* stmt) { +bool GeneratorImpl::EmitConstAssert(const ast::ConstAssert* stmt) { auto out = line(); out << "static_assert "; if (!EmitExpression(out, stmt->condition)) { diff --git a/src/tint/writer/wgsl/generator_impl.h b/src/tint/writer/wgsl/generator_impl.h index f314efbad5..6dd01b3c6c 100644 --- a/src/tint/writer/wgsl/generator_impl.h +++ b/src/tint/writer/wgsl/generator_impl.h @@ -165,10 +165,10 @@ class GeneratorImpl : public TextGenerator { /// @param stmt the statement to emit /// @returns true if the statement was successfully emitted bool EmitReturn(const ast::ReturnStatement* stmt); - /// Handles static assertion statements + /// Handles const assertion statements /// @param stmt the statement to emit /// @returns true if the statement was successfully emitted - bool EmitStaticAssert(const ast::StaticAssert* stmt); + bool EmitConstAssert(const ast::ConstAssert* stmt); /// Handles statement /// @param stmt the statement to emit /// @returns true if the statement was emitted diff --git a/src/tint/writer/wgsl/generator_impl_static_assert_test.cc b/src/tint/writer/wgsl/generator_impl_const_assert_test.cc similarity index 83% rename from src/tint/writer/wgsl/generator_impl_static_assert_test.cc rename to src/tint/writer/wgsl/generator_impl_const_assert_test.cc index 9e7a1c013a..9f76d65a29 100644 --- a/src/tint/writer/wgsl/generator_impl_static_assert_test.cc +++ b/src/tint/writer/wgsl/generator_impl_const_assert_test.cc @@ -21,8 +21,8 @@ namespace { using WgslGeneratorImplTest = TestHelper; -TEST_F(WgslGeneratorImplTest, Emit_GlobalStaticAssert) { - GlobalStaticAssert(true); +TEST_F(WgslGeneratorImplTest, Emit_GlobalConstAssert) { + GlobalConstAssert(true); GeneratorImpl& gen = Build(); @@ -31,8 +31,8 @@ TEST_F(WgslGeneratorImplTest, Emit_GlobalStaticAssert) { )"); } -TEST_F(WgslGeneratorImplTest, Emit_FunctionStaticAssert) { - Func("f", utils::Empty, ty.void_(), utils::Vector{StaticAssert(true)}); +TEST_F(WgslGeneratorImplTest, Emit_FunctionConstAssert) { + Func("f", utils::Empty, ty.void_(), utils::Vector{ConstAssert(true)}); GeneratorImpl& gen = Build();