[XL] Change in dart/sdk[main]: DeCo. Add AST for primary constructors behind feature flag.

0 views
Skip to first unread message

Paul Berry (Gerrit)

unread,
Oct 19, 2025, 10:27:56 PM (2 days ago) Oct 19
to Konstantin Shcheglov, Kallen Tu, Johnni Winther, Brian Wilkerson, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Brian Wilkerson, Johnni Winther and Konstantin Shcheglov

Paul Berry added 1 comment

Patchset-level comments
File-level comment, Patchset 12 (Latest):
Paul Berry . resolved

I feel like before landing this, it would be good to have a quick design review of what you plan for the ASTs to look like. Could you share a document with some examples of the declaring constructors syntax and what the corresponding ASTs would look like? I would find that way easier to review than jumping straight into looking at code right now.

Open in Gerrit

Related details

Attention is currently required from:
  • Brian Wilkerson
  • Johnni Winther
  • Konstantin Shcheglov
Submit Requirements:
  • requirement is not 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: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed
Gerrit-Change-Number: 455820
Gerrit-PatchSet: 12
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: Brian Wilkerson <brianwi...@google.com>
Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
Gerrit-Attention: Johnni Winther <johnni...@google.com>
Gerrit-Comment-Date: Mon, 20 Oct 2025 02:27:52 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
open
diffy

Konstantin Shcheglov (Gerrit)

unread,
Oct 19, 2025, 11:07:38 PM (2 days ago) Oct 19
to Kallen Tu, Paul Berry, Johnni Winther, Brian Wilkerson, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Brian Wilkerson, Johnni Winther and Paul Berry

Konstantin Shcheglov added 1 comment

Patchset-level comments
Paul Berry . unresolved

I feel like before landing this, it would be good to have a quick design review of what you plan for the ASTs to look like. Could you share a document with some examples of the declaring constructors syntax and what the corresponding ASTs would look like? I would find that way easier to review than jumping straight into looking at code right now.

Konstantin Shcheglov

1. This is not new AST, this is implementation for parser integration of previously reviewed AST for primary constructors. In fact, this CL serves exactly the same document that you are asking, IMHO: see all the parsing tests that show code and corresponding AST dumps. Do you need something more?
2. We don't have AST for in-body constructors yet, initially because I did not have time to design it, and now because it turned out that the language specification is apparently still changing.

Open in Gerrit

Related details

Attention is currently required from:
  • Brian Wilkerson
  • Johnni Winther
  • Paul Berry
Submit Requirements:
  • requirement is not 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: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed
Gerrit-Change-Number: 455820
Gerrit-PatchSet: 12
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: Brian Wilkerson <brianwi...@google.com>
Gerrit-Attention: Paul Berry <paul...@google.com>
Gerrit-Attention: Johnni Winther <johnni...@google.com>
Gerrit-Comment-Date: Mon, 20 Oct 2025 03:07:34 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Paul Berry <paul...@google.com>
unsatisfied_requirement
open
diffy

Paul Berry (Gerrit)

unread,
Oct 20, 2025, 12:02:32 AM (yesterday) Oct 20
to Konstantin Shcheglov, Kallen Tu, Johnni Winther, Brian Wilkerson, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Brian Wilkerson, Johnni Winther and Konstantin Shcheglov

Paul Berry added 1 comment

Patchset-level comments
Paul Berry . unresolved

I feel like before landing this, it would be good to have a quick design review of what you plan for the ASTs to look like. Could you share a document with some examples of the declaring constructors syntax and what the corresponding ASTs would look like? I would find that way easier to review than jumping straight into looking at code right now.

Konstantin Shcheglov

1. This is not new AST, this is implementation for parser integration of previously reviewed AST for primary constructors. In fact, this CL serves exactly the same document that you are asking, IMHO: see all the parsing tests that show code and corresponding AST dumps. Do you need something more?
2. We don't have AST for in-body constructors yet, initially because I did not have time to design it, and now because it turned out that the language specification is apparently still changing.

Paul Berry

This is not new AST, this is implementation for parser integration of previously reviewed AST for primary constructors.

I don't recall seeing the CL for the primary constructor AST. Would you mind sending me a link to that CL?

In fact, this CL serves exactly the same document that you are asking, IMHO: see all the parsing tests that show code and corresponding AST dumps. Do you need something more?

It looks like this CL contains over 2000 lines of new parser tests. In order to get an effective overview of your AST design, I would need to see a summary of what is being changed that is much more consise than that. Ideally a couple of paragraphs highlighting the essential differences. Some diagrams would be great too.

Open in Gerrit

Related details

Attention is currently required from:
  • Brian Wilkerson
  • Johnni Winther
  • Konstantin Shcheglov
Submit Requirements:
  • requirement is not 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: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed
Gerrit-Change-Number: 455820
Gerrit-PatchSet: 12
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: Brian Wilkerson <brianwi...@google.com>
Gerrit-Attention: Konstantin Shcheglov <sche...@google.com>
Gerrit-Attention: Johnni Winther <johnni...@google.com>
Gerrit-Comment-Date: Mon, 20 Oct 2025 04:02:28 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Paul Berry <paul...@google.com>
Comment-In-Reply-To: Konstantin Shcheglov <sche...@google.com>
unsatisfied_requirement
open
diffy

Konstantin Shcheglov (Gerrit)

unread,
Oct 20, 2025, 10:24:45 AM (yesterday) Oct 20
to Kallen Tu, Paul Berry, Johnni Winther, Brian Wilkerson, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Brian Wilkerson, Johnni Winther and Paul Berry

Konstantin Shcheglov added 1 comment

Patchset-level comments
Paul Berry . unresolved

I feel like before landing this, it would be good to have a quick design review of what you plan for the ASTs to look like. Could you share a document with some examples of the declaring constructors syntax and what the corresponding ASTs would look like? I would find that way easier to review than jumping straight into looking at code right now.

Konstantin Shcheglov

1. This is not new AST, this is implementation for parser integration of previously reviewed AST for primary constructors. In fact, this CL serves exactly the same document that you are asking, IMHO: see all the parsing tests that show code and corresponding AST dumps. Do you need something more?
2. We don't have AST for in-body constructors yet, initially because I did not have time to design it, and now because it turned out that the language specification is apparently still changing.

Paul Berry

This is not new AST, this is implementation for parser integration of previously reviewed AST for primary constructors.

I don't recall seeing the CL for the primary constructor AST. Would you mind sending me a link to that CL?

In fact, this CL serves exactly the same document that you are asking, IMHO: see all the parsing tests that show code and corresponding AST dumps. Do you need something more?

It looks like this CL contains over 2000 lines of new parser tests. In order to get an effective overview of your AST design, I would need to see a summary of what is being changed that is much more consise than that. Ideally a couple of paragraphs highlighting the essential differences. Some diagrams would be great too.

Konstantin Shcheglov
Open in Gerrit

Related details

Attention is currently required from:
  • Brian Wilkerson
  • Johnni Winther
  • Paul Berry
Submit Requirements:
  • requirement is not 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: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed
Gerrit-Change-Number: 455820
Gerrit-PatchSet: 12
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: Brian Wilkerson <brianwi...@google.com>
Gerrit-Attention: Paul Berry <paul...@google.com>
Gerrit-Attention: Johnni Winther <johnni...@google.com>
Gerrit-Comment-Date: Mon, 20 Oct 2025 14:24:41 +0000
unsatisfied_requirement
open
diffy

Brian Wilkerson (Gerrit)

unread,
Oct 20, 2025, 10:58:21 AM (yesterday) Oct 20
to Konstantin Shcheglov, Brian Wilkerson, Kallen Tu, 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 2 comments

Votes added by Brian Wilkerson

Code-Review+1

2 comments

Patchset-level comments
Brian Wilkerson . resolved

The api changes lgtm.

File pkg/analyzer/api.txt
Line 581, Patchset 12 (Latest): useDeclaringConstructorsAst (static getter: bool)
Brian Wilkerson . unresolved

I'm surprised that these aren't annotated as being experimental. I'm guessing that it's a bug in the api writer.

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: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed
Gerrit-Change-Number: 455820
Gerrit-PatchSet: 12
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: Konstantin Shcheglov <sche...@google.com>
Gerrit-Attention: Johnni Winther <johnni...@google.com>
Gerrit-Comment-Date: Mon, 20 Oct 2025 14:58:17 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Konstantin Shcheglov (Gerrit)

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

Konstantin Shcheglov added 1 comment

Patchset-level comments
Paul Berry . unresolved

I feel like before landing this, it would be good to have a quick design review of what you plan for the ASTs to look like. Could you share a document with some examples of the declaring constructors syntax and what the corresponding ASTs would look like? I would find that way easier to review than jumping straight into looking at code right now.

Konstantin Shcheglov

1. This is not new AST, this is implementation for parser integration of previously reviewed AST for primary constructors. In fact, this CL serves exactly the same document that you are asking, IMHO: see all the parsing tests that show code and corresponding AST dumps. Do you need something more?
2. We don't have AST for in-body constructors yet, initially because I did not have time to design it, and now because it turned out that the language specification is apparently still changing.

Paul Berry

This is not new AST, this is implementation for parser integration of previously reviewed AST for primary constructors.

I don't recall seeing the CL for the primary constructor AST. Would you mind sending me a link to that CL?

In fact, this CL serves exactly the same document that you are asking, IMHO: see all the parsing tests that show code and corresponding AST dumps. Do you need something more?

It looks like this CL contains over 2000 lines of new parser tests. In order to get an effective overview of your AST design, I would need to see a summary of what is being changed that is much more consise than that. Ideally a couple of paragraphs highlighting the essential differences. Some diagrams would be great too.

Konstantin Shcheglov

CL with primary constructor AST: https://dart-review.googlesource.com/c/sdk/+/454322

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: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed
Gerrit-Change-Number: 455820
Gerrit-PatchSet: 12
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: Mon, 20 Oct 2025 16:58:45 +0000
satisfied_requirement
open
diffy

Paul Berry (Gerrit)

unread,
Oct 20, 2025, 4:42:16 PM (21 hours ago) Oct 20
to Konstantin Shcheglov, Brian Wilkerson, Kallen Tu, Johnni Winther, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Johnni Winther and Konstantin Shcheglov

Paul Berry added 1 comment

File pkg/analyzer/api.txt
Line 581, Patchset 12 (Latest): useDeclaringConstructorsAst (static getter: bool)
Brian Wilkerson . unresolved

I'm surprised that these aren't annotated as being experimental. I'm guessing that it's a bug in the api writer.

Paul Berry

Agreed. I will fix this.

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: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed
Gerrit-Change-Number: 455820
Gerrit-PatchSet: 12
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: Konstantin Shcheglov <sche...@google.com>
Gerrit-Attention: Johnni Winther <johnni...@google.com>
Gerrit-Comment-Date: Mon, 20 Oct 2025 20:42:13 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Brian Wilkerson <brianwi...@google.com>
satisfied_requirement
open
diffy

Paul Berry (Gerrit)

unread,
Oct 20, 2025, 5:41:08 PM (20 hours ago) Oct 20
to Konstantin Shcheglov, Brian Wilkerson, Kallen Tu, Johnni Winther, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Johnni Winther and Konstantin Shcheglov

Paul Berry added 1 comment

Patchset-level comments
Paul Berry . unresolved

I feel like before landing this, it would be good to have a quick design review of what you plan for the ASTs to look like. Could you share a document with some examples of the declaring constructors syntax and what the corresponding ASTs would look like? I would find that way easier to review than jumping straight into looking at code right now.

Konstantin Shcheglov

1. This is not new AST, this is implementation for parser integration of previously reviewed AST for primary constructors. In fact, this CL serves exactly the same document that you are asking, IMHO: see all the parsing tests that show code and corresponding AST dumps. Do you need something more?
2. We don't have AST for in-body constructors yet, initially because I did not have time to design it, and now because it turned out that the language specification is apparently still changing.

Paul Berry

This is not new AST, this is implementation for parser integration of previously reviewed AST for primary constructors.

I don't recall seeing the CL for the primary constructor AST. Would you mind sending me a link to that CL?

In fact, this CL serves exactly the same document that you are asking, IMHO: see all the parsing tests that show code and corresponding AST dumps. Do you need something more?

It looks like this CL contains over 2000 lines of new parser tests. In order to get an effective overview of your AST design, I would need to see a summary of what is being changed that is much more consise than that. Ideally a couple of paragraphs highlighting the essential differences. Some diagrams would be great too.

Konstantin Shcheglov

CL with primary constructor AST: https://dart-review.googlesource.com/c/sdk/+/454322

Konstantin Shcheglov

Here is a short document for two interesting cases: https://docs.google.com/document/d/1nJsSX7hi2nxWlB47GfyuE8aECi5SN8peOv7kqXGyoQo/edit?resourcekey=0-TEIdcONjnjxNV0Ei-gahSA&tab=t.0

Paul Berry

Thanks! The CL link and the doc were very helpful.

Gerrit-Comment-Date: Mon, 20 Oct 2025 21:41:05 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
open
diffy

Paul Berry (Gerrit)

unread,
Oct 20, 2025, 6:13:17 PM (19 hours ago) Oct 20
to Konstantin Shcheglov, Brian Wilkerson, Kallen Tu, Johnni Winther, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Johnni Winther and Konstantin Shcheglov

Paul Berry voted and added 4 comments

Votes added by Paul Berry

Code-Review+1

4 comments

Patchset-level comments
Paul Berry . resolved

lgtm assuming comments are addressed.

File pkg/analyzer/lib/src/dart/ast/ast.dart
Line 1844, Patchset 12 (Latest):final class BlockClassBodyImplStub implements BlockClassBodyImpl {
Paul Berry . unresolved

Would you mind adding a TODO comment to remind us to remove this later?

E.g.:
```
// TODO(scheglov): Remove this stub once `useDeclaringConstructorsAst` is enabled
// by default.
```

A similar comment applies to `ClassBodyImplStub`, `ClassNamePartImplStub`, `EnumBodyImplStub`, and `RepresentationDeclarationImplStub`.

Line 3167, Patchset 12 (Latest): if (useDeclaringConstructorsAst) {
_becomeParentOf(namePart);
} else {
_becomeParentOf(typeParameters);
}
_becomeParentOf(extendsClause);
Paul Berry . unresolved

Would it be possible to add some assertions to make sure that the parts we're not becoming a parent of behave in the expected way? E.g.:

```suggestion
if (useDeclaringConstructorsAst) {
_becomeParentOf(namePart);
assert(identical(typeParameters, namePart.typeParameters));
} else {
_becomeParentOf(typeParameters);
assert(namePart is ClassNamePartImplStub);
}
_becomeParentOf(extendsClause);
```

That would have the advantages of (a) helping to make sure we don't screw up in the AST builder, and (b) documenting (for ourselves) how these internal fields behave when the feature is enabled/disabled.

Similar comments apply to the other uses of `useDeclaringConstructorsAst` in AST node constructors.

File pkg/analyzer/test/src/dart/parser/class_test.dart
Line 174, Patchset 12 (Latest): useDeclaringConstructorsAst = false;
Paul Berry . unresolved

If the test fails before reaching this line, `useDeclaringConstructorsAst` will not be reset to `false`, which might cause other tests to fail in confusing ways.

How about if we create methods in `ParserDiagnosticsTest` (or some other suitable base class or mixin):

```
void enableDeclaringConstructorsAst() {
tearDown(() {
useDeclaringConstructorsAst = false;
});
useDeclaringConstructorsAst = true;
}
void disableDeclaringConstructorsAst() {
useDeclaringConstructorsAst = false;
}
```

Then, in these tests, we can replace each call to `useDeclaringConstructorsAst = true` with `enableDeclaringConstructorsAst()` and each call to `useDeclaringConstructorsAst = false` with `disableDeclaringConstructorsAst()`, and then we'll always be guaranteed that each test starts with `useDeclaringConstructorsAst` in the proper state.

Gerrit-Comment-Date: Mon, 20 Oct 2025 22:13:13 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Konstantin Shcheglov (Gerrit)

unread,
Oct 20, 2025, 8:35:39 PM (17 hours ago) Oct 20
to Paul Berry, Brian Wilkerson, Kallen Tu, Johnni Winther, Commit Queue, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Johnni Winther

Konstantin Shcheglov voted and added 3 comments

Votes added by Konstantin Shcheglov

Commit-Queue+2

3 comments

File pkg/analyzer/lib/src/dart/ast/ast.dart
Line 1844, Patchset 12:final class BlockClassBodyImplStub implements BlockClassBodyImpl {
Paul Berry . resolved

Would you mind adding a TODO comment to remind us to remove this later?

E.g.:
```
// TODO(scheglov): Remove this stub once `useDeclaringConstructorsAst` is enabled
// by default.
```

A similar comment applies to `ClassBodyImplStub`, `ClassNamePartImplStub`, `EnumBodyImplStub`, and `RepresentationDeclarationImplStub`.

Konstantin Shcheglov

Done

Line 3167, Patchset 12: if (useDeclaringConstructorsAst) {
_becomeParentOf(namePart);
} else {
_becomeParentOf(typeParameters);
}
_becomeParentOf(extendsClause);
Paul Berry . resolved

Would it be possible to add some assertions to make sure that the parts we're not becoming a parent of behave in the expected way? E.g.:

```suggestion
if (useDeclaringConstructorsAst) {
_becomeParentOf(namePart);
assert(identical(typeParameters, namePart.typeParameters));
} else {
_becomeParentOf(typeParameters);
assert(namePart is ClassNamePartImplStub);
}
_becomeParentOf(extendsClause);
```

That would have the advantages of (a) helping to make sure we don't screw up in the AST builder, and (b) documenting (for ourselves) how these internal fields behave when the feature is enabled/disabled.

Similar comments apply to the other uses of `useDeclaringConstructorsAst` in AST node constructors.

Konstantin Shcheglov

Done

File pkg/analyzer/test/src/dart/parser/class_test.dart
Line 174, Patchset 12: useDeclaringConstructorsAst = false;
Paul Berry . resolved

If the test fails before reaching this line, `useDeclaringConstructorsAst` will not be reset to `false`, which might cause other tests to fail in confusing ways.

How about if we create methods in `ParserDiagnosticsTest` (or some other suitable base class or mixin):

```
void enableDeclaringConstructorsAst() {
tearDown(() {
useDeclaringConstructorsAst = false;
});
useDeclaringConstructorsAst = true;
}
void disableDeclaringConstructorsAst() {
useDeclaringConstructorsAst = false;
}
```

Then, in these tests, we can replace each call to `useDeclaringConstructorsAst = true` with `enableDeclaringConstructorsAst()` and each call to `useDeclaringConstructorsAst = false` with `disableDeclaringConstructorsAst()`, and then we'll always be guaranteed that each test starts with `useDeclaringConstructorsAst` in the proper state.

Konstantin Shcheglov

We already do this, see `ParserDiagnosticsTest` and methods `setUp()` and `tearDown()`.
This is `test_reflective_loader` magic.

Open in Gerrit

Related details

Attention is currently required from:
  • Johnni Winther
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: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed
Gerrit-Change-Number: 455820
Gerrit-PatchSet: 13
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: Johnni Winther <johnni...@google.com>
Gerrit-Comment-Date: Tue, 21 Oct 2025 00:35:35 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Paul Berry <paul...@google.com>
satisfied_requirement
open
diffy

Commit Queue (Gerrit)

unread,
Oct 20, 2025, 9:09:54 PM (16 hours ago) Oct 20
to Konstantin Shcheglov, Paul Berry, Brian Wilkerson, Kallen Tu, Johnni Winther, dart-analys...@google.com, rev...@dartlang.org

Commit Queue submitted the change with unreviewed changes

Unreviewed changes

12 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/fasta/ast_builder.dart
Insertions: 13, Deletions: 6.

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: 16, Deletions: 0.

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

Change information

Commit message:
DeCo. Add AST for primary constructors behind feature flag.

This change introduces experimental AST support for the "declaring
constructors" (DeCo) feature and wires the parser to build explicit
nodes for primary constructors. The new behavior is gated by a static
switch:

analyzer/dart/ast/ast.dart: useDeclaringConstructorsAst (experimental)

When the flag is **true** (must be set once before parsing and not
changed thereafter):

* Declarations expose structured bodies:
- `ClassDeclaration.body` / `MixinDeclaration.body`
- `EnumDeclaration.body`
- `ExtensionDeclaration.body`
- `ExtensionTypeDeclaration.body`
Legacy bracket/members tokens (`leftBracket`, `members`,
`rightBracket`) throw `UnsupportedError`.

* The declaration "name" area is modeled as `namePart: ClassNamePart`,
which is either:
- `NameWithTypeParameters` (e.g., `A<T>`), or
- `PrimaryConstructorDeclaration` (e.g., `A<T>.named(...)`).
Legacy fields (`name`, `typeParameters`) throw `UnsupportedError`.
For extension types, `representation` also throws under the flag and
is represented via `PrimaryConstructorDeclaration`.

* Child iteration (`childEntities`), visiting (`visitChildren`), and
token boundaries (`endToken`) adapt to the new shape.

Parser changes:

* Build `PrimaryConstructorDeclaration` / `PrimaryConstructorName` via a
new `_PrimaryConstructorBuilder`. For extension types, the existing
representation syntax is mapped to a primary constructor when the flag
is enabled.
* Add `NullValue.PrimaryConstructor` to the stack listener to carry the
parsed primary constructor through the builder pipeline.

Implementation details:

* Introduce small internal *Stub classes (e.g., `ClassBodyImplStub`,
`EnumBodyImplStub`, `RepresentationDeclarationImplStub`) to satisfy
constructor requirements for fields that are not surfaced under the
current mode, avoiding API churn while the feature is gated.
* Update API surface to make `body` and `namePart` available on the
affected declarations and document which legacy getters throw when the
flag is enabled.

Rationale:

This lays the AST groundwork for DeCo while preserving backwards
compatibility by default. Consumers can opt in to validate workflows and
migrate incrementally.

Bug: https://github.com/dart-lang/sdk/issues/61701
Change-Id: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed
Reviewed-by: Brian Wilkerson <brianwi...@google.com>
Commit-Queue: Konstantin Shcheglov <sche...@google.com>
Reviewed-by: Paul Berry <paul...@google.com>
Files:
  • M pkg/_fe_analyzer_shared/lib/src/parser/stack_listener.dart
  • M pkg/analyzer/api.txt
  • M pkg/analyzer/lib/dart/ast/ast.dart
  • M pkg/analyzer/lib/src/dart/ast/ast.dart
  • M pkg/analyzer/lib/src/fasta/ast_builder.dart
  • D pkg/analyzer/test/generated/declaring_constructor_parser_test.dart
  • M pkg/analyzer/test/generated/test_all.dart
  • M pkg/analyzer/test/src/dart/parser/class_test.dart
  • M pkg/analyzer/test/src/dart/parser/enum_test.dart
  • M pkg/analyzer/test/src/dart/parser/extension_test.dart
  • M pkg/analyzer/test/src/dart/parser/extension_type_test.dart
  • M pkg/analyzer/test/src/dart/parser/mixin_test.dart
  • M pkg/analyzer/test/src/diagnostics/parser_diagnostics.dart
  • M pkg/analyzer/test/src/summary/resolved_ast_printer.dart
  • M pkg/analyzer/tool/generators/ast_generator.dart
Change size: XL
Delta: 15 files changed, 3753 insertions(+), 659 deletions(-)
Branch: refs/heads/main
Submit Requirements:
  • requirement satisfiedCode-Review: +1 by Paul Berry, +1 by Brian Wilkerson
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: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed
Gerrit-Change-Number: 455820
Gerrit-PatchSet: 14
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

Johnni Winther (Gerrit)

unread,
9:07 AM (4 hours ago) 9:07 AM
to Konstantin Shcheglov, Commit Queue, Paul Berry, Brian Wilkerson, Kallen Tu, dart-analys...@google.com, rev...@dartlang.org
Attention needed from Konstantin Shcheglov

Johnni Winther added 1 comment

File pkg/analyzer/test/generated/declaring_constructor_parser_test.dart
Line 1, Patchset 14 (Parent):// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
Johnni Winther . unresolved

I guess this was deleted by accident.

Open in Gerrit

Related details

Attention is currently required from:
  • 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: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed
Gerrit-Change-Number: 455820
Gerrit-PatchSet: 14
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: Konstantin Shcheglov <sche...@google.com>
Gerrit-Comment-Date: Tue, 21 Oct 2025 13:07:30 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
open
diffy

Konstantin Shcheglov (Gerrit)

unread,
10:17 AM (3 hours ago) 10:17 AM
to Commit Queue, Paul Berry, Brian Wilkerson, Kallen Tu, Johnni Winther, dart-analys...@google.com, rev...@dartlang.org

Konstantin Shcheglov added 1 comment

File pkg/analyzer/test/generated/declaring_constructor_parser_test.dart
Line 1, Patchset 14 (Parent):// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
Johnni Winther . unresolved

I guess this was deleted by accident.

Konstantin Shcheglov

This was intentional. I moved these tests into corresponding `class_test.dart`, `enum_test.dart`, etc. So, that they are grouped by containers for better discovery. In these tests we check not only diagnostics, but also AST structures, so get full coverage.

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: Ie5300b2958383bf3b2e9d6faf138bb7f74c9d7ed
Gerrit-Change-Number: 455820
Gerrit-PatchSet: 14
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-Comment-Date: Tue, 21 Oct 2025 14:17:37 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Johnni Winther <johnni...@google.com>
satisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages