-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[5.10] Enable noncopyable resilient types. #69287
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
[5.10] Enable noncopyable resilient types. #69287
Conversation
…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.
When deciding whether to clean up copies of noncopyable captures, I got the parameter indexing wrong when the closure has non-capture arguments. Fixing this allows noncopyable captures to work in more general circumstances.
If SILGen emitted a marker, that ought to be indication enough that move only checking is necessary.
… base from loadable to in-memory. The code here was materializing the value in this case, but then re-loading it, which is unnecessary since call emission will materialize the value to match the callee's calling convention already. It does look like a copy into formal evaluation scope is necessary to get the correct lifetimes in some circumstances. The move-only checker doesn't like any additional copies at all because it thinks they're consumes, so only borrow in the case where the value is move-only.
@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
@swift-ci Please test |
@@ -725,6 +725,9 @@ static SILValue tryRewriteToPartialApplyStack( | |||
|
|||
SmallSetVector<SILValue, 4> borrowedOriginals; | |||
|
|||
unsigned appliedArgStartIdx = |
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 wouldn't fix this in this commit, but I think this is automatically fixed for you if you use callee conventions.
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.
Sorry, the API is actually on ApplySite.
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.
It's somewhere around here: https://github.com/apple/swift/blob/main/include/swift/SIL/ApplySite.h#L341. If there isn't an exact one for what you need, I would add it here. We do not want people to muck around with indices for partial apply since it is pretty easy to mess up (as you see here)
This PR cherry picks a bunch of fixes that affect the use of resilient noncopyable types:
#69169
#69184
#69191
#69263
#69281
• Explanation: Enables noncopyable resilient types, and fixes a number of bugs that would lead to incorrect errors when attempting to define noncopyable resilient types and use them within their defining module.
• Scope of Issue: New feature.
• Origination: Feature work to complete SE-390.
• Risk: Low. The bug fixes should largely only affect code that adopts noncopyable types.
• Reviewed By: TBD
rdar://117023457