@@ -1074,35 +1074,18 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
1074
1074
arguments.positional[positionalIndex++ ].accept (this );
1075
1075
builtArguments.add (pop ());
1076
1076
} else {
1077
- ConstantValue constantValue = _elementMap.getConstantValue (
1078
- member, parameter.initializer,
1079
- implicitNull: true );
1080
- assert (
1081
- constantValue != null ,
1082
- failedAt (_elementMap.getMethod (function.parent),
1083
- 'No constant computed for $parameter ' ));
1084
- builtArguments.add (graph.addConstant (constantValue, closedWorld));
1077
+ builtArguments.add (_defaultValueForParameter (member, parameter));
1085
1078
}
1086
1079
});
1080
+ // Evaluate named arguments in given order.
1081
+ Map <String , HInstruction > namedArguments = _visitNamedArguments (arguments);
1082
+ // And add them to `builtArguments` in calling-convention order.
1087
1083
function.namedParameters.toList ()
1088
1084
..sort (namedOrdering)
1089
1085
..forEach ((ir.VariableDeclaration parameter) {
1090
- var correspondingNamed = arguments.named.firstWhere (
1091
- (named) => named.name == parameter.name,
1092
- orElse: () => null );
1093
- if (correspondingNamed != null ) {
1094
- correspondingNamed.value.accept (this );
1095
- builtArguments.add (pop ());
1096
- } else {
1097
- ConstantValue constantValue = _elementMap.getConstantValue (
1098
- member, parameter.initializer,
1099
- implicitNull: true );
1100
- assert (
1101
- constantValue != null ,
1102
- failedAt (_elementMap.getMethod (function.parent),
1103
- 'No constant computed for $parameter ' ));
1104
- builtArguments.add (graph.addConstant (constantValue, closedWorld));
1105
- }
1086
+ var argument = namedArguments[parameter.name];
1087
+ argument ?? = _defaultValueForParameter (member, parameter);
1088
+ builtArguments.add (argument);
1106
1089
});
1107
1090
1108
1091
return builtArguments;
@@ -3586,7 +3569,8 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
3586
3569
}
3587
3570
}
3588
3571
3589
- /// Extracts the list of instructions for the positional subset of arguments.
3572
+ /// Generate instructions to evaluate the positional arguments in source
3573
+ /// order.
3590
3574
List <HInstruction > _visitPositionalArguments (ir.Arguments arguments) {
3591
3575
List <HInstruction > result = [];
3592
3576
for (ir.Expression argument in arguments.positional) {
@@ -3596,6 +3580,17 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
3596
3580
return result;
3597
3581
}
3598
3582
3583
+ /// Generate instructions to evaluate the named arguments in source order.
3584
+ /// Returns a fresh map from parameter name to evaluated argument.
3585
+ Map <String , HInstruction > _visitNamedArguments (ir.Arguments arguments) {
3586
+ Map <String , HInstruction > values = {};
3587
+ for (ir.NamedExpression argument in arguments.named) {
3588
+ argument.value.accept (this );
3589
+ values[argument.name] = pop ();
3590
+ }
3591
+ return values;
3592
+ }
3593
+
3599
3594
/// Builds the list of instructions for the expressions in the arguments to a
3600
3595
/// dynamic target (member function). Dynamic targets use stubs to add
3601
3596
/// defaulted arguments, so (unlike static targets) we do not add the default
@@ -3606,11 +3601,7 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
3606
3601
List <HInstruction > values = _visitPositionalArguments (arguments);
3607
3602
3608
3603
if (arguments.named.isNotEmpty) {
3609
- Map <String , HInstruction > namedValues = {};
3610
- for (ir.NamedExpression argument in arguments.named) {
3611
- argument.value.accept (this );
3612
- namedValues[argument.name] = pop ();
3613
- }
3604
+ Map <String , HInstruction > namedValues = _visitNamedArguments (arguments);
3614
3605
for (String name in selector.callStructure.getOrderedNamedArguments ()) {
3615
3606
values.add (namedValues[name]);
3616
3607
}
@@ -3638,11 +3629,7 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
3638
3629
if (function is ConstructorEntity && function.isFactoryConstructor) {
3639
3630
// TODO(sra): Have a "CompiledArguments" structure to just update with
3640
3631
// what values we have rather than creating a map and de-populating it.
3641
- Map <String , HInstruction > namedValues = {};
3642
- for (ir.NamedExpression argument in arguments.named) {
3643
- argument.value.accept (this );
3644
- namedValues[argument.name] = pop ();
3645
- }
3632
+ Map <String , HInstruction > namedValues = _visitNamedArguments (arguments);
3646
3633
3647
3634
// Visit named arguments in parameter-position order, selecting provided
3648
3635
// or default value.
@@ -3719,11 +3706,7 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
3719
3706
}
3720
3707
3721
3708
if (parameterStructure.namedParameters.isNotEmpty) {
3722
- Map <String , HInstruction > namedValues = {};
3723
- for (ir.NamedExpression argument in arguments.named) {
3724
- argument.value.accept (this );
3725
- namedValues[argument.name] = pop ();
3726
- }
3709
+ Map <String , HInstruction > namedValues = _visitNamedArguments (arguments);
3727
3710
3728
3711
// Visit named arguments in parameter-position order, selecting provided
3729
3712
// or default value.
0 commit comments