@@ -3039,7 +3039,7 @@ namespace {
3039
3039
auto contexts = getRValueEmissionContexts (loweredSubstArgType, param);
3040
3040
3041
3041
// If no abstraction is required, try to honor the emission contexts.
3042
- if (loweredSubstArgType. getSwiftRValueType () == param. getType () ) {
3042
+ if (!contexts. RequiresReabstraction ) {
3043
3043
auto loc = arg.getLocation ();
3044
3044
ManagedValue result =
3045
3045
std::move (arg).getAsSingleValue (SGF, contexts.ForEmission );
@@ -3117,16 +3117,20 @@ namespace {
3117
3117
AbstractionPattern origParamType,
3118
3118
SILParameterInfo param) {
3119
3119
ManagedValue value;
3120
-
3121
- switch (getSILFunctionLanguage (Rep)) {
3122
- case SILFunctionLanguage::Swift:
3123
- value = emitSubstToOrigArgument (std::move (arg), loweredSubstArgType,
3124
- origParamType, param);
3125
- break ;
3126
- case SILFunctionLanguage::C:
3127
- value = emitNativeToBridgedArgument (std::move (arg), loweredSubstArgType,
3128
- origParamType, param);
3129
- break ;
3120
+ auto contexts = getRValueEmissionContexts (loweredSubstArgType, param);
3121
+ if (contexts.RequiresReabstraction ) {
3122
+ switch (getSILFunctionLanguage (Rep)) {
3123
+ case SILFunctionLanguage::Swift:
3124
+ value = emitSubstToOrigArgument (std::move (arg), loweredSubstArgType,
3125
+ origParamType, param);
3126
+ break ;
3127
+ case SILFunctionLanguage::C:
3128
+ value = emitNativeToBridgedArgument (
3129
+ std::move (arg), loweredSubstArgType, origParamType, param);
3130
+ break ;
3131
+ }
3132
+ } else {
3133
+ value = std::move (arg).getAsSingleValue (SGF, contexts.ForEmission );
3130
3134
}
3131
3135
Args.push_back (value);
3132
3136
}
@@ -3400,12 +3404,16 @@ namespace {
3400
3404
SGFContext ForEmission;
3401
3405
// / The context for reabstracting the r-value.
3402
3406
SGFContext ForReabstraction;
3407
+ // / If the context requires reabstraction
3408
+ bool RequiresReabstraction;
3403
3409
};
3404
3410
static EmissionContexts getRValueEmissionContexts (SILType loweredArgType,
3405
3411
SILParameterInfo param) {
3412
+ bool requiresReabstraction =
3413
+ loweredArgType.getSwiftRValueType () != param.getType ();
3406
3414
// If the parameter is consumed, we have to emit at +1.
3407
3415
if (param.isConsumed ()) {
3408
- return { SGFContext (), SGFContext () };
3416
+ return {SGFContext (), SGFContext (), requiresReabstraction };
3409
3417
}
3410
3418
3411
3419
// Otherwise, we can emit the final value at +0 (but only with a
@@ -3418,12 +3426,12 @@ namespace {
3418
3426
3419
3427
// If the r-value doesn't require reabstraction, the final context
3420
3428
// is the emission context.
3421
- if (loweredArgType. getSwiftRValueType () == param. getType () ) {
3422
- return { finalContext, SGFContext () };
3429
+ if (!requiresReabstraction ) {
3430
+ return {finalContext, SGFContext (), requiresReabstraction };
3423
3431
}
3424
3432
3425
3433
// Otherwise, the final context is the reabstraction context.
3426
- return { SGFContext (), finalContext };
3434
+ return {SGFContext (), finalContext, requiresReabstraction };
3427
3435
}
3428
3436
};
3429
3437
}
0 commit comments