Skip to content

Commit fcf4045

Browse files
committed
Rename @unbox to @use
1 parent e7c018b commit fcf4045

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
@@ -392,7 +392,7 @@ class CheckCaptures extends Recheck, SymTransformer:
392392

393393
def checkUseDeclared(c: CaptureRef, env: Env) =
394394
c.pathRoot match
395-
case ref: NamedType if !ref.symbol.hasAnnotation(defn.UnboxAnnot) =>
395+
case ref: NamedType if !ref.symbol.hasAnnotation(defn.UseAnnot) =>
396396
val what = if ref.isType then "Capture set parameter" else "Local reach capability"
397397
report.error(
398398
em"""$what $c leaks into capture scope of ${env.ownerString}.
@@ -524,7 +524,7 @@ class CheckCaptures extends Recheck, SymTransformer:
524524
override def prepareFunction(funtpe: MethodType, meth: Symbol)(using Context): MethodType =
525525
val paramInfosWithUses = funtpe.paramInfos.zipWithConserve(funtpe.paramNames): (formal, pname) =>
526526
val paramOpt = meth.rawParamss.nestedFind(_.name == pname)
527-
paramOpt.flatMap(_.getAnnotation(defn.UnboxAnnot)) match
527+
paramOpt.flatMap(_.getAnnotation(defn.UseAnnot)) match
528528
case Some(ann) => AnnotatedType(formal, ann)
529529
case _ => formal
530530
funtpe.derivedLambdaType(paramInfos = paramInfosWithUses)
@@ -572,7 +572,7 @@ class CheckCaptures extends Recheck, SymTransformer:
572572
def recheckArg(arg: Tree, formal: Type)(using Context): Type =
573573
val argType = recheck(arg, formal)
574574
formal match
575-
case AnnotatedType(formal1, ann) if ann.symbol == defn.UnboxAnnot =>
575+
case AnnotatedType(formal1, ann) if ann.symbol == defn.UseAnnot =>
576576
capt.println(i"charging deep capture set of $arg: ${argType} = ${argType.deepCaptureSet}")
577577
markFree(argType.deepCaptureSet, arg.srcPos)
578578
case _ =>
@@ -586,13 +586,13 @@ class CheckCaptures extends Recheck, SymTransformer:
586586
* ---------------------
587587
* E |- f(a): Tr^C
588588
*
589-
* If the function `f` does not have an `@unboxed` parameter, then
589+
* If the function `f` does not have an `@use` parameter, then
590590
* any unboxing it does would be charged to the environment of the function
591591
* so they have to appear in Cq. Since any capabilities of the result of the
592592
* application must already be present in the application, an upper
593593
* approximation of the result capture set is Cq \union Ca, where `Ca`
594594
* is the capture set of the argument.
595-
* If the function `f` does have an `@unboxed` parameter, then it could in addition
595+
* If the function `f` does have an `@use` parameter, then it could in addition
596596
* unbox reach capabilities over its formal parameter. Therefore, the approximation
597597
* would be `Cq \union dcs(Ca)` instead.
598598
* If the approximation is known to subcapture the declared result Cr, we pick it for C
@@ -605,7 +605,7 @@ class CheckCaptures extends Recheck, SymTransformer:
605605
val argCaptures =
606606
for (argType, formal) <- argTypes.lazyZip(funType.paramInfos) yield
607607
formal match
608-
case AnnotatedType(_, ann) if ann.symbol == defn.UnboxAnnot => argType.deepCaptureSet
608+
case AnnotatedType(_, ann) if ann.symbol == defn.UseAnnot => argType.deepCaptureSet
609609
case _ => argType.captureSet
610610
appType match
611611
case appType @ CapturingType(appType1, refs)
@@ -1384,16 +1384,16 @@ class CheckCaptures extends Recheck, SymTransformer:
13841384

13851385
override def checkInheritedTraitParameters: Boolean = false
13861386

1387-
/** Check that overrides don't change the @unbox status of their parameters */
1387+
/** Check that overrides don't change the @use status of their parameters */
13881388
override def additionalChecks(member: Symbol, other: Symbol)(using Context): Unit =
13891389
for
13901390
(params1, params2) <- member.rawParamss.lazyZip(other.rawParamss)
13911391
(param1, param2) <- params1.lazyZip(params2)
13921392
do
1393-
if param1.hasAnnotation(defn.UnboxAnnot) != param2.hasAnnotation(defn.UnboxAnnot) then
1393+
if param1.hasAnnotation(defn.UseAnnot) != param2.hasAnnotation(defn.UseAnnot) then
13941394
report.error(
13951395
OverrideError(
1396-
i"has a parameter ${param1.name} with different @unbox status than the corresponding parameter in the overridden definition",
1396+
i"has a parameter ${param1.name} with different @use status than the corresponding parameter in the overridden definition",
13971397
self, member, other, self.memberInfo(member), self.memberInfo(other)
13981398
),
13991399
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`

0 commit comments

Comments
 (0)