Skip to content

Commit dc56ec1

Browse files
committed
[+0-normal-args] When partially applying a super method, be sure that upcasted self is at +1.
Since I used ensurePlusOne, this should not have any effect on the compiler today. This happens quite often once "normal arguments" are at +0 though. I also changed this code to use SILGenBuilder APIs to ensure that ownership is forwarded correctly. Found when updating SILGen tests for +0. rdar://34222540
1 parent 251093e commit dc56ec1

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4095,6 +4095,10 @@ CallEmission::applyPartiallyAppliedSuperMethod(SGFContext C) {
40954095
auto subs = callee.getSubstitutions();
40964096
auto upcastedSelf = uncurriedArgs.back();
40974097

4098+
// Make sure that upcasted self is at +1 since we are going to place it into a
4099+
// partial_apply.
4100+
upcastedSelf = upcastedSelf.ensurePlusOne(SGF, loc);
4101+
40984102
auto constantInfo = SGF.getConstantInfo(callee.getMethodName());
40994103
auto functionTy = constantInfo.getSILType();
41004104
ManagedValue superMethod;
@@ -4120,11 +4124,9 @@ CallEmission::applyPartiallyAppliedSuperMethod(SGFContext C) {
41204124
if (constantInfo.SILFnType->isPolymorphic() && !subs.empty())
41214125
partialApplyTy = partialApplyTy.substGenericArgs(module, subs);
41224126

4123-
SILValue partialApply =
4124-
SGF.B.createPartialApply(loc, superMethod.getValue(), partialApplyTy,
4125-
subs, {upcastedSelf.forward(SGF)}, closureTy);
4127+
ManagedValue pa = SGF.B.createPartialApply(loc, superMethod, partialApplyTy,
4128+
subs, {upcastedSelf}, closureTy);
41264129
assert(!closureTy.castTo<SILFunctionType>()->isNoEscape());
4127-
ManagedValue pa = SGF.emitManagedRValueWithCleanup(partialApply);
41284130
firstLevelResult.value = RValue(SGF, loc, formalApplyType.getResult(), pa);
41294131
return firstLevelResult;
41304132
}

0 commit comments

Comments
 (0)