-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Introduce return_borrow and unchecked_ownership instructions for use with borrow accessors #85040
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
Conversation
|
@swift-ci test |
d015bd1 to
c39967c
Compare
|
@swift-ci test |
c39967c to
a20983e
Compare
|
@swift-ci test |
a20983e to
32b64f7
Compare
|
@swift-ci test |
32b64f7 to
37c063b
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.
lgtm
|
@swift-ci smoke test macOS platform |
This instruction can be used to disable ownership verification on it's result and will be allowed only in raw SIL. Sometimes SILGen can produce invalid ownership SSA, that cannot be resolved until mandatory passes run. We have a few ways to piecewise disable verification. With unchecked_ownership instruction we can provide a uniform way to disable ownership verification for a value.
SILGen may produce a borrow accessor result from within a local borrow scope. Such as: ``` %ld = load_borrow %self %fwd = unchecked_ownership %ld %ex = struct_extract %fwd, #Struct.storedProperty end_borrow %ld return %ex ``` This is illegal OSSA, since the return uses a value outside it's borrow scope. Add a new SILGenCleanup transform, to turn this into valid OSSA: ``` %ld = load_borrow %self %ex = struct_extract %ld, #Struct.storedProperty return_borrow %ex from_scopes %ld ```
When return_borrow has both lifetime ending and non-lifetime ending use, consider it lifetime ending.
SILGen inserts mark_unresolved_noncopyable_value at the introducer in some cases and at uses in other cases. This inconsistency can causes insertion of a redundant mark* instruction which crashes the move-only checker. This change avoids inserting a redundant mark* instruction.
37c063b to
7c25466
Compare
|
@swift-ci smoke test |
|
@meg-gupta My one suggestion on
Obvious follow-up tasks? |
|
@atrick I'll follow up on comments and disabled cases. |
Currently borrow accessor SILGen uses
unchecked_ownership_conversioninstructions to produce a@guaranteedreturn value from an address in some cases:unchecked_ownership_conversionsilences the ownership verifier, but is an unsafe SIL operation which will get treated conservatively in the optimizer.Introduce a new
return_borrowinstruction and add a new SILGenCleanup transform, to turn this into valid OSSA:return_borrow generation becomes straightforward after the SILGen phase, introduce a raw SIL only -
unchecked_ownershipinstruction for SILGen which will get eliminated during SILGenCleanup.There are many different markers used today when we cannot resolve ownership right after SILGen. These markers are present until a mandatory pass resolves them.
unchecked_ownershipcan be used as a uniform marker for this purpose in the future.