From 51265542e99e3b2f0f03b8b759919d3e88078208 Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Thu, 7 Jul 2022 17:15:01 +0000 Subject: [PATCH] tint/sem: Remove TypeMappings for derived expressions Any AST expression may map to a sem::Materialize, so the inferred mapping is bug-prone (the implicit sem type may mismatch and Get() may return nullptr). Change-Id: I34485a4a067635df930a407316fae8b2e9628c3d Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/95763 Reviewed-by: Dan Sinclair Commit-Queue: Ben Clayton --- src/tint/resolver/array_accessor_test.cc | 28 ++++++++++++------------ src/tint/resolver/validator.h | 1 + src/tint/sem/type_mappings.h | 8 ------- src/tint/writer/append_vector.h | 5 ++++- 4 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/tint/resolver/array_accessor_test.cc b/src/tint/resolver/array_accessor_test.cc index be49546cfc..0f72cf8211 100644 --- a/src/tint/resolver/array_accessor_test.cc +++ b/src/tint/resolver/array_accessor_test.cc @@ -43,7 +43,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic_Ref) { EXPECT_TRUE(r()->Resolve()) << r()->error(); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -58,7 +58,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions_Dynamic_Ref) { EXPECT_TRUE(r()->Resolve()) << r()->error(); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -73,7 +73,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic) { EXPECT_TRUE(r()->Resolve()); EXPECT_EQ(r()->error(), ""); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -114,7 +114,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix) { ASSERT_TRUE(ref->StoreType()->Is()); EXPECT_EQ(ref->StoreType()->As()->Width(), 3u); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -134,7 +134,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions) { auto* ref = TypeOf(acc)->As(); EXPECT_TRUE(ref->StoreType()->Is()); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -157,7 +157,7 @@ TEST_F(ResolverIndexAccessorTest, Vector_Dynamic_Ref) { EXPECT_TRUE(r()->Resolve()); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -186,7 +186,7 @@ TEST_F(ResolverIndexAccessorTest, Vector) { auto* ref = TypeOf(acc)->As(); EXPECT_TRUE(ref->StoreType()->Is()); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -202,7 +202,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_i32) { ASSERT_NE(ref, nullptr); EXPECT_TRUE(ref->StoreType()->Is()); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -218,7 +218,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_u32) { ASSERT_NE(ref, nullptr); EXPECT_TRUE(ref->StoreType()->Is()); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -234,7 +234,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_AInt) { ASSERT_NE(ref, nullptr); EXPECT_TRUE(ref->StoreType()->Is()); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -256,7 +256,7 @@ TEST_F(ResolverIndexAccessorTest, Alias_Array) { auto* ref = TypeOf(acc)->As(); EXPECT_TRUE(ref->StoreType()->Is()); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -292,7 +292,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Dynamic_I32) { EXPECT_TRUE(r()->Resolve()); EXPECT_EQ(r()->error(), ""); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -325,7 +325,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_I32) { }); EXPECT_TRUE(r()->Resolve()) << r()->error(); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); @@ -346,7 +346,7 @@ TEST_F(ResolverIndexAccessorTest, Expr_Deref_FuncGoodParent) { EXPECT_TRUE(r()->Resolve()) << r()->error(); - auto idx_sem = Sem().Get(acc); + auto idx_sem = Sem().Get(acc); ASSERT_NE(idx_sem, nullptr); EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index); EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object); diff --git a/src/tint/resolver/validator.h b/src/tint/resolver/validator.h index 4fdac53b90..a591589bc7 100644 --- a/src/tint/resolver/validator.h +++ b/src/tint/resolver/validator.h @@ -51,6 +51,7 @@ class Array; class Atomic; class BlockStatement; class Builtin; +class Call; class CaseStatement; class ForLoopStatement; class IfStatement; diff --git a/src/tint/sem/type_mappings.h b/src/tint/sem/type_mappings.h index 7dc0ade0ae..07d32b31df 100644 --- a/src/tint/sem/type_mappings.h +++ b/src/tint/sem/type_mappings.h @@ -20,13 +20,10 @@ // Forward declarations namespace tint::ast { class Array; -class CallExpression; class Expression; class ForLoopStatement; class Function; class IfStatement; -class IndexAccessorExpression; -class MemberAccessorExpression; class Node; class Override; class Statement; @@ -40,13 +37,10 @@ class WhileStatement; } // namespace tint::ast namespace tint::sem { class Array; -class Call; class Expression; class ForLoopStatement; class Function; class IfStatement; -class IndexAccessorExpression; -class MemberAccessorExpression; class Node; class GlobalVariable; class Statement; @@ -71,8 +65,6 @@ struct TypeMappings { ForLoopStatement* operator()(ast::ForLoopStatement*); Function* operator()(ast::Function*); IfStatement* operator()(ast::IfStatement*); - IndexAccessorExpression* operator()(ast::IndexAccessorExpression*); - MemberAccessorExpression* operator()(ast::MemberAccessorExpression*); Node* operator()(ast::Node*); GlobalVariable* operator()(ast::Override*); Statement* operator()(ast::Statement*); diff --git a/src/tint/writer/append_vector.h b/src/tint/writer/append_vector.h index e6a72382d4..353e20e292 100644 --- a/src/tint/writer/append_vector.h +++ b/src/tint/writer/append_vector.h @@ -17,11 +17,14 @@ #include "src/tint/program_builder.h" -// Forward Declarations +// Forward declarations namespace tint::ast { class CallExpression; class Expression; } // namespace tint::ast +namespace tint::sem { +class Call; +} // namespace tint::sem namespace tint::writer {