Skip to content

[AddressLowering] End borrow scopes for begin_apply at coro endpoints. #67397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/SIL/OwnershipUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ struct BorrowedValue {
/// instructions and pass them individually to visitor. Asserts if this is
/// called with a scope that is not local.
///
/// Returns false and early exist if \p visitor returns false.
/// Returns false and exits early if \p visitor returns false.
///
/// The intention is that this method can be used instead of
/// BorrowScopeIntroducingValue::getLocalScopeEndingUses() to avoid
Expand Down
7 changes: 5 additions & 2 deletions lib/SILOptimizer/Mandatory/AddressLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2255,7 +2255,7 @@ void ApplyRewriter::rewriteApply(ArrayRef<SILValue> newCallArgs) {
// will be deleted with its destructure_tuple.
}

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

Expand Down Expand Up @@ -2332,7 +2332,10 @@ void ApplyRewriter::convertBeginApplyWithOpaqueYield() {
SILValue load =
resultBuilder.emitLoadBorrowOperation(callLoc, &newResult);
oldResult.replaceAllUsesWith(load);
emitEndBorrows(load, pass);
for (auto *user : origCall->getTokenResult()->getUsers()) {
pass.getBuilder(user->getIterator())
.createEndBorrow(pass.genLoc(), load);
}
} else {
auto *load = resultBuilder.createTrivialLoadOr(
callLoc, &newResult, LoadOwnershipQualifier::Take);
Expand Down
2 changes: 1 addition & 1 deletion test/SILOptimizer/address_lowering.sil
Original file line number Diff line number Diff line change
Expand Up @@ -1590,8 +1590,8 @@ entry:
// CHECK: ([[ADDR_1:%[^,]+]], [[ADDR_2:%[^,]+]], {{%[^,]+}}) = begin_apply
// CHECK: [[BORROW_1:%[^,]+]] = load_borrow [[ADDR_1]] : $*LoadableNontrivial
// CHECK: struct_extract [[BORROW_1]] : $LoadableNontrivial, #LoadableNontrivial.x
// CHECK: end_borrow [[BORROW_1]] : $LoadableNontrivial
// CHECK: copy_addr [[ADDR_2]] to [init] [[OPAQUE_OUT]] : $*T
// CHECK: end_borrow [[BORROW_1]] : $LoadableNontrivial
// CHECK-LABEL: } // end sil function 'testBeginApply9Yield1LoadableNontrivialGuaranteed1OpaqueGuaranteed'
sil [ossa] @testBeginApply9Yield1LoadableNontrivialGuaranteed1OpaqueGuaranteed : $@convention(thin) <T> () -> (@out Klass, @out T) {
entry:
Expand Down