Skip to content

Conversation

@jckarter
Copy link
Contributor

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.

@jckarter jckarter requested review from atrick and gottesmm October 13, 2023 16:49
@jckarter
Copy link
Contributor Author

@swift-ci Please test

Copy link
Contributor

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.

Copy link
Contributor

@gottesmm gottesmm left a 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

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

atrick added a commit to atrick/swift that referenced this pull request Oct 14, 2023
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
Copy link
Contributor

@atrick atrick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Copy link
Contributor

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.
@jckarter jckarter force-pushed the store-borrow-lifetime-nesting branch from 8f5afb6 to 1dcf271 Compare October 16, 2023 16:12
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter jckarter merged commit 25061fb into swiftlang:main Oct 16, 2023
jckarter pushed a commit to jckarter/swift that referenced this pull request Oct 19, 2023
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants