Skip to content

Commit 3a35fd4

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-next
2 parents b7eb3bf + 07c7b5a commit 3a35fd4

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

lib/SILGen/SILGenApply.cpp

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

3791+
// Make sure that upcasted self is at +1 since we are going to place it into a
3792+
// partial_apply.
3793+
upcastedSelf = upcastedSelf.ensurePlusOne(SGF, loc);
3794+
37913795
auto constantInfo = SGF.getConstantInfo(callee.getMethodName());
37923796
auto functionTy = constantInfo.getSILType();
37933797
ManagedValue superMethod;
@@ -3813,11 +3817,9 @@ CallEmission::applyPartiallyAppliedSuperMethod(SGFContext C) {
38133817
if (constantInfo.SILFnType->isPolymorphic() && !subs.empty())
38143818
partialApplyTy = partialApplyTy.substGenericArgs(module, subs);
38153819

3816-
SILValue partialApply =
3817-
SGF.B.createPartialApply(loc, superMethod.getValue(), partialApplyTy,
3818-
subs, {upcastedSelf.forward(SGF)}, closureTy);
3820+
ManagedValue pa = SGF.B.createPartialApply(loc, superMethod, partialApplyTy,
3821+
subs, {upcastedSelf}, closureTy);
38193822
assert(!closureTy.castTo<SILFunctionType>()->isNoEscape());
3820-
ManagedValue pa = SGF.emitManagedRValueWithCleanup(partialApply);
38213823
firstLevelResult.value = RValue(SGF, loc, formalApplyType.getResult(), pa);
38223824
return firstLevelResult;
38233825
}

lib/SILGen/SILGenBridging.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -801,19 +801,31 @@ static void buildBlockToFuncThunkBody(SILGenFunction &SGF,
801801
assert(formalBlockParams.size() == blockTy->getNumParameters());
802802
assert(formalFuncParams.size() == funcTy->getNumParameters());
803803

804+
// Create the arguments for the call.
804805
for (unsigned i : indices(funcTy->getParameters())) {
805806
auto &param = funcTy->getParameters()[i];
806807
CanType formalBlockParamTy = formalBlockParams[i];
807808
CanType formalFuncParamTy = formalFuncParams[i];
808809

809810
auto paramTy = fnConv.getSILType(param);
810811
SILValue v = entry->createFunctionArgument(paramTy);
812+
813+
// First get the managed parameter for this function.
811814
auto mv = emitManagedParameter(SGF, loc, param, v);
812815

813816
SILType loweredBlockArgTy = blockTy->getParameters()[i].getSILStorageType();
814-
args.push_back(SGF.emitNativeToBridgedValue(loc, mv, formalFuncParamTy,
815-
formalBlockParamTy,
816-
loweredBlockArgTy));
817+
818+
// Then bridge the native value to its bridged variant.
819+
mv = SGF.emitNativeToBridgedValue(loc, mv, formalFuncParamTy,
820+
formalBlockParamTy, loweredBlockArgTy);
821+
822+
// Finally change ownership if we need to. We do not need to care about the
823+
// case of a +1 parameter being passed to a +0 function since +1 parameters
824+
// can be "instantaneously" borrowed at the call site.
825+
if (blockTy->getParameters()[i].isConsumed()) {
826+
mv = mv.ensurePlusOne(SGF, loc);
827+
}
828+
args.push_back(mv);
817829
}
818830

819831
// Add the block argument.

lib/SILGen/SILGenConvert.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ SILGenFunction::emitOptionalToOptional(SILLocation loc,
369369
auto isNotPresentBB = createBasicBlock();
370370
auto isPresentBB = createBasicBlock();
371371

372+
// All conversions happen at +1.
373+
input = input.ensurePlusOne(*this, loc);
374+
372375
SwitchEnumBuilder SEBuilder(B, loc, input);
373376
SILType noOptResultTy = resultTy.getOptionalObjectType();
374377
assert(noOptResultTy);

0 commit comments

Comments
 (0)