-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Extend borrow accessor support #84595
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@swift-ci test |
cab01cf
to
4f1bfb2
Compare
@swift-ci test |
16715ad
to
01c03a7
Compare
@swift-ci test |
01c03a7
to
8efa0ab
Compare
@swift-ci test |
Also add forGuaranteedAddressReturn
Introduce copy_value + mark_unresolved_non_copyable_value + begin_borrow at the return value of borrow accessor apply to drive move-only diagnostics. Also strip the copy_value + mark_unresolved_non_copyable_value + begin_borrow trio in a few places, since they create an artificial scope out of which we cannot return values in a borrow accessor without resorting to unsafe SIL operations currently. Borrow accessor diagnostics allow stripping these instructions safely in the following places: - return value of a borrow accessor - self argument reference in the borrow accessor return expression and borrow accessor apply
It can be used in borrow/mutate accessors to unsafely specify that the result is dependent on the self access.
Under library evolution, loadable self arguments are passed as @in_guaranteed. SILGen generates load_borrow for such self arguments proactively. load_borrow creates an artifical scope and returning values produced within this scope will be illegal without resorting to unsafe operations today. This change avoids creating a load_borrow proactively for borrow accessors.
…n a local borrow Borrow accessor result can sometimes be generated from a local borrow and returning the result produced within the local borrow scope will cause ownership errors. We have to introduce new SIL semantics to make this possible. Until then use a pair of unchecked_ownership_conversion instructions to silence the ownership errors. We encounter this when we have: Address-only self and @guaranteed result Loadable self and @guaranteed result derived from an unsafe pointer stored property This change also updates the result convention of borrow accessors with loadable result types and indirect self argument type.
8efa0ab
to
3d74cf4
Compare
@swift-ci test |
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.
IRGen looks good to me.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds IRGen support and enables writing borrow accessors for ~Copyable types and library evolution.
It also introduces interim
@_unsafeSelfDependentResult
attribute to enable writing borrow accessors for unsafe pointer based containers.Borrow accessor result can sometimes be generated from a local borrow and returning the result produced within the
local borrow scope will cause ownership errors. This PR works around this issue for ~Copyable types and library evolution. But for nested borrow accessors that return
@guaranteed
values with an@in_guaranteed
self, I introduce a pair ofunchecked_ownership_conversion
instructions to silence the ownership errors. This is needed until we define new SIL semantics that allows returning values produced within local borrow scopes in borrow accessors.