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

Remove ^ in capture set syntax #22725

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

Conversation

noti0na1
Copy link
Member

@noti0na1 noti0na1 commented Mar 5, 2025

This PR simplifies the capture set syntax by removing unnecessary ^ symbols in capture sets.
This change is the first step making the syntax cleaner and more consistent for capture polymorphism.

  1. Added a new InCaptureSet mode in Mode.scala to handle capture set annotation typing;
  2. Modified the parser to remove the ^ suffix from capture set syntax
  3. If InCaptureSet is set and a term ident or select is not found, retry typing as a type wrapped in CapsOf.

@noti0na1 noti0na1 changed the title Remove upper arrow Remove ^ in capture set syntax Mar 5, 2025
@noti0na1 noti0na1 requested a review from bracevac March 5, 2025 20:01
Copy link
Contributor

@bracevac bracevac left a comment

Choose a reason for hiding this comment

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

Coolio!

@noti0na1 noti0na1 marked this pull request as ready for review March 5, 2025 22:36
@noti0na1 noti0na1 requested a review from odersky March 6, 2025 12:10
@bracevac
Copy link
Contributor

bracevac commented Mar 6, 2025

Let's rebase this on #22539 and wait until after the release cutoff before merging.

@noti0na1
Copy link
Member Author

noti0na1 commented Mar 6, 2025

I don't think we need to rebase onto the separation checking PR. The change here is only inside the Typer and should be independent to the core cc phase.

@odersky
Copy link
Contributor

odersky commented Mar 6, 2025

How about all the test cases that need to be updated? I think it's better to rebase.

@odersky
Copy link
Contributor

odersky commented Mar 11, 2025

This scheme has the advantage that the code is very simple. But there is an issue: Assume we have

object C
...
def foo[C^](x: A^{C}) = ...

then A^{C} will refer to the outer C and probably fail type checking. What's worse, if the outer C actually reads

val C: Capability = ...

then we get scope inversion. The outer C will be selected over the inner C. I think we should try to avoid these problems by using a scheme similar to CBCompanion where when we run the Namer on [C^] we add C under a term name and as a type name in the same scope. Then we will always find the innermost C.

@noti0na1
Copy link
Member Author

I see, if we keep searching terms first, we need to create a "fake" symbol for every type bounded by CapSet to avoid scope inversion.

@noti0na1
Copy link
Member Author

I need to wait for the syntax change in #22758, so it is easier to tell which type def is a capture variable.

@odersky
Copy link
Contributor

odersky commented Mar 12, 2025

I agree. I first thought this was independent of the syntax changes, but maybe that's not the case.

@bracevac
Copy link
Contributor

@noti0na1 it's fairly complete now, modulo adapting the test cases.

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.

3 participants