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

Refine rules for capture parameters and members #22000

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

Conversation

noti0na1
Copy link
Member

@noti0na1 noti0na1 commented Nov 21, 2024

This PR refines rules for capture variables (parameters and members).

Fix #21999, #22005

Add requirements for capture variables

When a capture set is encoded as a type, the type must refer to CapSet and bounded by >: CapSet <: CapSet^.

An unbounded capture parameter would be C >: CapSet <: CapSet^, which can be desugared from C^.

class A:
  type C^

def f[C^](io: IO^{C^}) = ???

// becomes

class A:
  type C >: CapSet <: CapSet^

def f[C >: CapSet <: CapSet^](io: IO^{C^}) = ???

Then, constaints between capture variables become possible:

def test[X^, Y^, Z >: X <: Y](x: C^{X^}, y: C^{Y^}, z: C^{Z^}) = ???
// Z is still bounded by >: CapSet <: CapSet^

Update definitions in the library caps.scala, such that a type following the rule can be used inside a capture set.

// Rule out C^{(Nothing)^} during typer
def capsOf[CS >: CapSet <: CapSet @retainsCap]: Any = ???

sealed trait Contains[+C >: CapSet <: CapSet @retainsCap, R <: Singleton]

Add cases to handle CapSet in subsumes

*   X = CapSet^cx, exists rx in cx, rx subsumes y ==>  X subsumes y
*   Y = CapSet^cy, forall ry in cy, x subsumes ry ==>  x subsumes Y
*   X: CapSet^c1...CapSet^c2, (CapSet^c1) subsumes y  ==> X subsumes y
*   Y: CapSet^c1...CapSet^c2, x subsumes (CapSet^c2) ==> x subsumes Y
*   Contains[X, y]  ==>  X subsumes y

@noti0na1 noti0na1 force-pushed the make-cap-params-bounded-by-capset branch from 651b674 to c933560 Compare November 22, 2024 09:59
@noti0na1
Copy link
Member Author

noti0na1 commented Nov 22, 2024

TODO: fix override check for type members during CC

@noti0na1 noti0na1 force-pushed the make-cap-params-bounded-by-capset branch from d016cce to a8c624e Compare November 24, 2024 22:22
@noti0na1 noti0na1 changed the title Make capture parameters and members bounded by CapSet by default Refine rules for capture parameters and members Nov 26, 2024



race[Either[T1, T2], Cap](left, right)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be necessary. I'll look into normalization and subtyping of captures.

tests/pos-custom-args/captures/cc-poly-varargs.scala Outdated Show resolved Hide resolved
tests/pos-custom-args/captures/cc-poly-varargs.scala Outdated Show resolved Hide resolved
tests/neg/cc-poly-2.scala Outdated Show resolved Hide resolved
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 Captureset Subtyping and Intervals
2 participants