Skip to content

Commit 595662b

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Add introductory TypedefFragment to SourceTypeAliasBuilder
This is a step towards creating builders through a set of fragments. Change-Id: I9cc79234ac10163b91b03912869fb5aa23d790c7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388820 Reviewed-by: Jens Johansen <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent c7bce42 commit 595662b

14 files changed

+65
-54
lines changed

pkg/front_end/lib/src/base/incremental_compiler.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,6 @@ class IncrementalCompiler implements IncrementalKernelGenerator {
666666
}
667667
}
668668
nextGoodKernelTarget.loader.buildersCreatedWithReferences.clear();
669-
nextGoodKernelTarget.loader.fragmentsCreatedWithReferences.clear();
670669
nextGoodKernelTarget.loader.hierarchyBuilder.clear();
671670
nextGoodKernelTarget.loader.membersBuilder.clear();
672671
nextGoodKernelTarget.loader.referenceFromIndex = null;

pkg/front_end/lib/src/builder/type_alias_builder.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,14 @@ abstract class TypeAliasBuilder implements TypeDeclarationBuilder {
99
TypeBuilder get type;
1010

1111
/// The [Typedef] built by this builder.
12+
///
13+
/// For a typedef built from source, this is only available after AST nodes
14+
/// have been built in [SourceLoader.buildOutlineNodes].
1215
Typedef get typedef;
1316

17+
/// Reference for the typedef built by this builder.
18+
Reference get reference;
19+
1420
DartType? thisType;
1521

1622
String get debugName;

pkg/front_end/lib/src/dill/dill_library_builder.dart

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import '../builder/name_iterator.dart';
2424
import '../builder/never_type_declaration_builder.dart';
2525
import '../codes/cfe_codes.dart'
2626
show LocatedMessage, Message, Severity, noLength, templateUnspecified;
27-
import '../fragment/fragment.dart';
2827
import '../kernel/constructor_tearoff_lowering.dart';
2928
import '../kernel/utils.dart';
3029
import 'dill_class_builder.dart' show DillClassBuilder;
@@ -400,14 +399,9 @@ class DillLibraryBuilder extends LibraryBuilderImpl {
400399

401400
Map<Reference, Builder>? sourceBuildersMap =
402401
loader.currentSourceLoader?.buildersCreatedWithReferences;
403-
Map<Reference, Fragment>? fragmentMap =
404-
loader.currentSourceLoader?.fragmentsCreatedWithReferences;
405402
for (Reference reference in library.additionalExports) {
406403
NamedNode node = reference.node as NamedNode;
407-
Builder? declaration = sourceBuildersMap?[reference] ??
408-
fragmentMap?[reference]
409-
// Coverage-ignore(suite): Not run.
410-
?.builder;
404+
Builder? declaration = sourceBuildersMap?[reference];
411405
String name;
412406
if (declaration != null) {
413407
// Coverage-ignore-block(suite): Not run.
@@ -476,7 +470,7 @@ class DillLibraryBuilder extends LibraryBuilderImpl {
476470
assert(
477471
(declaration is ClassBuilder && node == declaration.cls) ||
478472
(declaration is TypeAliasBuilder &&
479-
node == declaration.typedef) ||
473+
reference == declaration.reference) ||
480474
(declaration is MemberBuilder && node == declaration.member) ||
481475
(declaration is ExtensionBuilder &&
482476
node == declaration.extension) ||

pkg/front_end/lib/src/dill/dill_type_alias_builder.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class DillTypeAliasBuilder extends TypeAliasBuilderImpl {
2929
DillTypeAliasBuilder(this.typedef, this.tearOffs, DillLibraryBuilder parent)
3030
: super(typedef.name, parent, typedef.fileUri, typedef.fileOffset);
3131

32+
@override
33+
Reference get reference => typedef.reference;
34+
3235
@override
3336
List<NominalVariableBuilder>? get typeVariables {
3437
if (_typeVariables == null && typedef.typeParameters.isNotEmpty) {

pkg/front_end/lib/src/source/source_library_builder.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ class SourceLibraryBuilder extends LibraryBuilderImpl {
761761
case ClassBuilder():
762762
library.additionalExports.add(builder.cls.reference);
763763
case TypeAliasBuilder():
764-
library.additionalExports.add(builder.typedef.reference);
764+
library.additionalExports.add(builder.reference);
765765
case ExtensionBuilder():
766766
library.additionalExports.add(builder.extension.reference);
767767
case ExtensionTypeDeclarationBuilder():

pkg/front_end/lib/src/source/source_loader.dart

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ import '../codes/cfe_codes.dart';
6262
import '../codes/denylisted_classes.dart'
6363
show denylistedCoreClasses, denylistedTypedDataClasses;
6464
import '../dill/dill_library_builder.dart';
65-
import '../fragment/fragment.dart';
6665
import '../kernel/benchmarker.dart' show BenchmarkSubdivides;
6766
import '../kernel/body_builder.dart' show BodyBuilder;
6867
import '../kernel/body_builder_context.dart';
@@ -126,8 +125,6 @@ class SourceLoader extends Loader {
126125
/// exports in dill builders.
127126
Map<Reference, Builder> buildersCreatedWithReferences = {};
128127

129-
Map<Reference, Fragment> fragmentsCreatedWithReferences = {};
130-
131128
/// Used when checking whether a return type of an async function is valid.
132129
///
133130
/// The said return type is valid if it's a subtype of [futureOfBottom].

pkg/front_end/lib/src/source/source_type_alias_builder.dart

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5-
library fasta.source_type_alias_builder;
6-
75
import 'package:kernel/ast.dart';
86
import 'package:kernel/class_hierarchy.dart';
97

@@ -21,6 +19,7 @@ import '../builder/record_type_builder.dart';
2119
import '../builder/type_builder.dart';
2220
import '../codes/cfe_codes.dart'
2321
show templateCyclicTypedef, templateTypeArgumentMismatch;
22+
import '../fragment/fragment.dart';
2423
import '../kernel/body_builder_context.dart';
2524
import '../kernel/constructor_tearoff_lowering.dart';
2625
import '../kernel/expression_generator_helper.dart';
@@ -29,47 +28,55 @@ import 'source_library_builder.dart' show SourceLibraryBuilder;
2928
import 'source_loader.dart';
3029

3130
class SourceTypeAliasBuilder extends TypeAliasBuilderImpl {
32-
final List<MetadataBuilder>? metadata;
33-
34-
@override
35-
TypeBuilder type;
31+
late TypeBuilder _type;
3632

37-
final List<NominalVariableBuilder>? _typeVariables;
33+
final Reference _reference;
3834

39-
/// The [Typedef] built by this builder.
40-
@override
41-
final Typedef typedef;
35+
Typedef? _typedef;
4236

4337
@override
4438
DartType? thisType;
4539

4640
@override
4741
Map<Name, Procedure>? tearOffs;
4842

43+
TypedefFragment _introductory;
44+
4945
SourceTypeAliasBuilder(
50-
{required this.metadata,
51-
required String name,
52-
required List<NominalVariableBuilder>? typeVariables,
53-
required this.type,
46+
{required String name,
5447
required SourceLibraryBuilder enclosingLibraryBuilder,
5548
required Uri fileUri,
5649
required int fileOffset,
50+
required TypedefFragment fragment,
5751
required Reference? reference})
58-
: typedef = new Typedef(name, null,
59-
typeParameters: NominalVariableBuilder.typeParametersFromBuilders(
60-
typeVariables),
61-
fileUri: fileUri,
62-
reference: reference)
63-
..fileOffset = fileOffset,
64-
_typeVariables = typeVariables,
65-
super(name, enclosingLibraryBuilder, fileUri, fileOffset);
52+
: _reference = reference ?? new Reference(),
53+
_introductory = fragment,
54+
_type = fragment.type,
55+
super(name, enclosingLibraryBuilder, fileUri, fileOffset) {
56+
_introductory.builder = this;
57+
}
58+
59+
@override
60+
TypeBuilder get type => _type;
61+
62+
/// The [Typedef] built by this builder.
63+
@override
64+
Typedef get typedef {
65+
assert(
66+
_typedef != null, "Typedef node has not been created yet for $this.");
67+
return _typedef!;
68+
}
69+
70+
@override
71+
Reference get reference => _reference;
6672

6773
@override
6874
SourceLibraryBuilder get libraryBuilder =>
6975
super.libraryBuilder as SourceLibraryBuilder;
7076

7177
@override
72-
List<NominalVariableBuilder>? get typeVariables => _typeVariables;
78+
List<NominalVariableBuilder>? get typeVariables =>
79+
_introductory.typeVariables;
7380

7481
@override
7582
bool get fromDill => false;
@@ -81,9 +88,15 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl {
8188

8289
void _breakCyclicDependency() {
8390
if (_hasCheckedForCyclicDependency) return;
91+
_typedef = new Typedef(name, null,
92+
typeParameters:
93+
NominalVariableBuilder.typeParametersFromBuilders(typeVariables),
94+
fileUri: fileUri,
95+
reference: _reference)
96+
..fileOffset = charOffset;
8497
if (_checkCyclicTypedefDependency(type, this, {this})) {
8598
typedef.type = new InvalidType();
86-
type = new InvalidTypeBuilderImpl(fileUri, charOffset);
99+
_type = new InvalidTypeBuilderImpl(fileUri, charOffset);
87100
}
88101
if (typeVariables != null) {
89102
for (TypeVariableBuilder typeVariable in typeVariables!) {
@@ -97,15 +110,14 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl {
97110
// The typedef itself can't be used without proper bounds of its type
98111
// variables, so we set it to mean [InvalidType] too.
99112
typedef.type = new InvalidType();
100-
type = new InvalidTypeBuilderImpl(fileUri, charOffset);
113+
_type = new InvalidTypeBuilderImpl(fileUri, charOffset);
101114
}
102115
}
103116
}
104117
_hasCheckedForCyclicDependency = true;
105118
}
106119

107120
Typedef build() {
108-
_breakCyclicDependency();
109121
buildThisType();
110122
return typedef;
111123
}
@@ -257,8 +269,10 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl {
257269

258270
@override
259271
DartType buildThisType() {
272+
_breakCyclicDependency();
260273
if (thisType != null) {
261274
if (identical(thisType, pendingTypeAliasMarker)) {
275+
// Coverage-ignore-block(suite): Not run.
262276
thisType = cyclicTypeAliasMarker;
263277
assert(libraryBuilder.loader.assertProblemReportedElsewhere(
264278
"SourceTypeAliasBuilder.buildThisType",
@@ -346,7 +360,7 @@ class SourceTypeAliasBuilder extends TypeAliasBuilderImpl {
346360
List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
347361
MetadataBuilder.buildAnnotations(
348362
typedef,
349-
metadata,
363+
_introductory.metadata,
350364
createBodyBuilderContext(
351365
inOutlineBuildingPhase: true,
352366
inMetadata: true,

pkg/front_end/lib/src/source/type_parameter_scope_builder.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,12 @@ class _Added {
5353
case TypedefFragment():
5454
Reference? reference = indexedLibrary?.lookupTypedef(fragment.name);
5555
SourceTypeAliasBuilder typedefBuilder = new SourceTypeAliasBuilder(
56-
metadata: fragment.metadata,
5756
name: fragment.name,
58-
typeVariables: fragment.typeVariables,
59-
type: fragment.type,
6057
enclosingLibraryBuilder: enclosingLibraryBuilder,
6158
fileUri: fragment.fileUri,
6259
fileOffset: fragment.fileOffset,
60+
fragment: fragment,
6361
reference: reference);
64-
fragment.builder = typedefBuilder;
6562
builders.add(new _AddBuilder(fragment.name, typedefBuilder,
6663
fragment.fileUri, fragment.fileOffset));
6764
if (reference != null) {

pkg/front_end/test/coverage_suite_expected.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
150150
),
151151
// 100.0%.
152152
"package:front_end/src/base/incremental_compiler.dart": (
153-
hitCount: 849,
153+
hitCount: 846,
154154
missCount: 0,
155155
),
156156
// 100.0%.
@@ -450,7 +450,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
450450
),
451451
// 100.0%.
452452
"package:front_end/src/dill/dill_library_builder.dart": (
453-
hitCount: 339,
453+
hitCount: 335,
454454
missCount: 0,
455455
),
456456
// 100.0%.
@@ -470,7 +470,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
470470
),
471471
// 100.0%.
472472
"package:front_end/src/dill/dill_type_alias_builder.dart": (
473-
hitCount: 47,
473+
hitCount: 50,
474474
missCount: 0,
475475
),
476476
// 100.0%.
@@ -856,7 +856,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
856856
),
857857
// 100.0%.
858858
"package:front_end/src/source/source_library_builder.dart": (
859-
hitCount: 1362,
859+
hitCount: 1361,
860860
missCount: 0,
861861
),
862862
// 100.0%.
@@ -876,7 +876,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
876876
),
877877
// 100.0%.
878878
"package:front_end/src/source/source_type_alias_builder.dart": (
879-
hitCount: 335,
879+
hitCount: 349,
880880
missCount: 0,
881881
),
882882
// 100.0%.
@@ -886,7 +886,7 @@ const Map<String, ({int hitCount, int missCount})> _expect = {
886886
),
887887
// 100.0%.
888888
"package:front_end/src/source/type_parameter_scope_builder.dart": (
889-
hitCount: 698,
889+
hitCount: 694,
890890
missCount: 0,
891891
),
892892
// 100.0%.

pkg/front_end/test/spell_checking_list_code.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -906,6 +906,7 @@ interspersed
906906
interval
907907
intervals
908908
intl
909+
introductory
909910
introspect
910911
introspectable
911912
introspecting

0 commit comments

Comments
 (0)