[front_end] Update CFE code generators to use new constructor decl syntax.

(Part of https://github.com/dart-lang/sdk/issues/63288)

This change makes the code generators in the front_end package emit
code that uses the new constructor declaration syntax, described in
https://github.com/dart-lang/language/blob/main/accepted/future-releases/primary-constructors/feature-specification.md#abbreviations-of-in-body-constructor-declarations.

This avoids the need for `ignore_for_file:` comments and gives us a
bit more testing of the new feature.

Change-Id: Ica5c13018a286cd274dba2cf946304446a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507200
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
This commit is contained in:
Paul Berry
2026-06-03 07:27:41 -07:00
committed by dart-scoped@luci-project-accounts.iam.gserviceaccount.com
parent 7cc5515a6a
commit 189f25b873
10 changed files with 463 additions and 793 deletions
@@ -7,8 +7,6 @@
// Instead modify 'tools/experimental_features.yaml' and run
// 'dart pkg/front_end/tool/cfe.dart generate-experimental-flags' to update.
// ignore_for_file: unnecessary_type_name_in_constructor
part of 'experimental_flags.dart';
/// An experiment flag including its fixed properties.
@@ -45,7 +43,7 @@ class ExperimentalFlag {
/// sdk/lib/_internal/allowed_experiments.json
final Version experimentReleasedVersion;
const ExperimentalFlag({
const new({
required this.name,
required this.isEnabledByDefault,
required this.isExpired,
@@ -422,7 +420,7 @@ class GlobalFeatures {
final Map<ExperimentalFlag, Version>? experimentEnabledVersionForTesting;
final Map<ExperimentalFlag, Version>? experimentReleasedVersionForTesting;
GlobalFeatures(
new(
this.explicitExperimentalFlags, {
this.allowedExperimentalFlags,
this.defaultExperimentFlagsForTesting,
@@ -669,7 +667,7 @@ class LibraryFeatures {
final Uri canonicalUri;
final Version libraryVersion;
LibraryFeatures(this.globalFeatures, this.canonicalUri, this.libraryVersion);
new(this.globalFeatures, this.canonicalUri, this.libraryVersion);
LibraryFeature? _alternativeInvalidationStrategy;
LibraryFeature get alternativeInvalidationStrategy =>
File diff suppressed because it is too large Load Diff
+1 -3
View File
@@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// ignore_for_file: unnecessary_type_name_in_constructor
import 'package:_fe_analyzer_shared/src/experiments/flags.dart';
import 'package:_fe_analyzer_shared/src/parser/assert.dart';
import 'package:_fe_analyzer_shared/src/parser/block_kind.dart';
@@ -26,7 +24,7 @@ class ParserTestListener implements Listener {
final StringBuffer sb = new StringBuffer();
final bool trace;
ParserTestListener(this.trace);
new(this.trace);
String createTrace() {
List<String> traceLines = StackTrace.current.toString().split("\n");
@@ -37,21 +37,10 @@ String generateTestListener(Uri repoDir) {
);
Token firstToken = scanner.tokenize();
out.write("""
out.write(r"""
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
""");
// This code generator generates Dart 3.12-style constructor declarations, so
// ignore the `unnecessary_type_name_in_constructor` lint.
// TODO(paulberry): switch the code generator to Dart 3.13-style constructor
// declarations, and remove this ignore comment.
out.write("""
// ignore_for_file: unnecessary_type_name_in_constructor
""");
out.write(r"""
import 'package:_fe_analyzer_shared/src/experiments/flags.dart';
import 'package:_fe_analyzer_shared/src/parser/assert.dart';
@@ -75,7 +64,7 @@ class ParserTestListener implements Listener {
final StringBuffer sb = new StringBuffer();
final bool trace;
ParserTestListener(this.trace);
new(this.trace);
String createTrace() {
List<String> traceLines = StackTrace.current.toString().split("\n");
+1 -3
View File
@@ -2,8 +2,6 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// ignore_for_file: unnecessary_type_name_in_constructor
import 'package:_fe_analyzer_shared/src/experiments/flags.dart';
import 'package:_fe_analyzer_shared/src/parser/assert.dart';
import 'package:_fe_analyzer_shared/src/parser/block_kind.dart';
@@ -35,7 +33,7 @@ class TestParser extends Parser {
final bool trace;
bool _inhibitPrinting = false;
TestParser(
new(
Listener listener,
this.trace, {
required ExperimentalFeatures experimentalFeatures,
@@ -37,21 +37,10 @@ String generateTestParser(Uri repoDir) {
);
Token firstToken = scanner.tokenize();
out.write("""
out.write(r"""
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
""");
// This code generator generates Dart 3.12-style constructor declarations, so
// ignore the `unnecessary_type_name_in_constructor` lint.
// TODO(paulberry): switch the code generator to Dart 3.13-style constructor
// declarations, and remove this ignore comment.
out.write("""
// ignore_for_file: unnecessary_type_name_in_constructor
""");
out.write(r"""
import 'package:_fe_analyzer_shared/src/experiments/flags.dart';
import 'package:_fe_analyzer_shared/src/parser/assert.dart';
@@ -84,7 +73,7 @@ class TestParser extends Parser {
final bool trace;
bool _inhibitPrinting = false;
TestParser(Listener listener, this.trace,
new(Listener listener, this.trace,
{required ExperimentalFeatures experimentalFeatures})
: super(listener,
useImplicitCreationExpression: useImplicitCreationExpressionInCfe,
@@ -401,19 +401,8 @@ class EquivalenceVisitorStrategy extends Visitor1Strategy {
@override
void generateHeader(AstModel astModel, StringBuffer sb) {
sb.write('''
$preamble
''');
// This code generator generates Dart 3.12-style constructor declarations,
// so ignore the `unnecessary_type_name_in_constructor` lint.
// TODO(paulberry): switch the code generator to Dart 3.13-style constructor
// declarations, and remove this ignore comment.
sb.write('''
// ignore_for_file: unnecessary_type_name_in_constructor
''');
sb.writeln('''
$preamble
import 'package:kernel/ast.dart';
import 'package:kernel/src/printer.dart';
@@ -433,7 +422,7 @@ class $visitorName$visitorTypeParameters
implements Visitor1<$returnType, $argumentType> {
final $strategyName strategy;
$visitorName({
new({
this.strategy = const $strategyName()});
''');
}
@@ -849,7 +838,7 @@ EquivalenceResult checkEquivalence(
/// Custom strategies can be made by extending this strategy and override
/// methods where exceptions to the structural equivalence are needed.
class $strategyName {
const $strategyName();
const new();
''');
_classStrategyMembers.forEach((key, value) {
sb.write(value);
@@ -247,17 +247,6 @@ String generateCfeFile(Uri repoDir) {
//
// Instead modify 'tools/experimental_features.yaml' and run
// 'dart pkg/front_end/tool/cfe.dart generate-experimental-flags' to update.
''');
// This code generator generates Dart 3.12-style constructor declarations, so
// ignore the `unnecessary_type_name_in_constructor` lint.
// TODO(paulberry): switch the code generator to Dart 3.13-style constructor
// declarations, and remove this ignore comment.
sb.write('''
// ignore_for_file: unnecessary_type_name_in_constructor
''');
sb.write('''
part of 'experimental_flags.dart';
''');
@@ -313,7 +302,7 @@ class ExperimentalFlag {
/// sdk/lib/_internal/allowed_experiments.json
final Version experimentReleasedVersion;
const ExperimentalFlag(
const new(
{required this.name,
required this.isEnabledByDefault,
required this.isExpired,
@@ -382,7 +371,7 @@ class GlobalFeatures {
final Map<ExperimentalFlag, Version>? experimentEnabledVersionForTesting;
final Map<ExperimentalFlag, Version>? experimentReleasedVersionForTesting;
GlobalFeatures(this.explicitExperimentalFlags,
new(this.explicitExperimentalFlags,
{this.allowedExperimentalFlags,
this.defaultExperimentFlagsForTesting,
this.experimentEnabledVersionForTesting,
@@ -438,7 +427,7 @@ class LibraryFeatures {
final Uri canonicalUri;
final Version libraryVersion;
LibraryFeatures(this.globalFeatures, this.canonicalUri, this.libraryVersion);
new(this.globalFeatures, this.canonicalUri, this.libraryVersion);
''');
for (String key in keys) {
String identifier = keyToIdentifier(key);
@@ -38,21 +38,10 @@ String generateAstHelper(Uri repoDir) {
);
Token firstToken = scanner.tokenize();
out.write("""
out.write(r"""
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
""");
// This code generator generates Dart 3.12-style constructor declarations, so
// ignore the `unnecessary_type_name_in_constructor` lint.
// TODO(paulberry): switch the code generator to Dart 3.13-style constructor
// declarations, and remove this ignore comment.
out.write("""
// ignore_for_file: unnecessary_type_name_in_constructor
""");
out.write(r"""
import 'package:_fe_analyzer_shared/src/experiments/flags.dart';
import 'package:_fe_analyzer_shared/src/parser/assert.dart';
@@ -82,7 +71,7 @@ abstract class ParserAstNode {
List<ParserAstNode>? children;
ParserAstNode? parent;
ParserAstNode(this.what, this.type);
new(this.what, this.type);
R accept<R>(ParserAstVisitor<R> v);
@@ -390,7 +379,7 @@ class ParserCreatorListener extends Listener {
}
newClasses.write('\n');
newClasses.write(
" ${name}${typeStringCamel}"
" new"
"(ParserAstType type",
);
String separator = ", {";
+2 -4
View File
@@ -6,8 +6,6 @@
//
// Run 'dart pkg/front_end/tool/generate_ast_equivalence.dart' to update.
// ignore_for_file: unnecessary_type_name_in_constructor
import 'package:kernel/ast.dart';
import 'package:kernel/src/printer.dart';
import 'union_find.dart';
@@ -25,7 +23,7 @@ part 'equivalence_helpers.dart';
class EquivalenceVisitor implements Visitor1<bool, Node> {
final EquivalenceStrategy strategy;
EquivalenceVisitor({this.strategy = const EquivalenceStrategy()});
new({this.strategy = const EquivalenceStrategy()});
@override
bool visitAuxiliaryConstant(AuxiliaryConstant node, Node other) {
@@ -1574,7 +1572,7 @@ EquivalenceResult checkEquivalence(
/// Custom strategies can be made by extending this strategy and override
/// methods where exceptions to the structural equivalence are needed.
class EquivalenceStrategy {
const EquivalenceStrategy();
const new();
bool checkAuxiliaryConstant(
EquivalenceVisitor visitor,