[M] Change in dart/sdk[main]: [cfe] Make VariableBase.context independent from VariableBase.parent

0 views
Skip to first unread message

Chloe Stefantsova (Gerrit)

unread,
May 11, 2026, 6:57:46 AM (2 days ago) May 11
to Chloe Stefantsova, Johnni Winther, dart-...@luci-project-accounts.iam.gserviceaccount.com, Alexander Markov, Jens Johansen, rev...@dartlang.org
Attention needed from Johnni Winther

Chloe Stefantsova voted Commit-Queue+1

Commit-Queue+1
Open in Gerrit

Related details

Attention is currently required from:
  • Johnni Winther
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I307c9d2b23c8201f8d7d2a100acf9fb8f3af2572
Gerrit-Change-Number: 494441
Gerrit-PatchSet: 7
Gerrit-Owner: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Johnni Winther <johnni...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-CC: Jens Johansen <je...@google.com>
Gerrit-Attention: Johnni Winther <johnni...@google.com>
Gerrit-Comment-Date: Mon, 11 May 2026 10:57:40 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
unsatisfied_requirement
open
diffy

Johnni Winther (Gerrit)

unread,
May 11, 2026, 7:26:29 AM (2 days ago) May 11
to Chloe Stefantsova, dart-...@luci-project-accounts.iam.gserviceaccount.com, Alexander Markov, Jens Johansen, rev...@dartlang.org
Attention needed from Chloe Stefantsova

Johnni Winther voted Code-Review+1

Code-Review+1
Open in Gerrit

Related details

Attention is currently required from:
  • Chloe Stefantsova
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I307c9d2b23c8201f8d7d2a100acf9fb8f3af2572
Gerrit-Change-Number: 494441
Gerrit-PatchSet: 7
Gerrit-Owner: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Johnni Winther <johnni...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-CC: Jens Johansen <je...@google.com>
Gerrit-Attention: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Comment-Date: Mon, 11 May 2026 11:26:25 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Chloe Stefantsova (Gerrit)

unread,
May 11, 2026, 7:41:56 AM (2 days ago) May 11
to Chloe Stefantsova, Johnni Winther, dart-...@luci-project-accounts.iam.gserviceaccount.com, Alexander Markov, Jens Johansen, rev...@dartlang.org

Chloe Stefantsova voted Commit-Queue+2

Commit-Queue+2
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I307c9d2b23c8201f8d7d2a100acf9fb8f3af2572
Gerrit-Change-Number: 494441
Gerrit-PatchSet: 7
Gerrit-Owner: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Johnni Winther <johnni...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-CC: Jens Johansen <je...@google.com>
Gerrit-Comment-Date: Mon, 11 May 2026 11:41:52 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Alexander Markov (Gerrit)

unread,
May 11, 2026, 10:00:52 AM (2 days ago) May 11
to Chloe Stefantsova, Johnni Winther, dart-...@luci-project-accounts.iam.gserviceaccount.com, Alexander Markov, Jens Johansen, rev...@dartlang.org
Attention needed from Chloe Stefantsova

Alexander Markov added 1 comment

File pkg/kernel/lib/src/ast/variables.dart
Line 9, Patchset 7 (Latest): abstract VariableContext context;
Alexander Markov . unresolved

DBC

How is this going to work wrt kernel binary serializartion? At least for the VM, we need scopes, contexts and variables serialized before they can be used (to avoid multiple passes over kernel binary). So, during deserialization do you plan to create variable objects without parents and then corresponding VariableDeclaration statements would grab their ownership? How do we guarantee consistency if sub-tree containing VariableDeclaration is removed?

Open in Gerrit

Related details

Attention is currently required from:
  • Chloe Stefantsova
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I307c9d2b23c8201f8d7d2a100acf9fb8f3af2572
Gerrit-Change-Number: 494441
Gerrit-PatchSet: 7
Gerrit-Owner: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Johnni Winther <johnni...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-CC: Jens Johansen <je...@google.com>
Gerrit-Attention: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Comment-Date: Mon, 11 May 2026 14:00:47 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
open
diffy

dart-scoped@luci-project-accounts.iam.gserviceaccount.com (Gerrit)

unread,
May 12, 2026, 3:08:51 AM (yesterday) May 12
to Chloe Stefantsova, Johnni Winther, Alexander Markov, Jens Johansen, rev...@dartlang.org

dart-...@luci-project-accounts.iam.gserviceaccount.com submitted the change

Change information

Commit message:
[cfe] Make VariableBase.context independent from VariableBase.parent

Previously the getter VariableBase.context was redirecting to
VariableBase.parent, effectively requiring a change of the ownership
over the variable. This CL makes VariableBase.context a field of
VariableBase, allowing for the previously existing ownership structure
of the AST tree nodes.

The change allows to avoid workarounds for the existing
ownership-restoring logic, such as the assignments to the `parent`
pointer made in the constructors of the AST nodes and their
`transformChildren` and `transformOrRemoveChildren` methods.

Part of https://github.com/dart-lang/sdk/issues/61572
Change-Id: I307c9d2b23c8201f8d7d2a100acf9fb8f3af2572
Commit-Queue: Chloe Stefantsova <cstefa...@google.com>
Reviewed-by: Johnni Winther <johnni...@google.com>
Files:
  • M pkg/front_end/lib/src/builder/formal_parameter_builder.dart
  • M pkg/front_end/lib/src/kernel/body_builder.dart
  • M pkg/front_end/lib/src/kernel/internal_ast.dart
  • M pkg/front_end/lib/src/type_inference/inference_visitor.dart
  • M pkg/kernel/lib/src/ast/statements.dart
  • M pkg/kernel/lib/src/ast/types.dart
  • M pkg/kernel/lib/src/ast/variables.dart
  • M pkg/kernel/lib/src/equivalence.dart
  • M pkg/kernel/lib/verifier.dart
Change size: M
Delta: 9 files changed, 197 insertions(+), 50 deletions(-)
Branch: refs/heads/main
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by Johnni Winther
Open in Gerrit
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: merged
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I307c9d2b23c8201f8d7d2a100acf9fb8f3af2572
Gerrit-Change-Number: 494441
Gerrit-PatchSet: 8
Gerrit-Owner: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Johnni Winther <johnni...@google.com>
open
diffy
satisfied_requirement

Chloe Stefantsova (Gerrit)

unread,
May 12, 2026, 8:17:29 AM (yesterday) May 12
to Chloe Stefantsova, dart-...@luci-project-accounts.iam.gserviceaccount.com, Johnni Winther, Alexander Markov, Jens Johansen, rev...@dartlang.org

Chloe Stefantsova added 1 comment

File pkg/kernel/lib/src/ast/variables.dart
Line 9, Patchset 7: abstract VariableContext context;
Alexander Markov . unresolved

DBC

How is this going to work wrt kernel binary serializartion? At least for the VM, we need scopes, contexts and variables serialized before they can be used (to avoid multiple passes over kernel binary). So, during deserialization do you plan to create variable objects without parents and then corresponding VariableDeclaration statements would grab their ownership? How do we guarantee consistency if sub-tree containing VariableDeclaration is removed?

Chloe Stefantsova

Yes, we plan to serialize scopes, contexts, and variables. The parent pointers of the variables will point to the same nodes they point to now, while their context pointers will point to the contexts. As for the consistency in the sub-trees removal case, I don't see how having two pointers (one to the `TreeNode` parent, and the other one to the `VariableContext`) is a worse situation than what we currently have, with just one pointer. But maybe I'm missing something?

Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I307c9d2b23c8201f8d7d2a100acf9fb8f3af2572
Gerrit-Change-Number: 494441
Gerrit-PatchSet: 8
Gerrit-Owner: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Johnni Winther <johnni...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-CC: Jens Johansen <je...@google.com>
Gerrit-Comment-Date: Tue, 12 May 2026 12:17:25 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Alexander Markov <alexm...@google.com>
satisfied_requirement
open
diffy

Alexander Markov (Gerrit)

unread,
May 12, 2026, 10:32:09 AM (23 hours ago) May 12
to Chloe Stefantsova, dart-...@luci-project-accounts.iam.gserviceaccount.com, Johnni Winther, Alexander Markov, Jens Johansen, rev...@dartlang.org
Attention needed from Chloe Stefantsova

Alexander Markov added 1 comment

File pkg/kernel/lib/src/ast/variables.dart
Line 9, Patchset 7: abstract VariableContext context;
Alexander Markov . unresolved

DBC

How is this going to work wrt kernel binary serializartion? At least for the VM, we need scopes, contexts and variables serialized before they can be used (to avoid multiple passes over kernel binary). So, during deserialization do you plan to create variable objects without parents and then corresponding VariableDeclaration statements would grab their ownership? How do we guarantee consistency if sub-tree containing VariableDeclaration is removed?

Chloe Stefantsova

Yes, we plan to serialize scopes, contexts, and variables. The parent pointers of the variables will point to the same nodes they point to now, while their context pointers will point to the contexts. As for the consistency in the sub-trees removal case, I don't see how having two pointers (one to the `TreeNode` parent, and the other one to the `VariableContext`) is a worse situation than what we currently have, with just one pointer. But maybe I'm missing something?

Alexander Markov

Please correct me if I'm wrong, but my understanding is that `parent` pointer also reflects "ownership" of the child nodes. With Scope->Context->Variable ownership it would be correct to remove sub-trees using that variable via non-owning pointers (similarly to how it is currently correct to remove VariableGet/VariableSet which references VariableDeclaration). However, if we keep parent pointers intact removing sub-tree with VariableDeclaration but keeping Variable in Context would mean there are dangling references to removed nodes (Context->Variable/VariableDeclaration->it's parent).

Open in Gerrit

Related details

Attention is currently required from:
  • Chloe Stefantsova
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I307c9d2b23c8201f8d7d2a100acf9fb8f3af2572
Gerrit-Change-Number: 494441
Gerrit-PatchSet: 8
Gerrit-Owner: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Johnni Winther <johnni...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-CC: Jens Johansen <je...@google.com>
Gerrit-Attention: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Comment-Date: Tue, 12 May 2026 14:32:05 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Chloe Stefantsova <cstefa...@google.com>
Comment-In-Reply-To: Alexander Markov <alexm...@google.com>
satisfied_requirement
open
diffy

Chloe Stefantsova (Gerrit)

unread,
4:55 AM (4 hours ago) 4:55 AM
to Chloe Stefantsova, dart-...@luci-project-accounts.iam.gserviceaccount.com, Johnni Winther, Alexander Markov, Jens Johansen, rev...@dartlang.org

Chloe Stefantsova added 1 comment

File pkg/kernel/lib/src/ast/variables.dart
Line 9, Patchset 7: abstract VariableContext context;
Alexander Markov . unresolved

DBC

How is this going to work wrt kernel binary serializartion? At least for the VM, we need scopes, contexts and variables serialized before they can be used (to avoid multiple passes over kernel binary). So, during deserialization do you plan to create variable objects without parents and then corresponding VariableDeclaration statements would grab their ownership? How do we guarantee consistency if sub-tree containing VariableDeclaration is removed?

Chloe Stefantsova

Yes, we plan to serialize scopes, contexts, and variables. The parent pointers of the variables will point to the same nodes they point to now, while their context pointers will point to the contexts. As for the consistency in the sub-trees removal case, I don't see how having two pointers (one to the `TreeNode` parent, and the other one to the `VariableContext`) is a worse situation than what we currently have, with just one pointer. But maybe I'm missing something?

Alexander Markov

Please correct me if I'm wrong, but my understanding is that `parent` pointer also reflects "ownership" of the child nodes. With Scope->Context->Variable ownership it would be correct to remove sub-trees using that variable via non-owning pointers (similarly to how it is currently correct to remove VariableGet/VariableSet which references VariableDeclaration). However, if we keep parent pointers intact removing sub-tree with VariableDeclaration but keeping Variable in Context would mean there are dangling references to removed nodes (Context->Variable/VariableDeclaration->it's parent).

Chloe Stefantsova

The dangling reference problem would exist in the case where the `parent` pointer points to the `VariableContext`, too. Considering the following Dart program:

```
foo(bool c) {
if (c) {
int x = 0;
return () => [c, x];
}
return null;
}
```

Before the work on scopes and contexts began we, roughly, had the following:

```
FunctionNode (with PositionalParameter('c', parent=FunctionNode))
Block #1 (parent=FunctionNode)
IfStatement (parent=Block #1)
Block #2 (parent=IfStatement)
VariableDeclaration('x') (parent=Block #2)
ReturnStatement #1 (parent=Block #2)
ReturnStatement #2 (parent=Block #1)
```

If we remove the `IfStatement` node, the remainder of the AST won't have any references to the `VariableDeclaration`.

```
FunctionNode (with PositionalParameter('c', parent=FunctionNode))
Block #1 (parent=FunctionNode)
ReturnStatement #2 (parent=Block #1)
```

Prior to this CL, with the experiment flag enabled, the same program would look, roughly, as follows:

```
FunctionNode (with reference to positional parameter 'c', Context(PositionalParameter('c', parent=Context), VariableDeclaration('x', parent=Context)))
Block #1 (parent=FunctionNode)
IfStatement (parent=Block #1)
Block #2 (parent=IfStatement)
VariableInitialization (with refrence to 'x', parent=Block #2)
ReturnStatement #1 (parent=Block #2)
ReturnStatement #2 (parent=Block #1)
```

When we remove the `IfStatement`, the context still holds `VariableDeclaration('x')` it owns:

```
FunctionNode (with reference to positional parameter 'c', Context(PositionalParameter('c', parent=Context), VariableDeclaration('x', parent=Context)))
Block #1 (parent=FunctionNode)
ReturnStatement #2 (parent=Block #1)
```

With the changes in this CL the situation with dangling references won't change too much. Here's, roughly, how the compiled program would look like:

```
FunctionNode (with PositionalParameter('c', parent=FunctionNode), Context(reference to 'c', reference to 'x'))
Block #1 (parent=FunctionNode)
IfStatement (parent=Block #1)
Block #2 (parent=IfStatement)
VariableInitialization (with VariableDeclaration('x', parent=VariableInitialization), parent=Block #2)
ReturnStatement #1 (parent=Block #2)
ReturnStatement #2 (parent=Block #1)
```

When the `IfStatement` is removed, the dangling reference to `x` is still there in the `Context`. The only difference is that the reference is non-owning.

```
FunctionNode (with PositionalParameter('c', parent=FunctionNode), Context(reference to 'c', reference to 'x'))
Block #1 (parent=FunctionNode)
ReturnStatement #2 (parent=Block #1)
```
Open in Gerrit

Related details

Attention set is empty
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I307c9d2b23c8201f8d7d2a100acf9fb8f3af2572
Gerrit-Change-Number: 494441
Gerrit-PatchSet: 8
Gerrit-Owner: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Chloe Stefantsova <cstefa...@google.com>
Gerrit-Reviewer: Johnni Winther <johnni...@google.com>
Gerrit-CC: Alexander Markov <alexm...@google.com>
Gerrit-CC: Jens Johansen <je...@google.com>
Gerrit-Comment-Date: Wed, 13 May 2026 08:55:04 +0000
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages