diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index 054e7ecb58..e49c128903 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -368,6 +368,7 @@ libtint_source_set("libtint_syntax_tree_src") { "sem/call.h", "sem/call_target.h", "sem/evaluation_stage.h", + "sem/expression.h", "sem/for_loop_statement.h", "sem/function.h", "sem/if_statement.h", @@ -763,6 +764,8 @@ libtint_source_set("libtint_sem_src") { "sem/call_target.cc", "sem/call_target.h", "sem/evaluation_stage.h", + "sem/expression.cc", + "sem/expression.h", "sem/for_loop_statement.cc", "sem/for_loop_statement.h", "sem/function.cc", diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 8ffc4884cd..a8de1d6ad4 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -330,6 +330,8 @@ list(APPEND TINT_LIB_SRCS sem/call.cc sem/call.h sem/evaluation_stage.h + sem/expression.cc + sem/expression.h sem/for_loop_statement.cc sem/for_loop_statement.h sem/function.cc 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 9f8a14b999..7b3c41697b 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().GetVal(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/change_binary_operator.cc b/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.cc index 78cc131f87..29cfbcf9f9 100644 --- a/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.cc +++ b/src/tint/fuzzers/tint_ast_fuzzer/mutations/change_binary_operator.cc @@ -297,8 +297,8 @@ bool MutationChangeBinaryOperator::CanReplaceBinaryOperator( } // Get the types of the operators. - const auto* lhs_type = program.Sem().Get(binary_expr.lhs)->Type(); - const auto* rhs_type = program.Sem().Get(binary_expr.rhs)->Type(); + const auto* lhs_type = program.Sem().GetVal(binary_expr.lhs)->Type(); + const auto* rhs_type = program.Sem().GetVal(binary_expr.rhs)->Type(); // If these are reference types, unwrap them to get the pointee type. const type::Type* lhs_basic_type = 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 df5c13c011..25ac065a1c 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().GetVal(expression_ast_node); if (!expression_sem_node) { // Semantic information for the expression ast node is not present diff --git a/src/tint/inspector/inspector.cc b/src/tint/inspector/inspector.cc index e57dce3e86..b07536d119 100644 --- a/src/tint/inspector/inspector.cc +++ b/src/tint/inspector/inspector.cc @@ -900,7 +900,7 @@ void Inspector::GetOriginatingResources(std::array ex utils::UniqueVector callsites; for (size_t i = 0; i < N; i++) { - const sem::Variable* root_ident = sem.Get(exprs[i])->RootIdentifier(); + const sem::Variable* root_ident = sem.GetVal(exprs[i])->RootIdentifier(); if (auto* global = root_ident->As()) { globals[i] = global; } else if (auto* param = root_ident->As()) { diff --git a/src/tint/program.cc b/src/tint/program.cc index f2a766ad2b..a5d8c4563a 100644 --- a/src/tint/program.cc +++ b/src/tint/program.cc @@ -118,7 +118,7 @@ bool Program::IsValid() const { } const type::Type* Program::TypeOf(const ast::Expression* expr) const { - auto* sem = Sem().Get(expr); + auto* sem = Sem().GetVal(expr); return sem ? sem->Type() : nullptr; } diff --git a/src/tint/program_builder.cc b/src/tint/program_builder.cc index 1a0faf6438..0ce8f0b163 100644 --- a/src/tint/program_builder.cc +++ b/src/tint/program_builder.cc @@ -97,7 +97,7 @@ void ProgramBuilder::AssertNotMoved() const { } const type::Type* ProgramBuilder::TypeOf(const ast::Expression* expr) const { - auto* sem = Sem().Get(expr); + auto* sem = Sem().GetVal(expr); return sem ? sem->Type() : nullptr; } diff --git a/src/tint/resolver/builtin_validation_test.cc b/src/tint/resolver/builtin_validation_test.cc index cfd9877893..c9037baf26 100644 --- a/src/tint/resolver/builtin_validation_test.cc +++ b/src/tint/resolver/builtin_validation_test.cc @@ -175,7 +175,7 @@ TEST_F(ResolverBuiltinValidationTest, BuiltinRedeclaredAsGlobalVarUsedAsVariable WrapInFunction(Decl(Var("v", use))); ASSERT_TRUE(r()->Resolve()) << r()->error(); - auto* sem = Sem().Get(use)->UnwrapLoad()->As(); + auto* sem = Sem().GetVal(use)->UnwrapLoad()->As(); ASSERT_NE(sem, nullptr); EXPECT_EQ(sem->Variable(), Sem().Get(mix)); } diff --git a/src/tint/resolver/const_eval_binary_op_test.cc b/src/tint/resolver/const_eval_binary_op_test.cc index 30c802e14c..10c047cea0 100644 --- a/src/tint/resolver/const_eval_binary_op_test.cc +++ b/src/tint/resolver/const_eval_binary_op_test.cc @@ -896,7 +896,7 @@ TEST_F(ResolverConstEvalTest, NotAndOrOfVecs) { ASSERT_NE(value, nullptr); EXPECT_TYPE(value->Type(), sem->Type()); - auto* expected_sem = Sem().Get(expected_expr); + auto* expected_sem = Sem().GetVal(expected_expr); const constant::Value* expected_value = expected_sem->ConstantValue(); ASSERT_NE(expected_value, nullptr); EXPECT_TYPE(expected_value->Type(), expected_sem->Type()); @@ -1374,12 +1374,12 @@ static void ValidateAnd(const sem::Info& sem, const ast::BinaryExpression* binar auto* lhs = binary->lhs; auto* rhs = binary->rhs; - auto* lhs_sem = sem.Get(lhs); + auto* lhs_sem = sem.GetVal(lhs); ASSERT_TRUE(lhs_sem->ConstantValue()); EXPECT_EQ(lhs_sem->ConstantValue()->ValueAs(), false); EXPECT_EQ(lhs_sem->Stage(), sem::EvaluationStage::kConstant); - auto* rhs_sem = sem.Get(rhs); + auto* rhs_sem = sem.GetVal(rhs); EXPECT_EQ(rhs_sem->ConstantValue(), nullptr); EXPECT_EQ(rhs_sem->Stage(), sem::EvaluationStage::kNotEvaluated); @@ -1394,12 +1394,12 @@ static void ValidateOr(const sem::Info& sem, const ast::BinaryExpression* binary auto* lhs = binary->lhs; auto* rhs = binary->rhs; - auto* lhs_sem = sem.Get(lhs); + auto* lhs_sem = sem.GetVal(lhs); ASSERT_TRUE(lhs_sem->ConstantValue()); EXPECT_EQ(lhs_sem->ConstantValue()->ValueAs(), true); EXPECT_EQ(lhs_sem->Stage(), sem::EvaluationStage::kConstant); - auto* rhs_sem = sem.Get(rhs); + auto* rhs_sem = sem.GetVal(rhs); EXPECT_EQ(rhs_sem->ConstantValue(), nullptr); EXPECT_EQ(rhs_sem->Stage(), sem::EvaluationStage::kNotEvaluated); diff --git a/src/tint/resolver/const_eval_bitcast_test.cc b/src/tint/resolver/const_eval_bitcast_test.cc index 50d4693d87..32c138235b 100644 --- a/src/tint/resolver/const_eval_bitcast_test.cc +++ b/src/tint/resolver/const_eval_bitcast_test.cc @@ -76,7 +76,7 @@ TEST_P(ResolverConstEvalBitcastTest, Test) { if (expected) { EXPECT_TRUE(r()->Resolve()) << r()->error(); - auto* sem = Sem().Get(expr); + auto* sem = Sem().GetVal(expr); ASSERT_NE(sem, nullptr); EXPECT_TYPE(sem->Type(), target_sem_ty); ASSERT_NE(sem->ConstantValue(), nullptr); diff --git a/src/tint/resolver/const_eval_construction_test.cc b/src/tint/resolver/const_eval_construction_test.cc index d8b25b9484..96e37ca170 100644 --- a/src/tint/resolver/const_eval_construction_test.cc +++ b/src/tint/resolver/const_eval_construction_test.cc @@ -1712,7 +1712,7 @@ TEST_P(ResolverConstEvalArrayInitTest, Test) { EXPECT_TRUE(r()->Resolve()) << r()->error(); - auto* sem = Sem().Get(expr); + auto* sem = Sem().GetVal(expr); ASSERT_NE(sem, nullptr); auto* arr = sem->Type()->As(); ASSERT_NE(arr, nullptr); diff --git a/src/tint/resolver/const_eval_member_access_test.cc b/src/tint/resolver/const_eval_member_access_test.cc index f228509c70..04ed3f8790 100644 --- a/src/tint/resolver/const_eval_member_access_test.cc +++ b/src/tint/resolver/const_eval_member_access_test.cc @@ -287,7 +287,7 @@ TEST_P(ResolverConstEvalArrayAccessTest, Test) { EXPECT_TRUE(r()->Resolve()) << r()->error(); - auto* sem = Sem().Get(expr); + auto* sem = Sem().GetVal(expr); ASSERT_NE(sem, nullptr); auto* arr = sem->Type()->As(); ASSERT_NE(arr, nullptr); @@ -362,7 +362,7 @@ TEST_P(ResolverConstEvalVectorAccessTest, Test) { EXPECT_TRUE(r()->Resolve()) << r()->error(); - auto* sem = Sem().Get(expr); + auto* sem = Sem().GetVal(expr); ASSERT_NE(sem, nullptr); auto* vec = sem->Type()->As(); ASSERT_NE(vec, nullptr); diff --git a/src/tint/resolver/load_test.cc b/src/tint/resolver/load_test.cc index 3e9d50c45f..d44b34f7d5 100644 --- a/src/tint/resolver/load_test.cc +++ b/src/tint/resolver/load_test.cc @@ -361,7 +361,7 @@ TEST_F(ResolverLoadTest, AddressOf) { Let("l", AddressOf(ident))); ASSERT_TRUE(r()->Resolve()) << r()->error(); - auto* no_load = Sem().Get(ident); + auto* no_load = Sem().GetVal(ident); ASSERT_NE(no_load, nullptr); EXPECT_TRUE(no_load->Type()->Is()); // No load } diff --git a/src/tint/resolver/materialize_test.cc b/src/tint/resolver/materialize_test.cc index e34e99989f..4543f85a3e 100644 --- a/src/tint/resolver/materialize_test.cc +++ b/src/tint/resolver/materialize_test.cc @@ -404,7 +404,7 @@ TEST_P(MaterializeAbstractNumericToConcreteType, Test) { } case Expectation::kNoMaterialize: { ASSERT_TRUE(r()->Resolve()) << r()->error(); - auto* sem = Sem().Get(abstract_expr); + auto* sem = Sem().GetVal(abstract_expr); ASSERT_NE(sem, nullptr); EXPECT_FALSE(sem->Is()); CheckTypesAndValues(sem, data.target_sem_ty(*this), data.materialized_value); diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index 70820579d0..7dbd6ae578 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -1318,7 +1318,7 @@ sem::CaseStatement* Resolver::CaseStatement(const ast::CaseStatement* stmt, cons if (!sel->IsDefault()) { // The sem statement was created in the switch when attempting to determine the // common type. - auto* materialized = Materialize(sem_.Get(sel->expr), ty); + auto* materialized = Materialize(sem_.GetVal(sel->expr), ty); if (!materialized) { return false; } @@ -1923,11 +1923,11 @@ utils::Result> Resolver::ConvertArgumen } sem::ValueExpression* Resolver::IndexAccessor(const ast::IndexAccessorExpression* expr) { - auto* idx = Load(Materialize(sem_.Get(expr->index))); + auto* idx = Load(Materialize(sem_.GetVal(expr->index))); if (!idx) { return nullptr; } - const auto* obj = sem_.Get(expr->object); + const auto* obj = sem_.GetVal(expr->object); if (idx->Stage() != sem::EvaluationStage::kConstant) { // If the index is non-constant, then the resulting expression is non-constant, so we'll // have to materialize the object. For example, consider: @@ -1986,7 +1986,7 @@ sem::ValueExpression* Resolver::IndexAccessor(const ast::IndexAccessorExpression } sem::ValueExpression* Resolver::Bitcast(const ast::BitcastExpression* expr) { - auto* inner = Load(Materialize(sem_.Get(expr->expr))); + auto* inner = Load(Materialize(sem_.GetVal(expr->expr))); if (!inner) { return nullptr; } @@ -2031,7 +2031,7 @@ sem::Call* Resolver::Call(const ast::CallExpression* expr) { auto args_stage = sem::EvaluationStage::kConstant; sem::Behaviors arg_behaviors; for (size_t i = 0; i < expr->args.Length(); i++) { - auto* arg = sem_.Get(expr->args[i]); + auto* arg = sem_.GetVal(expr->args[i]); if (!arg) { return nullptr; } @@ -2780,13 +2780,17 @@ sem::ValueExpression* Resolver::Identifier(const ast::IdentifierExpression* expr sem::ValueExpression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* expr) { auto* structure = sem_.TypeOf(expr->object); auto* storage_ty = structure->UnwrapRef(); - auto* object = sem_.Get(expr->object); + auto* object = sem_.GetVal(expr->object); + if (!object) { + return nullptr; + } + auto* root_ident = object->RootIdentifier(); const type::Type* ty = nullptr; // Object may be a side-effecting expression (e.g. function call). - bool has_side_effects = object && object->HasSideEffects(); + bool has_side_effects = object->HasSideEffects(); Mark(expr->member); @@ -2909,8 +2913,8 @@ sem::ValueExpression* Resolver::MemberAccessor(const ast::MemberAccessorExpressi } sem::ValueExpression* Resolver::Binary(const ast::BinaryExpression* expr) { - const auto* lhs = sem_.Get(expr->lhs); - const auto* rhs = sem_.Get(expr->rhs); + const auto* lhs = sem_.GetVal(expr->lhs); + const auto* rhs = sem_.GetVal(expr->rhs); auto* lhs_ty = lhs->Type()->UnwrapRef(); auto* rhs_ty = rhs->Type()->UnwrapRef(); @@ -2986,7 +2990,7 @@ sem::ValueExpression* Resolver::Binary(const ast::BinaryExpression* expr) { } sem::ValueExpression* Resolver::UnaryOp(const ast::UnaryOpExpression* unary) { - const auto* expr = sem_.Get(unary->expr); + const auto* expr = sem_.GetVal(unary->expr); auto* expr_ty = expr->Type(); if (!expr_ty) { return nullptr; diff --git a/src/tint/resolver/resolver_test_helper.h b/src/tint/resolver/resolver_test_helper.h index f04b6970d0..2c175b9291 100644 --- a/src/tint/resolver/resolver_test_helper.h +++ b/src/tint/resolver/resolver_test_helper.h @@ -83,9 +83,12 @@ class TestHelper : public ProgramBuilder { /// @return the resolved sem::Variable of the identifier, or nullptr if /// the expression did not resolve to a variable. const sem::Variable* VarOf(const ast::Expression* expr) { - auto* sem_ident = Sem().Get(expr)->UnwrapLoad(); - auto* var_user = sem_ident ? sem_ident->As() : nullptr; - return var_user ? var_user->Variable() : nullptr; + if (auto* sem = Sem().GetVal(expr)) { + if (auto* var_user = As(sem->UnwrapLoad())) { + return var_user->Variable(); + } + } + return nullptr; } /// Checks that all the users of the given variable are as expected diff --git a/src/tint/resolver/root_identifier_test.cc b/src/tint/resolver/root_identifier_test.cc index 95806951a9..656b0a81b2 100644 --- a/src/tint/resolver/root_identifier_test.cc +++ b/src/tint/resolver/root_identifier_test.cc @@ -34,7 +34,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalPrivateVar) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().GetVal(expr)->RootIdentifier(), sem_a); } TEST_F(ResolverRootIdentifierTest, GlobalWorkgroupVar) { @@ -45,7 +45,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalWorkgroupVar) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().GetVal(expr)->RootIdentifier(), sem_a); } TEST_F(ResolverRootIdentifierTest, GlobalStorageVar) { @@ -56,7 +56,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalStorageVar) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().GetVal(expr)->RootIdentifier(), sem_a); } TEST_F(ResolverRootIdentifierTest, GlobalUniformVar) { @@ -67,7 +67,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalUniformVar) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().GetVal(expr)->RootIdentifier(), sem_a); } TEST_F(ResolverRootIdentifierTest, GlobalTextureVar) { @@ -79,7 +79,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalTextureVar) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().GetVal(expr)->RootIdentifier(), sem_a); } TEST_F(ResolverRootIdentifierTest, GlobalOverride) { @@ -90,7 +90,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalOverride) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().GetVal(expr)->RootIdentifier(), sem_a); } TEST_F(ResolverRootIdentifierTest, GlobalConst) { @@ -101,7 +101,7 @@ TEST_F(ResolverRootIdentifierTest, GlobalConst) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().GetVal(expr)->RootIdentifier(), sem_a); } TEST_F(ResolverRootIdentifierTest, FunctionVar) { @@ -112,7 +112,7 @@ TEST_F(ResolverRootIdentifierTest, FunctionVar) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().GetVal(expr)->RootIdentifier(), sem_a); } TEST_F(ResolverRootIdentifierTest, FunctionLet) { @@ -123,7 +123,7 @@ TEST_F(ResolverRootIdentifierTest, FunctionLet) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().GetVal(expr)->RootIdentifier(), sem_a); } TEST_F(ResolverRootIdentifierTest, Parameter) { @@ -134,7 +134,7 @@ TEST_F(ResolverRootIdentifierTest, Parameter) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().GetVal(expr)->RootIdentifier(), sem_a); } TEST_F(ResolverRootIdentifierTest, PointerParameter) { @@ -152,8 +152,8 @@ TEST_F(ResolverRootIdentifierTest, PointerParameter) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_param = Sem().Get(param); - EXPECT_EQ(Sem().Get(expr_param)->RootIdentifier(), sem_param); - EXPECT_EQ(Sem().Get(expr_let)->RootIdentifier(), sem_param); + EXPECT_EQ(Sem().GetVal(expr_param)->RootIdentifier(), sem_param); + EXPECT_EQ(Sem().GetVal(expr_let)->RootIdentifier(), sem_param); } TEST_F(ResolverRootIdentifierTest, VarCopyVar) { @@ -171,8 +171,8 @@ TEST_F(ResolverRootIdentifierTest, VarCopyVar) { auto* sem_a = Sem().Get(a); auto* sem_b = Sem().Get(b); - EXPECT_EQ(Sem().Get(expr_a)->RootIdentifier(), sem_a); - EXPECT_EQ(Sem().Get(expr_b)->RootIdentifier(), sem_b); + EXPECT_EQ(Sem().GetVal(expr_a)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().GetVal(expr_b)->RootIdentifier(), sem_b); } TEST_F(ResolverRootIdentifierTest, LetCopyVar) { @@ -190,8 +190,8 @@ TEST_F(ResolverRootIdentifierTest, LetCopyVar) { auto* sem_a = Sem().Get(a); auto* sem_b = Sem().Get(b); - EXPECT_EQ(Sem().Get(expr_a)->RootIdentifier(), sem_a); - EXPECT_EQ(Sem().Get(expr_b)->RootIdentifier(), sem_b); + EXPECT_EQ(Sem().GetVal(expr_a)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().GetVal(expr_b)->RootIdentifier(), sem_b); } TEST_F(ResolverRootIdentifierTest, ThroughIndexAccessor) { diff --git a/src/tint/resolver/sem_helper.cc b/src/tint/resolver/sem_helper.cc index 327b1cfd0f..fbabb5e9e0 100644 --- a/src/tint/resolver/sem_helper.cc +++ b/src/tint/resolver/sem_helper.cc @@ -32,7 +32,7 @@ std::string SemHelper::RawTypeNameOf(const type::Type* ty) const { } type::Type* SemHelper::TypeOf(const ast::Expression* expr) const { - auto* sem = Get(expr); + auto* sem = GetVal(expr); return sem ? const_cast(sem->Type()) : nullptr; } diff --git a/src/tint/resolver/sem_helper.h b/src/tint/resolver/sem_helper.h index ded9e59822..c8382db00e 100644 --- a/src/tint/resolver/sem_helper.h +++ b/src/tint/resolver/sem_helper.h @@ -34,11 +34,13 @@ class SemHelper { ~SemHelper(); /// Get is a helper for obtaining the semantic node for the given AST node. + /// Raises an ICE and returns `nullptr` if there is no semantic node associated with the AST + /// node. /// @param ast the ast node to get the sem for - /// @returns the sem node for the provided |ast| - template - auto* Get(const AST_OR_TYPE* ast) const { - using T = sem::Info::GetResultType; + /// @returns the sem node for @p ast + template + auto* Get(const AST* ast) const { + using T = sem::Info::GetResultType; auto* sem = builder_->Sem().Get(ast); if (TINT_UNLIKELY(!sem)) { TINT_ICE(Resolver, builder_->Diagnostics()) @@ -49,6 +51,31 @@ class SemHelper { return const_cast(As(sem)); } + /// GetVal is a helper for obtaining the semantic sem::ValueExpression for the given AST node. + /// Raises an error diagnostic and returns `nullptr` if the semantic node is not a + /// sem::ValueExpression. + /// @param ast the ast node to get the sem for + /// @returns the sem node for @p ast + template + auto* GetVal(const AST* ast) const { + if constexpr (traits::IsTypeOrDerived, + sem::ValueExpression>) { + return Get(ast); + } else { + if (auto* sem = Get(ast); TINT_LIKELY(sem)) { + auto* val = sem->template As(); + if (TINT_LIKELY(val)) { + return val; + } + // TODO(crbug.com/tint/1810): Improve error + builder_->Diagnostics().add_error(diag::System::Resolver, + "required value expression, got something else", + ast->source); + } + return static_cast(nullptr); + } + } + /// @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 diff --git a/src/tint/resolver/side_effects_test.cc b/src/tint/resolver/side_effects_test.cc index b0796d5caa..cca774177a 100644 --- a/src/tint/resolver/side_effects_test.cc +++ b/src/tint/resolver/side_effects_test.cc @@ -82,7 +82,7 @@ TEST_F(SideEffectsTest, VariableUser) { WrapInFunction(var, expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); - auto* sem = Sem().Get(expr); + auto* sem = Sem().GetVal(expr); ASSERT_NE(sem, nullptr); EXPECT_TRUE(sem->UnwrapLoad()->Is()); EXPECT_FALSE(sem->HasSideEffects()); diff --git a/src/tint/resolver/uniformity.cc b/src/tint/resolver/uniformity.cc index 69754da6c5..8fa6d64182 100644 --- a/src/tint/resolver/uniformity.cc +++ b/src/tint/resolver/uniformity.cc @@ -1141,9 +1141,11 @@ class UniformityGraph { return true; }; - auto* var_user = sem_.Get(ident)->Unwrap()->As(); - auto* sem = var_user->Variable(); auto* node = CreateNode({NameFor(ident->identifier), "_ident_expr"}, ident); + auto* sem_ident = sem_.GetVal(ident); + TINT_ASSERT(Resolver, sem_ident); + auto* var_user = sem_ident->Unwrap()->As(); + auto* sem = var_user->Variable(); return Switch( sem, @@ -1357,7 +1359,7 @@ class UniformityGraph { expr, [&](const ast::IdentifierExpression* i) { - auto* sem = sem_.Get(i)->UnwrapLoad()->As(); + auto* sem = sem_.GetVal(i)->UnwrapLoad()->As(); if (sem->Variable()->Is()) { return std::make_pair(cf, current_function_->may_be_non_uniform); } else if (auto* local = sem->Variable()->As()) { @@ -1452,7 +1454,7 @@ class UniformityGraph { // For pointer arguments, create an additional node to represent the contents of that // pointer prior to the function call. - auto* sem_arg = sem_.Get(call->args[i]); + auto* sem_arg = sem_.GetVal(call->args[i]); if (sem_arg->Type()->Is()) { auto* arg_contents = CreateNode({name, "_ptrarg_", std::to_string(i), "_contents"}, call); @@ -1581,7 +1583,7 @@ class UniformityGraph { // Capture the effects of other call parameters on the contents of this parameter // after the call returns. - auto* sem_arg = sem_.Get(call->args[i]); + auto* sem_arg = sem_.GetVal(call->args[i]); if (sem_arg->Type()->Is()) { auto* ptr_result = CreateNode({name, "_ptrarg_", std::to_string(i), "_result"}, call); @@ -1762,7 +1764,7 @@ class UniformityGraph { Switch( non_uniform_source->ast, [&](const ast::IdentifierExpression* ident) { - auto* var = sem_.Get(ident)->UnwrapLoad()->As()->Variable(); + auto* var = sem_.GetVal(ident)->UnwrapLoad()->As()->Variable(); std::ostringstream ss; if (auto* param = var->As()) { auto* func = param->Owner()->As(); @@ -1792,7 +1794,7 @@ class UniformityGraph { } case Node::kFunctionCallArgumentContents: { auto* arg = c->args[non_uniform_source->arg_index]; - auto* var = sem_.Get(arg)->RootIdentifier(); + auto* var = sem_.GetVal(arg)->RootIdentifier(); std::ostringstream ss; ss << "reading from " << var_type(var) << "'" << NameFor(var->Declaration()) << "' may result in a non-uniform value"; diff --git a/src/tint/resolver/variable_test.cc b/src/tint/resolver/variable_test.cc index 54629e3517..8dcff0f4c0 100644 --- a/src/tint/resolver/variable_test.cc +++ b/src/tint/resolver/variable_test.cc @@ -250,7 +250,7 @@ TEST_F(ResolverVariableTest, LocalVar_ShadowsGlobalVar) { EXPECT_EQ(local->Shadows(), global); auto* user_v = - Sem().Get(local->Declaration()->initializer)->UnwrapLoad()->As(); + Sem().GetVal(local->Declaration()->initializer)->UnwrapLoad()->As(); ASSERT_NE(user_v, nullptr); EXPECT_EQ(user_v->Variable(), global); } @@ -300,7 +300,7 @@ TEST_F(ResolverVariableTest, LocalVar_ShadowsLocalVar) { EXPECT_EQ(local_y->Shadows(), local_x); auto* user_y = - Sem().Get(local_y->Declaration()->initializer)->UnwrapLoad()->As(); + Sem().GetVal(local_y->Declaration()->initializer)->UnwrapLoad()->As(); ASSERT_NE(user_y, nullptr); EXPECT_EQ(user_y->Variable(), local_x); } @@ -370,7 +370,7 @@ TEST_F(ResolverVariableTest, LocalVar_ShadowsParam) { ASSERT_TRUE(r()->Resolve()) << r()->error(); - auto* param = Sem().Get(p); + auto* param = Sem().Get(p); auto* local = Sem().Get(v); ASSERT_NE(param, nullptr); @@ -566,7 +566,7 @@ TEST_F(ResolverVariableTest, LocalLet_ShadowsGlobalVar) { EXPECT_EQ(local->Shadows(), global); auto* user = - Sem().Get(local->Declaration()->initializer)->UnwrapLoad()->As(); + Sem().GetVal(local->Declaration()->initializer)->UnwrapLoad()->As(); ASSERT_NE(user, nullptr); EXPECT_EQ(user->Variable(), global); } @@ -616,7 +616,7 @@ TEST_F(ResolverVariableTest, LocalLet_ShadowsLocalVar) { EXPECT_EQ(local_l->Shadows(), local_v); auto* user = - Sem().Get(local_l->Declaration()->initializer)->UnwrapLoad()->As(); + Sem().GetVal(local_l->Declaration()->initializer)->UnwrapLoad()->As(); ASSERT_NE(user, nullptr); EXPECT_EQ(user->Variable(), local_v); } diff --git a/src/tint/sem/expression.cc b/src/tint/sem/expression.cc new file mode 100644 index 0000000000..f491ab4164 --- /dev/null +++ b/src/tint/sem/expression.cc @@ -0,0 +1,26 @@ +// Copyright 2023 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "src/tint/sem/expression.h" + +TINT_INSTANTIATE_TYPEINFO(tint::sem::Expression); + +namespace tint::sem { + +Expression::Expression(const ast::Expression* declaration, const Statement* statement) + : declaration_(declaration), statement_(statement) {} + +Expression::~Expression() = default; + +} // namespace tint::sem diff --git a/src/tint/sem/expression.h b/src/tint/sem/expression.h new file mode 100644 index 0000000000..884ff4dc5d --- /dev/null +++ b/src/tint/sem/expression.h @@ -0,0 +1,55 @@ +// Copyright 2023 The Tint Authors. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#ifndef SRC_TINT_SEM_EXPRESSION_H_ +#define SRC_TINT_SEM_EXPRESSION_H_ + +#include "src/tint/ast/expression.h" +#include "src/tint/sem/node.h" + +// Forward declarations +namespace tint::sem { +class Statement; +} // namespace tint::sem + +namespace tint::sem { + +/// Expression holds the semantic information for expression nodes. +class Expression : public Castable { + public: + /// Constructor + /// @param declaration the AST node + /// @param statement the statement that owns this expression + Expression(const ast::Expression* declaration, const Statement* statement); + + /// Destructor + ~Expression() override; + + /// @returns the AST node + const ast::Expression* Declaration() const { return declaration_; } + + /// @return the statement that owns this expression + const Statement* Stmt() const { return statement_; } + + protected: + /// The AST expression node for this semantic expression + const ast::Expression* const declaration_; + + private: + const Statement* const statement_; +}; + +} // namespace tint::sem + +#endif // SRC_TINT_SEM_EXPRESSION_H_ diff --git a/src/tint/sem/info.h b/src/tint/sem/info.h index 43a158ed3b..2ce46f5ea8 100644 --- a/src/tint/sem/info.h +++ b/src/tint/sem/info.h @@ -30,6 +30,7 @@ // Forward declarations namespace tint::sem { class Module; +class ValueExpression; } // namespace tint::sem namespace tint::type { class Node; @@ -88,6 +89,14 @@ class Info { return nullptr; } + /// Convenience function that's an alias for Get() + /// @param ast_node the AST node + /// @returns a pointer to the semantic node if found, otherwise nullptr + template + const sem::ValueExpression* GetVal(const AST* ast_node) const { + return Get(ast_node); + } + /// Add registers the semantic node `sem_node` for the AST node `ast_node`. /// @param ast_node the AST node /// @param sem_node the semantic node diff --git a/src/tint/sem/type_mappings.h b/src/tint/sem/type_mappings.h index 40e287c77f..419a9c2087 100644 --- a/src/tint/sem/type_mappings.h +++ b/src/tint/sem/type_mappings.h @@ -22,13 +22,19 @@ namespace tint { class CastableBase; } // namespace tint namespace tint::ast { +class AccessorExpression; class Array; +class BinaryExpression; +class BitcastExpression; +class CallExpression; class Expression; class ForLoopStatement; class Function; class IfStatement; +class LiteralExpression; class Node; class Override; +class PhonyExpression; class Statement; class Struct; class StructMember; @@ -37,8 +43,10 @@ class Type; class TypeDecl; class Variable; class WhileStatement; +class UnaryOpExpression; } // namespace tint::ast namespace tint::sem { +class Expression; class ForLoopStatement; class Function; class GlobalVariable; @@ -77,17 +85,24 @@ struct TypeMappings { SwitchStatement* operator()(ast::SwitchStatement*); type::Type* operator()(ast::Type*); type::Type* operator()(ast::TypeDecl*); - ValueExpression* operator()(ast::Expression*); + Expression* operator()(ast::Expression*); + ValueExpression* operator()(ast::AccessorExpression*); + ValueExpression* operator()(ast::CallExpression*); + ValueExpression* operator()(ast::BinaryExpression*); + ValueExpression* operator()(ast::BitcastExpression*); + ValueExpression* operator()(ast::LiteralExpression*); + ValueExpression* operator()(ast::PhonyExpression*); + ValueExpression* operator()(ast::UnaryOpExpression*); Variable* operator()(ast::Variable*); WhileStatement* operator()(ast::WhileStatement*); //! @endcond }; /// SemanticNodeTypeFor resolves to the appropriate sem::Node type for the -/// AST or type node `AST_OR_TYPE`. -template +/// AST node `AST`. +template using SemanticNodeTypeFor = - typename std::remove_pointer()))>::type; + typename std::remove_pointer()))>::type; } // namespace tint::sem diff --git a/src/tint/sem/value_expression.cc b/src/tint/sem/value_expression.cc index de3c4cfd5d..9fe4615a79 100644 --- a/src/tint/sem/value_expression.cc +++ b/src/tint/sem/value_expression.cc @@ -30,11 +30,10 @@ ValueExpression::ValueExpression(const ast::Expression* declaration, const constant::Value* constant, bool has_side_effects, const Variable* root_ident /* = nullptr */) - : declaration_(declaration), + : Base(declaration, statement), root_identifier_(root_ident), type_(type), stage_(stage), - statement_(statement), constant_(std::move(constant)), has_side_effects_(has_side_effects) { TINT_ASSERT(Semantic, type_); diff --git a/src/tint/sem/value_expression.h b/src/tint/sem/value_expression.h index 9840c116f0..a6fb62494a 100644 --- a/src/tint/sem/value_expression.h +++ b/src/tint/sem/value_expression.h @@ -15,11 +15,10 @@ #ifndef SRC_TINT_SEM_VALUE_EXPRESSION_H_ #define SRC_TINT_SEM_VALUE_EXPRESSION_H_ -#include "src/tint/ast/expression.h" #include "src/tint/constant/value.h" #include "src/tint/sem/behavior.h" #include "src/tint/sem/evaluation_stage.h" -#include "src/tint/sem/node.h" +#include "src/tint/sem/expression.h" // Forward declarations namespace tint::sem { @@ -30,7 +29,7 @@ class Variable; namespace tint::sem { /// ValueExpression holds the semantic information for expression nodes. -class ValueExpression : public Castable { +class ValueExpression : public Castable { public: /// Constructor /// @param declaration the AST node @@ -51,18 +50,12 @@ class ValueExpression : public Castable { /// Destructor ~ValueExpression() override; - /// @returns the AST node - const ast::Expression* Declaration() const { return declaration_; } - /// @return the resolved type of the expression const type::Type* Type() const { return type_; } /// @return the earliest evaluation stage for the expression EvaluationStage Stage() const { return stage_; } - /// @return the statement that owns this expression - const Statement* Stmt() const { return statement_; } - /// @return the constant value of this expression const constant::Value* ConstantValue() const { return constant_; } @@ -92,15 +85,12 @@ class ValueExpression : public Castable { const ValueExpression* Unwrap() const; protected: - /// The AST expression node for this semantic expression - const ast::Expression* const declaration_; /// The root identifier for this semantic expression, or nullptr const Variable* root_identifier_; private: const type::Type* const type_; const EvaluationStage stage_; - const Statement* const statement_; const constant::Value* const constant_; sem::Behaviors behaviors_{sem::Behavior::kNext}; const bool has_side_effects_; diff --git a/src/tint/transform/decompose_memory_access.cc b/src/tint/transform/decompose_memory_access.cc index 7d7dc3cda6..c3c8245b40 100644 --- a/src/tint/transform/decompose_memory_access.cc +++ b/src/tint/transform/decompose_memory_access.cc @@ -74,7 +74,7 @@ struct OffsetExpr : Offset { explicit OffsetExpr(const ast::Expression* e) : expr(e) {} const ast::Expression* Build(CloneContext& ctx) const override { - auto* type = ctx.src->Sem().Get(expr)->Type()->UnwrapRef(); + auto* type = ctx.src->Sem().GetVal(expr)->Type()->UnwrapRef(); auto* res = ctx.Clone(expr); if (!type->Is()) { res = ctx.dst->Construct(res); @@ -881,7 +881,7 @@ Transform::ApplyResult DecomposeMemoryAccess::Apply(const Program* src, for (auto* node : src->ASTNodes().Objects()) { if (auto* ident = node->As()) { // X - if (auto* sem_ident = sem.Get(ident)) { + if (auto* sem_ident = sem.GetVal(ident)) { if (auto* var = sem_ident->UnwrapLoad()->As()) { if (var->Variable()->AddressSpace() == type::AddressSpace::kStorage || var->Variable()->AddressSpace() == type::AddressSpace::kUniform) { diff --git a/src/tint/transform/demote_to_helper.cc b/src/tint/transform/demote_to_helper.cc index 3763f7ca0c..128894d9e9 100644 --- a/src/tint/transform/demote_to_helper.cc +++ b/src/tint/transform/demote_to_helper.cc @@ -123,7 +123,7 @@ Transform::ApplyResult DemoteToHelper::Apply(const Program* src, const DataMap&, } // Skip writes to invocation-private address spaces. - auto* ref = sem.Get(assign->lhs)->Type()->As(); + auto* ref = sem.GetVal(assign->lhs)->Type()->As(); switch (ref->AddressSpace()) { case type::AddressSpace::kStorage: // Need to mask these. diff --git a/src/tint/transform/direct_variable_access.cc b/src/tint/transform/direct_variable_access.cc index 9d3d37ba4a..92af018dd5 100644 --- a/src/tint/transform/direct_variable_access.cc +++ b/src/tint/transform/direct_variable_access.cc @@ -216,7 +216,7 @@ struct DirectVariableAccess::State { // are grown and moved up the expression tree. After this stage, we are left with all the // expression access chains to variables that we may need to transform. for (auto* node : ctx.src->ASTNodes().Objects()) { - if (auto* expr = sem.Get(node)) { + if (auto* expr = sem.GetVal(node)) { AppendAccessChain(expr); } } @@ -464,7 +464,7 @@ struct DirectVariableAccess::State { [&](const ast::Let*) { if (variable->Type()->Is()) { // variable is a pointer-let. - auto* init = sem.Get(variable->Declaration()->initializer); + auto* init = sem.GetVal(variable->Declaration()->initializer); // Note: We do not use take_chain() here, as we need to preserve the // AccessChain on the let's initializer, as the let needs its // initializer updated, and the let may be used multiple times. Instead @@ -498,7 +498,7 @@ struct DirectVariableAccess::State { // If this is a '&' or '*', simply move the chain to the unary op expression. if (unary->op == ast::UnaryOp::kAddressOf || unary->op == ast::UnaryOp::kIndirection) { - take_chain(sem.Get(unary->expr)); + take_chain(sem.GetVal(unary->expr)); } } }); @@ -990,7 +990,7 @@ struct DirectVariableAccess::State { return nullptr; // Just clone the expression. } - auto* expr = sem.Get(ast_expr); + auto* expr = sem.GetVal(ast_expr); if (!expr) { // No semantic node for the expression. return nullptr; // Just clone the expression. diff --git a/src/tint/transform/expand_compound_assignment.cc b/src/tint/transform/expand_compound_assignment.cc index 253eed4a68..f8b4111cba 100644 --- a/src/tint/transform/expand_compound_assignment.cc +++ b/src/tint/transform/expand_compound_assignment.cc @@ -86,7 +86,10 @@ struct ExpandCompoundAssignment::State { // Helper function that returns `true` if the type of `expr` is a vector. auto is_vec = [&](const ast::Expression* expr) { - return ctx.src->Sem().Get(expr)->Type()->UnwrapRef()->Is(); + if (auto* val_expr = ctx.src->Sem().GetVal(expr)) { + return val_expr->Type()->UnwrapRef()->Is(); + } + return false; }; // Hoist the LHS expression subtree into local constants to produce a new diff --git a/src/tint/transform/first_index_offset.cc b/src/tint/transform/first_index_offset.cc index 2359ae9c09..afc946da06 100644 --- a/src/tint/transform/first_index_offset.cc +++ b/src/tint/transform/first_index_offset.cc @@ -138,7 +138,7 @@ Transform::ApplyResult FirstIndexOffset::Apply(const Program* src, // Fix up all references to the builtins with the offsets ctx.ReplaceAll([=, &ctx](const ast::Expression* expr) -> const ast::Expression* { - if (auto* sem = ctx.src->Sem().Get(expr)) { + if (auto* sem = ctx.src->Sem().GetVal(expr)) { if (auto* user = sem->UnwrapLoad()->As()) { auto it = builtin_vars.find(user->Variable()); if (it != builtin_vars.end()) { diff --git a/src/tint/transform/localize_struct_array_assignment.cc b/src/tint/transform/localize_struct_array_assignment.cc index 0d40ccf81b..5f70731827 100644 --- a/src/tint/transform/localize_struct_array_assignment.cc +++ b/src/tint/transform/localize_struct_array_assignment.cc @@ -164,7 +164,7 @@ struct LocalizeStructArrayAssignment::State { ast::TraverseExpressions( expr, b.Diagnostics(), [&](const ast::IndexAccessorExpression* ia) { // Indexing using a runtime value? - auto* idx_sem = src->Sem().Get(ia->index); + auto* idx_sem = src->Sem().GetVal(ia->index); if (!idx_sem->ConstantValue()) { // Indexing a member access expr? if (auto* ma = ia->object->As()) { @@ -186,7 +186,7 @@ struct LocalizeStructArrayAssignment::State { // See https://www.w3.org/TR/WGSL/#originating-variable-section std::pair GetOriginatingTypeAndAddressSpace( const ast::AssignmentStatement* assign_stmt) { - auto* root_ident = src->Sem().Get(assign_stmt->lhs)->RootIdentifier(); + auto* root_ident = src->Sem().GetVal(assign_stmt->lhs)->RootIdentifier(); if (TINT_UNLIKELY(!root_ident)) { TINT_ICE(Transform, b.Diagnostics()) << "Unable to determine originating variable for lhs of assignment " diff --git a/src/tint/transform/multiplanar_external_texture.cc b/src/tint/transform/multiplanar_external_texture.cc index 652023e53d..6e68428c64 100644 --- a/src/tint/transform/multiplanar_external_texture.cc +++ b/src/tint/transform/multiplanar_external_texture.cc @@ -198,7 +198,7 @@ struct MultiplanarExternalTexture::State { builtin->Parameters()[0]->Type()->Is() && builtin->Type() != sem::BuiltinType::kTextureDimensions) { if (auto* var_user = - sem.Get(expr->args[0])->UnwrapLoad()->As()) { + sem.GetVal(expr->args[0])->UnwrapLoad()->As()) { auto it = new_binding_symbols.find(var_user->Variable()); if (it == new_binding_symbols.end()) { // If valid new binding locations were not provided earlier, we would have @@ -223,7 +223,7 @@ struct MultiplanarExternalTexture::State { // texture_external parameter. These need to be expanded out to multiple plane // textures and the texture parameters structure. for (auto* arg : expr->args) { - if (auto* var_user = sem.Get(arg)->UnwrapLoad()->As()) { + if (auto* var_user = sem.GetVal(arg)->UnwrapLoad()->As()) { // Check if a parameter is a texture_external by trying to find // it in the transform state. auto it = new_binding_symbols.find(var_user->Variable()); diff --git a/src/tint/transform/packed_vec3.cc b/src/tint/transform/packed_vec3.cc index 26cad634b8..c553a32dc0 100644 --- a/src/tint/transform/packed_vec3.cc +++ b/src/tint/transform/packed_vec3.cc @@ -109,7 +109,7 @@ struct PackedVec3::State { if (unary->op == ast::UnaryOp::kAddressOf || unary->op == ast::UnaryOp::kIndirection) { // Memory access on the packed vector. Track these. - auto* inner = sem.Get(unary->expr); + auto* inner = sem.GetVal(unary->expr); if (refs.Remove(inner)) { refs.Add(expr); } @@ -121,7 +121,7 @@ struct PackedVec3::State { [&](const sem::Statement* e) { if (auto* assign = e->Declaration()->As()) { // We don't want to cast packed_vectors if they're being assigned to. - refs.Remove(sem.Get(assign->lhs)); + refs.Remove(sem.GetVal(assign->lhs)); } }); } diff --git a/src/tint/transform/preserve_padding.cc b/src/tint/transform/preserve_padding.cc index c5c0d1bb41..1946ca51c0 100644 --- a/src/tint/transform/preserve_padding.cc +++ b/src/tint/transform/preserve_padding.cc @@ -48,7 +48,7 @@ struct PreservePadding::State { Switch( node, // [&](const ast::AssignmentStatement* assign) { - auto* ty = sem.Get(assign->lhs)->Type(); + auto* ty = sem.GetVal(assign->lhs)->Type(); if (assign->lhs->Is()) { // Ignore phony assignment. return; @@ -80,7 +80,7 @@ struct PreservePadding::State { if (!assignments_to_transform.count(assign)) { return nullptr; } - auto* ty = sem.Get(assign->lhs)->Type()->UnwrapRef(); + auto* ty = sem.GetVal(assign->lhs)->Type()->UnwrapRef(); return MakeAssignment(ty, ctx.Clone(assign->lhs), ctx.Clone(assign->rhs)); }); diff --git a/src/tint/transform/promote_initializers_to_let.cc b/src/tint/transform/promote_initializers_to_let.cc index 0ad37de91c..20f7d32d1b 100644 --- a/src/tint/transform/promote_initializers_to_let.cc +++ b/src/tint/transform/promote_initializers_to_let.cc @@ -83,7 +83,7 @@ Transform::ApplyResult PromoteInitializersToLet::Apply(const Program* src, // Walk the AST nodes. This order guarantees that leaf-expressions are visited first. for (auto* node : src->ASTNodes().Objects()) { - if (auto* sem = src->Sem().Get(node)) { + if (auto* sem = src->Sem().GetVal(node)) { auto* stmt = sem->Stmt(); if (!stmt) { // Expression is outside of a statement. This usually means the expression is part @@ -118,7 +118,7 @@ Transform::ApplyResult PromoteInitializersToLet::Apply(const Program* src, // After walking the full AST, const_chains only contains the outer-most constant expressions. // Check if any of these need hoisting, and append those to to_hoist. for (auto* expr : const_chains) { - if (auto* sem = src->Sem().Get(expr); should_hoist(sem)) { + if (auto* sem = src->Sem().GetVal(expr); should_hoist(sem)) { to_hoist.Push(sem); } } diff --git a/src/tint/transform/promote_side_effects_to_decl.cc b/src/tint/transform/promote_side_effects_to_decl.cc index d4ad5d7a6b..15f4674568 100644 --- a/src/tint/transform/promote_side_effects_to_decl.cc +++ b/src/tint/transform/promote_side_effects_to_decl.cc @@ -66,9 +66,8 @@ Transform::ApplyResult SimplifySideEffectStatements::Apply(const Program* src, HoistToDeclBefore hoist_to_decl_before(ctx); for (auto* node : ctx.src->ASTNodes().Objects()) { - if (auto* expr = node->As()) { - auto* sem_expr = src->Sem().Get(expr); - if (!sem_expr || !sem_expr->HasSideEffects()) { + if (auto* sem_expr = src->Sem().GetVal(node)) { + if (!sem_expr->HasSideEffects()) { continue; } @@ -278,7 +277,7 @@ class DecomposeSideEffects::CollectHoistsState : public StateBase { return true; }, [&](const ast::IdentifierExpression* e) { - if (auto* sem_e = sem.Get(e)) { + if (auto* sem_e = sem.GetVal(e)) { if (auto* var_user = sem_e->UnwrapLoad()->As()) { // Don't hoist constants. if (var_user->ConstantValue()) { @@ -417,8 +416,8 @@ class DecomposeSideEffects::DecomposeState : public StateBase { // Returns true if `binary_expr` should be decomposed for short-circuit eval. bool IsLogicalWithSideEffects(const ast::BinaryExpression* binary_expr) { - return binary_expr->IsLogical() && (sem.Get(binary_expr->lhs)->HasSideEffects() || - sem.Get(binary_expr->rhs)->HasSideEffects()); + return binary_expr->IsLogical() && (sem.GetVal(binary_expr->lhs)->HasSideEffects() || + sem.GetVal(binary_expr->rhs)->HasSideEffects()); } // Recursive function used to decompose an expression for short-circuit eval. @@ -560,7 +559,8 @@ class DecomposeSideEffects::DecomposeState : public StateBase { return Switch( stmt, [&](const ast::AssignmentStatement* s) -> const ast::Statement* { - if (!sem.Get(s->lhs)->HasSideEffects() && !sem.Get(s->rhs)->HasSideEffects()) { + if (!sem.GetVal(s->lhs)->HasSideEffects() && + !sem.GetVal(s->rhs)->HasSideEffects()) { return nullptr; } // rhs before lhs @@ -580,7 +580,7 @@ class DecomposeSideEffects::DecomposeState : public StateBase { return ctx.CloneWithoutTransform(s); }, [&](const ast::ForLoopStatement* s) -> const ast::Statement* { - if (!s->condition || !sem.Get(s->condition)->HasSideEffects()) { + if (!s->condition || !sem.GetVal(s->condition)->HasSideEffects()) { return nullptr; } tint::utils::Vector stmts; @@ -589,7 +589,7 @@ class DecomposeSideEffects::DecomposeState : public StateBase { return ctx.CloneWithoutTransform(s); }, [&](const ast::WhileStatement* s) -> const ast::Statement* { - if (!sem.Get(s->condition)->HasSideEffects()) { + if (!sem.GetVal(s->condition)->HasSideEffects()) { return nullptr; } tint::utils::Vector stmts; @@ -598,7 +598,7 @@ class DecomposeSideEffects::DecomposeState : public StateBase { return ctx.CloneWithoutTransform(s); }, [&](const ast::IfStatement* s) -> const ast::Statement* { - if (!sem.Get(s->condition)->HasSideEffects()) { + if (!sem.GetVal(s->condition)->HasSideEffects()) { return nullptr; } tint::utils::Vector stmts; @@ -607,7 +607,7 @@ class DecomposeSideEffects::DecomposeState : public StateBase { return ctx.CloneWithoutTransform(s); }, [&](const ast::ReturnStatement* s) -> const ast::Statement* { - if (!s->value || !sem.Get(s->value)->HasSideEffects()) { + if (!s->value || !sem.GetVal(s->value)->HasSideEffects()) { return nullptr; } tint::utils::Vector stmts; @@ -626,7 +626,7 @@ class DecomposeSideEffects::DecomposeState : public StateBase { }, [&](const ast::VariableDeclStatement* s) -> const ast::Statement* { auto* var = s->variable; - if (!var->initializer || !sem.Get(var->initializer)->HasSideEffects()) { + if (!var->initializer || !sem.GetVal(var->initializer)->HasSideEffects()) { return nullptr; } tint::utils::Vector stmts; diff --git a/src/tint/transform/remove_phonies.cc b/src/tint/transform/remove_phonies.cc index cb2d914fd0..3b0dabd3b7 100644 --- a/src/tint/transform/remove_phonies.cc +++ b/src/tint/transform/remove_phonies.cc @@ -102,7 +102,7 @@ Transform::ApplyResult RemovePhonies::Apply(const Program* src, const DataMap&, ctx.Replace(stmt, [&, side_effects] { SinkSignature sig; for (auto* arg : side_effects) { - sig.push_back(sem.Get(arg)->Type()->UnwrapRef()); + sig.push_back(sem.GetVal(arg)->Type()->UnwrapRef()); } auto sink = sinks.GetOrCreate(sig, [&] { auto name = b.Symbols().New("phony_sink"); diff --git a/src/tint/transform/renamer.cc b/src/tint/transform/renamer.cc index 4f353926c8..63962389cc 100644 --- a/src/tint/transform/renamer.cc +++ b/src/tint/transform/renamer.cc @@ -1286,7 +1286,7 @@ Transform::ApplyResult Renamer::Apply(const Program* src, auto* sem = src->Sem().Get(accessor)->UnwrapLoad(); if (sem->Is()) { preserved_identifiers.Add(accessor->member); - } else if (auto* str_expr = src->Sem().Get(accessor->object)) { + } else if (auto* str_expr = src->Sem().GetVal(accessor->object)) { if (auto* ty = str_expr->Type()->UnwrapRef()->As()) { if (ty->Declaration() == nullptr) { // Builtin structure preserved_identifiers.Add(accessor->member); diff --git a/src/tint/transform/spirv_atomic.cc b/src/tint/transform/spirv_atomic.cc index 07879e802d..3a53e7123e 100644 --- a/src/tint/transform/spirv_atomic.cc +++ b/src/tint/transform/spirv_atomic.cc @@ -101,7 +101,7 @@ struct SpirvAtomic::State { // Keep track of this expression. We'll need to modify the root identifier / // structure to be atomic. - atomic_expressions.Add(ctx.src->Sem().Get(args[0])); + atomic_expressions.Add(ctx.src->Sem().GetVal(args[0])); } // Remove the stub from the output program @@ -186,7 +186,7 @@ struct SpirvAtomic::State { }, [&](const sem::ValueExpression* e) { if (auto* unary = e->Declaration()->As()) { - atomic_expressions.Add(ctx.src->Sem().Get(unary->expr)); + atomic_expressions.Add(ctx.src->Sem().GetVal(unary->expr)); } }); } @@ -249,7 +249,7 @@ struct SpirvAtomic::State { Switch( vu->Stmt()->Declaration(), [&](const ast::AssignmentStatement* assign) { - auto* sem_lhs = ctx.src->Sem().Get(assign->lhs); + auto* sem_lhs = ctx.src->Sem().GetVal(assign->lhs); if (is_ref_to_atomic_var(sem_lhs)) { ctx.Replace(assign, [=] { auto* lhs = ctx.CloneWithoutTransform(assign->lhs); @@ -261,7 +261,7 @@ struct SpirvAtomic::State { return; } - auto sem_rhs = ctx.src->Sem().Get(assign->rhs); + auto sem_rhs = ctx.src->Sem().GetVal(assign->rhs); if (is_ref_to_atomic_var(sem_rhs->UnwrapLoad())) { ctx.Replace(assign->rhs, [=] { auto* rhs = ctx.CloneWithoutTransform(assign->rhs); @@ -273,7 +273,7 @@ struct SpirvAtomic::State { }, [&](const ast::VariableDeclStatement* decl) { auto* var = decl->variable; - if (auto* sem_init = ctx.src->Sem().Get(var->initializer)) { + if (auto* sem_init = ctx.src->Sem().GetVal(var->initializer)) { if (is_ref_to_atomic_var(sem_init->UnwrapLoad())) { ctx.Replace(var->initializer, [=] { auto* rhs = ctx.CloneWithoutTransform(var->initializer); diff --git a/src/tint/transform/std140.cc b/src/tint/transform/std140.cc index cde4a3f4ae..46f71bcc67 100644 --- a/src/tint/transform/std140.cc +++ b/src/tint/transform/std140.cc @@ -494,7 +494,7 @@ struct Std140::State { /// @returns an AccessChain if the expression is an access to a std140-forked uniform buffer, /// otherwise returns a std::nullopt. std::optional AccessChainFor(const ast::Expression* ast_expr) { - auto* expr = sem.Get(ast_expr); + auto* expr = sem.GetVal(ast_expr); if (!expr) { return std::nullopt; } @@ -580,7 +580,7 @@ struct Std140::State { switch (u->op) { case ast::UnaryOp::kAddressOf: case ast::UnaryOp::kIndirection: - expr = sem.Get(u->expr); + expr = sem.GetVal(u->expr); return Action::kContinue; default: TINT_ICE(Transform, b.Diagnostics()) diff --git a/src/tint/transform/unshadow.cc b/src/tint/transform/unshadow.cc index 7c9f75cced..bbb3a27845 100644 --- a/src/tint/transform/unshadow.cc +++ b/src/tint/transform/unshadow.cc @@ -106,7 +106,7 @@ struct Unshadow::State { ctx.ReplaceAll( [&](const ast::IdentifierExpression* ident) -> const tint::ast::IdentifierExpression* { - if (auto* sem_ident = sem.Get(ident)) { + if (auto* sem_ident = sem.GetVal(ident)) { if (auto* user = sem_ident->UnwrapLoad()->As()) { if (auto renamed = renamed_to.Find(user->Variable())) { return b.Expr(*renamed); diff --git a/src/tint/transform/utils/hoist_to_decl_before_test.cc b/src/tint/transform/utils/hoist_to_decl_before_test.cc index c5dca5de64..8f166752c9 100644 --- a/src/tint/transform/utils/hoist_to_decl_before_test.cc +++ b/src/tint/transform/utils/hoist_to_decl_before_test.cc @@ -108,7 +108,7 @@ TEST_F(HoistToDeclBeforeTest, ForLoopCond) { CloneContext ctx(&cloned_b, &original); HoistToDeclBefore hoistToDeclBefore(ctx); - auto* sem_expr = ctx.src->Sem().Get(expr); + auto* sem_expr = ctx.src->Sem().GetVal(expr); hoistToDeclBefore.Add(sem_expr, expr, HoistToDeclBefore::VariableKind::kConst); ctx.Clone(); @@ -189,7 +189,7 @@ TEST_F(HoistToDeclBeforeTest, WhileCond) { CloneContext ctx(&cloned_b, &original); HoistToDeclBefore hoistToDeclBefore(ctx); - auto* sem_expr = ctx.src->Sem().Get(expr); + auto* sem_expr = ctx.src->Sem().GetVal(expr); hoistToDeclBefore.Add(sem_expr, expr, HoistToDeclBefore::VariableKind::kVar); ctx.Clone(); @@ -233,7 +233,7 @@ TEST_F(HoistToDeclBeforeTest, ElseIf) { CloneContext ctx(&cloned_b, &original); HoistToDeclBefore hoistToDeclBefore(ctx); - auto* sem_expr = ctx.src->Sem().Get(expr); + auto* sem_expr = ctx.src->Sem().GetVal(expr); hoistToDeclBefore.Add(sem_expr, expr, HoistToDeclBefore::VariableKind::kConst); ctx.Clone(); @@ -339,7 +339,7 @@ TEST_F(HoistToDeclBeforeTest, Prepare_ForLoopCond) { CloneContext ctx(&cloned_b, &original); HoistToDeclBefore hoistToDeclBefore(ctx); - auto* sem_expr = ctx.src->Sem().Get(expr); + auto* sem_expr = ctx.src->Sem().GetVal(expr); hoistToDeclBefore.Prepare(sem_expr); ctx.Clone(); @@ -422,7 +422,7 @@ TEST_F(HoistToDeclBeforeTest, Prepare_ElseIf) { CloneContext ctx(&cloned_b, &original); HoistToDeclBefore hoistToDeclBefore(ctx); - auto* sem_expr = ctx.src->Sem().Get(expr); + auto* sem_expr = ctx.src->Sem().GetVal(expr); hoistToDeclBefore.Prepare(sem_expr); ctx.Clone(); diff --git a/src/tint/transform/var_for_dynamic_index.cc b/src/tint/transform/var_for_dynamic_index.cc index de69d5387e..18f71bb282 100644 --- a/src/tint/transform/var_for_dynamic_index.cc +++ b/src/tint/transform/var_for_dynamic_index.cc @@ -40,13 +40,13 @@ Transform::ApplyResult VarForDynamicIndex::Apply(const Program* src, auto* object_expr = access_expr->object; auto& sem = src->Sem(); - if (sem.Get(index_expr)->ConstantValue()) { + if (sem.GetVal(index_expr)->ConstantValue()) { // Index expression resolves to a compile time value. // As this isn't a dynamic index, we can ignore this. return true; } - auto* indexed = sem.Get(object_expr); + auto* indexed = sem.GetVal(object_expr); if (!indexed->Type()->IsAnyOf()) { // We only care about array and matrices. return true; diff --git a/src/tint/transform/vectorize_matrix_conversions.cc b/src/tint/transform/vectorize_matrix_conversions.cc index f22e32dc6b..8aa36900e9 100644 --- a/src/tint/transform/vectorize_matrix_conversions.cc +++ b/src/tint/transform/vectorize_matrix_conversions.cc @@ -34,7 +34,7 @@ namespace { bool ShouldRun(const Program* program) { for (auto* node : program->ASTNodes().Objects()) { - if (auto* sem = program->Sem().Get(node)) { + if (auto* sem = program->Sem().GetVal(node)) { if (auto* call = sem->UnwrapMaterialize()->As()) { if (call->Target()->Is() && call->Type()->Is()) { auto& args = call->Arguments(); diff --git a/src/tint/transform/zero_init_workgroup_memory.cc b/src/tint/transform/zero_init_workgroup_memory.cc index 61d7a4bab6..c7e1b8a899 100644 --- a/src/tint/transform/zero_init_workgroup_memory.cc +++ b/src/tint/transform/zero_init_workgroup_memory.cc @@ -403,7 +403,7 @@ struct ZeroInitWorkgroupMemory::State { if (!expr) { continue; } - auto* sem = ctx.src->Sem().Get(expr); + auto* sem = ctx.src->Sem().GetVal(expr); if (auto* c = sem->ConstantValue()) { workgroup_size_const *= c->ValueAs(); continue; diff --git a/src/tint/writer/append_vector.cc b/src/tint/writer/append_vector.cc index c39c61947a..40222c073d 100644 --- a/src/tint/writer/append_vector.cc +++ b/src/tint/writer/append_vector.cc @@ -75,8 +75,8 @@ const sem::Call* AppendVector(ProgramBuilder* b, const ast::Expression* scalar_ast) { uint32_t packed_size; const type::Type* packed_el_sem_ty; - auto* vector_sem = b->Sem().Get(vector_ast); - auto* scalar_sem = b->Sem().Get(scalar_ast); + auto* vector_sem = b->Sem().GetVal(vector_ast); + auto* scalar_sem = b->Sem().GetVal(scalar_ast); auto* vector_ty = vector_sem->Type()->UnwrapRef(); if (auto* vec = vector_ty->As()) { packed_size = vec->Width() + 1; diff --git a/src/tint/writer/glsl/generator_impl.cc b/src/tint/writer/glsl/generator_impl.cc index 86695501fa..1e2279ae3b 100644 --- a/src/tint/writer/glsl/generator_impl.cc +++ b/src/tint/writer/glsl/generator_impl.cc @@ -1814,7 +1814,7 @@ bool GeneratorImpl::EmitDiscard(const ast::DiscardStatement*) { } bool GeneratorImpl::EmitExpression(std::ostream& out, const ast::Expression* expr) { - if (auto* sem = builder_.Sem().Get(expr)) { + if (auto* sem = builder_.Sem().GetVal(expr)) { if (auto* constant = sem->ConstantValue()) { return EmitConstant(out, constant); } diff --git a/src/tint/writer/hlsl/generator_impl.cc b/src/tint/writer/hlsl/generator_impl.cc index 5b0b012558..df0f75bbe1 100644 --- a/src/tint/writer/hlsl/generator_impl.cc +++ b/src/tint/writer/hlsl/generator_impl.cc @@ -658,8 +658,8 @@ bool GeneratorImpl::EmitAssign(const ast::AssignmentStatement* stmt) { // with at least one dynamic index if (auto* lhs_sub_access = lhs_access->object->As()) { if (auto* mat = TypeOf(lhs_sub_access->object)->UnwrapRef()->As()) { - auto* rhs_row_idx_sem = builder_.Sem().Get(lhs_access->index); - auto* rhs_col_idx_sem = builder_.Sem().Get(lhs_sub_access->index); + auto* rhs_row_idx_sem = builder_.Sem().GetVal(lhs_access->index); + auto* rhs_col_idx_sem = builder_.Sem().GetVal(lhs_sub_access->index); if (!rhs_row_idx_sem->ConstantValue() || !rhs_col_idx_sem->ConstantValue()) { return EmitDynamicMatrixScalarAssignment(stmt, mat); } @@ -669,7 +669,7 @@ bool GeneratorImpl::EmitAssign(const ast::AssignmentStatement* stmt) { // with dynamic indices const auto* lhs_access_type = TypeOf(lhs_access->object)->UnwrapRef(); if (auto* mat = lhs_access_type->As()) { - auto* lhs_index_sem = builder_.Sem().Get(lhs_access->index); + auto* lhs_index_sem = builder_.Sem().GetVal(lhs_access->index); if (!lhs_index_sem->ConstantValue()) { return EmitDynamicMatrixVectorAssignment(stmt, mat); } @@ -677,7 +677,7 @@ bool GeneratorImpl::EmitAssign(const ast::AssignmentStatement* stmt) { // BUG(crbug.com/tint/534): work around assignment to vectors with dynamic // indices if (auto* vec = lhs_access_type->As()) { - auto* rhs_sem = builder_.Sem().Get(lhs_access->index); + auto* rhs_sem = builder_.Sem().GetVal(lhs_access->index); if (!rhs_sem->ConstantValue()) { return EmitDynamicVectorAssignment(stmt, vec); } @@ -1109,7 +1109,7 @@ bool GeneratorImpl::EmitUniformBufferAccess( const ast::CallExpression* expr, const transform::DecomposeMemoryAccess::Intrinsic* intrinsic) { const auto& args = expr->args; - auto* offset_arg = builder_.Sem().Get(args[1]); + auto* offset_arg = builder_.Sem().GetVal(args[1]); // offset in bytes uint32_t scalar_offset_bytes = 0; @@ -2790,7 +2790,7 @@ bool GeneratorImpl::EmitDiscard(const ast::DiscardStatement*) { } bool GeneratorImpl::EmitExpression(std::ostream& out, const ast::Expression* expr) { - if (auto* sem = builder_.Sem().Get(expr)) { + if (auto* sem = builder_.Sem().GetVal(expr)) { if (auto* constant = sem->ConstantValue()) { bool is_variable_initializer = false; if (auto* stmt = sem->Stmt()) { @@ -3864,7 +3864,7 @@ bool GeneratorImpl::EmitDefaultOnlySwitch(const ast::SwitchStatement* stmt) { // Emit the switch condition as-is if it has side-effects (e.g. // function call). Note that we can ignore the result of the expression (if any). - if (auto* sem_cond = builder_.Sem().Get(stmt->condition); sem_cond->HasSideEffects()) { + if (auto* sem_cond = builder_.Sem().GetVal(stmt->condition); sem_cond->HasSideEffects()) { auto out = line(); if (!EmitExpression(out, stmt->condition)) { return false; diff --git a/src/tint/writer/msl/generator_impl.cc b/src/tint/writer/msl/generator_impl.cc index a1ce6134ea..a57b42318a 100644 --- a/src/tint/writer/msl/generator_impl.cc +++ b/src/tint/writer/msl/generator_impl.cc @@ -733,7 +733,7 @@ bool GeneratorImpl::EmitBuiltinCall(std::ostream& out, } case sem::BuiltinType::kLength: { - auto* sem = builder_.Sem().Get(expr->args[0]); + auto* sem = builder_.Sem().GetVal(expr->args[0]); if (sem->Type()->UnwrapRef()->is_scalar()) { // Emulate scalar overload using fabs(x). name = "fabs"; @@ -742,7 +742,7 @@ bool GeneratorImpl::EmitBuiltinCall(std::ostream& out, } case sem::BuiltinType::kDistance: { - auto* sem = builder_.Sem().Get(expr->args[0]); + auto* sem = builder_.Sem().GetVal(expr->args[0]); if (sem->Type()->UnwrapRef()->is_scalar()) { // Emulate scalar overload using fabs(x - y); out << "fabs"; @@ -1827,7 +1827,7 @@ bool GeneratorImpl::EmitLiteral(std::ostream& out, const ast::LiteralExpression* } bool GeneratorImpl::EmitExpression(std::ostream& out, const ast::Expression* expr) { - if (auto* sem = builder_.Sem().Get(expr)) { + if (auto* sem = builder_.Sem().GetVal(expr)) { if (auto* constant = sem->ConstantValue()) { return EmitConstant(out, constant); } diff --git a/src/tint/writer/spirv/builder.cc b/src/tint/writer/spirv/builder.cc index e9383963c9..c8f32bda34 100644 --- a/src/tint/writer/spirv/builder.cc +++ b/src/tint/writer/spirv/builder.cc @@ -424,7 +424,7 @@ bool Builder::GenerateLabel(uint32_t id) { bool Builder::GenerateAssignStatement(const ast::AssignmentStatement* assign) { if (assign->lhs->Is()) { - if (builder_.Sem().Get(assign->rhs)->ConstantValue()) { + if (builder_.Sem().GetVal(assign->rhs)->ConstantValue()) { // RHS of phony assignment is constant. // Constants can't have side-effects, so just drop this. return true; @@ -558,9 +558,11 @@ bool Builder::GenerateExecutionModes(const ast::Function* func, uint32_t id) { return true; } -uint32_t Builder::GenerateExpression(const sem::ValueExpression* expr) { - if (auto* constant = expr->ConstantValue()) { - return GenerateConstantIfNeeded(constant); +uint32_t Builder::GenerateExpression(const sem::Expression* expr) { + if (auto* val_expr = expr->As()) { + if (auto* constant = val_expr->ConstantValue()) { + return GenerateConstantIfNeeded(constant); + } } if (auto* load = expr->As()) { auto ref_id = GenerateExpression(load->Reference()); @@ -909,7 +911,7 @@ bool Builder::GenerateIndexAccessor(const ast::IndexAccessorExpression* expr, Ac auto extract_id = std::get(extract); // If the index is compile-time constant, we use OpCompositeExtract. - auto* idx = builder_.Sem().Get(expr->index); + auto* idx = builder_.Sem().GetVal(expr->index); if (auto idx_constval = idx->ConstantValue()) { if (!push_function_inst(spv::Op::OpCompositeExtract, { @@ -1140,8 +1142,7 @@ uint32_t Builder::GenerateAccessorExpression(const ast::AccessorExpression* expr } uint32_t Builder::GenerateIdentifierExpression(const ast::IdentifierExpression* expr) { - auto* sem = builder_.Sem().Get(expr); - if (sem) { + if (auto* sem = builder_.Sem().GetVal(expr); sem) { if (auto* user = sem->UnwrapLoad()->As()) { return LookupVariableID(user->Variable()); } @@ -1231,7 +1232,7 @@ uint32_t Builder::GetGLSLstd450Import() { uint32_t Builder::GenerateInitializerExpression(const ast::Variable* var, const ast::Expression* expr) { - if (auto* sem = builder_.Sem().Get(expr)) { + if (auto* sem = builder_.Sem().GetVal(expr)) { if (auto constant = sem->ConstantValue()) { return GenerateConstantIfNeeded(constant); } diff --git a/src/tint/writer/spirv/builder.h b/src/tint/writer/spirv/builder.h index e468a31fe5..6f9bf5d99f 100644 --- a/src/tint/writer/spirv/builder.h +++ b/src/tint/writer/spirv/builder.h @@ -275,7 +275,7 @@ class Builder { /// Generates an expression /// @param expr the expression to generate /// @returns the resulting ID of the expression or 0 on error - uint32_t GenerateExpression(const sem::ValueExpression* expr); + uint32_t GenerateExpression(const sem::Expression* expr); /// Generates an expression /// @param expr the expression to generate /// @returns the resulting ID of the expression or 0 on error