Skip to content

Commit 4c95df4

Browse files
committed
Rename SharedCapability to Sharable and add Control capability class
1 parent 6da745b commit 4c95df4

23 files changed

+46
-39
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,7 +1290,7 @@ class CheckCaptures extends Recheck, SymTransformer:
12901290
case ExistentialSubsumesFailure(ex, other) =>
12911291
def since =
12921292
if other.isTerminalCapability then ""
1293-
else " since that capability is not a SharedCapability"
1293+
else " since that capability is not a `Sharable` capability"
12941294
i"""the existential capture root in ${ex.originalBinder.resType}
12951295
|cannot subsume the capability $other$since"""
12961296
case MutAdaptFailure(cs, lo, hi) =>

compiler/src/dotty/tools/dotc/cc/SepCheck.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ class SepCheck(checker: CheckCaptures.CheckerAPI) extends tpd.TreeTraverser:
597597
* - If the reference is to a this type of the enclosing class, the
598598
* access must be in a @consume method.
599599
*
600-
* References that extend SharedCapability are excluded from checking.
600+
* References that extend cpas.Sharable are excluded from checking.
601601
* As a side effect, add all checked references with the given position `pos`
602602
* to the global `consumed` map.
603603
*

compiler/src/dotty/tools/dotc/cc/Setup.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,10 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
375375
else fntpe
376376

377377
/** 1. Check that parents of capturing types are not pure.
378-
* 2. Check that types extending SharedCapability don't have a `cap` in their capture set.
378+
* 2. Check that types extending caps.Sharable don't have a `cap` in their capture set.
379379
* TODO This is not enough.
380380
* We need to also track that we cannot get exclusive capabilities in paths
381-
* where some prefix derives from SharedCapability. Also, can we just
381+
* where some prefix derives from Sharable. Also, can we just
382382
* exclude `cap`, or do we have to extend this to all exclusive capabilties?
383383
* The problem is that we know what is exclusive in general only after capture
384384
* checking, not before.

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ class Definitions {
10111011
@tu lazy val Caps_ContainsModule: Symbol = requiredModule("scala.caps.Contains")
10121012
@tu lazy val Caps_containsImpl: TermSymbol = Caps_ContainsModule.requiredMethod("containsImpl")
10131013
@tu lazy val Caps_Mutable: ClassSymbol = requiredClass("scala.caps.Mutable")
1014-
@tu lazy val Caps_SharedCapability: ClassSymbol = requiredClass("scala.caps.SharedCapability")
1014+
@tu lazy val Caps_SharedCapability: ClassSymbol = requiredClass("scala.caps.Sharable")
10151015

10161016
@tu lazy val PureClass: Symbol = requiredClass("scala.Pure")
10171017

library/src/scala/CanThrow.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import annotation.{implicitNotFound, experimental, capability}
88
*/
99
@experimental
1010
@implicitNotFound("The capability to throw exception ${E} is missing.\nThe capability can be provided by one of the following:\n - Adding a using clause `(using CanThrow[${E}])` to the definition of the enclosing method\n - Adding `throws ${E}` clause after the result type of the enclosing method\n - Wrapping this piece of code with a `try` block that catches ${E}")
11-
erased class CanThrow[-E <: Exception] extends caps.SharedCapability
11+
erased class CanThrow[-E <: Exception] extends caps.Control
1212

1313
@experimental
1414
object unsafeExceptions:

library/src/scala/caps/package.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,13 @@ trait Mutable extends Capability
3737
* During separation checking, shared capabilities are not taken into account.
3838
*/
3939
@experimental
40-
trait SharedCapability extends Capability
40+
trait Sharable extends Capability
41+
42+
/** Base trait for capabilities that capture some continuation or return point in
43+
* the stack. Examples are exceptions, labels, Async, CanThrow.
44+
*/
45+
@experimental
46+
trait Control extends Sharable
4147

4248
/** Carrier trait for capture set type parameters */
4349
@experimental

tests/neg-custom-args/captures/capt-capability.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import caps.{Capability, SharedCapability}
1+
import caps.{Capability, Sharable}
22

33
def foo() =
4-
val x: SharedCapability = ???
4+
val x: Sharable = ???
55

66
val z3 =
77
if x == null then (y: Unit) => x else (y: Unit) => new Capability() {} // error

tests/neg-custom-args/captures/cc-existential-conformance.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
| where: ^ refers to a root capability associated with the result type of (x: A): B^
2020
|
2121
| Note that the existential capture root in B^
22-
| cannot subsume the capability y* since that capability is not a SharedCapability
22+
| cannot subsume the capability y* since that capability is not a `Sharable` capability
2323
|
2424
| longer explanation available when compiling with `-explain`
2525
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/cc-existential-conformance.scala:13:19 -------------------
@@ -43,6 +43,6 @@
4343
| where: ^ refers to a root capability associated with the result type of (x: A): B^
4444
|
4545
| Note that the existential capture root in B^
46-
| cannot subsume the capability y* since that capability is not a SharedCapability
46+
| cannot subsume the capability y* since that capability is not a `Sharable` capability
4747
|
4848
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/cc-poly-source.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import caps.use
3030
val listeners = lbls.map(makeListener) // error
3131
// we get an error here because we no longer allow contravariant cap
3232
// to subsume other capabilities. The problem can be solved by declaring
33-
// Label a SharedCapability, see cc-poly-source-capability.scala
33+
// Label a Sharable, see cc-poly-source-capability.scala
3434
val src = Source[{lbls*}]
3535
for l <- listeners do
3636
src.register(l)

tests/neg-custom-args/captures/effect-swaps-explicit.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end boundary
1414

1515
import boundary.{Label, break}
1616

17-
trait Async extends caps.SharedCapability
17+
trait Async extends caps.Sharable
1818
object Async:
1919
def blocking[T](body: Async ?=> T): T = ???
2020

0 commit comments

Comments
 (0)