@@ -3270,26 +3270,33 @@ class ArgEmitter {
3270
3270
}
3271
3271
3272
3272
void maybeEmitForeignArgument () {
3273
- if (Foreign.async
3274
- && Foreign.async ->completionHandlerParamIndex () == Args.size ()) {
3275
- SILParameterInfo param = claimNextParameters (1 ).front ();
3276
- (void )param;
3277
-
3278
- // Leave a placeholder in the position. We'll fill this in with a block
3279
- // capturing the current continuation right before we invoke the
3280
- // function.
3281
- // (We can't do this immediately, because evaluating other arguments
3282
- // may require suspending the async task, which is not allowed while its
3283
- // continuation is active.)
3284
- Args.push_back (ManagedValue::forInContext ());
3285
- } else if (Foreign.error
3286
- && Foreign.error ->getErrorParameterIndex () == Args.size ()) {
3287
- SILParameterInfo param = claimNextParameters (1 ).front ();
3288
- assert (param.getConvention () == ParameterConvention::Direct_Unowned);
3289
- (void ) param;
3290
-
3291
- // Leave a placeholder in the position.
3292
- Args.push_back (ManagedValue::forInContext ());
3273
+ bool keepGoing = true ;
3274
+ while (keepGoing) {
3275
+ keepGoing = false ;
3276
+ if (Foreign.async &&
3277
+ Foreign.async ->completionHandlerParamIndex () == Args.size ()) {
3278
+ SILParameterInfo param = claimNextParameters (1 ).front ();
3279
+ (void )param;
3280
+
3281
+ // Leave a placeholder in the position. We'll fill this in with a block
3282
+ // capturing the current continuation right before we invoke the
3283
+ // function.
3284
+ // (We can't do this immediately, because evaluating other arguments
3285
+ // may require suspending the async task, which is not allowed while its
3286
+ // continuation is active.)
3287
+ Args.push_back (ManagedValue::forInContext ());
3288
+ keepGoing = true ;
3289
+ }
3290
+ if (Foreign.error &&
3291
+ Foreign.error ->getErrorParameterIndex () == Args.size ()) {
3292
+ SILParameterInfo param = claimNextParameters (1 ).front ();
3293
+ assert (param.getConvention () == ParameterConvention::Direct_Unowned);
3294
+ (void )param;
3295
+
3296
+ // Leave a placeholder in the position.
3297
+ Args.push_back (ManagedValue::forInContext ());
3298
+ keepGoing = true ;
3299
+ }
3293
3300
}
3294
3301
}
3295
3302
@@ -3515,7 +3522,9 @@ struct ParamLowering {
3515
3522
}
3516
3523
}
3517
3524
3518
- if (foreign.error || foreign.async )
3525
+ if (foreign.error )
3526
+ ++count;
3527
+ if (foreign.async )
3519
3528
++count;
3520
3529
3521
3530
if (foreign.self .isImportAsMember ()) {
@@ -4172,18 +4181,12 @@ ApplyOptions CallEmission::emitArgumentsForNormalApply(
4172
4181
4173
4182
args.push_back ({});
4174
4183
4175
- if (!foreign.async || (foreign.async && foreign.error )) {
4176
- // Claim the foreign error argument(s) with the method formal params.
4177
- auto siteForeignError = CalleeTypeInfo::ForeignInfo{foreign.error , {}, {}};
4178
- std::move (*callSite).emit (SGF, origFormalType, substFnType, paramLowering,
4179
- args.back (), delayedArgs, siteForeignError);
4180
- }
4181
- if (foreign.async ) {
4182
- // Claim the foreign async argument(s) with the method formal params.
4183
- auto siteForeignAsync = CalleeTypeInfo::ForeignInfo{{}, foreign.async , {}};
4184
- std::move (*callSite).emit (SGF, origFormalType, substFnType, paramLowering,
4185
- args.back (), delayedArgs, siteForeignAsync);
4186
- }
4184
+ // Claim the foreign error and/or async arguments when claiming the formal
4185
+ // params.
4186
+ auto siteForeignError = CalleeTypeInfo::ForeignInfo{foreign.error , foreign.async , {}};
4187
+ // Claim the method formal params.
4188
+ std::move (*callSite).emit (SGF, origFormalType, substFnType, paramLowering,
4189
+ args.back (), delayedArgs, siteForeignError);
4187
4190
}
4188
4191
4189
4192
uncurriedLoc = callSite->Loc ;
0 commit comments