-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
Conversation
Currently it doesn't have any effect.
…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.
@swift-ci test |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.