Skip to content

Commit ca0a6f9

Browse files
committed
Rename @unbox to @use
1 parent 913c5bb commit ca0a6f9

26 files changed

+65
-64
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ class CheckCaptures extends Recheck, SymTransformer:
387387

388388
def checkUseDeclared(c: CaptureRef, env: Env) =
389389
c.pathRoot match
390-
case ref: NamedType if !ref.symbol.hasAnnotation(defn.UnboxAnnot) =>
390+
case ref: NamedType if !ref.symbol.hasAnnotation(defn.UseAnnot) =>
391391
val what = if ref.isType then "Capture set parameter" else "Local reach capability"
392392
report.error(
393393
em"""$what $c leaks into capture scope of ${env.ownerString}.
@@ -519,7 +519,7 @@ class CheckCaptures extends Recheck, SymTransformer:
519519
override def prepareFunction(funtpe: MethodType, meth: Symbol)(using Context): MethodType =
520520
val paramInfosWithUses = funtpe.paramInfos.zipWithConserve(funtpe.paramNames): (formal, pname) =>
521521
val paramOpt = meth.rawParamss.nestedFind(_.name == pname)
522-
paramOpt.flatMap(_.getAnnotation(defn.UnboxAnnot)) match
522+
paramOpt.flatMap(_.getAnnotation(defn.UseAnnot)) match
523523
case Some(ann) => AnnotatedType(formal, ann)
524524
case _ => formal
525525
funtpe.derivedLambdaType(paramInfos = paramInfosWithUses)
@@ -567,7 +567,7 @@ class CheckCaptures extends Recheck, SymTransformer:
567567
def recheckArg(arg: Tree, formal: Type)(using Context): Type =
568568
val argType = recheck(arg, formal)
569569
formal match
570-
case AnnotatedType(formal1, ann) if ann.symbol == defn.UnboxAnnot =>
570+
case AnnotatedType(formal1, ann) if ann.symbol == defn.UseAnnot =>
571571
capt.println(i"charging deep capture set of $arg: ${argType} = ${argType.deepCaptureSet}")
572572
markFree(argType.deepCaptureSet, arg.srcPos)
573573
case _ =>
@@ -581,13 +581,13 @@ class CheckCaptures extends Recheck, SymTransformer:
581581
* ---------------------
582582
* E |- f(a): Tr^C
583583
*
584-
* If the function `f` does not have an `@unboxed` parameter, then
584+
* If the function `f` does not have an `@use` parameter, then
585585
* any unboxing it does would be charged to the environment of the function
586586
* so they have to appear in Cq. Since any capabilities of the result of the
587587
* application must already be present in the application, an upper
588588
* approximation of the result capture set is Cq \union Ca, where `Ca`
589589
* is the capture set of the argument.
590-
* If the function `f` does have an `@unboxed` parameter, then it could in addition
590+
* If the function `f` does have an `@use` parameter, then it could in addition
591591
* unbox reach capabilities over its formal parameter. Therefore, the approximation
592592
* would be `Cq \union dcs(Ca)` instead.
593593
* If the approximation is known to subcapture the declared result Cr, we pick it for C
@@ -600,7 +600,7 @@ class CheckCaptures extends Recheck, SymTransformer:
600600
val argCaptures =
601601
for (argType, formal) <- argTypes.lazyZip(funType.paramInfos) yield
602602
formal match
603-
case AnnotatedType(_, ann) if ann.symbol == defn.UnboxAnnot => argType.deepCaptureSet
603+
case AnnotatedType(_, ann) if ann.symbol == defn.UseAnnot => argType.deepCaptureSet
604604
case _ => argType.captureSet
605605
appType match
606606
case appType @ CapturingType(appType1, refs)
@@ -1379,16 +1379,16 @@ class CheckCaptures extends Recheck, SymTransformer:
13791379

13801380
override def checkInheritedTraitParameters: Boolean = false
13811381

1382-
/** Check that overrides don't change the @unbox status of their parameters */
1382+
/** Check that overrides don't change the @use status of their parameters */
13831383
override def additionalChecks(member: Symbol, other: Symbol)(using Context): Unit =
13841384
for
13851385
(params1, params2) <- member.rawParamss.lazyZip(other.rawParamss)
13861386
(param1, param2) <- params1.lazyZip(params2)
13871387
do
1388-
if param1.hasAnnotation(defn.UnboxAnnot) != param2.hasAnnotation(defn.UnboxAnnot) then
1388+
if param1.hasAnnotation(defn.UseAnnot) != param2.hasAnnotation(defn.UseAnnot) then
13891389
report.error(
13901390
OverrideError(
1391-
i"has a parameter ${param1.name} with different @unbox status than the corresponding parameter in the overridden definition",
1391+
i"has a parameter ${param1.name} with different @use status than the corresponding parameter in the overridden definition",
13921392
self, member, other, self.memberInfo(member), self.memberInfo(other)
13931393
),
13941394
if member.owner == clazz then member.srcPos else clazz.srcPos

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1057,12 +1057,12 @@ class Definitions {
10571057
@tu lazy val ExperimentalAnnot: ClassSymbol = requiredClass("scala.annotation.experimental")
10581058
@tu lazy val ThrowsAnnot: ClassSymbol = requiredClass("scala.throws")
10591059
@tu lazy val TransientAnnot: ClassSymbol = requiredClass("scala.transient")
1060-
@tu lazy val UnboxAnnot: ClassSymbol = requiredClass("scala.caps.unbox")
10611060
@tu lazy val UncheckedAnnot: ClassSymbol = requiredClass("scala.unchecked")
10621061
@tu lazy val UncheckedStableAnnot: ClassSymbol = requiredClass("scala.annotation.unchecked.uncheckedStable")
10631062
@tu lazy val UncheckedVarianceAnnot: ClassSymbol = requiredClass("scala.annotation.unchecked.uncheckedVariance")
10641063
@tu lazy val UncheckedCapturesAnnot: ClassSymbol = requiredClass("scala.annotation.unchecked.uncheckedCaptures")
10651064
@tu lazy val UntrackedCapturesAnnot: ClassSymbol = requiredClass("scala.caps.untrackedCaptures")
1065+
@tu lazy val UseAnnot: ClassSymbol = requiredClass("scala.caps.use")
10661066
@tu lazy val VolatileAnnot: ClassSymbol = requiredClass("scala.volatile")
10671067
@tu lazy val BeanGetterMetaAnnot: ClassSymbol = requiredClass("scala.annotation.meta.beanGetter")
10681068
@tu lazy val BeanSetterMetaAnnot: ClassSymbol = requiredClass("scala.annotation.meta.beanSetter")

library/src/scala/caps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import annotation.{experimental, compileTimeOnly, retainsCap}
5555
/** This should go into annotations. For now it is here, so that we
5656
* can experiment with it quickly between minor releases
5757
*/
58-
final class unbox extends annotation.StaticAnnotation
58+
final class use extends annotation.StaticAnnotation
5959

6060
object unsafe:
6161

tests/neg-custom-args/captures/delayedRunops.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import language.experimental.captureChecking
2-
import caps.unbox
2+
import caps.use
33

44
// ok
5-
def runOps(@unbox ops: List[() => Unit]): Unit =
5+
def runOps(@use ops: List[() => Unit]): Unit =
66
ops.foreach(op => op())
77

88
// ok
9-
def delayedRunOps(@unbox ops: List[() => Unit]): () ->{ops*} Unit = // @unbox should not be necessary in the future
9+
def delayedRunOps(@use ops: List[() => Unit]): () ->{ops*} Unit = // @use should not be necessary in the future
1010
() => runOps(ops)
1111

1212
// unsound: impure operation pretended pure

tests/neg-custom-args/captures/i15749a.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import caps.cap
2-
import caps.unbox
2+
import caps.use
33

44
class Unit
55
object u extends Unit
@@ -18,7 +18,7 @@ def test =
1818

1919
def force[A](thunk: Unit ->{cap} A): A = thunk(u)
2020

21-
def forceWrapper[A](@unbox mx: Wrapper[Unit ->{cap} A]): Wrapper[A] =
21+
def forceWrapper[A](@use mx: Wrapper[Unit ->{cap} A]): Wrapper[A] =
2222
// Γ ⊢ mx: Wrapper[□ {cap} Unit => A]
2323
// `force` should be typed as ∀(□ {cap} Unit -> A) A, but it can not
2424
strictMap[Unit ->{mx*} A, A](mx)(t => force[A](t)) // error // should work
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import language.experimental.captureChecking
22
import caps.Capability
3-
import caps.unbox
3+
import caps.use
44

55
trait File extends Capability
66
class Logger(f: File^) extends Capability // <- will work if we remove the extends clause
77

8-
def mkLoggers1[F <: File^](@unbox files: List[F]): List[Logger^] =
8+
def mkLoggers1[F <: File^](@use files: List[F]): List[Logger^] =
99
files.map((f: F) => new Logger(f)) // error, Q: can we make this pass (see #19076)?
1010

11-
def mkLoggers2(@unbox files: List[File^]): List[Logger^] =
11+
def mkLoggers2(@use files: List[File^]): List[Logger^] =
1212
files.map(new Logger(_)) // error, Q: can we improve the error message?

tests/neg-custom-args/captures/leak-problem-2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import language.experimental.captureChecking
22

33
trait Source[+T]
44

5-
def race[T](@caps.unbox sources: Seq[Source[T]^]): Source[T]^{sources*} = ???
5+
def race[T](@caps.use sources: Seq[Source[T]^]): Source[T]^{sources*} = ???
66

77
def raceTwo[T](src1: Source[T]^, src2: Source[T]^): Source[T]^{}
88
= race(Seq(src1, src2)) // error

tests/neg-custom-args/captures/reaches.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import caps.unbox
1+
import caps.use
22
class File:
33
def write(): Unit = ???
44

@@ -11,7 +11,7 @@ class Ref[T](init: T):
1111
def get: T = x
1212
def set(y: T) = { x = y }
1313

14-
def runAll0(@unbox xs: List[Proc]): Unit =
14+
def runAll0(@use xs: List[Proc]): Unit =
1515
var cur: List[() ->{xs*} Unit] = xs
1616
while cur.nonEmpty do
1717
val next: () ->{xs*} Unit = cur.head
@@ -21,7 +21,7 @@ def runAll0(@unbox xs: List[Proc]): Unit =
2121
usingFile: f =>
2222
cur = (() => f.write()) :: Nil // error
2323

24-
def runAll1(@unbox xs: List[Proc]): Unit =
24+
def runAll1(@use xs: List[Proc]): Unit =
2525
val cur = Ref[List[() ->{xs*} Unit]](xs) // OK, by revised VAR
2626
while cur.get.nonEmpty do
2727
val next: () ->{xs*} Unit = cur.get.head
@@ -78,5 +78,5 @@ def compose1[A, B, C](f: A => B, g: B => C): A ->{f, g} C =
7878
def mapCompose[A](ps: List[(A => A, A => A)]): List[A ->{ps*} A] =
7979
ps.map((x, y) => compose1(x, y)) // error // error
8080

81-
def mapCompose2[A](@unbox ps: List[(A => A, A => A)]): List[A ->{ps*} A] =
81+
def mapCompose2[A](@use ps: List[(A => A, A => A)]): List[A ->{ps*} A] =
8282
ps.map((x, y) => compose1(x, y))

tests/neg-custom-args/captures/spread-problem.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import language.experimental.captureChecking
22

33
trait Source[+T]
44

5-
def race[T](@caps.unbox sources: (Source[T]^)*): Source[T]^{sources*} = ???
5+
def race[T](@caps.use sources: (Source[T]^)*): Source[T]^{sources*} = ???
66

77
def raceTwo[T](src1: Source[T]^, src2: Source[T]^): Source[T]^{} =
88
race(Seq(src1, src2)*) // error

tests/neg-custom-args/captures/unbox-overrides.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,20 @@
22
8 | def foo(x: C): C // error
33
| ^
44
|error overriding method foo in trait A of type (x: C): C;
5-
| method foo of type (x: C): C has a parameter x with different @unbox status than the corresponding parameter in the overridden definition
5+
| method foo of type (x: C): C has a parameter x with different @use status than the corresponding parameter in the overridden definition
66
|
77
| longer explanation available when compiling with `-explain`
88
-- [E164] Declaration Error: tests/neg-custom-args/captures/unbox-overrides.scala:9:6 ----------------------------------
9-
9 | def bar(@unbox x: C): C // error
9+
9 | def bar(@use x: C): C // error
1010
| ^
1111
|error overriding method bar in trait A of type (x: C): C;
12-
| method bar of type (x: C): C has a parameter x with different @unbox status than the corresponding parameter in the overridden definition
12+
| method bar of type (x: C): C has a parameter x with different @use status than the corresponding parameter in the overridden definition
1313
|
1414
| longer explanation available when compiling with `-explain`
1515
-- [E164] Declaration Error: tests/neg-custom-args/captures/unbox-overrides.scala:15:15 --------------------------------
1616
15 |abstract class C extends A[C], B2 // error
1717
| ^
1818
|error overriding method foo in trait A of type (x: C): C;
19-
| method foo in trait B2 of type (x: C): C has a parameter x with different @unbox status than the corresponding parameter in the overridden definition
19+
| method foo in trait B2 of type (x: C): C has a parameter x with different @use status than the corresponding parameter in the overridden definition
2020
|
2121
| longer explanation available when compiling with `-explain`
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import caps.unbox
1+
import caps.use
22

33
trait A[X]:
4-
def foo(@unbox x: X): X
4+
def foo(@use x: X): X
55
def bar(x: X): X
66

77
trait B extends A[C]:
88
def foo(x: C): C // error
9-
def bar(@unbox x: C): C // error
9+
def bar(@use x: C): C // error
1010

1111
trait B2:
1212
def foo(x: C): C
13-
def bar(@unbox x: C): C
13+
def bar(@use x: C): C
1414

1515
abstract class C extends A[C], B2 // error

tests/neg/i20503.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import language.experimental.captureChecking
2-
import caps.unbox
2+
import caps.use
33

44
class List[+A]:
55
def head: A = ???
@@ -8,7 +8,7 @@ class List[+A]:
88
def foreach[U](f: A => U): Unit = ???
99
def nonEmpty: Boolean = ???
1010

11-
def runOps(@unbox ops: List[() => Unit]): Unit =
11+
def runOps(@use ops: List[() => Unit]): Unit =
1212
// See i20156, due to limitation in expressiveness of current system,
1313
// we could map over the list of impure elements. OK with existentials.
1414
ops.foreach(op => op())

tests/neg/leak-problem-unboxed.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import language.experimental.captureChecking
2-
import caps.unbox
2+
import caps.use
33

44
// Some capabilities that should be used locally
55
trait Async:
@@ -9,12 +9,12 @@ def usingAsync[X](op: Async^ => X): X = ???
99

1010
case class Box[+T](get: T)
1111

12-
def useBoxedAsync(@unbox x: Box[Async^]): Unit =
12+
def useBoxedAsync(@use x: Box[Async^]): Unit =
1313
val t0 = x
1414
val t1 = t0.get // ok
1515
t1.read()
1616

17-
def useBoxedAsync1(@unbox x: Box[Async^]): Unit = x.get.read() // ok
17+
def useBoxedAsync1(@use x: Box[Async^]): Unit = x.get.read() // ok
1818

1919
def test(): Unit =
2020

tests/neg/leak-problem.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import language.experimental.captureChecking
2-
import caps.unbox
2+
import caps.use
33

44
// Some capabilities that should be used locally
55
trait Async:
@@ -17,12 +17,12 @@ def useBoxedAsync(x: Box[Async^]): Unit =
1717
def useBoxedAsync1(x: Box[Async^]): Unit = x.get.read() // error
1818

1919
def test(): Unit =
20-
def useBoxedAsync(@unbox x: Box[Async^]): Unit =
20+
def useBoxedAsync(@use x: Box[Async^]): Unit =
2121
val t0 = x
2222
val t1 = t0.get
2323
t1.read()
2424

25-
def useBoxedAsync1(@unbox x: Box[Async^]): Unit = x.get.read()
25+
def useBoxedAsync1(@use x: Box[Async^]): Unit = x.get.read()
2626

2727
val xs: Box[Async^] = ???
2828
val xsLambda = () => useBoxedAsync(xs) // error

tests/pos-custom-args/captures/Buffer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ trait Buffer[A]:
1010
val s = 10
1111
// capture checking: we need the copy since we box/unbox on g* on the next line
1212
// TODO: This looks fishy, need to investigate
13-
// Alternative would be to mark `f` as @unbox. It's not inferred
13+
// Alternative would be to mark `f` as @use. It's not inferred
1414
// since `^ appears in a function result, not under a box.
1515
val newElems = new Array[(IterableOnce[A]^{f})](s)
1616
var i = 0

tests/pos-custom-args/captures/dep-reach.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import caps.unbox
1+
import caps.use
22
object Test:
33
class C
44
type Proc = () => Unit
55

66
def f(c: C^, d: C^): () ->{c, d} Unit =
7-
def foo(@unbox xs: Proc*): () ->{xs*} Unit =
7+
def foo(@use xs: Proc*): () ->{xs*} Unit =
88
xs.head
99
val a: () ->{c} Unit = () => ()
1010
val b: () ->{d} Unit = () => ()
@@ -13,7 +13,7 @@ object Test:
1313

1414
def g(c: C^, d: C^): () ->{c, d} Unit =
1515

16-
def foo(@unbox xs: Seq[() => Unit]): () ->{xs*} Unit =
16+
def foo(@use xs: Seq[() => Unit]): () ->{xs*} Unit =
1717
xs.head
1818

1919
val a: () ->{c} Unit = () => ()

tests/pos-custom-args/captures/gears-problem.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import language.experimental.captureChecking
2-
import caps.unbox
2+
import caps.use
33

44
trait Future[+T]:
55
def await: T
@@ -11,7 +11,7 @@ class Collector[T](val futures: Seq[Future[T]^]):
1111
val results: Channel[Future[T]^{futures*}] = ???
1212
end Collector
1313

14-
extension [T](@unbox fs: Seq[Future[T]^])
14+
extension [T](@use fs: Seq[Future[T]^])
1515
def awaitAll =
1616
val collector: Collector[T]{val futures: Seq[Future[T]^{fs*}]}
1717
= Collector(fs)

tests/pos-custom-args/captures/path-use.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import language.experimental.namedTuples
2-
import caps.unbox
2+
import caps.use
33

44
class IO
55

@@ -9,7 +9,7 @@ class C(val f: IO^):
99
type Proc = () => Unit
1010

1111
def test(io: IO^) =
12-
def test1(@unbox c: C { val f: IO^{io}}^{io}) =
12+
def test1(@use c: C { val f: IO^{io}}^{io}) =
1313
val f = () => println(c.f)
1414
val _: () ->{c.f} Unit = f
1515

@@ -19,3 +19,4 @@ def test(io: IO^) =
1919
val g = () => println(c.procs.head)
2020
val _: () ->{c.procs*} Unit = g
2121
test1(C(io))
22+

tests/pos-custom-args/captures/reaches.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import caps.unbox
1+
import caps.use
22

33
class C
44
def f(xs: List[C^]) =
@@ -22,7 +22,7 @@ extension [A](x: A) def :: (xs: List[A]): List[A] = ???
2222

2323
object Nil extends List[Nothing]
2424

25-
def runAll(@unbox xs: List[Proc]): Unit =
25+
def runAll(@use xs: List[Proc]): Unit =
2626
var cur: List[() ->{xs*} Unit] = xs // OK, by revised VAR
2727
while cur.nonEmpty do
2828
val next: () ->{xs*} Unit = cur.head

tests/pos/Buffer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ trait Buffer[A]:
1010
val s = 10
1111
// capture checking: we need the copy since we box/unbox on g* on the next line
1212
// TODO: This looks fishy, need to investigate
13-
// Alternative would be to mark `f` as @unbox. It's not inferred
13+
// Alternative would be to mark `f` as @use. It's not inferred
1414
// since `^ appears in a function result, not under a box.
1515
val newElems = new Array[(IterableOnce[A]^{f})](s)
1616
var i = 0

0 commit comments

Comments
 (0)