Skip to content

Commit 666a5c9

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Make Factory/TypeAliasConstructor extend InternalExpression
This decouples these internal nodes from the ExpressionJudgment making a clearer distinction between pre- and post-inference nodes. A lot of helpers have also been moved to the inference visitor since they are only used there. Change-Id: I6c7278f5fc6cec6753169e6fd75d4307a9dcdf36 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448384 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Chloe Stefantsova <[email protected]>
1 parent e7ef580 commit 666a5c9

34 files changed

+783
-718
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ class MetadataBuilder {
7474
// store it in `_expression` of the corresponding [MetadataBuilder].
7575
Map<MetadataBuilder, int> parsedAnnotationBuilders = {};
7676

77+
List<int> indicesOfAnnotationsToBeInferred = [];
7778
for (int i = 0; i < metadata.length; ++i) {
7879
MetadataBuilder annotationBuilder = metadata[i];
7980
bool createFileUriExpression =
@@ -118,8 +119,9 @@ class MetadataBuilder {
118119
)..fileOffset = annotationBuilder.atOffset;
119120
}
120121
// Record the index of [annotation] in `parent.annotations`.
121-
parsedAnnotationBuilders[annotationBuilder] =
122-
annotatable.annotations.length;
122+
int annotationIndex = annotatable.annotations.length;
123+
parsedAnnotationBuilders[annotationBuilder] = annotationIndex;
124+
indicesOfAnnotationsToBeInferred.add(annotationIndex);
123125
// It is important for the inference and backlog computations that the
124126
// annotation is already a child of [parent].
125127
annotatable.addAnnotation(annotation);
@@ -156,9 +158,11 @@ class MetadataBuilder {
156158
}
157159
}
158160
if (bodyBuilder != null) {
159-
// TODO(johnniwinther): Avoid potentially inferring annotations multiple
160-
// times.
161-
bodyBuilder.inferAnnotations(annotatable, annotatable.annotations);
161+
bodyBuilder.inferAnnotations(
162+
annotatable,
163+
annotatable.annotations,
164+
indices: indicesOfAnnotationsToBeInferred,
165+
);
162166
bodyBuilder.performBacklogComputations();
163167
for (MapEntry<MetadataBuilder, int> entry
164168
in parsedAnnotationBuilders.entries) {

pkg/front_end/lib/src/fragment/enum_element.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,16 +408,14 @@ class EnumElementDeclaration
408408
_field!.initializer = bodyBuilder.buildUnresolvedError(
409409
fullConstructorNameForErrors,
410410
fileOffset,
411-
arguments: arguments,
412411
kind: UnresolvedKind.Constructor,
413412
)..parent = _field;
414413
} else {
415-
Expression initializer = bodyBuilder.buildStaticInvocation(
414+
Expression initializer = bodyBuilder.buildConstructorInvocation(
416415
constructorBuilder.invokeTarget,
417416
arguments,
418417
constness: Constness.explicitConst,
419-
charOffset: nameOffset,
420-
isConstructorInvocation: true,
418+
fileOffset: nameOffset,
421419
);
422420
ExpressionInferenceResult inferenceResult = bodyBuilder.typeInferrer
423421
.inferFieldInitializer(

0 commit comments

Comments
 (0)