Canonicalize capture variable subtype comparisons #22299
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #22103
Subtype problems where at least one side is a type variable representing a capture variable are canonicalized to capturing type comparisons on the special
CapSet
for the universe capture sets. For example,C <: CapSet^{C^}
becomesCapSet^{C^} <: CapSet^{C^}
, andA <: B
becomesCapSet^{A^} <: CapSet^{B^}
if bothA
andB
are capture variables.Supersedes #22183 and #22289. This solution is overall cleaner and does not require adding a new bit to the TypeComparer's ApproxState.
TODOs/Issues/Questions:
D <: E
fails, but its canonicalized formCapSet^{D^} <: CapSet^{E^}
now succeeds. Potential problem in the subcapturing implementation.Extend to intersection/unionsLacking good uses cases, not planned right now.def f[C^, D^, E <: C | D, F <: C & D](...) = ...
etc.If we haveWill be addressed by a new scheme for declaring capture variables using context bounds.C^
declared in the current context, should there be a difference betweenC
vs.C^
for subsequent mentions? We currently do, but seems a bit too subtle for users.