-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Sema: Accept tautological assoc type inference candidates when same-typed. #7875
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
Sema: Accept tautological assoc type inference candidates when same-typed. #7875
Conversation
@swift-ci Please test |
@DougGregor or @slavapestov, does this look OK? Is there a better way to ask a generic environment whether an associated type is same-typed to another one than trawling the requirements? |
lib/Sema/TypeCheckProtocol.cpp
Outdated
dmt->getAssocType()); | ||
for (auto &reqt : witness->getDeclContext() | ||
->getGenericSignatureOfContext() | ||
->getCanonicalSignature() |
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.
getCanonicalSignature() won't change the signature, it just canonicalizes the types themselves; you don't need that here
Build failed |
lib/Sema/TypeCheckProtocol.cpp
Outdated
// If this associated type is same-typed to another associated type | ||
// on `Self`, then it may still be an interesting candidate if we find | ||
// an answer for that other type. | ||
if (witness->getDeclContext()->getAsProtocolExtensionContext() |
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.
If you want to check that two specific associated types are equal, you can map both into context and compare archetypes for pointer equality.
To see if an associated type is equal to some other associated type, the only way that's slightly saner than yours is to get the canonical generic signature builder for the signature, and ask it for the equivalence class of the associated type. But I don't know if the right APIs are public or sane.
So what you have here might be your best bet.
lib/Sema/TypeCheckProtocol.cpp
Outdated
auto selfTy = witness->getDeclContext()->getSelfInterfaceType(); | ||
auto selfAssocTy = DependentMemberType::get(selfTy, | ||
dmt->getAssocType()); | ||
for (auto &reqt : witness->getDeclContext() |
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.
I feel like factoring out 'witness->getDeclContext()' and 'dc->getGenericSignatureOfContext()' would make this code easier to read.
…yped. `X := Self.X` is still interesting information if it came from a witness candidate in a context where `X == Y` and we can infer a concrete witness for Y, for example: ```swift protocol SameTypedDefault { associatedtype X associatedtype Y static var x: X { get } static var y: Y { get } } extension SameTypedDefault where Y == X { static var x: X { return y } } struct UsesSameTypedDefault: SameTypedDefault { static var y: Int { return 0 } } ``` Defer checking whether such a witness candidate satisfies associated type requirements until we consider a complete solution system, since `ConformingType.X` isn't a valid type until we've settled on a witness for X, and its abilities depend on what we choose for Y. Fixes SR-4143.
4addc8f
to
cdc3c1b
Compare
@swift-ci Please test |
1 similar comment
@swift-ci Please test |
@slavapestov Thanks, I updated the patch in response to your feedback. How's this look? Reasonable for 3.1? |
LGTM |
X := Self.X
is still interesting information if it came from a witness candidate in a context whereX == Y
and we can infer a concrete witness for Y, for example:Defer checking whether such a witness candidate satisfies associated type requirements until we consider a complete solution system, since
ConformingType.X
isn't a valid type until we've settled on a witness for X, and its abilities depend on what we choose for Y. Fixes SR-4143.