Skip to content

Commit 655cdcb

Browse files
chloestefantsovaCommit Queue
authored andcommitted
[cfe] Move formal inference to SourceFunctionBuilderImpl hierarchy
This is a follow-up to https://dart-review.googlesource.com/c/sdk/+/404822 Change-Id: Id0b41562de44a89515b65c80f082ba16c823b09b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405006 Commit-Queue: Chloe Stefantsova <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 7198fb9 commit 655cdcb

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,9 @@ class DeclaredSourceConstructorBuilder
879879
void buildOutlineExpressions(ClassHierarchy classHierarchy,
880880
List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
881881
if (_hasBuiltOutlines) return;
882+
883+
inferFormals(formals, classHierarchy);
884+
882885
if (isConst && isAugmenting) {
883886
origin.buildOutlineExpressions(
884887
classHierarchy, delayedDefaultValueCloners);

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

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import '../builder/declaration_builders.dart';
2525
import '../builder/formal_parameter_builder.dart';
2626
import '../builder/function_builder.dart';
2727
import '../builder/metadata_builder.dart';
28-
import '../builder/omitted_type_builder.dart';
2928
import '../builder/type_builder.dart';
3029
import '../codes/cfe_codes.dart';
3130
import '../dill/dill_extension_type_member_builder.dart';
@@ -263,6 +262,9 @@ class SourceFactoryBuilder extends SourceFunctionBuilderImpl {
263262
void buildOutlineExpressions(ClassHierarchy classHierarchy,
264263
List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
265264
if (_hasBuiltOutlines) return;
265+
266+
inferFormals(formals, classHierarchy);
267+
266268
if (_delayedDefaultValueCloner != null) {
267269
delayedDefaultValueCloners.add(_delayedDefaultValueCloner!);
268270
}
@@ -560,6 +562,9 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder {
560562
void buildOutlineExpressions(ClassHierarchy classHierarchy,
561563
List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
562564
if (_hasBuiltOutlines) return;
565+
566+
inferFormals(formals, classHierarchy);
567+
563568
if (isConst && isAugmenting) {
564569
origin.buildOutlineExpressions(
565570
classHierarchy, delayedDefaultValueCloners);
@@ -583,31 +588,6 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder {
583588
createBodyBuilderContext(), declarationBuilder.scope, fileUri);
584589
Builder? targetBuilder = redirectionTarget.target;
585590

586-
// Inference of target's formals should happen before building of the
587-
// outline expressions in members and before inferring target's type
588-
// arguments.
589-
//
590-
// (1) The outline expressions, such as formal parameter initializers,
591-
// need properly inferred type contexts. Among other things, it ensures
592-
// that the required coercions, such as int-to-double conversion, are
593-
// run.
594-
//
595-
// (2) Type arguments for the targets of redirecting factories can only
596-
// be inferred if the formal parameters of the targets are inferred too.
597-
// That may not be the case when the target's parameters are initializing
598-
// parameters referring to fields with types that are to be inferred.
599-
if (targetBuilder is SourceFunctionBuilderImpl) {
600-
List<FormalParameterBuilder>? formals = targetBuilder.formals;
601-
if (formals != null) {
602-
for (FormalParameterBuilder formal in formals) {
603-
TypeBuilder formalType = formal.type;
604-
if (formalType is InferableTypeBuilder) {
605-
formalType.inferType(classHierarchy);
606-
}
607-
}
608-
}
609-
}
610-
611591
if (targetBuilder is SourceMemberBuilder) {
612592
// Ensure that target has been built.
613593
targetBuilder.buildOutlineExpressions(

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,8 @@ abstract class SourceFunctionBuilderImpl extends SourceMemberBuilderImpl
423423
void buildOutlineExpressions(ClassHierarchy classHierarchy,
424424
List<DelayedDefaultValueCloner> delayedDefaultValueCloners) {
425425
if (!hasBuiltOutlineExpressions) {
426+
inferFormals(formals, classHierarchy);
427+
426428
DeclarationBuilder? classOrExtensionBuilder =
427429
isClassMember || isExtensionMember || isExtensionTypeMember
428430
? parent as DeclarationBuilder
@@ -572,3 +574,16 @@ void reportAugmentationMismatch(
572574
origin.fileUri!, origin.fileOffset, noLength)
573575
]);
574576
}
577+
578+
/// Ensures the type of each of the [formals] is inferred.
579+
void inferFormals(
580+
List<FormalParameterBuilder>? formals, ClassHierarchy classHierarchy) {
581+
if (formals != null) {
582+
for (FormalParameterBuilder formal in formals) {
583+
TypeBuilder formalType = formal.type;
584+
if (formalType is InferableTypeBuilder) {
585+
formalType.inferType(classHierarchy);
586+
}
587+
}
588+
}
589+
}

0 commit comments

Comments
 (0)