-
Notifications
You must be signed in to change notification settings - Fork 10.5k
SIL: Treat store_borrow as borrowing its source, and have the move-only checker account for borrow scopes. #69169
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
SIL: Treat store_borrow as borrowing its source, and have the move-only checker account for borrow scopes. #69169
Conversation
@swift-ci Please test |
auto *nextInst = inst->getNextInstruction(); | ||
LLVM_DEBUG(llvm::dbgs() << "ending after momentary use\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you forgot to delete code here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks reasonable to me
@@ -159,7 +167,7 @@ bool CanonicalizeOSSALifetime::computeCanonicalLiveness() { | |||
continue; | |||
} | |||
} | |||
switch (use->getOperandOwnership()) { | |||
switch (auto ownership = use->getOperandOwnership()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I didn't know this pattern worked. Where are you using the value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was going to use it in the debug message below, but I forgot to. I can remove it.
LLVM_DEBUG(llvm::dbgs() << " Canonicalizing: " << currentDef); | ||
|
||
if (currentDef->getOwnershipKind() != OwnershipKind::Owned) { | ||
LLVM_DEBUG(llvm::dbgs() << " not owned, never mind\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you need to git-clang-format the patch. This needs indentation.
Function call arguments were not being treated as liveness uses. Unblocks SIL: Treat store_borrow as borrowing its source, and have the move-only checker account for borrow scopes. swiftlang#69169 swiftlang#69169
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome!
// to extend the lifetime of a strong reference being assigned into a weak | ||
// reference. | ||
// | ||
// REQUIRES: further_investigation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't mind waiting for #69184 to land, you can keep the diagnose_lifetime_issues test enabled.
…ly checker account for borrow scopes. When rewriting uses of a noncopyable value, the move-only checker failed to take into account the scope of borrowing uses when establishing the final lifetimes of values. One way this manifested was when borrowed values get reabstracted from value to in-memory representations, using a store_borrow instruction, the lifetime of the original borrow would be ended immediately after the store_borrow begins rather than after the matching end_borrow. Fix this by, first, changing `store_borrow` to be treated as a borrowing use of its source rather than an interior-pointer use; this should be more accurate overall since `store_borrow` borrows the entire source value for a well-scoped duration balanced by `end_borrow` instructions. That done, change MoveOnlyBorrowToDestructureUtils so that when it sees a borrow use, it ends the borrow at the end(s) of the use's borrow scope, instead of immediately after the beginning of the use.
8f5afb6
to
1dcf271
Compare
@swift-ci Please test |
Function call arguments were not being treated as liveness uses. Unblocks SIL: Treat store_borrow as borrowing its source, and have the move-only checker account for borrow scopes. swiftlang#69169 swiftlang#69169
When rewriting uses of a noncopyable value, the move-only checker failed to take into account the scope of borrowing uses when establishing the final lifetimes of values. One way this manifested was when borrowed values get reabstracted from value to in-memory representations, using a store_borrow instruction, the lifetime of the original borrow would be ended immediately after the store_borrow begins rather than after the matching end_borrow. Fix this by, first, changing
store_borrow
to be treated as a borrowing use of its source rather than an interior-pointer use; this should be more accurate overall sincestore_borrow
borrows the entire source value for a well-scoped duration balanced byend_borrow
instructions. That done, change MoveOnlyBorrowToDestructureUtils so that when it sees a borrow use, it ends the borrow at the end(s) of the use's borrow scope, instead of immediately after the beginning of the use.