Skip to content

Commit a78bb3d

Browse files
committed
Instead of just fixing the ClosureLifetimeFixup change releasePartialApplyCapturedArg to handle undef captures
1 parent 7d09aee commit a78bb3d

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

lib/SILOptimizer/Mandatory/ClosureLifetimeFixup.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -458,9 +458,6 @@ static bool tryRewriteToPartialApplyStack(
458458
saveDeleteInst(convertOrPartialApply);
459459
saveDeleteInst(origPA);
460460

461-
// Only insert destroys for defined partial_apply arguments.
462-
auto isDefined = [](SILValue arg) -> bool { return !isa<SILUndef>(arg); };
463-
464461
// Insert destroys of arguments after the apply and the dealloc_stack.
465462
if (auto *apply = dyn_cast<ApplyInst>(singleApplyUser)) {
466463
auto insertPt = std::next(SILBasicBlock::iterator(apply));
@@ -469,12 +466,12 @@ static bool tryRewriteToPartialApplyStack(
469466
return true;
470467
SILBuilderWithScope b3(insertPt);
471468
b3.createDeallocStack(loc, newPA);
472-
insertDestroyOfCapturedArguments(newPA, b3, isDefined);
469+
insertDestroyOfCapturedArguments(newPA, b3);
473470
} else if (auto *tai = dyn_cast<TryApplyInst>(singleApplyUser)) {
474471
for (auto *succBB : tai->getSuccessorBlocks()) {
475472
SILBuilderWithScope b3(succBB->begin());
476473
b3.createDeallocStack(loc, newPA);
477-
insertDestroyOfCapturedArguments(newPA, b3, isDefined);
474+
insertDestroyOfCapturedArguments(newPA, b3);
478475
}
479476
} else {
480477
llvm_unreachable("Unknown FullApplySite instruction kind");

lib/SILOptimizer/Utils/InstOptUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,7 @@ void swift::releasePartialApplyCapturedArg(SILBuilder &builder, SILLocation loc,
10201020
// possible for that value.
10211021

10221022
// If we have qualified ownership, we should just emit a destroy value.
1023-
if (arg->getFunction()->hasOwnership()) {
1023+
if (builder.getFunction().hasOwnership()) {
10241024
callbacks.createdNewInst(builder.createDestroyValue(loc, arg));
10251025
return;
10261026
}

0 commit comments

Comments
 (0)