-
Notifications
You must be signed in to change notification settings - Fork 10.6k
AssociatedTypeInference: Initial refactoring of abstract type witness inference #40269
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
AssociatedTypeInference: Initial refactoring of abstract type witness inference #40269
Conversation
|
@swift-ci please smoke test |
6477e7b to
f85ce32
Compare
|
@swift-ci please smoke test |
f85ce32 to
614359a
Compare
|
@swift-ci please smoke test |
614359a to
4c96b74
Compare
|
@swift-ci please smoke test |
4c96b74 to
a18fe75
Compare
|
@swift-ci please smoke test |
|
@swift-ci please clean smoke test macOS |
slavapestov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this PR fix the problem where associated types must be re-stated in inherited protocols?
Eg, this doesn't type check today:
protocol Base {
associatedtype A
}
protocol Derived : Base {
func foo() -> A
}
struct S : Derived {
func foo() -> Int { return 0 }
}
You need to pointlessly re-declare the 'associatedtype A' inside 'protocol Derived'. It would be nice to make this work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about Self.X.Y == Self.X.Y.*, etc?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anything other than Self.X := Y is not considered at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this is sensitive to the order of protocols in the inheritance clause, which might be weird. Perhaps you should canonicalize the list of inherited protocols when walking (or walk over conformance requirements on 'Self' in the requirement signature instead, which are in canonical order).
|
@AnthonyLatsis can you run source compat testing on this once you resolve the merge conflict? |
Not in general, I haven't touched inference via value witnesses yet. |
a18fe75 to
530181c
Compare
|
@swift-ci please smoke test |
|
@swift-ci please test source compatibility |
2 similar comments
|
@swift-ci please test source compatibility |
|
@swift-ci please test source compatibility |
|
@slavapestov source compatibility failures are unrelated, but in isolation this is in fact a source breaking change. There is a group of conformances we are not yet prepared to deal with for which associated type inference now fails. A selected few of these compile today, e.g. protocol P { associatedtype A = Int }
protocol Q { associatedtype B }
protocol R: P, Q where A == B {}
struct S: R {} // A := Int, B := Int (correct)and while some infer the correct type witnesses by chance like the above, others do not: protocol P { associatedtype B = Int }
protocol Q { associatedtype A }
protocol R: P, Q where A == B {}
struct S<A>: R {} // A := A (generic parameter), B := A (wrong)They all have two things in common: you need more information than just the same-type constraints to decide on a type witness, and the type witnesses of one conformance cannot be resolved independently of another in general. |
|
@swift-ci please test source compatibility Let's make these green. |
|
The probability of someone relying on the entailing source compatibility nuance I mentioned is really low, given that these cases just started "working" in the last minor release or so, so I'm going to merge this and try do deal with the existing bigger issue in 5.7. Then again, we can always defer or revert this if something goes left. |
|
@swift-ci please smoke test |
…omputeAbstractTypeWitness'
… the type witness system
Since we collect same-type constraints by scanning requirement signatures, the type witness system must be prerared to face conflicting solutions for a particular type witness
…esses in inferAbstractTypeWitnesses() A regular type.subst() is not enough, because tentative type witnesses may contain type parameters, and we have to substitute them as well, recursively, e.g A := G<B>, B := G<C>, C := Never. Avoiding subst() here also eliminates a use case of the getSubstOptionsWithCurrentTypeWitnesses() hack.
530181c to
2ebb123
Compare
|
@swift-ci please smoke test |
|
@swift-ci please test source compatibility |
|
@swift-ci please smoke test macOS |
|
@swift-ci please test source compatibility |
|
@swift-ci clean smoke test macOS |
1 similar comment
|
@swift-ci clean smoke test macOS |
|
@swift-ci please test source compatibility |
|
@shahmishal Did something happen with the archiving of build artefacts in source compat builds? |
|
@swift-ci please test source compatibility |
No description provided.