Skip to content

[move-only] Address Only Patches #65604

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 10 commits into from
May 4, 2023
Merged

Conversation

gottesmm
Copy link
Contributor

@gottesmm gottesmm commented May 2, 2023

NOTE: In the following when I refer to an address only move only type, I am not referring to a generic type that is move only, instead I am referring to a concrete move only type that is generic over a copyable type T and contains that copyable type T as a field.

This PR contains a few changes needed for address only move only types.

Specifically:

  1. This fixes SILGenProlog so arguments are handled correctly.
  2. This changes the move checker so that if one uses an address only copyable type that is stored within a move only type, it is not considered to be a consume of the move only type.
  3. It changes SILGenLValue so that we do not emit redundant mark_must_check if we are emitting an rvalue access to an address only. move only function argument.
  4. It teaches the compiler how to properly check address only move only types.
  5. It adds a bunch of tests both for address only move only types and also for some other cases that I noticed we did not have enough tests for.

rdar://105106470

gottesmm added 9 commits May 2, 2023 16:30
Specifically, I changed emitRValueForDecl and SILGenProlog to do the right
thing. I also added some tests.

Some notes:

1. We currently consider using a copyable field of a move only address type to
be a consume of that type. I am going to fix that in the next commit to make it
easier to understand.

2. I am going to need to write more tests/flesh out the behavior more. I am sure
there is more here.

rdar://105106470
…ess only type as consuming the address only type.

rdar://105106470
…only type used by escaping closures.

When we have a loadable type, SILGen always eagerly loads the value, so the move
checker handled checking those cases by just looking for loads and emitting the
error based off of a load. Of course for address only types, the codegen looks
slightly different (we consume the value directly rather than load it). So this
change just teaches the checker how to do that.

rdar://105106470
This just creates a new SILUndef with the same type as the SILValue. This just
prevents one from having to write
SILUndef::get(value->getType(), *value->getModule()).
It was actually testing that we properly handle something related to debug info.
With subsequent changes, this causes a crash since it doesn't match the expected
output.
…nd fields of an address only move only type correctly.
@gottesmm gottesmm requested a review from jckarter May 2, 2023 23:30
@gottesmm gottesmm force-pushed the address-only-stuff branch from 42f0531 to e4cdc66 Compare May 2, 2023 23:30
@gottesmm
Copy link
Contributor Author

gottesmm commented May 3, 2023

@swift-ci test

… form.

For some reason in a previous commit, this started to work so I just added
support. In this PR, it changed again and the test started to fail again. We are
not shipping noimplicitcopy in 5.9, so I just changed the error message to the
old "I don't understand" error message.

I additionally looked at why the failure is occuring. The reason why is that the
frontend emits an unchecked_ref_cast since currently the
moveonlywrapper_to_copyable instruction does not accept addresses (even though
it could) and the field sensitive liveness analysis does not know how to
represent an unchecked_ref_cast (which is ok, since we would like it to be
rejected).
@gottesmm
Copy link
Contributor Author

gottesmm commented May 3, 2023

@swift-ci smoke test

@gottesmm gottesmm merged commit e1f2a20 into swiftlang:main May 4, 2023
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