Skip to content

[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

Merged
merged 4 commits into from
Nov 1, 2021

Conversation

gottesmm
Copy link
Contributor

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:

func myFunc(@_noImplicitCopy _ x: Klass) {
...
}

operationally this has the following effects:

  1. x is a move only value and goes through move only checking.
  2. x is passed at +1 by default.

This lets one now create whole call trees by passing @_noImplicitCopy lets as @_noImplicitCopy arguments.

rdar://83957088

@gottesmm gottesmm force-pushed the no_implicit_copy_arguments branch from a37cc9e to d1c122c Compare October 31, 2021 04:29
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm gottesmm force-pushed the no_implicit_copy_arguments branch from d1c122c to 08ff730 Compare October 31, 2021 20:27
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm
Copy link
Contributor Author

The bug before was that in deserialization I did not shift by the right amount. Its fixed now.

@gottesmm gottesmm force-pushed the no_implicit_copy_arguments branch from 08ff730 to e5db347 Compare October 31, 2021 23:20
@gottesmm
Copy link
Contributor Author

@swift-ci smoke test

@gottesmm gottesmm force-pushed the no_implicit_copy_arguments branch from e5db347 to ec7589e Compare October 31, 2021 23:22
@gottesmm
Copy link
Contributor Author

@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
…in such a form that move checking works on it.

This means that one can pass around let moveOnly values using @_noImplicitCopy.
@gottesmm gottesmm closed this Nov 1, 2021
@gottesmm gottesmm force-pushed the no_implicit_copy_arguments branch from ec7589e to 3290833 Compare November 1, 2021 16:35
@gottesmm
Copy link
Contributor Author

gottesmm commented Nov 1, 2021

By mistake pushed main instead of my branch X ).

@gottesmm gottesmm reopened this Nov 1, 2021
@gottesmm
Copy link
Contributor Author

gottesmm commented Nov 1, 2021

@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) {
Copy link
Contributor Author

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).

@gottesmm
Copy link
Contributor Author

gottesmm commented Nov 1, 2021

Again, this is all behind a flag, so it shouldn't effect normal codegen.

@gottesmm gottesmm merged commit bb0883d into swiftlang:main Nov 1, 2021
@gottesmm gottesmm deleted the no_implicit_copy_arguments branch November 1, 2021 21:42
@gottesmm
Copy link
Contributor Author

gottesmm commented Nov 1, 2021

@swift-ci build toolchain

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.

1 participant