-
Notifications
You must be signed in to change notification settings - Fork 10.6k
[Requirement Machine] Implement same-element requirements. #70227
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
[Requirement Machine] Implement same-element requirements. #70227
Conversation
63a701c to
147c2b9
Compare
9d3be68 to
2ae722f
Compare
|
@swift-ci please clean smoke test |
|
Thank you for continuing the work on this feature ! Does this PR will also allow construct like this: protocol P {
associatedtype A
}
struct Foo<each T> {
func bar<each S: P>(s: repeat each S)
where repeat (each S).A == each T /* or something like (repeat (each S).A) == (repeat each T)*/
{ /**/ }
}? |
|
@martialln Yes, this construct will be allowed🙂 |
2ae722f to
a2b97a8
Compare
cc9030a to
7d4eebf
Compare
|
@swift-ci Please smoke test |
|
@swift-ci Please smoke test macOS |
|
Amazing to see this making progress. Just curious when we might see this available? Thanks! |
|
@shaps80 Currently, this implementation is missing concrete same-element requirements, and unfortunately I can't provide an estimate of when this will be ready. |
|
Ok fair enough. Thanks for letting me know |
|
Will this be part of Swift 6? |
struct Variadic<each T> {}
extension Variadic where T == {Int, String} {} // {Int, String} is a concrete pack
extension Variadic where T == Never {} // client passed no parameter packHi! I'm looking for (someday in the future) using something like this to enable an "optional" parameter pack. Do we think this diff would also implement the "Explicit type pack syntax" from SE-03931 or would that land in another diff? Thanks! Footnotes |
17fc634 to
5893cf6
Compare
|
@swift-ci please smoke test |
5893cf6 to
f4e8a40
Compare
|
@swift-ci please smoke test |
f4e8a40 to
c5daf7d
Compare
|
@swift-ci please smoke test |
|
@swift-ci please smoke test macOS |
opened element generic environments containing same-element requirements.
…n up existing code
…rite rules, swap the sides depending on which one is longer once the `[element]` symbol is dropped. This change fixes the "out-of-order" type parameters error in `GenericSignature::verify`
…s to always appear on the left-hand side of the same-element rewrite rule.
c5daf7d to
0dc6719
Compare
|
@swift-ci please smoke test |
|
We are hitting this limitation constantly at raycast. We would jump of joy if it could reach Swift 6 by this September 😆 In any case, thank you for working on this. |
This change will not be included in Swift 6. I understand that people are hitting this limitation frequently and would like for it to be lifted, but there are still open technical challenges with this change. As noted in the PR description, the implementation is gated behind an experimental flag because there are issues with how same-element requirements are represented that we're not happy with. These issues impact the user-facing semantics; they're not just implementation challenges. |
|
@swift-ci please smoke test |
|
I see! Thank you for the openness and setting expectations. I am sad to hear it won’t be there for Swift 6, but if it is not ready, it is not ready 😅 |
|
@simanerush IMO we should merge this with the user-visible requirement desugaring change behind an experimental flag. |
Resolves rdar://131630764.
This is the continuation of the original PR #67465 since I hope to fix the CI errors to be able to land the changes.
From the original PR:
SE-0393 supports same-element requirements. From the proposal:
We represent pack elements in the requirement machine through a new singleton
PackElementsymbol, written[element]. Same-element requirements are mapped to re-write rules that prefix type parameter pack terms with the[element]symbol.For example, given a protocol
Pwith an associated typeA, the generic signature<each T, U> where repeat each T: P, repeat (each T).A == Umaps to the following re-write system:The implementation is gated behind
-enable-experimental-feature SameElementRequirementsbecause the minimal conformance computation doesn't yet support same-element requirements. The current rewrite rules also do not support deriving pack element conformance from a scalar type parameter conformance through same-element requirements. For example, the generic signature<each T, U> where U: P, repeat each T == Umaps to the following rewrite system:The conformance rule
τ_0_1.[P] => τ_0_1and the same-element rule[element].each τ_0_0 => τ_0_1do not provide a rewrite path to the pack conformance ruleeach τ_0_0.[P] => each τ_0_0. One possible solution is to use element symbols for all property rules, which would also allow the minimal conformance support to fallout naturally. However, this approach poses a problem for same-type-pack requirements. If we use[element]symbols for same-type-pack requirements, e.g.[element].each τ_0_0 => [element].each τ_0_1, then this rule no longer implies a same-shape ruleeach τ_0_0.[shape] => each τ_0_1.[shape]. Stripping the[element]symbols from same-type-pack rewrite rules creates a different set of problems for conformances, because the pack conformance rules contain[element]symbols, which would prohibit applying associated type rewrite rules to non-element pack terms. I'm still exploring strategies for resolving these issues, hence the experimental flag!