Skip to content
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

Canonicalize capture variable subtype comparisons #22299

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

bracevac
Copy link
Contributor

@bracevac bracevac commented Jan 2, 2025

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^} becomes CapSet^{C^} <: CapSet^{C^}, and A <: B becomes CapSet^{A^} <: CapSet^{B^} if both A and B 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:

  • Fix extension method in test cc-poly-varargs.scala. Currently causes an infinite regress.
  • Some negative cases in test capture-vars-subtyping.scala pass: D <: E fails, but its canonicalized form CapSet^{D^} <: CapSet^{E^} now succeeds. Potential problem in the subcapturing implementation.
  • Extend to intersection/unions def f[C^, D^, E <: C | D, F <: C & D](...) = ... etc. Lacking good uses cases, not planned right now.
  • If we have C^ declared in the current context, should there be a difference between C vs. C^ for subsequent mentions? We currently do, but seems a bit too subtle for users. Will be addressed by a new scheme for declaring capture variables using context bounds.

Fixes scala#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^}`
becomes `CapSet^{C^} <: CapSet^{C^}`, and `A <: B` becomes
`CapSet^{A^} <: CapSet^{B^}` if both `A` and `B` are capture
variables.
@bracevac
Copy link
Contributor Author

bracevac commented Jan 2, 2025

Moved to dotty @odersky

This change now makes both the tests cc-poly-varargs and capturesubtyping
pass.

- Move CapSet-related methods to CaptureOps
- Let NamedType case in secondTry of TypeComparer handle capture variables as well
- Added a case in capturesubtyping test to test forgotten NamedType case above
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Subtyping and Normalization of Capture Sets
1 participant