Skip to content

Commit c24f875

Browse files
committed
Change root capability to cap
1 parent dbe0ec9 commit c24f875

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+158
-159
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ sealed abstract class CaptureSet extends Showable:
7070
assert(!isConst)
7171
asInstanceOf[Var]
7272

73-
/** Does this capture set contain the root reference `*` as element? */
73+
/** Does this capture set contain the root reference `cap` as element? */
7474
final def isUniversal(using Context) =
7575
elems.exists {
7676
case ref: TermRef => ref.symbol == defn.captureRoot
@@ -133,7 +133,7 @@ sealed abstract class CaptureSet extends Showable:
133133
* for `x` in a state where we assume all supersets of `x` have just the elements
134134
* known at this point. On the other hand if x's capture set has no known elements,
135135
* a set `cs` might account for `x` only if it subsumes `x` or it contains the
136-
* root capability `*`.
136+
* root capability `cap`.
137137
*/
138138
def mightAccountFor(x: CaptureRef)(using Context): Boolean =
139139
reporting.trace(i"$this mightAccountFor $x, ${x.captureSetOfInfo}?", show = true) {
@@ -270,7 +270,7 @@ sealed abstract class CaptureSet extends Showable:
270270
def substParams(tl: BindingType, to: List[Type])(using Context) =
271271
map(Substituters.SubstParamsMap(tl, to))
272272

273-
/** Invoke handler if this set has (or later aquires) the root capability `*` */
273+
/** Invoke handler if this set has (or later aquires) the root capability `cap` */
274274
def disallowRootCapability(handler: () => Context ?=> Unit)(using Context): this.type =
275275
if isUniversal then handler()
276276
this
@@ -372,7 +372,7 @@ object CaptureSet:
372372
def isConst = isSolved
373373
def isAlwaysEmpty = false
374374

375-
/** A handler to be invoked if the root reference `*` is added to this set */
375+
/** A handler to be invoked if the root reference `cap` is added to this set */
376376
var rootAddedHandler: () => Context ?=> Unit = () => ()
377377

378378
var description: String = ""

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ class CheckCaptures extends Recheck, SymTransformer:
433433
case defn.FunctionOf(ptformals, _, _)
434434
if ptformals.nonEmpty && ptformals.forall(_.captureSet.isAlwaysEmpty) =>
435435
// Redo setup of the anonymous function so that formal parameters don't
436-
// get capture sets. This is important to avoid false widenings to `*`
436+
// get capture sets. This is important to avoid false widenings to `cap`
437437
// when taking the base type of the actual closures's dependent function
438438
// type so that it conforms to the expected non-dependent function type.
439439
// See withLogFile.scala for a test case.
@@ -582,7 +582,7 @@ class CheckCaptures extends Recheck, SymTransformer:
582582
refs.disallowRootCapability { () =>
583583
val kind = if tree.isInstanceOf[ValDef] then "mutable variable" else "expression"
584584
report.error(
585-
em"""The $kind's type $wtp is not allowed to capture the root capability `*`.
585+
em"""The $kind's type $wtp is not allowed to capture the root capability `cap`.
586586
|This usually means that a capability persists longer than its allowed lifetime.""",
587587
tree.srcPos)
588588
}
@@ -768,9 +768,9 @@ class CheckCaptures extends Recheck, SymTransformer:
768768
styp1.capturing(if alwaysConst then CaptureSet(cs1.elems) else cs1).forceBoxStatus(resultBoxed)
769769

770770
if needsAdaptation then
771-
val criticalSet = // the set which is not allowed to have `*`
772-
if covariant then cs1 // can't box with `*`
773-
else expected.captureSet // can't unbox with `*`
771+
val criticalSet = // the set which is not allowed to have `cap`
772+
if covariant then cs1 // can't box with `cap`
773+
else expected.captureSet // can't unbox with `cap`
774774
if criticalSet.isUniversal && expected.isValueType then
775775
// We can't box/unbox the universal capability. Leave `actual` as it is
776776
// so we get an error in checkConforms. This tends to give better error
@@ -779,11 +779,11 @@ class CheckCaptures extends Recheck, SymTransformer:
779779
println(i"cannot box/unbox $actual vs $expected")
780780
actual
781781
else
782-
// Disallow future addition of `*` to `criticalSet`.
782+
// Disallow future addition of `cap` to `criticalSet`.
783783
criticalSet.disallowRootCapability { () =>
784784
report.error(
785785
em"""$actual cannot be box-converted to $expected
786-
|since one of their capture sets contains the root capability `*`""",
786+
|since one of their capture sets contains the root capability `cap`""",
787787
pos)
788788
}
789789
if !insertBox then // unboxing
@@ -922,8 +922,8 @@ class CheckCaptures extends Recheck, SymTransformer:
922922
* usingLogFile[box ?1 () -> Unit] { (f: {*} File) => () => { f.write(0) } }
923923
*
924924
* We may propagate `f` into ?1, making ?1 ill-formed.
925-
* This also causes soundness issues, since `f` in ?1 should be widened to `*`,
926-
* giving rise to an error that `*` cannot be included in a boxed capture set.
925+
* This also causes soundness issues, since `f` in ?1 should be widened to `cap`,
926+
* giving rise to an error that `cap` cannot be included in a boxed capture set.
927927
*
928928
* To solve this, we still allow ?1 to capture parameter refs like `f`, but
929929
* compensate this by pushing the widened capture set of `f` into ?1.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,7 +968,7 @@ class Definitions {
968968
@tu lazy val BreakClass: Symbol = requiredClass("scala.util.boundary.Break")
969969

970970
@tu lazy val CapsModule: Symbol = requiredModule("scala.caps")
971-
@tu lazy val captureRoot: TermSymbol = CapsModule.requiredValue("*")
971+
@tu lazy val captureRoot: TermSymbol = CapsModule.requiredValue("cap")
972972
@tu lazy val CapsUnsafeModule: Symbol = requiredModule("scala.caps.unsafe")
973973
@tu lazy val Caps_unsafeBox: Symbol = CapsUnsafeModule.requiredMethod("unsafeBox")
974974
@tu lazy val Caps_unsafeUnbox: Symbol = CapsUnsafeModule.requiredMethod("unsafeUnbox")

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,7 @@ object StdNames {
286286
// ----- Term names -----------------------------------------
287287

288288
// Compiler-internal
289-
val CAPTURE_ROOT: N = "*"
290-
val CAPTURE_ROOT_ALT: N = "any"
289+
val CAPTURE_ROOT: N = "cap"
291290
val CONSTRUCTOR: N = "<init>"
292291
val STATIC_CONSTRUCTOR: N = "<clinit>"
293292
val EVT2U: N = "evt2u$"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2102,7 +2102,7 @@ object Types {
21022102
*/
21032103
final def isTracked(using Context): Boolean = canBeTracked && !captureSetOfInfo.isAlwaysEmpty
21042104

2105-
/** Is this reference the root capability `*` ? */
2105+
/** Is this reference the root capability `cap` ? */
21062106
def isRootCapability(using Context): Boolean = false
21072107

21082108
/** Normalize reference so that it can be compared with `eq` for equality */

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,6 @@ object Parsers {
14441444
if in.token == THIS then simpleRef()
14451445
else termIdent() match
14461446
case Ident(nme.CAPTURE_ROOT) => captureRoot
1447-
case Ident(nme.CAPTURE_ROOT_ALT) => captureRoot
14481447
case id => id
14491448

14501449
/** CaptureSet ::= `{` CaptureRef {`,` CaptureRef} `}` -- under captureChecking
@@ -1681,7 +1680,7 @@ object Parsers {
16811680

16821681
def refinedType() = refinedTypeRest(withType())
16831682

1684-
/** Disambiguation: a `^` is treated as a postfix operator meaning `^{any}`
1683+
/** Disambiguation: a `^` is treated as a postfix operator meaning `^{cap}`
16851684
* if followed by `{`, `->`, or `?->`,
16861685
* or followed by a new line (significant or not),
16871686
* or followed by a token that cannot start an infix type.

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
386386

387387
def toTextCaptureRef(tp: Type): Text =
388388
homogenize(tp) match
389-
case tp: TermRef if tp.symbol == defn.captureRoot => Str("*")
389+
case tp: TermRef if tp.symbol == defn.captureRoot => Str("cap")
390390
case tp: SingletonType => toTextRef(tp)
391391
case _ => toText(tp)
392392

library/src/scala/caps.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import annotation.experimental
55
@experimental object caps:
66

77
/** The universal capture reference */
8-
val `*`: Any = ()
8+
val `*`: Any = () // OLD
9+
val cap: Any = () // NEW
910

1011
object unsafe:
1112

tests/neg-custom-args/boxmap.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import annotation.retains
2-
type Top = Any @retains(caps.*)
2+
type Top = Any @retains(caps.cap)
33

44
type Box[+T <: Top] = ([K <: Top] -> (T => K) -> K)
55

@@ -16,6 +16,6 @@ def test[A <: Top, B <: Top] =
1616
def lazymap[A <: Top, B <: Top](b: Box[A])(f: A => B) =
1717
() => b[Box[B]]((x: A) => box(f(x)))
1818
val x0: (b: Box[A]) -> (f: A => B) -> (() -> Box[B]) = lazymap[A, B] // error
19-
val x: (b: Box[A]) -> (f: A => B) -> {b, f} (() -> Box[B]) = lazymap[A, B] // works
20-
val y: (b: Box[A]) -> (f: A => B) -> {*} (() -> Box[B]) = lazymap[A, B] // works
19+
val x: (b: Box[A]) -> (f: A => B) ->{b, f} (() -> Box[B]) = lazymap[A, B] // works
20+
val y: (b: Box[A]) -> (f: A => B) ->{cap} (() -> Box[B]) = lazymap[A, B] // works
2121
()

tests/neg-custom-args/capt-wf.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ def test(c: Cap, other: String): Unit =
1414
val x5: C^{c, c} = ??? // error: redundant
1515
// val x6: C^{c}^{c} = ??? // would be syntax error
1616
val x7: Cap^{c} = ??? // error: redundant
17-
// val x8: C^{c}^{*} = ??? // would be syntax error
18-
val x9: C^{c, *} = ??? // error: redundant
19-
val x10: C^{*, c} = ??? // error: redundant
17+
// val x8: C^{c}^{cap} = ??? // would be syntax error
18+
val x9: C^{c, cap} = ??? // error: redundant
19+
val x10: C^{cap, c} = ??? // error: redundant
2020

2121
def even(n: Int): Boolean = if n == 0 then true else odd(n - 1)
2222
def odd(n: Int): Boolean = if n == 1 then true else even(n - 1)

0 commit comments

Comments
 (0)