[XL] Change in dart/sdk[main]: DeCo. Build elements from new ASTs.

0 views
Skip to first unread message

Brian Wilkerson (Gerrit)

unread,
Oct 29, 2025, 4:43:10 PM (2 days ago) Oct 29
to Konstantin Shcheglov, Brian Wilkerson, Paul Berry, Johnni Winther, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Johnni Winther, Konstantin Shcheglov and Paul Berry

Brian Wilkerson voted and added 1 comment

Votes added by Brian Wilkerson

Code-Review+1

1 comment

Patchset-level comments
File-level comment, Patchset 6 (Latest):
Brian Wilkerson . resolved

The API changes lgtm

Open in Gerrit

Related details

Attention is currently required from:
  • Johnni Winther
  • Konstantin Shcheglov
  • Paul Berry
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: I768c16ea4a8bee4579732f80c1beb4bb8a42de43
Gerrit-Change-Number: 457161
Gerrit-PatchSet: 6
Gerrit-Owner: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Brian Wilkerson <brianwi...@google.com>
Gerrit-Reviewer: Johnni Winther <johnni...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Paul Berry <paul...@google.com>
Gerrit-Attention: Paul Berry <paul...@google.com>
Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
Gerrit-Attention: Johnni Winther <johnni...@google.com>
Gerrit-Comment-Date: Wed, 29 Oct 2025 20:43:07 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Paul Berry (Gerrit)

unread,
Oct 29, 2025, 4:59:07 PM (2 days ago) Oct 29
to Konstantin Shcheglov, Brian Wilkerson, Johnni Winther, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Johnni Winther and Konstantin Shcheglov

Paul Berry voted and added 13 comments

Votes added by Paul Berry

Code-Review+1

13 comments

Patchset-level comments
Paul Berry . resolved

lgtm assuming comments are addressed.

File pkg/analyzer/lib/src/dart/analysis/defined_names.dart
Line 35, Patchset 6 (Latest): if (member.body case BlockClassBody body) {
Paul Berry . unresolved

I believe this code is correct, but it's hard to tell why. You have to know that there are only two possible types that `member.body` can have in practice: `BlockClassBody` and `EmptyClassBody`; if you know that, then you can see that for an empty class body there's nothing that needs to be done.

What if we changed line 32 to `case ClassDeclarationImpl()` and then changed this `if` statement to a `switch` statement, so that exhaustiveness checking would ensure that all cases are handled? E.g.:

```
switch (member.body) {
case BlockClassBodyImpl body:
body.members.forEach(appendClassMemberName);
case EmptyClassBodyImpl():
// An empty class body declarations.
break;
case EnumBodyImpl():
assert(
false,
'A class declaration should never have an enum body',
);
}
```

Alternatively, add an abstract `members` getter to `ClassBodyImpl` and provide an implementation in `EmptyClassBodyImpl` that returns `const []`. Then this `if` wouldn't be needed, and we could just unconditionally do:

```
member.body.members.forEach(appendClassMemberName);
```

Aside: why is `EnumBodyImpl` a subtype of `ClassBodyImpl`? It seems like `EnumBodyImpl` should just extend `AstNodeImpl` (and similarly, `EnumBody` should just implement `AstNode`). After all, an enum body can't be used where a class body is expected, right?

Line 59, Patchset 6 (Latest): if (member.body case BlockClassBody body) {
Paul Berry . unresolved

Similar issue here

File pkg/analyzer/lib/src/dart/analysis/referenced_names.dart
Line 127, Patchset 6 (Latest): if (node.body case BlockClassBody body) {
Paul Berry . unresolved

Similar issue here

File pkg/analyzer/lib/src/dart/analysis/unlinked_api_signature.dart
Line 67, Patchset 6 (Latest): if (node.body case BlockClassBody body) {
Paul Berry . unresolved

Similar issue here

Line 107, Patchset 6 (Latest): if (useDeclaringConstructorsAst) {
Paul Berry . unresolved

It should be possible to do this without so much code duplication:

```
void _addEnum(EnumDeclaration node) {
var members = useDeclaringConstructorsAst
? node.body.members
: node.members;
    // If not enhanced, include the whole node.
var firstMember = members.firstOrNull;
if (firstMember == null) {
_addNode(node);
return;
}
    _addTokens(node.beginToken, firstMember.beginToken);
_addClassMembers(members, true);
}
```
Line 137, Patchset 6 (Latest): if (node.body case BlockClassBody body) {
Paul Berry . unresolved

Similar issue to the issue raised in `pkg/analyzer/lib/src/dart/analysis/defined_names.dart`.

File pkg/analyzer/lib/src/summary2/element_builder.dart
Line 2051, Patchset 6 (Latest): void _builtRepresentationDeclaration2({
Paul Berry . unresolved

There's a lot of code duplication between `_builtRepresentationDeclaration` and `_builtRepresentationDeclaration2`. How about if we move the differences to the call site so that a single method can be used? Something like:

```
({
FieldFragmentImpl fieldFragment,
ConstructorFragmentImpl constructorFragment,
FieldFormalParameterFragmentImpl formalParameterFragment,
})
_builtRepresentationDeclaration({
required ExtensionTypeFragmentImpl extensionFragment,
required PrimaryConstructorDeclarationImpl representation,
required TypeAnnotationImpl fieldType,
required Token? fieldNameToken,
required NodeListImpl<AnnotationImpl> fieldMetadata,
}) {
var fieldFragment = FieldFragmentImpl(
name: _getFragmentName(fieldNameToken),
);
fieldFragment.isAugmentation = extensionFragment.isAugmentation;
fieldFragment.isFinal = true;
fieldFragment.metadata = _buildMetadata(fieldMetadata);
_linker.elementNodes[fieldFragment] = representation;
    _addChildFragment(fieldFragment);
    var formalParameterFragment = FieldFormalParameterFragmentImpl(
name: _getFragmentName(fieldNameToken),
nameOffset: null,
parameterKind: ParameterKind.REQUIRED,
)..hasImplicitType = true;
    var constructorFragment =
ConstructorFragmentImpl(
name: representation.constructorName?.name.lexeme ?? 'new',
)
..isAugmentation = extensionFragment.isAugmentation
..isConst = representation.constKeyword != null
..formalParameters = [formalParameterFragment];
constructorFragment.typeName = extensionFragment.name;
_linker.elementNodes[constructorFragment] = representation;
    _addChildFragment(constructorFragment);
    fieldType.accept(this);
    return (
fieldFragment: fieldFragment,
constructorFragment: constructorFragment,
formalParameterFragment: formalParameterFragment,
);
}
```
File pkg/analyzer/lib/src/summary2/informative_data.dart
Line 893, Patchset 6 (Latest): if (useDeclaringConstructorsAst) {
Paul Berry . unresolved

It should be possible to avoid the code duplication by pushing the test into the `members` expression:

```
_InfoExtensionDeclaration _buildExtension(ExtensionDeclaration node) {
return _InfoExtensionDeclaration(
data: _buildInstanceData(
node,
name: node.name,
typeParameters: node.typeParameters,
members: useDeclaringConstructorsAst ? node.body.members : node.members,
),
);
}
```
Line 1192, Patchset 6 (Latest): if (useDeclaringConstructorsAst) {
Paul Berry . unresolved

Similar issue here.

Line 1244, Patchset 6 (Latest): _InfoExtensionTypeRepresentation _buildRepresentation2(
Paul Berry . unresolved

Can we use a more descriptive name here? `2` doesn't convey any useful information.

File pkg/analyzer/test/src/summary/elements/class_test.dart
Line 31502, Patchset 6 (Latest):class ClassElementTest_fromBytes2 extends ClassElementTest {
Paul Berry . unresolved

Similar issue here (need a more descriptive name suffix than `2`).

Line 31526, Patchset 6 (Latest):class ClassElementTest_keepLinking2 extends ClassElementTest {
Paul Berry . unresolved

Similar issue here, and also in the files that follow.

Open in Gerrit

Related details

Attention is currently required from:
  • Johnni Winther
  • Konstantin Shcheglov
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: I768c16ea4a8bee4579732f80c1beb4bb8a42de43
Gerrit-Change-Number: 457161
Gerrit-PatchSet: 6
Gerrit-Owner: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Brian Wilkerson <brianwi...@google.com>
Gerrit-Reviewer: Johnni Winther <johnni...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Paul Berry <paul...@google.com>
Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
Gerrit-Attention: Johnni Winther <johnni...@google.com>
Gerrit-Comment-Date: Wed, 29 Oct 2025 20:59:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Konstantin Shcheglov (Gerrit)

unread,
Oct 30, 2025, 2:57:34 PM (yesterday) Oct 30
to Kallen Tu, Paul Berry, Brian Wilkerson, Johnni Winther, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Johnni Winther and Paul Berry

Konstantin Shcheglov added 12 comments

File pkg/analyzer/lib/src/dart/analysis/defined_names.dart
Line 35, Patchset 6: if (member.body case BlockClassBody body) {
Paul Berry . resolved

I believe this code is correct, but it's hard to tell why. You have to know that there are only two possible types that `member.body` can have in practice: `BlockClassBody` and `EmptyClassBody`; if you know that, then you can see that for an empty class body there's nothing that needs to be done.

What if we changed line 32 to `case ClassDeclarationImpl()` and then changed this `if` statement to a `switch` statement, so that exhaustiveness checking would ensure that all cases are handled? E.g.:

```
switch (member.body) {
case BlockClassBodyImpl body:
body.members.forEach(appendClassMemberName);
case EmptyClassBodyImpl():
// An empty class body declarations.
break;
case EnumBodyImpl():
assert(
false,
'A class declaration should never have an enum body',
);
}
```

Alternatively, add an abstract `members` getter to `ClassBodyImpl` and provide an implementation in `EmptyClassBodyImpl` that returns `const []`. Then this `if` wouldn't be needed, and we could just unconditionally do:

```
member.body.members.forEach(appendClassMemberName);
```

Aside: why is `EnumBodyImpl` a subtype of `ClassBodyImpl`? It seems like `EnumBodyImpl` should just extend `AstNodeImpl` (and similarly, `EnumBody` should just implement `AstNode`). After all, an enum body can't be used where a class body is expected, right?

Konstantin Shcheglov

I added `members` to `ClassBodyImpl`.

And in a separate CL `EnumBodyImpl` is not `ClassBodyImpl` anymore.

Line 59, Patchset 6: if (member.body case BlockClassBody body) {
Paul Berry . resolved

Similar issue here

Konstantin Shcheglov

Done

File pkg/analyzer/lib/src/dart/analysis/referenced_names.dart
Line 127, Patchset 6: if (node.body case BlockClassBody body) {
Paul Berry . resolved

Similar issue here

Konstantin Shcheglov

Done

File pkg/analyzer/lib/src/dart/analysis/unlinked_api_signature.dart
Line 67, Patchset 6: if (node.body case BlockClassBody body) {
Paul Berry . resolved

Similar issue here

Konstantin Shcheglov

Done

Line 107, Patchset 6: if (useDeclaringConstructorsAst) {
Paul Berry . resolved

It should be possible to do this without so much code duplication:

```
void _addEnum(EnumDeclaration node) {
var members = useDeclaringConstructorsAst
? node.body.members
: node.members;
    // If not enhanced, include the whole node.
var firstMember = members.firstOrNull;
if (firstMember == null) {
_addNode(node);
return;
}
    _addTokens(node.beginToken, firstMember.beginToken);
_addClassMembers(members, true);
}
```
Konstantin Shcheglov

Done

Line 137, Patchset 6: if (node.body case BlockClassBody body) {
Paul Berry . resolved

Similar issue to the issue raised in `pkg/analyzer/lib/src/dart/analysis/defined_names.dart`.

Konstantin Shcheglov

Done. Actually here it cannot be anything else than `BlockClassBody`.

File pkg/analyzer/lib/src/summary2/element_builder.dart
Line 2051, Patchset 6: void _builtRepresentationDeclaration2({
Konstantin Shcheglov

I decided that here I prefer simplicity over code duplication.

File pkg/analyzer/lib/src/summary2/informative_data.dart
Line 893, Patchset 6: if (useDeclaringConstructorsAst) {
Paul Berry . resolved

It should be possible to avoid the code duplication by pushing the test into the `members` expression:

```
_InfoExtensionDeclaration _buildExtension(ExtensionDeclaration node) {
return _InfoExtensionDeclaration(
data: _buildInstanceData(
node,
name: node.name,
typeParameters: node.typeParameters,
members: useDeclaringConstructorsAst ? node.body.members : node.members,
),
);
}
```
Konstantin Shcheglov

Done

Line 1192, Patchset 6: if (useDeclaringConstructorsAst) {
Paul Berry . resolved

Similar issue here.

Konstantin Shcheglov

Done

Line 1244, Patchset 6: _InfoExtensionTypeRepresentation _buildRepresentation2(
Paul Berry . resolved

Can we use a more descriptive name here? `2` doesn't convey any useful information.

Konstantin Shcheglov

Done

File pkg/analyzer/test/src/summary/elements/class_test.dart
Line 31502, Patchset 6:class ClassElementTest_fromBytes2 extends ClassElementTest {
Paul Berry . resolved

Similar issue here (need a more descriptive name suffix than `2`).

Konstantin Shcheglov

Done

Line 31526, Patchset 6:class ClassElementTest_keepLinking2 extends ClassElementTest {
Paul Berry . resolved

Similar issue here, and also in the files that follow.

Konstantin Shcheglov

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Johnni Winther
  • Paul Berry
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: I768c16ea4a8bee4579732f80c1beb4bb8a42de43
Gerrit-Change-Number: 457161
Gerrit-PatchSet: 8
Gerrit-Owner: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Brian Wilkerson <brianwi...@google.com>
Gerrit-Reviewer: Johnni Winther <johnni...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Paul Berry <paul...@google.com>
Gerrit-CC: Kallen Tu <kall...@google.com>
Gerrit-Attention: Paul Berry <paul...@google.com>
Gerrit-Attention: Johnni Winther <johnni...@google.com>
Gerrit-Comment-Date: Thu, 30 Oct 2025 18:57:31 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Paul Berry <paul...@google.com>
satisfied_requirement
open
diffy

Konstantin Shcheglov (Gerrit)

unread,
Oct 30, 2025, 2:57:43 PM (yesterday) Oct 30
to Kallen Tu, Paul Berry, Brian Wilkerson, Johnni Winther, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Johnni Winther and Paul Berry

Konstantin Shcheglov voted Commit-Queue+2

Commit-Queue+2
Gerrit-Comment-Date: Thu, 30 Oct 2025 18:57:40 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Commit Queue (Gerrit)

unread,
Oct 30, 2025, 3:30:03 PM (yesterday) Oct 30
to Konstantin Shcheglov, Kallen Tu, Paul Berry, Brian Wilkerson, Johnni Winther, dart-analys...@google.com, rev...@dartlang.org

Commit Queue submitted the change with unreviewed changes

Unreviewed changes

6 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:

```
The name of the file: pkg/analyzer/lib/src/dart/analysis/referenced_names.dart
Insertions: 19, Deletions: 20.

The diff is too large to show. Please review the diff.
```
```
The name of the file: pkg/analyzer/lib/src/dart/analysis/unlinked_api_signature.dart
Insertions: 20, Deletions: 35.

The diff is too large to show. Please review the diff.
```
```
The name of the file: pkg/analyzer/lib/src/dart/ast/ast.dart
Insertions: 6, Deletions: 1.

The diff is too large to show. Please review the diff.
```
```
The name of the file: pkg/analyzer/lib/src/summary2/element_builder.dart
Insertions: 47, Deletions: 46.

The diff is too large to show. Please review the diff.
```
```
The name of the file: pkg/analyzer/lib/src/summary2/informative_data.dart
Insertions: 42, Deletions: 63.

The diff is too large to show. Please review the diff.
```
```
The name of the file: pkg/analyzer/test/src/summary/elements/class_test.dart
Insertions: 6, Deletions: 4.

The diff is too large to show. Please review the diff.
```
```
The name of the file: pkg/analyzer/test/src/summary/elements/enum_test.dart
Insertions: 5, Deletions: 4.

The diff is too large to show. Please review the diff.
```
```
The name of the file: pkg/analyzer/test/src/summary/elements/extension_test.dart
Insertions: 8, Deletions: 4.

The diff is too large to show. Please review the diff.
```
```
The name of the file: pkg/analyzer/test/src/summary/elements/extension_type_test.dart
Insertions: 10, Deletions: 4.

The diff is too large to show. Please review the diff.
```
```
The name of the file: pkg/analyzer/test/src/summary/elements/mixin_test.dart
Insertions: 6, Deletions: 4.

The diff is too large to show. Please review the diff.
```
```
The name of the file: pkg/analyzer/lib/src/dart/analysis/defined_names.dart
Insertions: 5, Deletions: 8.

The diff is too large to show. Please review the diff.
```

Change information

Commit message:
DeCo. Build elements from new ASTs.

For now just to understand the same syntax represented with new AST
nodes. We now run element tests for classes, enums, extensions,
extension types, and mixins in both modes: old AST and new AST.
Change-Id: I768c16ea4a8bee4579732f80c1beb4bb8a42de43
Reviewed-by: Paul Berry <paul...@google.com>
Commit-Queue: Konstantin Shcheglov <sche...@google.com>
Reviewed-by: Brian Wilkerson <brianwi...@google.com>
Files:
  • M pkg/analyzer/api.txt
  • M pkg/analyzer/lib/dart/ast/ast.dart
  • M pkg/analyzer/lib/src/dart/analysis/defined_names.dart
  • M pkg/analyzer/lib/src/dart/analysis/driver.dart
  • M pkg/analyzer/lib/src/dart/analysis/file_state.dart
  • M pkg/analyzer/lib/src/dart/analysis/referenced_names.dart
  • M pkg/analyzer/lib/src/dart/analysis/unlinked_api_signature.dart
  • M pkg/analyzer/lib/src/dart/ast/ast.dart
  • M pkg/analyzer/lib/src/dartdoc/dartdoc_directive_info.dart
  • M pkg/analyzer/lib/src/fasta/ast_builder.dart
  • M pkg/analyzer/lib/src/summary2/default_types_builder.dart
  • M pkg/analyzer/lib/src/summary2/element_builder.dart
  • M pkg/analyzer/lib/src/summary2/extension_type.dart
  • M pkg/analyzer/lib/src/summary2/informative_data.dart
  • M pkg/analyzer/lib/src/summary2/library_builder.dart
  • M pkg/analyzer/lib/src/summary2/metadata_resolver.dart
  • M pkg/analyzer/lib/src/summary2/reference_resolver.dart
  • M pkg/analyzer/lib/src/summary2/simply_bounded.dart
  • M pkg/analyzer/lib/src/summary2/type_alias.dart
  • M pkg/analyzer/lib/src/summary2/variance_builder.dart
  • M pkg/analyzer/test/src/diagnostics/parser_diagnostics.dart
  • M pkg/analyzer/test/src/summary/elements/class_test.dart
  • M pkg/analyzer/test/src/summary/elements/enum_test.dart
  • M pkg/analyzer/test/src/summary/elements/extension_test.dart
  • M pkg/analyzer/test/src/summary/elements/extension_type_test.dart
  • M pkg/analyzer/test/src/summary/elements/mixin_test.dart
Change size: XL
Delta: 26 files changed, 849 insertions(+), 167 deletions(-)
Branch: refs/heads/main
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by Brian Wilkerson, +1 by Paul Berry
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: I768c16ea4a8bee4579732f80c1beb4bb8a42de43
Gerrit-Change-Number: 457161
Gerrit-PatchSet: 9
Gerrit-Owner: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Brian Wilkerson <brianwi...@google.com>
Gerrit-Reviewer: Johnni Winther <johnni...@google.com>
Gerrit-Reviewer: Konstantin Shcheglov <sche...@google.com>
Gerrit-Reviewer: Paul Berry <paul...@google.com>
Gerrit-CC: Kallen Tu <kall...@google.com>
open
diffy
satisfied_requirement
Reply all
Reply to author
Forward
0 new messages