Skip to content

[SIL] Represent copies to @sil_unowned values. #67722

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

nate-chandler
Copy link
Contributor

@nate-chandler nate-chandler commented Aug 3, 2023

Based on #67690 . Adds four commits.

Introduce the instructions unowned_copy_value. The effect of unowned_copy_value %o : $T is to increment the unowned reference count of the instance %o of the reference type T.

AddressLowering transforms as follows:

  • strong_copy_unowned_value -> load_unowned
  • unowned_copy_value -> store_unowned

@nate-chandler nate-chandler changed the title [SIL] Represent copies to and from @sil_unowned values. [SIL] Represent copies to @sil_unowned values. Aug 3, 2023
@nate-chandler nate-chandler force-pushed the opaque-values/1/20230803/unowned-copies branch 3 times, most recently from b00ccb1 to 7477911 Compare August 4, 2023 20:26
The new instruction unwraps an `@sil_weak` box and produces an owned
value. It is only legal in opaque values mode and is transformed by
`AddressLowering` to `load_weak`.
The new instruction wraps a value in a `@sil_weak` box and produces an
owned value. It is only legal in opaque values mode and is transformed
by `AddressLowering` to `store_weak`.
Lower the `strong_copy_weak_value` and `weak_copy_value` to `load_weak`
and `store_weak` respectively.
In opaque values mode, emit the new weak copy instructions to convert as
follows:

strong_copy_weak_value: `@owned $sil_weak T?` -> `@owned $T?`
weak_copy_value: `@owned $T?` -> `@owned $@sil_weak T?`

Doing so is necessary in opaque values mode where it is needed to deal
with weak values directly rather than indirectly via `load_weak`s and
`store_weak`s.
The ref_to_* and *_to_ref instructions must not produce or take as their
operands values of address-only type.  The AddressLowering pass would
trap on encountering such illegal instructions already.  Enforce the
invariant in the verifier.
Lower the `strong_copy_unowned_value` and `unowned_copy_value` to
`load_unowned` and `store_unowned` respectively.
In opaque values mode, emit the unowned copy instructions to convert as
follows:

strong_copy_unowned_value: `@owned $sil_unowned T` -> `@owned $T`
unowned_copy_value: `@owned T` -> `@owned $sil_unowned T`

Doing so is necessary in opaque values mode where it is needed to deal
with unowned values directly rather than indirectly via `load_unowned`s
and `store_unowned`s.
@nate-chandler nate-chandler force-pushed the opaque-values/1/20230803/unowned-copies branch from 7477911 to ded4d32 Compare August 8, 2023 22:49
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.

Looks all the reference types have been covered!

@nate-chandler
Copy link
Contributor Author

@swift-ci please test

@nate-chandler nate-chandler merged commit 1791108 into swiftlang:main Aug 9, 2023
@nate-chandler nate-chandler deleted the opaque-values/1/20230803/unowned-copies branch August 9, 2023 13:59
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.

2 participants