-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Emit error when move-only type is used as a generic type #62599
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
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35896a5
to
67e52e2
Compare
0e8fca6
to
e3a0ade
Compare
e3a0ade
to
f68c14b
Compare
@swift-ci please test |
f68c14b
to
30c728d
Compare
30c728d
to
6a9732c
Compare
@swift-ci please test |
@swift-ci pls smoke test macOS platform |
@swift-ci please smoke test macOS platform |
a0fb617
to
8b0ce29
Compare
@swift-ci please test and merge |
xedin
reviewed
Feb 1, 2023
@swift-ci Please Test Source Compatibility |
@swift-ci please test |
8b0ce29
to
3cd43bf
Compare
@swift-ci please smoke test and merge |
95ce272
to
82740a4
Compare
Since values of generic type are currently assumed to always support copying, we need to prevent move-only types from being substituted for generic type parameters. This approach leans on a `_Copyable` marker protocol to which all generic type parameters implicitly must conform. A few other changes in this initial implementation: - Now every concrete type that can conform to Copyable will do so. This fixes issues with conforming to a protocol that requires Copyable. - Narrowly ban writing a concrete type `[T]` when `T` is move-only.
`Any`, which is effectively `any _Copyable`, is obviously copyable.
`matchExistentialTypes` ends up getting called in most cases, to ensure the conversion is legal.
Since structs and enums only participate in subtyping via protocols, move-only types that are structs and enums effectively are only subtypes of themselves.
Also, only generate those conformances when the move-only feature is on, for now.
where `MO` is a move-only type. turns out it was being allowed because the cast is represented as a disjunction in the constraint solver: - `MO conv AnyObject` - `MO bridge conv AnyObject` I caught the first one but missed the second, which was unconditionally being allowed.
Previous implementation blindly took the first solution and tried to diagnose, but that's not a safe assumption. It's possible that among the solution-fix pairs, one of `noncopyableTy`'s within the fix differs from the others. Things probably can go wrong because the solution doesn't correspond to that type. Also, in that case we'd be emitting a diagnostic that may not make any sense. In such cases, now we decline to emit a diagnostic. Thanks Pavel for catching this.
A number of our existing tests put move-only types in optionals and used them as arguments to generic type parameters. It turns out that many of these appearances in the tests were not crucial for the test's functionality itself. The little coverage for force-unwrapping an Optional<moveOnly> that was lost will be regained once we make these types sound. I also tried to tidy up some of the tests with consistent naming for operations on values, i.e., `consumeVal` and `borrowVal` functions.
0ec9a08
to
d2da71a
Compare
@swift-ci please smoke test and merge |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
resolves rdar://101651405
Needed-before-merge TODOs:
Copyable
from appearing in swiftinterface files (seeSema/missing-import-typealias.swift
)Deferrable TODOs:
mo as! AnyHashable
. Alternatively, make sure they truly do fail at runtime.repeat each T
) conform to_Copyable
(seeGenerics/tuple-conformances.swift
)_Copyable
out of the stdlib and make it some sort of builtin that's pre-populated in the ASTContext, likeAny
. We can't bootstrap the stdlib if that protocol is defined in some part of the stdlib, because every generic parameter is implicitly constrained to it and we have to be able to typecheck with-parse-stdlib
. (seeSema/stdlib_sugar_types.swift
)