-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[NoncopyableGenerics] handle ~Copyable
in where
, some
, and compositions.
#69406
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
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
We really should be checking for the presence of the ownership annotation from the top of the parameter's TypeRepr hierarchy, instead of the bottom. This fixes some missed edge cases that are now relevant, like `some ~Copyable`. parameters
This type will become the corresponding type that is resolved for an `InverseTypeRepr`. This kind of type is not expected to appear past type checking (currently, not even past requirement lowering!).
@swift-ci please smoke test |
8a2058a
to
8650984
Compare
@swift-ci please smoke test |
1 similar comment
@swift-ci please smoke test |
Previously, inverses were only accounted-for in inheritance clauses. This batch of changes handles inverses appearing in other places, like: - Protocol compositions - `some ~Copyable` - where clauses with proper attribution of default requirements in their absence.
We're not yet going to allow noncopyable types into packs, so this change prevents the use of `~Copyable` on an `each T` generic parameter. It also fixes how we query for whether a `repeat X` parameter is copyable.
Since there is no propagation of inverse constraints in the requirement machine, we need to fully desugar these requirements at the point of defining a generic parameter. That desugaring involves determining which default conformance requirements need to be applied to a generic parameter, accounting for inverses. But, nested generic contexts in scope of those expanded generic parameters can still write constraints on that outer parameter. For example, this method's where clause can have its own constraints on `T`: ``` struct S<T> { func f() where T: ~Copyable {} } ``` But, the generic signature of `S` already has a `T: Copyable` that was expanded. The method `f` will always see a `T` that conforms to `Copyable`, so it's impossible for `f` to claim that it applies for `T`'s that lack Copyable. Put another way, it's not valid for this method `f`, whose generic signature is based on its parent's `S`, to weaken or remove requirements from parent's signature. Only positive requirements can be added to them.
d2f9dd6
to
dcd465e
Compare
@swift-ci please test |
We already don't diagnose all redundant requirements. Because inverses can be written in both inheritance and where clauses, but they're not treated uniformly in the implementation, it's a bit annoying to try and account for the redundancies in both places; `checkInheritanceClause` will go over the same "requirements" that we'll also check again in `swift::rewriting::expandDefaultRequirements`.
@swift-ci please test |
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.
This is a pile of fixes and improvement for
NoncopyableGenerics
:some
parameters that are noncopyable.Copyable
conformances.some
types.~Copyable
in protocol compositions.~Copyable
constraints inwhere
clauses wherever they may appear.