Skip to content

Noncopyable means no conformance to Copyable #68818

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 18 commits into from
Oct 19, 2023

Conversation

kavon
Copy link
Member

@kavon kavon commented Sep 28, 2023

More work that is a NFC unless using -enable-experimental-feature NoncopyableGenerics

This change-set primarily overhauls the isNoncopyable methods of TypeBase and ValueDecl:

First, I've narrowed the scope of ValueDecl::isNoncopyable to TypeDecl::isNoncopyable. We are still defining TypeDecl::isNoncopyable as meaning "is always noncopyable" via checking for a ~Copyable written on the decl.
I'd eventually like this method to go away and/or be substantially changed into

  1. decl->isNoncopyable() is rewritten as getInterfaceType()->isNoncopyable()
  2. TypeDecl::implicitCopyableBehavior() returning one of {None, Conditional, Always} to reflect the different meanings of physically annotating the type with ~Copyable.

For TypeBase::isNoncopyable, we now query whether the type conforms to Copyable. This change happens in coordination with actually synthesizing conformances to Copyable for all nominal types when it makes sense to (i.e., it doesn't have ~Copyable written on it, hence why the legacy-form of TypeDecl::isNoncopyable lingers).

@kavon
Copy link
Member Author

kavon commented Sep 28, 2023

@swift-ci please smoke test

@kavon kavon force-pushed the noncopyable-means-no-conformance branch from 925a901 to a243dcb Compare October 7, 2023 01:36
@kavon
Copy link
Member Author

kavon commented Oct 7, 2023

@swift-ci smoke test

checking what I broke

@kavon
Copy link
Member Author

kavon commented Oct 9, 2023

@swift-ci please smoke test

@kavon
Copy link
Member Author

kavon commented Oct 9, 2023

@swift-ci please smoke test macOS platform

@kavon kavon force-pushed the noncopyable-means-no-conformance branch from 2e11cca to 4dbfca7 Compare October 10, 2023 01:14
@kavon
Copy link
Member Author

kavon commented Oct 10, 2023

@swift-ci please smoke test

1 similar comment
@kavon
Copy link
Member Author

kavon commented Oct 10, 2023

@swift-ci please smoke test

@kavon kavon force-pushed the noncopyable-means-no-conformance branch 3 times, most recently from 2d83c52 to c95d87d Compare October 15, 2023 04:09
@kavon
Copy link
Member Author

kavon commented Oct 16, 2023

@swift-ci please smoke test

@kavon kavon force-pushed the noncopyable-means-no-conformance branch from f6fd818 to e49bf23 Compare October 18, 2023 20:41
kavon added 9 commits October 18, 2023 13:45
I've renamed the method to `TypeDecl::isNoncopyable`, because the query
doesn't make sense for many other kinds of `ValueDecl`'s beyond the
`TypeDecl`'s. In fact, it looks like no one was relying on that anyway.

Thus, we now have a distinction where in Sema, you ask whether
a `Type` or `TypeDecl` is "Noncopyable". But within SIL, we still
preserve the notion of "move-only" since there is additionally the
move-only type wrapper for types that otherwise support copying.
This implementation has the function execute a request to scan the
inheritance clause of non-protocol nominals for a `~Copyable`. For
protocols, we look in the requirement signature.

This isn't our final state, as the GenericEnvironment needs to be
queried in general to determine of a Type is noncopyable. So for now
checking for a `~Copyable` only makes sense for Decls.
This visitor is generally useful for other kinds of marker protocols
like `Copyable` that require structural checking over the storage of the
struct or enum.
The generic signature for the built-in TupleDecl was incorrect, stating
that the Element type must be Copyable. That in combination with an
extension that says tuples are Copyable when Element is copyable was
giving unconditional Copyable conformances for tuples that never
actually get checked.

Given that the existence of a conformance and no out-standing
conditional requirements is now what is used to determine if a value is
noncopyable, this was causing tuples with noncopyable elements to report
 that they are copyable in `isNoncopyable` requests.
We were allowing the catch-all "X is not compatible with generics yet"
diagnostic to be emitted when there's a failure to satisfy a requirement
for a conditional Copyable conformance. Instead, allow the existing
infrastructure to diagnose such failures-to-conform to emit a diagnostic
.

This patch also adds a check to catch future catch-all diagnostics in
asserts builds, since I'd like to phase out that diagnostic when
NoncopyableGenerics is enabled.
kavon added 3 commits October 18, 2023 13:52
Adds rudiementary support for searching `where` clauses for `~Copyable`
constraints, but the implementation is known to have flaws.
@kavon kavon force-pushed the noncopyable-means-no-conformance branch from e49bf23 to 75d45fc Compare October 18, 2023 20:52
@kavon kavon marked this pull request as ready for review October 18, 2023 20:52
@kavon kavon requested a review from slavapestov October 18, 2023 20:53
@kavon
Copy link
Member Author

kavon commented Oct 18, 2023

@swift-ci please test

kavon added 5 commits October 18, 2023 15:00
Turns out my caching was busted and `requiresProtocol` is fast enough
to go without it.
Calling `mapTypeIntoContext` on n interface type with no type
parameters is a no-op. In addition, we can avoid calling
`getGenericEnvironmentOfContext` twice, which does a search of the
DeclContext to find it.
@kavon kavon force-pushed the noncopyable-means-no-conformance branch from 4b9a93f to 018ae15 Compare October 18, 2023 22:01
@kavon
Copy link
Member Author

kavon commented Oct 18, 2023

@swift-ci please test

Seems we already emit 6 duplicate diagnostics for this test, so what's
one more?

I'm not sure what change I made triggered this additional diagnostic.
@kavon
Copy link
Member Author

kavon commented Oct 19, 2023

@swift-ci please test and merge

@swift-ci swift-ci merged commit d47ef5f into swiftlang:main Oct 19, 2023
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.

3 participants