tint: static_assert that Sem.Get() template arg is needed

Change-Id: I91a73c22bd417fd9f32d45a1c91ffcb8f8d83d82
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/118405
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
This commit is contained in:
Ben Clayton 2023-02-05 14:33:08 +00:00 committed by Dawn LUCI CQ
parent 80e78e5a15
commit ef1811a18b
9 changed files with 27 additions and 20 deletions

View File

@ -51,7 +51,7 @@ MutationList MutationFinderWrapUnaryOperators::FindMutations(
continue;
}
const auto* expr_sem_node = program.Sem().Get<sem::ValueExpression>(expr_ast_node);
const auto* expr_sem_node = program.Sem().Get(expr_ast_node);
// Transformation applies only when the semantic node for the given
// expression is present.

View File

@ -50,7 +50,7 @@ bool MutationWrapUnaryOperator::IsApplicable(const tint::Program& program,
return false;
}
const auto* expression_sem_node = program.Sem().Get<sem::ValueExpression>(expression_ast_node);
const auto* expression_sem_node = program.Sem().Get(expression_ast_node);
if (!expression_sem_node) {
// Semantic information for the expression ast node is not present

View File

@ -1628,16 +1628,16 @@ TEST_F(InspectorGetConstantNameToIdMapTest, WithAndWithoutIds) {
EXPECT_EQ(result["v300"].value, 300u);
ASSERT_TRUE(result.count("a"));
ASSERT_TRUE(program_->Sem().Get<sem::GlobalVariable>(a));
EXPECT_EQ(result["a"], program_->Sem().Get<sem::GlobalVariable>(a)->OverrideId());
ASSERT_TRUE(program_->Sem().Get(a));
EXPECT_EQ(result["a"], program_->Sem().Get(a)->OverrideId());
ASSERT_TRUE(result.count("b"));
ASSERT_TRUE(program_->Sem().Get<sem::GlobalVariable>(b));
EXPECT_EQ(result["b"], program_->Sem().Get<sem::GlobalVariable>(b)->OverrideId());
ASSERT_TRUE(program_->Sem().Get(b));
EXPECT_EQ(result["b"], program_->Sem().Get(b)->OverrideId());
ASSERT_TRUE(result.count("c"));
ASSERT_TRUE(program_->Sem().Get<sem::GlobalVariable>(c));
EXPECT_EQ(result["c"], program_->Sem().Get<sem::GlobalVariable>(c)->OverrideId());
ASSERT_TRUE(program_->Sem().Get(c));
EXPECT_EQ(result["c"], program_->Sem().Get(c)->OverrideId());
}
TEST_F(InspectorGetStorageSizeTest, Empty) {

View File

@ -881,9 +881,11 @@ bool Resolver::AllocateOverridableConstantIds() {
continue;
}
auto* sem = sem_.Get(override);
OverrideId id;
if (ast::HasAttribute<ast::IdAttribute>(override->attributes)) {
id = builder_->Sem().Get<sem::GlobalVariable>(override)->OverrideId();
id = sem->OverrideId();
} else {
// No ID was specified, so allocate the next available ID.
while (!ids_exhausted && override_ids_.Contains(next_id)) {
@ -899,7 +901,6 @@ bool Resolver::AllocateOverridableConstantIds() {
increment_next_id();
}
auto* sem = sem_.Get<sem::GlobalVariable>(override);
const_cast<sem::GlobalVariable*>(sem)->SetOverrideId(id);
}
return true;

View File

@ -499,7 +499,7 @@ TEST_F(ResolverTest, ArraySize_NamedOverride) {
auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr);
auto* ary = ref->StoreType()->As<type::Array>();
auto* sem_override = Sem().Get<sem::GlobalVariable>(override);
auto* sem_override = Sem().Get(override);
ASSERT_NE(sem_override, nullptr);
EXPECT_EQ(ary->Count(), create<sem::NamedOverrideArrayCount>(sem_override));
}
@ -524,7 +524,7 @@ TEST_F(ResolverTest, ArraySize_NamedOverride_Equivalence) {
ASSERT_NE(ref_b, nullptr);
auto* ary_b = ref_b->StoreType()->As<type::Array>();
auto* sem_override = Sem().Get<sem::GlobalVariable>(override);
auto* sem_override = Sem().Get(override);
ASSERT_NE(sem_override, nullptr);
EXPECT_EQ(ary_a->Count(), create<sem::NamedOverrideArrayCount>(sem_override));
EXPECT_EQ(ary_b->Count(), create<sem::NamedOverrideArrayCount>(sem_override));
@ -544,7 +544,7 @@ TEST_F(ResolverTest, ArraySize_UnnamedOverride) {
auto* ref = TypeOf(a)->As<type::Reference>();
ASSERT_NE(ref, nullptr);
auto* ary = ref->StoreType()->As<type::Array>();
auto* sem_override = Sem().Get<sem::GlobalVariable>(override);
auto* sem_override = Sem().Get(override);
ASSERT_NE(sem_override, nullptr);
EXPECT_EQ(ary->Count(), create<sem::UnnamedOverrideArrayCount>(Sem().Get(cnt)));
}
@ -571,7 +571,7 @@ TEST_F(ResolverTest, ArraySize_UnamedOverride_Equivalence) {
ASSERT_NE(ref_b, nullptr);
auto* ary_b = ref_b->StoreType()->As<type::Array>();
auto* sem_override = Sem().Get<sem::GlobalVariable>(override);
auto* sem_override = Sem().Get(override);
ASSERT_NE(sem_override, nullptr);
EXPECT_EQ(ary_a->Count(), create<sem::UnnamedOverrideArrayCount>(Sem().Get(a_cnt)));
EXPECT_EQ(ary_b->Count(), create<sem::UnnamedOverrideArrayCount>(Sem().Get(b_cnt)));

View File

@ -52,10 +52,13 @@ class SemHelper {
/// @returns the resolved symbol (function, type or variable) for the given ast::Identifier or
/// ast::TypeName cast to the given semantic type.
/// @param node the node to retrieve
template <typename SEM = CastableBase>
SEM* ResolvedSymbol(const ast::Node* node) const {
auto resolved = dependencies_.resolved_symbols.Find(node);
return resolved ? const_cast<SEM*>(builder_->Sem().Get<SEM>(*resolved)) : nullptr;
template <typename SEM = sem::Info::InferFromAST>
sem::Info::GetResultType<SEM, ast::Node>* ResolvedSymbol(const ast::Node* node) const {
if (auto resolved = dependencies_.resolved_symbols.Find(node)) {
auto* sem = builder_->Sem().Get<SEM>(*resolved);
return const_cast<sem::Info::GetResultType<SEM, ast::Node>*>(sem);
}
return nullptr;
}
/// @returns the resolved type of the ast::Expression `expr`

View File

@ -79,6 +79,9 @@ class Info {
typename AST = CastableBase,
typename RESULT = GetResultType<SEM, AST>>
const RESULT* Get(const AST* ast_node) const {
static_assert(std::is_same_v<SEM, InferFromAST> ||
!traits::IsTypeOrDerived<SemanticNodeTypeFor<AST>, SEM>,
"explicit template argument is unnecessary");
if (ast_node && ast_node->node_id.value < nodes_.size()) {
return As<RESULT>(nodes_[ast_node->node_id.value]);
}

View File

@ -990,7 +990,7 @@ struct DirectVariableAccess::State {
return nullptr; // Just clone the expression.
}
auto* expr = sem.Get<sem::ValueExpression>(ast_expr);
auto* expr = sem.Get(ast_expr);
if (!expr) {
// No semantic node for the expression.
return nullptr; // Just clone the expression.

View File

@ -59,7 +59,7 @@ Transform::ApplyResult PadStructs::Apply(const Program* src, const DataMap&, Dat
utils::Hashset<const ast::StructMember*, 8> padding_members;
ctx.ReplaceAll([&](const ast::Struct* ast_str) -> const ast::Struct* {
auto* str = sem.Get<sem::Struct>(ast_str);
auto* str = sem.Get(ast_str);
if (!str || !str->IsHostShareable()) {
return nullptr;
}