Skip to content

Commit 445a654

Browse files
Merge pull request #67397 from nate-chandler/opaque-values/20230719/1/emit_end_borrows/begin_apply
[AddressLowering] End borrow scopes for begin_apply at coro endpoints.
2 parents 67e919f + d98994e commit 445a654

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

include/swift/SIL/OwnershipUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ struct BorrowedValue {
580580
/// instructions and pass them individually to visitor. Asserts if this is
581581
/// called with a scope that is not local.
582582
///
583-
/// Returns false and early exist if \p visitor returns false.
583+
/// Returns false and exits early if \p visitor returns false.
584584
///
585585
/// The intention is that this method can be used instead of
586586
/// BorrowScopeIntroducingValue::getLocalScopeEndingUses() to avoid

lib/SILOptimizer/Mandatory/AddressLowering.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2255,7 +2255,7 @@ void ApplyRewriter::rewriteApply(ArrayRef<SILValue> newCallArgs) {
22552255
// will be deleted with its destructure_tuple.
22562256
}
22572257

2258-
/// Emit end_borrows for a an incomplete BorrowedValue with only nonlifetime
2258+
/// Emit end_borrows for an incomplete BorrowedValue with only nonlifetime
22592259
/// ending uses.
22602260
static void emitEndBorrows(SILValue value, AddressLoweringState &pass);
22612261

@@ -2332,7 +2332,10 @@ void ApplyRewriter::convertBeginApplyWithOpaqueYield() {
23322332
SILValue load =
23332333
resultBuilder.emitLoadBorrowOperation(callLoc, &newResult);
23342334
oldResult.replaceAllUsesWith(load);
2335-
emitEndBorrows(load, pass);
2335+
for (auto *user : origCall->getTokenResult()->getUsers()) {
2336+
pass.getBuilder(user->getIterator())
2337+
.createEndBorrow(pass.genLoc(), load);
2338+
}
23362339
} else {
23372340
auto *load = resultBuilder.createTrivialLoadOr(
23382341
callLoc, &newResult, LoadOwnershipQualifier::Take);

test/SILOptimizer/address_lowering.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1590,8 +1590,8 @@ entry:
15901590
// CHECK: ([[ADDR_1:%[^,]+]], [[ADDR_2:%[^,]+]], {{%[^,]+}}) = begin_apply
15911591
// CHECK: [[BORROW_1:%[^,]+]] = load_borrow [[ADDR_1]] : $*LoadableNontrivial
15921592
// CHECK: struct_extract [[BORROW_1]] : $LoadableNontrivial, #LoadableNontrivial.x
1593-
// CHECK: end_borrow [[BORROW_1]] : $LoadableNontrivial
15941593
// CHECK: copy_addr [[ADDR_2]] to [init] [[OPAQUE_OUT]] : $*T
1594+
// CHECK: end_borrow [[BORROW_1]] : $LoadableNontrivial
15951595
// CHECK-LABEL: } // end sil function 'testBeginApply9Yield1LoadableNontrivialGuaranteed1OpaqueGuaranteed'
15961596
sil [ossa] @testBeginApply9Yield1LoadableNontrivialGuaranteed1OpaqueGuaranteed : $@convention(thin) <T> () -> (@out Klass, @out T) {
15971597
entry:

0 commit comments

Comments
 (0)