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:
parent
b6c8ea9624
commit
51265542e9
|
@ -43,7 +43,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic_Ref) {
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
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);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
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();
|
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);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
@ -73,7 +73,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix_Dynamic) {
|
||||||
EXPECT_TRUE(r()->Resolve());
|
EXPECT_TRUE(r()->Resolve());
|
||||||
EXPECT_EQ(r()->error(), "");
|
EXPECT_EQ(r()->error(), "");
|
||||||
|
|
||||||
auto idx_sem = Sem().Get(acc);
|
auto idx_sem = Sem().Get<sem::IndexAccessorExpression>(acc);
|
||||||
ASSERT_NE(idx_sem, nullptr);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
@ -114,7 +114,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix) {
|
||||||
ASSERT_TRUE(ref->StoreType()->Is<sem::Vector>());
|
ASSERT_TRUE(ref->StoreType()->Is<sem::Vector>());
|
||||||
EXPECT_EQ(ref->StoreType()->As<sem::Vector>()->Width(), 3u);
|
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);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
@ -134,7 +134,7 @@ TEST_F(ResolverIndexAccessorTest, Matrix_BothDimensions) {
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
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);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
@ -157,7 +157,7 @@ TEST_F(ResolverIndexAccessorTest, Vector_Dynamic_Ref) {
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve());
|
EXPECT_TRUE(r()->Resolve());
|
||||||
|
|
||||||
auto idx_sem = Sem().Get(acc);
|
auto idx_sem = Sem().Get<sem::IndexAccessorExpression>(acc);
|
||||||
ASSERT_NE(idx_sem, nullptr);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
@ -186,7 +186,7 @@ TEST_F(ResolverIndexAccessorTest, Vector) {
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
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);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
@ -202,7 +202,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_i32) {
|
||||||
ASSERT_NE(ref, nullptr);
|
ASSERT_NE(ref, nullptr);
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
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);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
@ -218,7 +218,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_u32) {
|
||||||
ASSERT_NE(ref, nullptr);
|
ASSERT_NE(ref, nullptr);
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
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);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
@ -234,7 +234,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_AInt) {
|
||||||
ASSERT_NE(ref, nullptr);
|
ASSERT_NE(ref, nullptr);
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
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);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
@ -256,7 +256,7 @@ TEST_F(ResolverIndexAccessorTest, Alias_Array) {
|
||||||
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
auto* ref = TypeOf(acc)->As<sem::Reference>();
|
||||||
EXPECT_TRUE(ref->StoreType()->Is<sem::F32>());
|
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);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
@ -292,7 +292,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Dynamic_I32) {
|
||||||
EXPECT_TRUE(r()->Resolve());
|
EXPECT_TRUE(r()->Resolve());
|
||||||
EXPECT_EQ(r()->error(), "");
|
EXPECT_EQ(r()->error(), "");
|
||||||
|
|
||||||
auto idx_sem = Sem().Get(acc);
|
auto idx_sem = Sem().Get<sem::IndexAccessorExpression>(acc);
|
||||||
ASSERT_NE(idx_sem, nullptr);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
@ -325,7 +325,7 @@ TEST_F(ResolverIndexAccessorTest, Array_Literal_I32) {
|
||||||
});
|
});
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
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);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
@ -346,7 +346,7 @@ TEST_F(ResolverIndexAccessorTest, Expr_Deref_FuncGoodParent) {
|
||||||
|
|
||||||
EXPECT_TRUE(r()->Resolve()) << r()->error();
|
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);
|
ASSERT_NE(idx_sem, nullptr);
|
||||||
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
EXPECT_EQ(idx_sem->Index()->Declaration(), acc->index);
|
||||||
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
EXPECT_EQ(idx_sem->Object()->Declaration(), acc->object);
|
||||||
|
|
|
@ -51,6 +51,7 @@ class Array;
|
||||||
class Atomic;
|
class Atomic;
|
||||||
class BlockStatement;
|
class BlockStatement;
|
||||||
class Builtin;
|
class Builtin;
|
||||||
|
class Call;
|
||||||
class CaseStatement;
|
class CaseStatement;
|
||||||
class ForLoopStatement;
|
class ForLoopStatement;
|
||||||
class IfStatement;
|
class IfStatement;
|
||||||
|
|
|
@ -20,13 +20,10 @@
|
||||||
// Forward declarations
|
// Forward declarations
|
||||||
namespace tint::ast {
|
namespace tint::ast {
|
||||||
class Array;
|
class Array;
|
||||||
class CallExpression;
|
|
||||||
class Expression;
|
class Expression;
|
||||||
class ForLoopStatement;
|
class ForLoopStatement;
|
||||||
class Function;
|
class Function;
|
||||||
class IfStatement;
|
class IfStatement;
|
||||||
class IndexAccessorExpression;
|
|
||||||
class MemberAccessorExpression;
|
|
||||||
class Node;
|
class Node;
|
||||||
class Override;
|
class Override;
|
||||||
class Statement;
|
class Statement;
|
||||||
|
@ -40,13 +37,10 @@ class WhileStatement;
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
namespace tint::sem {
|
namespace tint::sem {
|
||||||
class Array;
|
class Array;
|
||||||
class Call;
|
|
||||||
class Expression;
|
class Expression;
|
||||||
class ForLoopStatement;
|
class ForLoopStatement;
|
||||||
class Function;
|
class Function;
|
||||||
class IfStatement;
|
class IfStatement;
|
||||||
class IndexAccessorExpression;
|
|
||||||
class MemberAccessorExpression;
|
|
||||||
class Node;
|
class Node;
|
||||||
class GlobalVariable;
|
class GlobalVariable;
|
||||||
class Statement;
|
class Statement;
|
||||||
|
@ -71,8 +65,6 @@ struct TypeMappings {
|
||||||
ForLoopStatement* operator()(ast::ForLoopStatement*);
|
ForLoopStatement* operator()(ast::ForLoopStatement*);
|
||||||
Function* operator()(ast::Function*);
|
Function* operator()(ast::Function*);
|
||||||
IfStatement* operator()(ast::IfStatement*);
|
IfStatement* operator()(ast::IfStatement*);
|
||||||
IndexAccessorExpression* operator()(ast::IndexAccessorExpression*);
|
|
||||||
MemberAccessorExpression* operator()(ast::MemberAccessorExpression*);
|
|
||||||
Node* operator()(ast::Node*);
|
Node* operator()(ast::Node*);
|
||||||
GlobalVariable* operator()(ast::Override*);
|
GlobalVariable* operator()(ast::Override*);
|
||||||
Statement* operator()(ast::Statement*);
|
Statement* operator()(ast::Statement*);
|
||||||
|
|
|
@ -17,11 +17,14 @@
|
||||||
|
|
||||||
#include "src/tint/program_builder.h"
|
#include "src/tint/program_builder.h"
|
||||||
|
|
||||||
// Forward Declarations
|
// Forward declarations
|
||||||
namespace tint::ast {
|
namespace tint::ast {
|
||||||
class CallExpression;
|
class CallExpression;
|
||||||
class Expression;
|
class Expression;
|
||||||
} // namespace tint::ast
|
} // namespace tint::ast
|
||||||
|
namespace tint::sem {
|
||||||
|
class Call;
|
||||||
|
} // namespace tint::sem
|
||||||
|
|
||||||
namespace tint::writer {
|
namespace tint::writer {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue