diff --git a/src/ast/function.cc b/src/ast/function.cc index 5348b6297c..b636559cd7 100644 --- a/src/ast/function.cc +++ b/src/ast/function.cc @@ -55,8 +55,8 @@ Function::~Function() = default; std::tuple Function::workgroup_size() const { for (auto* deco : decorations_) { - if (deco->IsWorkgroup()) { - return deco->AsWorkgroup()->values(); + if (auto* workgroup = deco->As()) { + return workgroup->values(); } } return {1, 1, 1}; diff --git a/src/ast/function_decoration.cc b/src/ast/function_decoration.cc index 0b746befa6..25476a5906 100644 --- a/src/ast/function_decoration.cc +++ b/src/ast/function_decoration.cc @@ -14,10 +14,6 @@ #include "src/ast/function_decoration.h" -#include - -#include "src/ast/workgroup_decoration.h" - namespace tint { namespace ast { @@ -31,14 +27,5 @@ DecorationKind FunctionDecoration::GetKind() const { return Kind; } -bool FunctionDecoration::IsWorkgroup() const { - return false; -} - -const WorkgroupDecoration* FunctionDecoration::AsWorkgroup() const { - assert(IsWorkgroup()); - return static_cast(this); -} - } // namespace ast } // namespace tint diff --git a/src/ast/function_decoration.h b/src/ast/function_decoration.h index fe1a9dd3a9..556a0d90eb 100644 --- a/src/ast/function_decoration.h +++ b/src/ast/function_decoration.h @@ -24,8 +24,6 @@ namespace tint { namespace ast { -class WorkgroupDecoration; - /// A decoration attached to a function class FunctionDecoration : public Castable { public: @@ -37,12 +35,6 @@ class FunctionDecoration : public Castable { /// @return the decoration kind DecorationKind GetKind() const override; - /// @returns true if this is a workgroup decoration - virtual bool IsWorkgroup() const; - - /// @returns the decoration as a workgroup decoration - const WorkgroupDecoration* AsWorkgroup() const; - protected: /// Constructor /// @param source the source of this decoration diff --git a/src/ast/stage_decoration_test.cc b/src/ast/stage_decoration_test.cc index 5adb97ee20..83acb5b191 100644 --- a/src/ast/stage_decoration_test.cc +++ b/src/ast/stage_decoration_test.cc @@ -17,6 +17,7 @@ #include #include "src/ast/test_helper.h" +#include "src/ast/workgroup_decoration.h" namespace tint { namespace ast { @@ -32,8 +33,8 @@ TEST_F(StageDecorationTest, Creation_1param) { TEST_F(StageDecorationTest, Is) { StageDecoration sd{ast::PipelineStage::kFragment, Source{}}; Decoration* d = &sd; - EXPECT_FALSE(sd.IsWorkgroup()); - EXPECT_TRUE(d->Is()); + EXPECT_FALSE(d->Is()); + EXPECT_TRUE(d->Is()); } TEST_F(StageDecorationTest, ToStr) { diff --git a/src/ast/workgroup_decoration.cc b/src/ast/workgroup_decoration.cc index 248718b8a1..f32d09ac91 100644 --- a/src/ast/workgroup_decoration.cc +++ b/src/ast/workgroup_decoration.cc @@ -33,10 +33,6 @@ WorkgroupDecoration::WorkgroupDecoration(uint32_t x, WorkgroupDecoration::~WorkgroupDecoration() = default; -bool WorkgroupDecoration::IsWorkgroup() const { - return true; -} - void WorkgroupDecoration::to_str(std::ostream& out, size_t indent) const { make_indent(out, indent); out << "WorkgroupDecoration{" << x_ << " " << y_ << " " << z_ << "}" diff --git a/src/ast/workgroup_decoration.h b/src/ast/workgroup_decoration.h index 47cc51a428..2345b53e5c 100644 --- a/src/ast/workgroup_decoration.h +++ b/src/ast/workgroup_decoration.h @@ -45,9 +45,6 @@ class WorkgroupDecoration WorkgroupDecoration(uint32_t x, uint32_t y, uint32_t z, const Source& source); ~WorkgroupDecoration() override; - /// @returns true if this is a workgroup decoration - bool IsWorkgroup() const override; - /// @returns the workgroup dimensions std::tuple values() const { return {x_, y_, z_}; diff --git a/src/ast/workgroup_decoration_test.cc b/src/ast/workgroup_decoration_test.cc index 1d722f37f4..e285d35ef8 100644 --- a/src/ast/workgroup_decoration_test.cc +++ b/src/ast/workgroup_decoration_test.cc @@ -60,7 +60,7 @@ TEST_F(WorkgroupDecorationTest, Creation_3param) { TEST_F(WorkgroupDecorationTest, Is) { WorkgroupDecoration wd{2, 4, 6, Source{}}; Decoration* d = &wd; - EXPECT_TRUE(wd.IsWorkgroup()); + EXPECT_TRUE(d->Is()); EXPECT_FALSE(d->Is()); } diff --git a/src/reader/wgsl/parser_impl_function_decl_test.cc b/src/reader/wgsl/parser_impl_function_decl_test.cc index d25e44d799..ca155f2453 100644 --- a/src/reader/wgsl/parser_impl_function_decl_test.cc +++ b/src/reader/wgsl/parser_impl_function_decl_test.cc @@ -74,12 +74,12 @@ TEST_F(ParserImplTest, FunctionDecl_DecorationList) { auto& decorations = f->decorations(); ASSERT_EQ(decorations.size(), 1u); - ASSERT_TRUE(decorations[0]->IsWorkgroup()); + ASSERT_TRUE(decorations[0]->Is()); uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - std::tie(x, y, z) = decorations[0]->AsWorkgroup()->values(); + std::tie(x, y, z) = decorations[0]->As()->values(); EXPECT_EQ(x, 2u); EXPECT_EQ(y, 3u); EXPECT_EQ(z, 4u); @@ -116,14 +116,14 @@ fn main() -> void { return; })"); uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - ASSERT_TRUE(decorations[0]->IsWorkgroup()); - std::tie(x, y, z) = decorations[0]->AsWorkgroup()->values(); + ASSERT_TRUE(decorations[0]->Is()); + std::tie(x, y, z) = decorations[0]->As()->values(); EXPECT_EQ(x, 2u); EXPECT_EQ(y, 3u); EXPECT_EQ(z, 4u); - ASSERT_TRUE(decorations[1]->IsWorkgroup()); - std::tie(x, y, z) = decorations[1]->AsWorkgroup()->values(); + ASSERT_TRUE(decorations[1]->Is()); + std::tie(x, y, z) = decorations[1]->As()->values(); EXPECT_EQ(x, 5u); EXPECT_EQ(y, 6u); EXPECT_EQ(z, 7u); @@ -161,14 +161,14 @@ fn main() -> void { return; })"); uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - ASSERT_TRUE(decos[0]->IsWorkgroup()); - std::tie(x, y, z) = decos[0]->AsWorkgroup()->values(); + ASSERT_TRUE(decos[0]->Is()); + std::tie(x, y, z) = decos[0]->As()->values(); EXPECT_EQ(x, 2u); EXPECT_EQ(y, 3u); EXPECT_EQ(z, 4u); - ASSERT_TRUE(decos[1]->IsWorkgroup()); - std::tie(x, y, z) = decos[1]->AsWorkgroup()->values(); + ASSERT_TRUE(decos[1]->Is()); + std::tie(x, y, z) = decos[1]->As()->values(); EXPECT_EQ(x, 5u); EXPECT_EQ(y, 6u); EXPECT_EQ(z, 7u); diff --git a/src/reader/wgsl/parser_impl_function_decoration_list_test.cc b/src/reader/wgsl/parser_impl_function_decoration_list_test.cc index c77e78371e..9fd25c585a 100644 --- a/src/reader/wgsl/parser_impl_function_decoration_list_test.cc +++ b/src/reader/wgsl/parser_impl_function_decoration_list_test.cc @@ -38,12 +38,12 @@ TEST_F(ParserImplTest, FunctionDecorationList_Parses) { uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - ASSERT_TRUE(deco_0->IsWorkgroup()); - std::tie(x, y, z) = deco_0->AsWorkgroup()->values(); + ASSERT_TRUE(deco_0->Is()); + std::tie(x, y, z) = deco_0->As()->values(); EXPECT_EQ(x, 2u); - ASSERT_TRUE(deco_1->IsWorkgroup()); - std::tie(x, y, z) = deco_1->AsWorkgroup()->values(); + ASSERT_TRUE(deco_1->Is()); + std::tie(x, y, z) = deco_1->As()->values(); EXPECT_EQ(x, 3u); EXPECT_EQ(y, 4u); EXPECT_EQ(z, 5u); diff --git a/src/reader/wgsl/parser_impl_function_decoration_test.cc b/src/reader/wgsl/parser_impl_function_decoration_test.cc index 0e39a34c95..13b9d4563d 100644 --- a/src/reader/wgsl/parser_impl_function_decoration_test.cc +++ b/src/reader/wgsl/parser_impl_function_decoration_test.cc @@ -32,12 +32,12 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup) { ASSERT_FALSE(p->has_error()); auto* func_deco = deco.value->As(); ASSERT_NE(func_deco, nullptr); - ASSERT_TRUE(func_deco->IsWorkgroup()); + ASSERT_TRUE(func_deco->Is()); uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - std::tie(x, y, z) = func_deco->AsWorkgroup()->values(); + std::tie(x, y, z) = func_deco->As()->values(); EXPECT_EQ(x, 4u); EXPECT_EQ(y, 1u); EXPECT_EQ(z, 1u); @@ -52,12 +52,12 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_2Param) { ASSERT_FALSE(p->has_error()); auto* func_deco = deco.value->As(); ASSERT_NE(func_deco, nullptr) << p->error(); - ASSERT_TRUE(func_deco->IsWorkgroup()); + ASSERT_TRUE(func_deco->Is()); uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - std::tie(x, y, z) = func_deco->AsWorkgroup()->values(); + std::tie(x, y, z) = func_deco->As()->values(); EXPECT_EQ(x, 4u); EXPECT_EQ(y, 5u); EXPECT_EQ(z, 1u); @@ -72,12 +72,12 @@ TEST_F(ParserImplTest, FunctionDecoration_Workgroup_3Param) { ASSERT_FALSE(p->has_error()); auto* func_deco = deco.value->As(); ASSERT_NE(func_deco, nullptr); - ASSERT_TRUE(func_deco->IsWorkgroup()); + ASSERT_TRUE(func_deco->Is()); uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - std::tie(x, y, z) = func_deco->AsWorkgroup()->values(); + std::tie(x, y, z) = func_deco->As()->values(); EXPECT_EQ(x, 4u); EXPECT_EQ(y, 5u); EXPECT_EQ(z, 6u); diff --git a/src/writer/wgsl/generator_impl.cc b/src/writer/wgsl/generator_impl.cc index ad77a7cd78..a417837e20 100644 --- a/src/writer/wgsl/generator_impl.cc +++ b/src/writer/wgsl/generator_impl.cc @@ -346,11 +346,11 @@ bool GeneratorImpl::EmitFunction(ast::Function* func) { for (auto* deco : func->decorations()) { make_indent(); out_ << "[["; - if (deco->IsWorkgroup()) { + if (auto* workgroup = deco->As()) { uint32_t x = 0; uint32_t y = 0; uint32_t z = 0; - std::tie(x, y, z) = deco->AsWorkgroup()->values(); + std::tie(x, y, z) = workgroup->values(); out_ << "workgroup_size(" << std::to_string(x) << ", " << std::to_string(y) << ", " << std::to_string(z) << ")"; }