Skip to content

Commit bd49107

Browse files
author
Joe Shajrawi
authored
Merge pull request #5405 from shajrawi/contexts_reabstraction
add requiresReabstraction flag / check(s) to RValueEmission
2 parents 082103f + 8f634f2 commit bd49107

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3039,7 +3039,7 @@ namespace {
30393039
auto contexts = getRValueEmissionContexts(loweredSubstArgType, param);
30403040

30413041
// If no abstraction is required, try to honor the emission contexts.
3042-
if (loweredSubstArgType.getSwiftRValueType() == param.getType()) {
3042+
if (!contexts.RequiresReabstraction) {
30433043
auto loc = arg.getLocation();
30443044
ManagedValue result =
30453045
std::move(arg).getAsSingleValue(SGF, contexts.ForEmission);
@@ -3117,16 +3117,20 @@ namespace {
31173117
AbstractionPattern origParamType,
31183118
SILParameterInfo param) {
31193119
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);
31303134
}
31313135
Args.push_back(value);
31323136
}
@@ -3400,12 +3404,16 @@ namespace {
34003404
SGFContext ForEmission;
34013405
/// The context for reabstracting the r-value.
34023406
SGFContext ForReabstraction;
3407+
/// If the context requires reabstraction
3408+
bool RequiresReabstraction;
34033409
};
34043410
static EmissionContexts getRValueEmissionContexts(SILType loweredArgType,
34053411
SILParameterInfo param) {
3412+
bool requiresReabstraction =
3413+
loweredArgType.getSwiftRValueType() != param.getType();
34063414
// If the parameter is consumed, we have to emit at +1.
34073415
if (param.isConsumed()) {
3408-
return { SGFContext(), SGFContext() };
3416+
return {SGFContext(), SGFContext(), requiresReabstraction};
34093417
}
34103418

34113419
// Otherwise, we can emit the final value at +0 (but only with a
@@ -3418,12 +3426,12 @@ namespace {
34183426

34193427
// If the r-value doesn't require reabstraction, the final context
34203428
// is the emission context.
3421-
if (loweredArgType.getSwiftRValueType() == param.getType()) {
3422-
return { finalContext, SGFContext() };
3429+
if (!requiresReabstraction) {
3430+
return {finalContext, SGFContext(), requiresReabstraction};
34233431
}
34243432

34253433
// Otherwise, the final context is the reabstraction context.
3426-
return { SGFContext(), finalContext };
3434+
return {SGFContext(), finalContext, requiresReabstraction};
34273435
}
34283436
};
34293437
}

0 commit comments

Comments
 (0)