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
[SR-6569] Recursive conditional conformances #49119
Comments
cc @DougGregor |
@swift-ci create |
Reduced slightly:
The problem here is a circular dependency on the conformance lookup table of One possibility would be to special-case the 'current type conforms to current protocol' case, which should covers the original bug and probably most cases in the wild. But, I don't think this actually works to cover all cases (this differs to the original by having the type conform to both protocols):
This currently gets 3 errors:
It's the middle one that's problematic, since it's the cross-over, where the problem is that the |
Maybe we should be more aggressive about putting in placeholders as we start validating/checking the conformances, so we (successfully) find partial conformances, and latter fill them in, with the GSB (and anything else that operates that early) resilient to information being missing from those conformances. |
Ah! I think I've got a strategy: currently we pull the fully minimised and canonical set of requirements out of the conformances referenced while building a generic signature, but we don't actually need to: the set of raw requirements (RequirementReprs) has just as much information, and, since we're building generic signature anyway, we're already going to be minimizing things away. Approximate sketch: in the GSB, if a conformance returned by lookupConformance doesn't have the minimal conditional requirements, pull out the TrailingWhereClause of the extension defining the conformance (if those exist) and add those requirements (with appropriate substitution). This also requires being able to build a normal conformance without computing its conditional requirements and either having some sort of compute-the-requirements step or doing it on-demand, once the declcontext declaring the conformance has been validated. |
Initial work breaking some of the recursion in #15268 |
This applies to non-conditional conformances too:
|
The original example and the above with the conformance declared in a separate extension (i.e.
|
There probably needs to be care for extensions of generic type aliases, since they can add bounds too, e.g. the following two extensions are equivalent:
|
Additional Detail from JIRA
md5: e6b335158cc4e2963fcaeb9f6bc8d539
Issue Description:
In the Swift 4.1 version toolchain snapshot from 19-12-2017 there's already some ongoing work with implementation of conditional conformances. In this version though, it is not possible to define somewhat recursive, safe-aware conditional conformances which would allow generic type to conform to a given protocol only if condition which regards the type itself is met.
I don't really know if there's any kind of a specific term for such property in type theory, but basically what I was trying to achieve was:
Currently trying to compile such code using the toolchain results in following:
The text was updated successfully, but these errors were encountered: