Skip to content

[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

Merged

Conversation

jckarter
Copy link
Contributor

@jckarter jckarter commented Oct 19, 2023

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

…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.
@jckarter
Copy link
Contributor Author

@swift-ci Please test

atrick and others added 2 commits October 19, 2023 16:51
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
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter jckarter marked this pull request as ready for review October 19, 2023 23:55
@jckarter jckarter requested a review from a team as a code owner October 19, 2023 23:55
@@ -725,6 +725,9 @@ static SILValue tryRewriteToPartialApplyStack(

SmallSetVector<SILValue, 4> borrowedOriginals;

unsigned appliedArgStartIdx =
Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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)

@jckarter jckarter merged commit 451489d into swiftlang:release/5.10 Oct 20, 2023
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.

4 participants