diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/wrap_unary_operators.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/wrap_unary_operators.cc index 11c8cd606a..9f8a14b999 100644 --- a/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/wrap_unary_operators.cc +++ b/src/tint/fuzzers/tint_ast_fuzzer/mutation_finders/wrap_unary_operators.cc @@ -51,7 +51,7 @@ MutationList MutationFinderWrapUnaryOperators::FindMutations( continue; } - const auto* expr_sem_node = program.Sem().Get(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. diff --git a/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.cc index 9d65d78610..df5c13c011 100644 --- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.cc +++ b/src/tint/fuzzers/tint_ast_fuzzer/mutations/wrap_unary_operator.cc @@ -50,7 +50,7 @@ bool MutationWrapUnaryOperator::IsApplicable(const tint::Program& program, return false; } - const auto* expression_sem_node = program.Sem().Get(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 diff --git a/src/tint/inspector/inspector_test.cc b/src/tint/inspector/inspector_test.cc index 160b3b6f58..da789560df 100644 --- a/src/tint/inspector/inspector_test.cc +++ b/src/tint/inspector/inspector_test.cc @@ -1628,16 +1628,16 @@ TEST_F(InspectorGetConstantNameToIdMapTest, WithAndWithoutIds) { EXPECT_EQ(result["v300"].value, 300u); ASSERT_TRUE(result.count("a")); - ASSERT_TRUE(program_->Sem().Get(a)); - EXPECT_EQ(result["a"], program_->Sem().Get(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(b)); - EXPECT_EQ(result["b"], program_->Sem().Get(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(c)); - EXPECT_EQ(result["c"], program_->Sem().Get(c)->OverrideId()); + ASSERT_TRUE(program_->Sem().Get(c)); + EXPECT_EQ(result["c"], program_->Sem().Get(c)->OverrideId()); } TEST_F(InspectorGetStorageSizeTest, Empty) { diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 179c3394bd..70820579d0 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -881,9 +881,11 @@ bool Resolver::AllocateOverridableConstantIds() { continue; } + auto* sem = sem_.Get(override); + OverrideId id; if (ast::HasAttribute(override->attributes)) { - id = builder_->Sem().Get(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(override); const_cast(sem)->SetOverrideId(id); } return true; diff --git a/src/tint/resolver/resolver_test.cc b/src/tint/resolver/resolver_test.cc index dcd6b063bf..a71bebc1f1 100644 --- a/src/tint/resolver/resolver_test.cc +++ b/src/tint/resolver/resolver_test.cc @@ -499,7 +499,7 @@ TEST_F(ResolverTest, ArraySize_NamedOverride) { auto* ref = TypeOf(a)->As(); ASSERT_NE(ref, nullptr); auto* ary = ref->StoreType()->As(); - auto* sem_override = Sem().Get(override); + auto* sem_override = Sem().Get(override); ASSERT_NE(sem_override, nullptr); EXPECT_EQ(ary->Count(), create(sem_override)); } @@ -524,7 +524,7 @@ TEST_F(ResolverTest, ArraySize_NamedOverride_Equivalence) { ASSERT_NE(ref_b, nullptr); auto* ary_b = ref_b->StoreType()->As(); - auto* sem_override = Sem().Get(override); + auto* sem_override = Sem().Get(override); ASSERT_NE(sem_override, nullptr); EXPECT_EQ(ary_a->Count(), create(sem_override)); EXPECT_EQ(ary_b->Count(), create(sem_override)); @@ -544,7 +544,7 @@ TEST_F(ResolverTest, ArraySize_UnnamedOverride) { auto* ref = TypeOf(a)->As(); ASSERT_NE(ref, nullptr); auto* ary = ref->StoreType()->As(); - auto* sem_override = Sem().Get(override); + auto* sem_override = Sem().Get(override); ASSERT_NE(sem_override, nullptr); EXPECT_EQ(ary->Count(), create(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(); - auto* sem_override = Sem().Get(override); + auto* sem_override = Sem().Get(override); ASSERT_NE(sem_override, nullptr); EXPECT_EQ(ary_a->Count(), create(Sem().Get(a_cnt))); EXPECT_EQ(ary_b->Count(), create(Sem().Get(b_cnt))); diff --git a/src/tint/resolver/sem_helper.h b/src/tint/resolver/sem_helper.h index d6a51308d8..ded9e59822 100644 --- a/src/tint/resolver/sem_helper.h +++ b/src/tint/resolver/sem_helper.h @@ -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 - SEM* ResolvedSymbol(const ast::Node* node) const { - auto resolved = dependencies_.resolved_symbols.Find(node); - return resolved ? const_cast(builder_->Sem().Get(*resolved)) : nullptr; + template + sem::Info::GetResultType* ResolvedSymbol(const ast::Node* node) const { + if (auto resolved = dependencies_.resolved_symbols.Find(node)) { + auto* sem = builder_->Sem().Get(*resolved); + return const_cast*>(sem); + } + return nullptr; } /// @returns the resolved type of the ast::Expression `expr` diff --git a/src/tint/sem/info.h b/src/tint/sem/info.h index c97b014a10..43a158ed3b 100644 --- a/src/tint/sem/info.h +++ b/src/tint/sem/info.h @@ -79,6 +79,9 @@ class Info { typename AST = CastableBase, typename RESULT = GetResultType> const RESULT* Get(const AST* ast_node) const { + static_assert(std::is_same_v || + !traits::IsTypeOrDerived, SEM>, + "explicit template argument is unnecessary"); if (ast_node && ast_node->node_id.value < nodes_.size()) { return As(nodes_[ast_node->node_id.value]); } diff --git a/src/tint/transform/direct_variable_access.cc b/src/tint/transform/direct_variable_access.cc index 2d1b5148d1..9d3d37ba4a 100644 --- a/src/tint/transform/direct_variable_access.cc +++ b/src/tint/transform/direct_variable_access.cc @@ -990,7 +990,7 @@ struct DirectVariableAccess::State { return nullptr; // Just clone the expression. } - auto* expr = sem.Get(ast_expr); + auto* expr = sem.Get(ast_expr); if (!expr) { // No semantic node for the expression. return nullptr; // Just clone the expression. diff --git a/src/tint/transform/pad_structs.cc b/src/tint/transform/pad_structs.cc index 9607851d81..449cde8f82 100644 --- a/src/tint/transform/pad_structs.cc +++ b/src/tint/transform/pad_structs.cc @@ -59,7 +59,7 @@ Transform::ApplyResult PadStructs::Apply(const Program* src, const DataMap&, Dat utils::Hashset padding_members; ctx.ReplaceAll([&](const ast::Struct* ast_str) -> const ast::Struct* { - auto* str = sem.Get(ast_str); + auto* str = sem.Get(ast_str); if (!str || !str->IsHostShareable()) { return nullptr; }