@@ -902,13 +902,14 @@ void swift::emitDestroyOperation(SILBuilder &builder, SILLocation loc,
902
902
callbacks.createdNewInst (u.get <ReleaseValueInst *>());
903
903
}
904
904
905
- // *HEY YOU, YES YOU, PLEASE READ*. Even though a textual partial apply is
906
- // printed with the convention of the closed over function upon it, all
907
- // non-inout arguments to a partial_apply are passed at +1. This includes
908
- // arguments that will eventually be passed as guaranteed or in_guaranteed to
909
- // the closed over function. This is because the partial apply is building up a
910
- // boxed aggregate to send off to the closed over function. Of course when you
911
- // call the function, the proper conventions will be used.
905
+ // NOTE: The ownership of the partial_apply argument does not match the
906
+ // convention of the closed over function. All non-inout arguments to a
907
+ // partial_apply are passed at +1 for regular escaping closures and +0 for
908
+ // closures that have been promoted to partial_apply [on_stack]. An escaping
909
+ // partial apply stores each capture in an owned box, even for guaranteed and
910
+ // in_guaranteed argument convention. A non-escaping/on-stack closure either
911
+ // borrows its arguments or takes an inout_aliasable address. Non-escaping
912
+ // closures do not support owned arguments.
912
913
void swift::releasePartialApplyCapturedArg (SILBuilder &builder, SILLocation loc,
913
914
SILValue arg,
914
915
SILParameterInfo paramInfo,
@@ -1479,7 +1480,7 @@ swift::findLocalApplySites(FunctionRefBaseInst *fri) {
1479
1480
// / Insert destroys of captured arguments of partial_apply [stack].
1480
1481
void swift::insertDestroyOfCapturedArguments (
1481
1482
PartialApplyInst *pai, SILBuilder &builder,
1482
- llvm::function_ref<bool (SILValue)> shouldInsertDestroy ,
1483
+ llvm::function_ref<SILValue (SILValue)> getValueToDestroy ,
1483
1484
SILLocation origLoc) {
1484
1485
assert (pai->isOnStack ());
1485
1486
@@ -1488,27 +1489,25 @@ void swift::insertDestroyOfCapturedArguments(
1488
1489
pai->getModule ());
1489
1490
auto loc = CleanupLocation (origLoc);
1490
1491
for (auto &arg : pai->getArgumentOperands ()) {
1491
- SILValue argValue = arg.get ();
1492
- if (auto *m = dyn_cast<MoveOnlyWrapperToCopyableValueInst>(argValue))
1493
- if (m->hasGuaranteedInitialKind ())
1494
- argValue = m->getOperand ();
1495
- auto *argBorrow = dyn_cast<BeginBorrowInst>(argValue);
1496
- if (argBorrow) {
1497
- argValue = argBorrow->getOperand ();
1498
- builder.createEndBorrow (loc, argBorrow);
1499
- }
1500
- if (!shouldInsertDestroy (argValue))
1492
+ SILValue argValue = getValueToDestroy (arg.get ());
1493
+ if (!argValue)
1501
1494
continue ;
1495
+
1496
+ assert (!pai->getFunction ()->hasOwnership ()
1497
+ || (argValue->getOwnershipKind ().isCompatibleWith (
1498
+ OwnershipKind::Owned)));
1499
+
1502
1500
unsigned calleeArgumentIndex = site.getCalleeArgIndex (arg);
1503
1501
assert (calleeArgumentIndex >= calleeConv.getSILArgIndexOfFirstParam ());
1504
1502
auto paramInfo = calleeConv.getParamInfoForSILArg (calleeArgumentIndex);
1505
1503
releasePartialApplyCapturedArg (builder, loc, argValue, paramInfo);
1506
1504
}
1507
1505
}
1508
1506
1509
- void swift::insertDeallocOfCapturedArguments (PartialApplyInst *pai,
1510
- DominanceInfo *domInfo,
1511
- llvm::function_ref<bool (SILValue)> shouldInsertDestroy)
1507
+ void swift::insertDeallocOfCapturedArguments (
1508
+ PartialApplyInst *pai,
1509
+ DominanceInfo *domInfo,
1510
+ llvm::function_ref<SILValue(SILValue)> getAddressToDealloc)
1512
1511
{
1513
1512
assert (pai->isOnStack ());
1514
1513
@@ -1522,13 +1521,10 @@ void swift::insertDeallocOfCapturedArguments(PartialApplyInst *pai,
1522
1521
if (!paramInfo.isIndirectInGuaranteed ())
1523
1522
continue ;
1524
1523
1525
- SILValue argValue = arg.get ();
1526
- if (!shouldInsertDestroy ( argValue) ) {
1524
+ SILValue argValue = getAddressToDealloc ( arg.get () );
1525
+ if (!argValue) {
1527
1526
continue ;
1528
1527
}
1529
- if (auto moveWrapper =
1530
- dyn_cast<MoveOnlyWrapperToCopyableAddrInst>(argValue))
1531
- argValue = moveWrapper->getOperand ();
1532
1528
1533
1529
SmallVector<SILBasicBlock *, 4 > boundary;
1534
1530
auto *asi = cast<AllocStackInst>(argValue);
0 commit comments