From a7cd3aeff08d734a79259dba47066076d5379c42 Mon Sep 17 00:00:00 2001 From: James Price Date: Wed, 9 Nov 2022 12:16:56 +0000 Subject: [PATCH] tint: Rename SourceVariable() to RootIdentifier() This is now a well-defined term in the WGSL spec, so we should use it. Change-Id: Icc46a77f0a465afbfd39cdaec84e506b143c8c0c Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/109220 Commit-Queue: Ben Clayton Kokoro: Kokoro Reviewed-by: Ben Clayton Auto-Submit: James Price --- src/tint/BUILD.gn | 2 +- src/tint/CMakeLists.txt | 2 +- src/tint/inspector/inspector.cc | 6 +- src/tint/resolver/resolver.cc | 16 ++-- ...riable_test.cc => root_identifier_test.cc} | 96 +++++++++---------- src/tint/resolver/uniformity.cc | 16 ++-- src/tint/sem/expression.cc | 4 +- src/tint/sem/expression.h | 12 +-- src/tint/sem/expression_test.cc | 2 +- src/tint/sem/index_accessor_expression.cc | 4 +- src/tint/sem/index_accessor_expression.h | 4 +- src/tint/sem/materialize.cc | 2 +- src/tint/sem/member_accessor_expression.cc | 12 +-- src/tint/sem/member_accessor_expression.h | 12 +-- src/tint/sem/variable.cc | 4 +- .../localize_struct_array_assignment.cc | 6 +- src/tint/transform/spirv_atomic.cc | 6 +- src/tint/transform/std140.cc | 10 +- 18 files changed, 108 insertions(+), 108 deletions(-) rename src/tint/resolver/{source_variable_test.cc => root_identifier_test.cc} (69%) diff --git a/src/tint/BUILD.gn b/src/tint/BUILD.gn index 39fae600e2..eb863dea7d 100644 --- a/src/tint/BUILD.gn +++ b/src/tint/BUILD.gn @@ -1160,7 +1160,7 @@ if (tint_build_unittests) { "resolver/resolver_test_helper.cc", "resolver/resolver_test_helper.h", "resolver/side_effects_test.cc", - "resolver/source_variable_test.cc", + "resolver/root_identifier_test.cc", "resolver/static_assert_test.cc", "resolver/struct_address_space_use_test.cc", "resolver/struct_layout_test.cc", diff --git a/src/tint/CMakeLists.txt b/src/tint/CMakeLists.txt index 1d392434a4..69712dd5f6 100644 --- a/src/tint/CMakeLists.txt +++ b/src/tint/CMakeLists.txt @@ -885,7 +885,7 @@ if(TINT_BUILD_TESTS) resolver/resolver_test.cc resolver/side_effects_test.cc resolver/static_assert_test.cc - resolver/source_variable_test.cc + resolver/root_identifier_test.cc resolver/address_space_layout_validation_test.cc resolver/address_space_validation_test.cc resolver/struct_layout_test.cc diff --git a/src/tint/inspector/inspector.cc b/src/tint/inspector/inspector.cc index 516c1dc0aa..b641f53308 100644 --- a/src/tint/inspector/inspector.cc +++ b/src/tint/inspector/inspector.cc @@ -892,10 +892,10 @@ void Inspector::GetOriginatingResources(std::array ex utils::UniqueVector callsites; for (size_t i = 0; i < N; i++) { - const sem::Variable* source_var = sem.Get(exprs[i])->SourceVariable(); - if (auto* global = source_var->As()) { + const sem::Variable* root_ident = sem.Get(exprs[i])->RootIdentifier(); + if (auto* global = root_ident->As()) { globals[i] = global; - } else if (auto* param = source_var->As()) { + } else if (auto* param = root_ident->As()) { auto* func = tint::As(param->Owner()); if (func->CallSites().empty()) { // One or more of the expressions is a parameter, but this function diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc index cb249559c0..daec00aeac 100644 --- a/src/tint/resolver/resolver.cc +++ b/src/tint/resolver/resolver.cc @@ -1712,7 +1712,7 @@ sem::Expression* Resolver::IndexAccessor(const ast::IndexAccessorExpression* exp bool has_side_effects = idx->HasSideEffects() || obj->HasSideEffects(); auto* sem = builder_->create( expr, ty, stage, obj, idx, current_statement_, std::move(val), has_side_effects, - obj->SourceVariable()); + obj->RootIdentifier()); sem->Behaviors() = idx->Behaviors() + obj->Behaviors(); return sem; } @@ -2365,7 +2365,7 @@ sem::Expression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* e auto* structure = sem_.TypeOf(expr->structure); auto* storage_ty = structure->UnwrapRef(); auto* object = sem_.Get(expr->structure); - auto* source_var = object->SourceVariable(); + auto* root_ident = object->RootIdentifier(); const sem::Type* ty = nullptr; @@ -2404,7 +2404,7 @@ sem::Expression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* e } return builder_->create(expr, ty, current_statement_, val.Get(), object, member, - has_side_effects, source_var); + has_side_effects, root_ident); }, [&](const sem::Vector* vec) -> sem::Expression* { @@ -2476,7 +2476,7 @@ sem::Expression* Resolver::MemberAccessor(const ast::MemberAccessorExpression* e return nullptr; } return builder_->create(expr, ty, current_statement_, val.Get(), object, - std::move(swizzle), has_side_effects, source_var); + std::move(swizzle), has_side_effects, root_ident); }, [&](Default) { @@ -2549,7 +2549,7 @@ sem::Expression* Resolver::UnaryOp(const ast::UnaryOpExpression* unary) { } const sem::Type* ty = nullptr; - const sem::Variable* source_var = nullptr; + const sem::Variable* root_ident = nullptr; const sem::Constant* value = nullptr; auto stage = sem::EvaluationStage::kRuntime; @@ -2573,7 +2573,7 @@ sem::Expression* Resolver::UnaryOp(const ast::UnaryOpExpression* unary) { ty = builder_->create(ref->StoreType(), ref->AddressSpace(), ref->Access()); - source_var = expr->SourceVariable(); + root_ident = expr->RootIdentifier(); } else { AddError("cannot take the address of expression", unary->expr->source); return nullptr; @@ -2584,7 +2584,7 @@ sem::Expression* Resolver::UnaryOp(const ast::UnaryOpExpression* unary) { if (auto* ptr = expr_ty->As()) { ty = builder_->create(ptr->StoreType(), ptr->AddressSpace(), ptr->Access()); - source_var = expr->SourceVariable(); + root_ident = expr->RootIdentifier(); } else { AddError("cannot dereference expression of type '" + sem_.TypeNameOf(expr_ty) + "'", unary->expr->source); @@ -2623,7 +2623,7 @@ sem::Expression* Resolver::UnaryOp(const ast::UnaryOpExpression* unary) { } auto* sem = builder_->create(unary, ty, stage, current_statement_, value, - expr->HasSideEffects(), source_var); + expr->HasSideEffects(), root_ident); sem->Behaviors() = expr->Behaviors(); return sem; } diff --git a/src/tint/resolver/source_variable_test.cc b/src/tint/resolver/root_identifier_test.cc similarity index 69% rename from src/tint/resolver/source_variable_test.cc rename to src/tint/resolver/root_identifier_test.cc index e6623952c5..934feaee75 100644 --- a/src/tint/resolver/source_variable_test.cc +++ b/src/tint/resolver/root_identifier_test.cc @@ -23,9 +23,9 @@ using namespace tint::number_suffixes; // NOLINT namespace tint::resolver { namespace { -class ResolverSourceVariableTest : public ResolverTest {}; +class ResolverRootIdentifierTest : public ResolverTest {}; -TEST_F(ResolverSourceVariableTest, GlobalPrivateVar) { +TEST_F(ResolverRootIdentifierTest, GlobalPrivateVar) { auto* a = GlobalVar("a", ty.f32(), ast::AddressSpace::kPrivate); auto* expr = Expr(a); WrapInFunction(expr); @@ -33,10 +33,10 @@ TEST_F(ResolverSourceVariableTest, GlobalPrivateVar) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, GlobalWorkgroupVar) { +TEST_F(ResolverRootIdentifierTest, GlobalWorkgroupVar) { auto* a = GlobalVar("a", ty.f32(), ast::AddressSpace::kWorkgroup); auto* expr = Expr(a); WrapInFunction(expr); @@ -44,10 +44,10 @@ TEST_F(ResolverSourceVariableTest, GlobalWorkgroupVar) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, GlobalStorageVar) { +TEST_F(ResolverRootIdentifierTest, GlobalStorageVar) { auto* a = GlobalVar("a", ty.f32(), ast::AddressSpace::kStorage, Group(0_a), Binding(0_a)); auto* expr = Expr(a); WrapInFunction(expr); @@ -55,10 +55,10 @@ TEST_F(ResolverSourceVariableTest, GlobalStorageVar) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, GlobalUniformVar) { +TEST_F(ResolverRootIdentifierTest, GlobalUniformVar) { auto* a = GlobalVar("a", ty.f32(), ast::AddressSpace::kUniform, Group(0_a), Binding(0_a)); auto* expr = Expr(a); WrapInFunction(expr); @@ -66,10 +66,10 @@ TEST_F(ResolverSourceVariableTest, GlobalUniformVar) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, GlobalTextureVar) { +TEST_F(ResolverRootIdentifierTest, GlobalTextureVar) { auto* a = GlobalVar("a", ty.sampled_texture(ast::TextureDimension::k2d, ty.f32()), ast::AddressSpace::kNone, Group(0_a), Binding(0_a)); auto* expr = Expr(a); @@ -78,10 +78,10 @@ TEST_F(ResolverSourceVariableTest, GlobalTextureVar) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, GlobalOverride) { +TEST_F(ResolverRootIdentifierTest, GlobalOverride) { auto* a = Override("a", ty.f32(), Expr(1_f)); auto* expr = Expr(a); WrapInFunction(expr); @@ -89,10 +89,10 @@ TEST_F(ResolverSourceVariableTest, GlobalOverride) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, GlobalConst) { +TEST_F(ResolverRootIdentifierTest, GlobalConst) { auto* a = GlobalConst("a", ty.f32(), Expr(1_f)); auto* expr = Expr(a); WrapInFunction(expr); @@ -100,10 +100,10 @@ TEST_F(ResolverSourceVariableTest, GlobalConst) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, FunctionVar) { +TEST_F(ResolverRootIdentifierTest, FunctionVar) { auto* a = Var("a", ty.f32()); auto* expr = Expr(a); WrapInFunction(a, expr); @@ -111,10 +111,10 @@ TEST_F(ResolverSourceVariableTest, FunctionVar) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, FunctionLet) { +TEST_F(ResolverRootIdentifierTest, FunctionLet) { auto* a = Let("a", ty.f32(), Expr(1_f)); auto* expr = Expr(a); WrapInFunction(a, expr); @@ -122,10 +122,10 @@ TEST_F(ResolverSourceVariableTest, FunctionLet) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, Parameter) { +TEST_F(ResolverRootIdentifierTest, Parameter) { auto* a = Param("a", ty.f32()); auto* expr = Expr(a); Func("foo", utils::Vector{a}, ty.void_(), utils::Vector{WrapInStatement(expr)}); @@ -133,10 +133,10 @@ TEST_F(ResolverSourceVariableTest, Parameter) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, PointerParameter) { +TEST_F(ResolverRootIdentifierTest, PointerParameter) { // fn foo(a : ptr) // { // let b = a; @@ -151,11 +151,11 @@ TEST_F(ResolverSourceVariableTest, PointerParameter) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_param = Sem().Get(param); - EXPECT_EQ(Sem().Get(expr_param)->SourceVariable(), sem_param); - EXPECT_EQ(Sem().Get(expr_let)->SourceVariable(), sem_param); + EXPECT_EQ(Sem().Get(expr_param)->RootIdentifier(), sem_param); + EXPECT_EQ(Sem().Get(expr_let)->RootIdentifier(), sem_param); } -TEST_F(ResolverSourceVariableTest, VarCopyVar) { +TEST_F(ResolverRootIdentifierTest, VarCopyVar) { // { // var a : f32; // var b = a; @@ -170,11 +170,11 @@ TEST_F(ResolverSourceVariableTest, VarCopyVar) { auto* sem_a = Sem().Get(a); auto* sem_b = Sem().Get(b); - EXPECT_EQ(Sem().Get(expr_a)->SourceVariable(), sem_a); - EXPECT_EQ(Sem().Get(expr_b)->SourceVariable(), sem_b); + EXPECT_EQ(Sem().Get(expr_a)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().Get(expr_b)->RootIdentifier(), sem_b); } -TEST_F(ResolverSourceVariableTest, LetCopyVar) { +TEST_F(ResolverRootIdentifierTest, LetCopyVar) { // { // var a : f32; // let b = a; @@ -189,11 +189,11 @@ TEST_F(ResolverSourceVariableTest, LetCopyVar) { auto* sem_a = Sem().Get(a); auto* sem_b = Sem().Get(b); - EXPECT_EQ(Sem().Get(expr_a)->SourceVariable(), sem_a); - EXPECT_EQ(Sem().Get(expr_b)->SourceVariable(), sem_b); + EXPECT_EQ(Sem().Get(expr_a)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().Get(expr_b)->RootIdentifier(), sem_b); } -TEST_F(ResolverSourceVariableTest, ThroughIndexAccessor) { +TEST_F(ResolverRootIdentifierTest, ThroughIndexAccessor) { // var a : array; // { // a[2i] @@ -205,10 +205,10 @@ TEST_F(ResolverSourceVariableTest, ThroughIndexAccessor) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, ThroughMemberAccessor) { +TEST_F(ResolverRootIdentifierTest, ThroughMemberAccessor) { // struct S { f : f32 } // var a : S; // { @@ -222,10 +222,10 @@ TEST_F(ResolverSourceVariableTest, ThroughMemberAccessor) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, ThroughPointers) { +TEST_F(ResolverRootIdentifierTest, ThroughPointers) { // var a : f32; // { // let a_ptr1 = &*&a; @@ -244,49 +244,49 @@ TEST_F(ResolverSourceVariableTest, ThroughPointers) { EXPECT_TRUE(r()->Resolve()) << r()->error(); auto* sem_a = Sem().Get(a); - EXPECT_EQ(Sem().Get(address_of_1)->SourceVariable(), sem_a); - EXPECT_EQ(Sem().Get(address_of_2)->SourceVariable(), sem_a); - EXPECT_EQ(Sem().Get(address_of_3)->SourceVariable(), sem_a); - EXPECT_EQ(Sem().Get(deref_1)->SourceVariable(), sem_a); - EXPECT_EQ(Sem().Get(deref_2)->SourceVariable(), sem_a); + EXPECT_EQ(Sem().Get(address_of_1)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().Get(address_of_2)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().Get(address_of_3)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().Get(deref_1)->RootIdentifier(), sem_a); + EXPECT_EQ(Sem().Get(deref_2)->RootIdentifier(), sem_a); } -TEST_F(ResolverSourceVariableTest, Literal) { +TEST_F(ResolverRootIdentifierTest, Literal) { auto* expr = Expr(1_f); WrapInFunction(expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), nullptr); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), nullptr); } -TEST_F(ResolverSourceVariableTest, FunctionReturnValue) { +TEST_F(ResolverRootIdentifierTest, FunctionReturnValue) { auto* expr = Call("min", 1_f, 2_f); WrapInFunction(expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), nullptr); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), nullptr); } -TEST_F(ResolverSourceVariableTest, BinaryExpression) { +TEST_F(ResolverRootIdentifierTest, BinaryExpression) { auto* a = Var("a", ty.f32()); auto* expr = Add(a, Expr(1_f)); WrapInFunction(a, expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), nullptr); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), nullptr); } -TEST_F(ResolverSourceVariableTest, UnaryExpression) { +TEST_F(ResolverRootIdentifierTest, UnaryExpression) { auto* a = Var("a", ty.f32()); auto* expr = create(ast::UnaryOp::kNegation, Expr(a)); WrapInFunction(a, expr); EXPECT_TRUE(r()->Resolve()) << r()->error(); - EXPECT_EQ(Sem().Get(expr)->SourceVariable(), nullptr); + EXPECT_EQ(Sem().Get(expr)->RootIdentifier(), nullptr); } } // namespace diff --git a/src/tint/resolver/uniformity.cc b/src/tint/resolver/uniformity.cc index d5ff80349b..f5389f7d5f 100644 --- a/src/tint/resolver/uniformity.cc +++ b/src/tint/resolver/uniformity.cc @@ -1157,8 +1157,8 @@ class UniformityGraph { if (u->op == ast::UnaryOp::kIndirection) { // Cut the analysis short, since we only need to know the originating variable // which is being accessed. - auto* source_var = sem_.Get(u)->SourceVariable(); - auto* value = current_function_->variables.Get(source_var); + auto* root_ident = sem_.Get(u)->RootIdentifier(); + auto* value = current_function_->variables.Get(root_ident); if (!value) { value = cf; } @@ -1251,10 +1251,10 @@ class UniformityGraph { if (u->op == ast::UnaryOp::kIndirection) { // Cut the analysis short, since we only need to know the originating variable // that is being written to. - auto* source_var = sem_.Get(u)->SourceVariable(); - auto name = builder_->Symbols().NameFor(source_var->Declaration()->symbol); + auto* root_ident = sem_.Get(u)->RootIdentifier(); + auto name = builder_->Symbols().NameFor(root_ident->Declaration()->symbol); auto* deref = CreateNode(name + "_deref"); - auto* old_value = current_function_->variables.Set(source_var, deref); + auto* old_value = current_function_->variables.Set(root_ident, deref); if (old_value) { // If derefercing a partial reference or partial pointer, we link back to @@ -1405,9 +1405,9 @@ class UniformityGraph { } // Update the current stored value for this pointer argument. - auto* source_var = sem_arg->SourceVariable(); - TINT_ASSERT(Resolver, source_var); - current_function_->variables.Set(source_var, ptr_result); + auto* root_ident = sem_arg->RootIdentifier(); + TINT_ASSERT(Resolver, root_ident); + current_function_->variables.Set(root_ident, ptr_result); } } else { // All builtin function parameters are RequiredToBeUniformForReturnValue, as are diff --git a/src/tint/sem/expression.cc b/src/tint/sem/expression.cc index cdaa2bca3d..d7fd255b0d 100644 --- a/src/tint/sem/expression.cc +++ b/src/tint/sem/expression.cc @@ -28,9 +28,9 @@ Expression::Expression(const ast::Expression* declaration, const Statement* statement, const Constant* constant, bool has_side_effects, - const Variable* source_var /* = nullptr */) + const Variable* root_ident /* = nullptr */) : declaration_(declaration), - source_variable_(source_var), + root_identifier_(root_ident), type_(type), stage_(stage), statement_(statement), diff --git a/src/tint/sem/expression.h b/src/tint/sem/expression.h index 5942a71108..cc87031ba2 100644 --- a/src/tint/sem/expression.h +++ b/src/tint/sem/expression.h @@ -40,14 +40,14 @@ class Expression : public Castable { /// @param statement the statement that owns this expression /// @param constant the constant value of the expression. May be null /// @param has_side_effects true if this expression may have side-effects - /// @param source_var the (optional) source variable for this expression + /// @param root_ident the (optional) root identifier for this expression Expression(const ast::Expression* declaration, const sem::Type* type, EvaluationStage stage, const Statement* statement, const Constant* constant, bool has_side_effects, - const Variable* source_var = nullptr); + const Variable* root_ident = nullptr); /// Destructor ~Expression() override; @@ -71,8 +71,8 @@ class Expression : public Castable { /// For reference and pointer expressions, this will either be the originating /// variable or a function parameter. For other types of expressions, it will /// either be the parameter or constant declaration, or nullptr. - /// @return the source variable of this expression, or nullptr - const Variable* SourceVariable() const { return source_variable_; } + /// @return the root identifier of this expression, or nullptr + const Variable* RootIdentifier() const { return root_identifier_; } /// @return the behaviors of this statement const sem::Behaviors& Behaviors() const { return behaviors_; } @@ -89,8 +89,8 @@ class Expression : public Castable { protected: /// The AST expression node for this semantic expression const ast::Expression* const declaration_; - /// The source variable for this semantic expression, or nullptr - const Variable* source_variable_; + /// The root identifier for this semantic expression, or nullptr + const Variable* root_identifier_; private: const sem::Type* const type_; diff --git a/src/tint/sem/expression_test.cc b/src/tint/sem/expression_test.cc index 63e01fbce0..845b279002 100644 --- a/src/tint/sem/expression_test.cc +++ b/src/tint/sem/expression_test.cc @@ -46,7 +46,7 @@ TEST_F(ExpressionTest, UnwrapMaterialize) { auto* a = create(/* declaration */ nullptr, create(), sem::EvaluationStage::kRuntime, /* statement */ nullptr, /* constant_value */ nullptr, - /* has_side_effects */ false, /* source_var */ nullptr); + /* has_side_effects */ false, /* root_ident */ nullptr); auto* b = create(a, /* statement */ nullptr, &c); EXPECT_EQ(a, a->UnwrapMaterialize()); diff --git a/src/tint/sem/index_accessor_expression.cc b/src/tint/sem/index_accessor_expression.cc index 70d1d5f89c..05656957a7 100644 --- a/src/tint/sem/index_accessor_expression.cc +++ b/src/tint/sem/index_accessor_expression.cc @@ -30,8 +30,8 @@ IndexAccessorExpression::IndexAccessorExpression(const ast::IndexAccessorExpress const Statement* statement, const Constant* constant, bool has_side_effects, - const Variable* source_var /* = nullptr */) - : Base(declaration, type, stage, statement, constant, has_side_effects, source_var), + const Variable* root_ident /* = nullptr */) + : Base(declaration, type, stage, statement, constant, has_side_effects, root_ident), object_(object), index_(index) {} diff --git a/src/tint/sem/index_accessor_expression.h b/src/tint/sem/index_accessor_expression.h index ea93df72ed..19ae82b2db 100644 --- a/src/tint/sem/index_accessor_expression.h +++ b/src/tint/sem/index_accessor_expression.h @@ -38,7 +38,7 @@ class IndexAccessorExpression final : public CastableSourceVariable()), + /* root_ident */ expr->RootIdentifier()), expr_(expr) {} Materialize::~Materialize() = default; diff --git a/src/tint/sem/member_accessor_expression.cc b/src/tint/sem/member_accessor_expression.cc index 4d194a9d9e..8d08008851 100644 --- a/src/tint/sem/member_accessor_expression.cc +++ b/src/tint/sem/member_accessor_expression.cc @@ -30,8 +30,8 @@ MemberAccessorExpression::MemberAccessorExpression(const ast::MemberAccessorExpr const Constant* constant, const Expression* object, bool has_side_effects, - const Variable* source_var /* = nullptr */) - : Base(declaration, type, stage, statement, constant, has_side_effects, source_var), + const Variable* root_ident /* = nullptr */) + : Base(declaration, type, stage, statement, constant, has_side_effects, root_ident), object_(object) {} MemberAccessorExpression::~MemberAccessorExpression() = default; @@ -43,7 +43,7 @@ StructMemberAccess::StructMemberAccess(const ast::MemberAccessorExpression* decl const Expression* object, const StructMember* member, bool has_side_effects, - const Variable* source_var /* = nullptr */) + const Variable* root_ident /* = nullptr */) : Base(declaration, type, object->Stage(), @@ -51,7 +51,7 @@ StructMemberAccess::StructMemberAccess(const ast::MemberAccessorExpression* decl constant, object, has_side_effects, - source_var), + root_ident), member_(member) {} StructMemberAccess::~StructMemberAccess() = default; @@ -63,7 +63,7 @@ Swizzle::Swizzle(const ast::MemberAccessorExpression* declaration, const Expression* object, utils::VectorRef indices, bool has_side_effects, - const Variable* source_var /* = nullptr */) + const Variable* root_ident /* = nullptr */) : Base(declaration, type, object->Stage(), @@ -71,7 +71,7 @@ Swizzle::Swizzle(const ast::MemberAccessorExpression* declaration, constant, object, has_side_effects, - source_var), + root_ident), indices_(std::move(indices)) {} Swizzle::~Swizzle() = default; diff --git a/src/tint/sem/member_accessor_expression.h b/src/tint/sem/member_accessor_expression.h index 2541f33725..5541d1cafb 100644 --- a/src/tint/sem/member_accessor_expression.h +++ b/src/tint/sem/member_accessor_expression.h @@ -48,7 +48,7 @@ class MemberAccessorExpression : public Castable { /// @param object the object that holds the member being accessed /// @param indices the swizzle indices /// @param has_side_effects whether this expression may have side effects - /// @param source_var the (optional) source variable for this expression + /// @param root_ident the (optional) root identifier for this expression Swizzle(const ast::MemberAccessorExpression* declaration, const sem::Type* type, const Statement* statement, @@ -115,7 +115,7 @@ class Swizzle final : public Castable { const Expression* object, utils::VectorRef indices, bool has_side_effects, - const Variable* source_var = nullptr); + const Variable* root_ident = nullptr); /// Destructor ~Swizzle() override; diff --git a/src/tint/sem/variable.cc b/src/tint/sem/variable.cc index 225e308b7e..f83745f626 100644 --- a/src/tint/sem/variable.cc +++ b/src/tint/sem/variable.cc @@ -97,9 +97,9 @@ VariableUser::VariableUser(const ast::IdentifierExpression* declaration, variable_(variable) { auto* type = variable->Type(); if (type->Is() && variable->Initializer()) { - source_variable_ = variable->Initializer()->SourceVariable(); + root_identifier_ = variable->Initializer()->RootIdentifier(); } else { - source_variable_ = variable; + root_identifier_ = variable; } } diff --git a/src/tint/transform/localize_struct_array_assignment.cc b/src/tint/transform/localize_struct_array_assignment.cc index bfe8865ffa..cb536455a7 100644 --- a/src/tint/transform/localize_struct_array_assignment.cc +++ b/src/tint/transform/localize_struct_array_assignment.cc @@ -174,15 +174,15 @@ struct LocalizeStructArrayAssignment::State { // See https://www.w3.org/TR/WGSL/#originating-variable-section std::pair GetOriginatingTypeAndAddressSpace( const ast::AssignmentStatement* assign_stmt) { - auto* source_var = src->Sem().Get(assign_stmt->lhs)->SourceVariable(); - if (!source_var) { + auto* root_ident = src->Sem().Get(assign_stmt->lhs)->RootIdentifier(); + if (!root_ident) { TINT_ICE(Transform, b.Diagnostics()) << "Unable to determine originating variable for lhs of assignment " "statement"; return {}; } - auto* type = source_var->Type(); + auto* type = root_ident->Type(); if (auto* ref = type->As()) { return {ref->StoreType(), ref->AddressSpace()}; } else if (auto* ptr = type->As()) { diff --git a/src/tint/transform/spirv_atomic.cc b/src/tint/transform/spirv_atomic.cc index eba66813bf..319975ae44 100644 --- a/src/tint/transform/spirv_atomic.cc +++ b/src/tint/transform/spirv_atomic.cc @@ -97,7 +97,7 @@ struct SpirvAtomic::State { b.Call(sem::str(stub->builtin), std::move(out_args))); } - // Keep track of this expression. We'll need to modify the source variable / + // 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])); } @@ -230,8 +230,8 @@ struct SpirvAtomic::State { void ReplaceLoadsAndStores() { // Returns true if 'e' is a reference to an atomic variable or struct member auto is_ref_to_atomic_var = [&](const sem::Expression* e) { - if (tint::Is(e->Type()) && e->SourceVariable() && - (atomic_variables.count(e->SourceVariable()) != 0)) { + if (tint::Is(e->Type()) && e->RootIdentifier() && + (atomic_variables.count(e->RootIdentifier()) != 0)) { // If it's a struct member, make sure it's one we marked as atomic if (auto* ma = e->As()) { auto it = forked_structs.find(ma->Member()->Struct()->Declaration()); diff --git a/src/tint/transform/std140.cc b/src/tint/transform/std140.cc index 0746bda412..2116b0fcf4 100644 --- a/src/tint/transform/std140.cc +++ b/src/tint/transform/std140.cc @@ -498,26 +498,26 @@ struct Std140::State { AccessChain access; - // Start by looking at the source variable. This must be a std140-forked uniform buffer. - access.var = tint::As(expr->SourceVariable()); + // Start by looking at the root identifier. This must be a std140-forked uniform buffer. + access.var = tint::As(expr->RootIdentifier()); if (!access.var || !std140_uniforms.Contains(access.var)) { // Not at std140-forked uniform buffer access chain. return std::nullopt; } - // Walk from the outer-most expression, inwards towards the source variable. + // Walk from the outer-most expression, inwards towards the root identifier. while (true) { enum class Action { kStop, kContinue, kError }; Action action = Switch( expr, // [&](const sem::VariableUser* user) { if (user->Variable() == access.var) { - // Walked all the way to the source variable. We're done traversing. + // Walked all the way to the root identifier. We're done traversing. access.indices.Push(UniformVariable{}); return Action::kStop; } if (user->Variable()->Type()->Is()) { - // Found a pointer. As the source variable is a uniform buffer variable, + // Found a pointer. As the root identifier is a uniform buffer variable, // this must be a pointer-let. Continue traversing from the let // initializer. expr = user->Variable()->Initializer();