Skip to content

Make caps.Capability non-experimental #23507

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

Merged
merged 3 commits into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2112,8 +2112,8 @@ class Definitions {
*/
@tu lazy val ccExperimental: Set[Symbol] = Set(
CapsModule, CapsModule.moduleClass, PureClass,
Caps_Capability, // TODO: Remove when Capability is stabilized
Caps_Classifier, Caps_SharedCapability, Caps_Control, Caps_ExclusiveCapability, Caps_Mutable, Caps_Read,
/* Caps_Classifier, Caps_SharedCapability, Caps_Control, -- already stable */
Caps_ExclusiveCapability, Caps_Mutable, Caps_Read,
RequiresCapabilityAnnot,
captureRoot, Caps_CapSet, Caps_ContainsTrait, Caps_ContainsModule, Caps_ContainsModule.moduleClass,
ConsumeAnnot, UseAnnot, ReserveAnnot,
Expand Down
33 changes: 24 additions & 9 deletions library/src/scala/caps/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,43 +22,58 @@ import annotation.{experimental, compileTimeOnly, retainsCap}
* But even without capture checking, extending this trait can be useful for documenting the intended purpose
* of a class.
*
* Capability has exactly two subtraits: Shared and Exclusive.
* Capability has exactly two subtraits: [[SharedCapability Shared]] and [[ExclusiveCapability Exclusive]].
*/
@experimental
sealed trait Capability extends Any

/** A marker trait for classifier capabilities that can appear in `.only`
* qualifiers. Capability classes directly extending `Classifier` are treated
* as classifier capbilities
* as classifier capbilities.
*
* [[Classifier]] has a formal meaning when
* [[scala.language.experimental.captureChecking Capture Checking]]
* is turned on. It should not be used outside of capture checking.
*/
@experimental
trait Classifier

/** The universal capture reference. */
@experimental
object cap extends Capability

/** Marker trait for capabilities that can be safely shared in a concurrent context.
*
* [[SharedCapability]] has a formal meaning when
* [[scala.language.experimental.captureChecking Capture Checking]]
* is turned on.
* During separation checking, shared capabilities are not taken into account.
*/
@experimental
trait SharedCapability extends Capability, Classifier

@experimental
Copy link
Member

Choose a reason for hiding this comment

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

Why not remove the experimental from this alias too?

Suggested change
@experimental

Copy link
Contributor

Choose a reason for hiding this comment

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

We don't need to remove experimental here, and we want to work a bit with it to see whether it is a good idea to have a short alias.

type Shared = SharedCapability

/** Marker trait for exclusive capabilities that are separation-checked
/** Marker trait for capabilities that should only be used by one concurrent process
* at a given time. For example, write-access to a shared mutable buffer.
*
* [[ExclusiveCapability]] has a formal meaning when
* [[scala.language.experimental.captureChecking Capture Checking]]
* is turned on.
* During separation checking, exclusive usage of marked capabilities will be enforced.
*/
@experimental
trait ExclusiveCapability extends Capability, Classifier

@experimental
type Exclusive = ExclusiveCapability

/** Base trait for capabilities that capture some continuation or return point in
* the stack. Examples are exceptions, labels, Async, CanThrow.
/** Marker trait for capabilities that capture some continuation or return point in
* the stack. Examples are exceptions, [[scala.util.boundary.Label labels]], [[scala.CanThrow CanThrow]]
* or Async contexts.
*
* [[Control]] has a formal meaning when
* [[scala.language.experimental.captureChecking Capture Checking]]
* is turned on.
*/
@experimental
trait Control extends SharedCapability, Classifier

/** Marker trait for classes with methods that require an exclusive reference. */
Expand Down
4 changes: 4 additions & 0 deletions project/MiMaFilters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ object MiMaFilters {
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.internal.onlyCapability"),
ProblemFilters.exclude[MissingFieldProblem]("scala.runtime.stdLibPatches.language#experimental.separationChecking"),
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.stdLibPatches.language$experimental$separationChecking$"),
ProblemFilters.exclude[MissingClassProblem]("scala.caps.Capability"),
ProblemFilters.exclude[MissingClassProblem]("scala.caps.Classifier"),
ProblemFilters.exclude[MissingClassProblem]("scala.caps.SharedCapability"),
ProblemFilters.exclude[MissingClassProblem]("scala.caps.Control"),
),

// Additions since last LTS
Expand Down
4 changes: 0 additions & 4 deletions tests/run-tasty-inspector/stdlibExperimentalDefinitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,13 @@ val experimentalDefinitionInLibrary = Set(
"scala.annotation.retainsCap",
"scala.Pure",
"scala.caps.CapSet",
"scala.caps.Capability",
"scala.caps.Classifier",
"scala.caps.Contains",
"scala.caps.Contains$",
"scala.caps.Contains$.containsImpl",
"scala.caps.Exists",
"scala.caps.SharedCapability",
"scala.caps.ExclusiveCapability",
"scala.caps.Mutable",
"scala.caps.Read",
"scala.caps.Control",
"scala.caps.consume",
"scala.caps.internal",
"scala.caps.internal$",
Expand Down
Loading