Skip to content

Copyable as a Requirement Against the Machine #67930

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 5 commits into from
Sep 21, 2023

Conversation

kavon
Copy link
Member

@kavon kavon commented Aug 15, 2023

This PR introduces the NoncopyableGenerics feature flag and should be a non-functional change when that feature is not enabled.

When the flag is enabled:

  • Type parameters gain an implicit Requirement to be Copyable, rather than synthesizing extra constraints in the solver.
  • Rudimentary support for removing that Copyable requirement via ~Copyable from a protocol, associatedtype, or generic type parameter.
  • Using ~Copyable in the inheritance clause of a struct/enum now doesn't actually make the type recognized as noncopyable to the rest of the compiler. That's because we need to move away from the MoveOnlyAttr. This will be fixed in another PR.

This changeset is probably best reviewed one-commit-at-a-time.

resolves rdar://110420673&115812856

@slavapestov
Copy link
Contributor

Also didDiagnoseMoveOnlyGenericArgs() in TypeCheckType.cpp is now redundant right?

@kavon kavon requested a review from jckarter August 15, 2023 18:07
@kavon kavon force-pushed the copyable-requirement branch from d05ba66 to dc1bf91 Compare September 7, 2023 22:29
An initial implementation of a rework in how
we prevent noncopyable types from being
substituted in places they are not permitted.

Instead of generating a constraint for every
generic parameter in the solver, we produce
real Copyable conformance requirements. This
is much better for our longer-term goal of
supporting `~Copyable` in more places.
@kavon kavon force-pushed the copyable-requirement branch from dc1bf91 to 68ae729 Compare September 19, 2023 23:35
I think from SIL's perspective, it should only worry about whether the
type is move-only. That includes MoveOnlyWrapped SILTypes and regular
types that cannot be copied.

Most of the code querying `SILType::isPureMoveOnly` is in SILGen, where
it's very likely that the original AST type is sitting around already.
In such cases, I think it's fine to ask the AST type if it is
noncopyable. The clarity of only asking the ASTType if it's noncopyable
is beneficial, I think.
@kavon kavon force-pushed the copyable-requirement branch from 7cb31a2 to 500a470 Compare September 20, 2023 23:48
@kavon kavon marked this pull request as ready for review September 20, 2023 23:52
@kavon
Copy link
Member Author

kavon commented Sep 20, 2023

@swift-ci please smoke test

This replaces the old, unavailable `_Copyable`.

rdar://110420673
Have `~Copyable` change the signatures of a generic type param,
protocol, or associated type if written in the inheritance clause
position.
@kavon kavon force-pushed the copyable-requirement branch from 500a470 to 80097bc Compare September 21, 2023 07:56
@kavon
Copy link
Member Author

kavon commented Sep 21, 2023

@swift-ci please smoke test

@kavon
Copy link
Member Author

kavon commented Sep 21, 2023

@swift-ci please smoke test linux platform

@ahoppen ahoppen removed their request for review September 21, 2023 16:42
@kavon kavon merged commit a69bcf8 into swiftlang:main Sep 21, 2023
@kavon kavon deleted the copyable-requirement branch September 23, 2023 00:12
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.

2 participants