Skip to content

Commit 8972d62

Browse files
committed
[CoroutineAccessors] Don't observe caller errors.
Experience with `_modify`/`_read` has shown that it is never desireable to cleanup differently based on whether the caller has thrown. Emit an `end_apply` in either case.
1 parent df1c4f6 commit 8972d62

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4989,7 +4989,11 @@ class EndCoroutineApply : public Cleanup {
49894989
SGF.B.createEndBorrow(l, *i);
49904990
SGF.B.createDestroyValue(l, (*i)->getOperand());
49914991
}
4992-
if (forUnwind) {
4992+
auto *beginApply =
4993+
cast<BeginApplyInst>(ApplyToken->getDefiningInstruction());
4994+
auto isCalleeAllocated = beginApply->isCalleeAllocated();
4995+
auto unwindOnCallerError = !isCalleeAllocated;
4996+
if (forUnwind && unwindOnCallerError) {
49934997
SGF.B.createAbortApply(l, ApplyToken);
49944998
} else {
49954999
SGF.B.createEndApply(l, ApplyToken,

test/SILGen/coroutine_accessors.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public var irm: Int {
115115
// CHECK: dealloc_stack [[OLD_VALUE_ADDR]]
116116
// CHECK: return [[OLD_VALUE]]
117117
// CHECK: bb2([[ERROR:%[^,]+]] : @owned $any Error):
118-
// CHECK: abort_apply [[TOKEN]]
118+
// CHECK: end_apply [[TOKEN]]
119119
// CHECK: end_access [[SELF_ACCESS]]
120120
// CHECK: dealloc_stack [[NEW_VALUE_ADDR]]
121121
// CHECK: dealloc_stack [[OLD_VALUE_ADDR]]

0 commit comments

Comments
 (0)