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 <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2022-07-07 17:15:01 +00:00 committed by Dawn LUCI CQ
parent b6c8ea9624
commit 51265542e9
4 changed files with 19 additions and 23 deletions

View File

@ -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<sem::IndexAccessorExpression>(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<sem::IndexAccessorExpression>(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<sem::IndexAccessorExpression>(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<sem::Vector>());
EXPECT_EQ(ref->StoreType()->As<sem::Vector>()->Width(), 3u);
auto idx_sem = Sem().Get(acc);
auto idx_sem = Sem().Get<sem::IndexAccessorExpression>(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<sem::Reference>();
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
auto idx_sem = Sem().Get(acc);
auto idx_sem = Sem().Get<sem::IndexAccessorExpression>(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<sem::IndexAccessorExpression>(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<sem::Reference>();
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
auto idx_sem = Sem().Get(acc);
auto idx_sem = Sem().Get<sem::IndexAccessorExpression>(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<sem::F32>());
auto idx_sem = Sem().Get(acc);
auto idx_sem = Sem().Get<sem::IndexAccessorExpression>(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<sem::F32>());
auto idx_sem = Sem().Get(acc);
auto idx_sem = Sem().Get<sem::IndexAccessorExpression>(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<sem::F32>());
auto idx_sem = Sem().Get(acc);
auto idx_sem = Sem().Get<sem::IndexAccessorExpression>(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<sem::Reference>();
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
auto idx_sem = Sem().Get(acc);
auto idx_sem = Sem().Get<sem::IndexAccessorExpression>(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<sem::IndexAccessorExpression>(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<sem::IndexAccessorExpression>(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<sem::IndexAccessorExpression>(acc);
ASSERT_NE(idx_sem, nullptr);
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);

View File

@ -51,6 +51,7 @@ class Array;
class Atomic;
class BlockStatement;
class Builtin;
class Call;
class CaseStatement;
class ForLoopStatement;
class IfStatement;

View File

@ -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*);

View File

@ -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 {