Skip to content

[move-only-addresses] Slicing some patches off of the larger patch. #60511

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

gottesmm
Copy link
Contributor

In this PR, I am just slicing off some work from the larger series of address move only patches that I am preparing. Specifically this:

  1. Teaches the SILVerifier that like copy_value, load [copy] and copy_addr [init] can not be used on move only typed values once we are in canonical SIL.
  2. It adds a new SIL instruction called explicit_copy_addr. This is exactly like copy_addr except that one /can/ use it to copy move only values once we are in canonical SIL. It has two uses: to enable us to implement explicit copy for no implicit copy addresses and to enable the move checker to transform copy_addr that it cannot eliminate into explicit_copy_addr so that we still produce valid SIL when we emit an error. NOTE: We don't need this for load [copy], since we can just transform the load [copy] into a load_borrow + explicit_copy_value.
  3. Since I added docs to SIL.rst for explicit_copy_addr, I decided to clean up the SIL.rst docs around explicit_copy_value/copy_value.
  4. With all that together I added a small very preliminary section to SIL.rst about move only types and their restriction around copy_value/copy_addr/load [copy] and how one can use the explicit variants when appropriate [see point 2 above].

…init]/load [copy] on move only values in Raw SIL.

This is already an invariant for copy_value and now that I am implementing move
semantics for addresses, it makes sense to ban those in a similar
way. Specifically, we are enforcing the invariant that move only types are
allowed to be copied in Raw SIL, but not in later parts of SIL. For those who
are unaware, we then run checkers later to validate that we preserve ownership
semantics.
…w SIL, but not in later SIL stages.

Since I am going to start enforcing this invariant more broadly, I want to
document it in SIL.rst. I also included a discussion explaining why we maintain
this invariant: it enables SILGen to use a simple algorithm to insert copies/us
to clean that up using a diagnostic guaranteed optimization pass which runs on
Raw SIL.
…ve copy_value a move only value as an operand.

I am enforcing this in the verifier, so it makes sense to document in SIL.rst.
There really isn't a point in repeating the verbage from copy_value. So I
removed that and just referred back to the copy_value documentation and focused
instead on what makes explicit_copy_value different semantically from
copy_value, how it is used to work around the invariant in Canonical SIL that
move only typed values can not be copied. This is useful for:

1. Implementing an explicit copy for no implicit copy types.

2. When the move checker errors since it can't produce a move only solution for
a value, we change all of the copies into explicit_copy_value. We need some sort
of copy to ensure later once we are in Canonical SIL, Ownership SSA is correct
/and/ we maintain the no copy of move only typed values in Canonical SIL.
This is exactly like copy_addr except that it is not viewed from the verifiers
perspective as an "invalid" copy of a move only value. It is intended to be used
in two contexts:

1. When the move checker emits a diagnostic since it could not eliminate a copy,
we still need to produce valid SIL without copy_addr on move only types since we
will hit canonical SIL eventually even if we don't actually codegen the SIL. The
pass can just convert said copy_addr to explicit_copy_addr and everyone is
happy.

2. To implement the explicit copy function for address only types.
@gottesmm gottesmm force-pushed the pr-0796eed23b86f5812f817b15b928dbe11485c361 branch from 32d72c7 to 5baf2af Compare August 11, 2022 18:41
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm gottesmm merged commit accc282 into swiftlang:main Aug 11, 2022
@gottesmm gottesmm deleted the pr-0796eed23b86f5812f817b15b928dbe11485c361 branch August 11, 2022 23:25
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.

1 participant