Skip to content

[move-only] Implement very initial work for move only #60187

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 3 commits into from
Jul 22, 2022

Conversation

gottesmm
Copy link
Contributor

I need to add more tests/expand it to more of SILGen. But for today, this is enough to get started/be incremental. Of course this is behind the experimental move only flag.

gottesmm added 3 commits July 21, 2022 15:33
…ve only type".

I also created a SILType::isMoveOnly() helper that returns true if a type is
a move only wrapped type or a first class move only type. The verifier check
that move only types aren't copied in canonical SIL was rewired to use that as well.
This is just the very beginning... I still need to implement more parts of
SILGen for this. But all great things start small. I am going to iterate on top
of this and just wanted to get some initial parts of the work in as I go.
@gottesmm
Copy link
Contributor Author

@swift-ci test

2 similar comments
@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm
Copy link
Contributor Author

@swift-ci test

@gottesmm gottesmm merged commit b044958 into swiftlang:main Jul 22, 2022
@gottesmm gottesmm deleted the moveonly_type_begin branch July 22, 2022 18:35
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.

Good start, but the diagnostics are not really working until the copy_value's are gone

// We are pattern matching against these patterns:
//
// bb0(%0 : @guaranteed $T):
// %1 = copy_value %0
Copy link
Contributor

Choose a reason for hiding this comment

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

@gottesmm if an argument is marked @moveOnly, then we need to be sure no copy_value exists in the argument, at least by the time this diagnostic runs. This is true for both owned and guaranteed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I talked with Andy about this, what actually happens here is that as part of the diagnostic I eliminate the copy_value and the mark_must_check. I did it this way since today copy propagation doesn't support guaranteed parameters (although we could extend it, I decided to just hack around it).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The right thing here is I think to just see if we can get copy propagation working on guaranteed things and rip this out.

Copy link
Contributor

Choose a reason for hiding this comment

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

@gottesmm for future reference, copy propagation always handled guaranteed function arguments. It's done in RewriteInnerBorrowUses and CanonicalizeBorrowScope::visitBorrowScopeUses.


// CHECK-LABEL: sil [ossa] @$s8moveonly15useKlassConsumeyyAA0C0CnF : $@convention(thin) (@owned Klass) -> () {
// CHECK: bb0([[ARG:%.*]] : @owned $Klass):
// TODO: Is this move_value [lexical] necessary?
Copy link
Contributor

Choose a reason for hiding this comment

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

TODO: Is this move_value [lexical] necessary?

The move_value is not necessary. Function arguments have implicit "lexical" scope

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did this b/c I was worried that we had baked in this notion that owned arguments needed an implicit lexical scope. This can be seen by how we for other cases insert a begin_borrow [lexical] on the owned argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am fine fixing this in a follow on commit.

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