Skip to content

[moveOnly] Add a semi-generic _copy function similar to the semi-generic _move #39984

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

The way this works is that:

  1. I added a new instruction called explicit_copy_value. From the perspective of Copy Propagation it is just a copy_value that it can not remove. This ensures that we have a way of explicitly forcing a copy of a value. After ownership is lowered, it just becomes a retain.
  2. I did the same trick that I did with _move to make this function able to be generically used only on values that are not address only (that is not generic or existential). We do this by allowing one level of specialization to occur. We error otherwise since to handle that other case we would need to support opaque values (which we do not yet).

NOTE: I also noted in a different PR I did not make _move public. I did this in this PR as well so we can get both of these operators together. Thanks to @glessard for helping me to catch that!

@gottesmm gottesmm requested a review from glessard October 29, 2021 20:35
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

…opy value.

The key thing is that the move checker will not consider the explicit copy value
to be a copy_value that can be rewritten, ensuring that any uses of the result
of the explicit copy_value (consuming or other wise) are not checked.

Similar to the _move operator I recently introduced, this is a transparent
function so we can perform one level of specialization and thus at least be
generic over all concrete types.
Just a thinko on my part.
@gottesmm gottesmm force-pushed the pr-135d6a4f34ad56ff7b7f978fdb5599412fd608c0 branch from 930a07e to 3a5049f Compare October 29, 2021 22:39
@gottesmm
Copy link
Contributor Author

Unhappily, I didn't clang-format this. So I just did that and now need to restart testing =---(.

@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

Copy link
Contributor

@glessard glessard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, though I am not so familiar with the SIL-related code.

@gottesmm gottesmm merged commit 3ea9e9e into swiftlang:main Oct 30, 2021
@gottesmm gottesmm deleted the pr-135d6a4f34ad56ff7b7f978fdb5599412fd608c0 branch October 30, 2021 02:26
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