Skip to content

Revise capability hierarchy and fix classifiers #23656

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

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

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Aug 4, 2025

We now make Capability a sealed trait with two subtraits: SharedCapability and ExclusiveCapability. This forces one to pick one or the other when defining a new Capability type. Most tests were changed to use SharedCapability instead of Capability. Since classifiers are now much more common than before, this showed up some bugs and anomalies for classifyer handling, which are also addressed in this PR.

Details:

  1. Further improvement to error messages. We now explain why FreshCaps cannot subsume a capability.
  2. We turn caching off by default for captureSetOfInfo. During experimentation I found that sometimes captureSetOfInfo could be cached too early, leading to a locked in universal cap in the info where we would expect to see a fresh cap. On the standard library it did not look like this had a noticeable performance impact.
  3. Fixes to tryClassifyAs and transClassifiers. In particular, we need to distinguish FreshCaps that can still be classified from ones that cannot. Once a FreshCap is part of a constant capture set, it gets classified by the type that prefixes the set and that classification cannot be changed anymore. But other FreshCaps are created as members of variable sets and then their classification status is open and can be constrained further.
  4. Convert a fresh cap to a reach capability only if the reach capability might subcapture the fresh cap. Since fresh caps are now classified that is not always the case.
  5. Turn pre-type closure results on for parametric expected function types. This gives sometimes better errors and avoids premature mapings to scoped result types in closure bodies.
  6. Use cap.rd as implicitly added capability only for references extending ExclusiveCapability. Use cap for the others.

We also include now captures in the result type of a function in the captureSetofInfo of that function.

@odersky odersky requested a review from a team as a code owner August 4, 2025 07:59
@odersky odersky requested a review from Linyxus August 4, 2025 16:22
@odersky
Copy link
Contributor Author

odersky commented Aug 4, 2025

I think this is ready for review now.

Copy link
Contributor

@Linyxus Linyxus left a comment

Choose a reason for hiding this comment

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

LGTM!

@Linyxus Linyxus assigned odersky and unassigned Linyxus Aug 4, 2025
trait ExclusiveCapability extends Capability, Classifier

@experimental
type Exclusive = SharedCapability
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes indeed.

odersky added 13 commits August 5, 2025 15:20
We now always give a reason in a TypeMismatch about which capture set inclusion failed.
Include result capabilities unless they are bound in the result.
Now we also report on level and classifier errors when comparing with FreshCaps.
Make reach improvement also dependent on migthSubCapture
 - fix tryClassify and trsnaClassifiers for core capabilities
 - freeze classifications of FreshCaps in constant sets
 - two subtraits: SharedCapability and ExclusiveCapability
Pre-type closure bodies with expected result type if expected type is a parametric function.
This avoids turning fresh caps in their result type into result caps
For capabilities classified as Shared, assume `cap` instead.
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.

2 participants