-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[moveOnly] Allow the @_noImplicitCopy decl attribute to be applied to parameters #39991
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
a37cc9e
to
d1c122c
Compare
@swift-ci smoke test |
d1c122c
to
08ff730
Compare
@swift-ci smoke test |
The bug before was that in deserialization I did not shift by the right amount. Its fixed now. |
08ff730
to
e5db347
Compare
@swift-ci smoke test |
e5db347
to
ec7589e
Compare
@swift-ci smoke test |
…mplicitCopy argument. I am purposely doing this in SILGen rather than at the type system level to avoid having to have to add a bunch of boilerplate to the type system. Instead of doing that, I am in SILGen checking for the isNoImplicitCopy bit on the ParamDecl when we emit arguments. At that point, I set on the specific SILArgument being emitted the bit that it is no implicit copy. In terms of printing at the SIL level, I just printed it in front of the function argument type like @owned, e.x.: func myFunc(_ x: @_noImplicitCopy T) -> T { ... } becomes: bb0(%0 : @noImplicitCopy @owned $T): Some notes: * Just to be explicit, I am making it so that no implicit copy parameters by default are always passed at +1. The reason why I think this makes sense is that this is the natural way of working with a move only value. * As always, one can not write no implicit copy the attribute without passing the flag -enable-experimental-move-only so this is NFC. rdar://83957088
…ssed at +1 by default.
…in such a form that move checking works on it. This means that one can pass around let moveOnly values using @_noImplicitCopy.
ec7589e
to
3290833
Compare
By mistake pushed main instead of my branch X ). |
@swift-ci smoke test |
@@ -83,7 +83,7 @@ class MyGenericClass<T> { | |||
return nil | |||
} | |||
|
|||
func foo(@_noImplicitCopy _ t: T) { // expected-error {{@_noImplicitCopy may only be used on 'var' declarations}} | |||
func foo(@_noImplicitCopy _ t: T) { |
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.
NOTE: The error for using this on a generic parameter is a SILGen error, not a semi error, so it is in the SILGen test that I added. This is b/c the type checker doesn't have enough information to distinguish in between a type that contains a generic type and a type that just has a type parameter (consider UnsafePointer, a loadable type at the SIL level despite the type parameter at the AST level).
Again, this is all behind a flag, so it shouldn't effect normal codegen. |
@swift-ci build toolchain |
Everything in this PR can only be used if one passes in the flag -enable-experimental-move-only.
Marking a parameter with this attribute looks as follows:
operationally this has the following effects:
This lets one now create whole call trees by passing @_noImplicitCopy lets as @_noImplicitCopy arguments.
rdar://83957088