Skip to content

[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
merged 12 commits into from
Oct 29, 2023

Conversation

kavon
Copy link
Member

@kavon kavon commented Oct 25, 2023

This is a pile of fixes and improvement for NoncopyableGenerics:

  1. Fixes ownership checking for some parameters that are noncopyable.
  2. Fixes an issue with conditional Copyable conformances.
  3. Fixes generic signatures for some types.
  4. Correctly handle ~Copyable in protocol compositions.
  5. Handle ~Copyable constraints in where clauses wherever they may appear.

kavon added 5 commits October 23, 2023 10:37
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!).
@kavon
Copy link
Member Author

kavon commented Oct 25, 2023

@swift-ci please smoke test

@kavon kavon force-pushed the noncopyable-generics-pt2 branch from 8a2058a to 8650984 Compare October 25, 2023 20:45
@kavon
Copy link
Member Author

kavon commented Oct 26, 2023

@swift-ci please smoke test

1 similar comment
@kavon
Copy link
Member Author

kavon commented Oct 26, 2023

@swift-ci please smoke test

kavon added 5 commits October 27, 2023 15:01
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.
@kavon kavon force-pushed the noncopyable-generics-pt2 branch from d2f9dd6 to dcd465e Compare October 28, 2023 00:41
@kavon
Copy link
Member Author

kavon commented Oct 28, 2023

@swift-ci please test

kavon added 2 commits October 28, 2023 15:31
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`.
@kavon
Copy link
Member Author

kavon commented Oct 28, 2023

@swift-ci please test

@kavon kavon merged commit 29acda5 into swiftlang:main Oct 29, 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.

1 participant