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

Add capture-checking annotations to scala.util.boundary #22775

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

Conversation

natsukagami
Copy link
Contributor

Adds capture-tracking annotations to scala.util.boundary.

The following changes are made:

  • Label[T] is now a capability, directly inheriting caps.Capability.
  • Break exception:
    • now does not expose the .label field. This is a source-breaking change. - however, label is still private[boundary], which should make it TASTy- and binary-compatible.
    • While we don't expect any code to inspect the values inside a Break exception, if some code is manually implementing boundary.apply's logic, we instead provide a isSameLabelAs method, that compares the given Label[T] with the inner Label without leaking it.
  • Note that catching Break exceptions may still possibly cause them to escape the boundary.

To demonstrate that capture-checking works, a test is included.

@natsukagami natsukagami marked this pull request as ready for review March 11, 2025 16:00
@natsukagami natsukagami requested a review from odersky March 11, 2025 16:00
@hamzaremmal
Copy link
Member

hamzaremmal commented Mar 11, 2025

Shouldn't cc changes in the library go to https://github.com/scala/scala3/tree/main/scala2-library-cc/src/scala and not the actual library ?

@natsukagami
Copy link
Contributor Author

Shouldn't cc changes in the library go to https://github.com/scala/scala3/tree/main/scala2-library-cc/src/scala and not the actual library ?

scala.util.boundary is not part of scala2-library

@natsukagami
Copy link
Contributor Author

@sjrd what's your opinion on the breaking changes?

Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

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

Breaking change or not, I don't think we have consensus about taking the risk of introducing CC annotations in the standard standard library.

So far, it has always been pretty clear that CC goes to an alternate library that people can depend on if they want to. Here this is a much bigger "attack surface".

At the very least this requires a Core discussion.

@hamzaremmal
Copy link
Member

scala.util.boundary is not part of scala2-library

Right, I'm overlooked that. Nevertheless, I agree with @sjrd, we don't have a consensus about adding cc-related code in the stdlib.

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