Skip to content

Commit 63603a8

Browse files
committed
Move unsafe box/unbox ops into separate caps.unsafe module
1 parent bedeb29 commit 63603a8

File tree

12 files changed

+29
-24
lines changed

12 files changed

+29
-24
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -961,10 +961,11 @@ class Definitions {
961961
def RuntimeTupleFunctionsModule(using Context): Symbol = requiredModule("scala.runtime.TupledFunctions")
962962

963963
@tu lazy val CapsModule: Symbol = requiredModule("scala.caps")
964-
@tu lazy val Caps_unsafeBox: Symbol = CapsModule.requiredMethod("unsafeBox")
965-
@tu lazy val Caps_unsafeUnbox: Symbol = CapsModule.requiredMethod("unsafeUnbox")
966-
@tu lazy val Caps_unsafeBoxFunArg: Symbol = CapsModule.requiredMethod("unsafeBoxFunArg")
967964
@tu lazy val captureRoot: TermSymbol = CapsModule.requiredValue("*")
965+
@tu lazy val CapsUnsafeModule: Symbol = requiredModule("scala.caps.unsafe")
966+
@tu lazy val Caps_unsafeBox: Symbol = CapsUnsafeModule.requiredMethod("unsafeBox")
967+
@tu lazy val Caps_unsafeUnbox: Symbol = CapsUnsafeModule.requiredMethod("unsafeUnbox")
968+
@tu lazy val Caps_unsafeBoxFunArg: Symbol = CapsUnsafeModule.requiredMethod("unsafeBoxFunArg")
968969

969970
// Annotation base classes
970971
@tu lazy val AnnotationClass: ClassSymbol = requiredClass("scala.annotation.Annotation")

library/src/scala/caps.scala

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,23 @@ import annotation.experimental
77
/** The universal capture reference */
88
val `*`: Any = ()
99

10-
/** If argument is of type `cs T`, converts to type `box cs T`. This
11-
* avoids the error that would be raised when boxing `*`.
12-
*/
13-
extension [T](x: T) def unsafeBox: T = x
10+
object unsafe:
1411

15-
/** If argument is of type `box cs T`, converts to type `cs T`. This
16-
* avoids the error that would be raised when unboxing `*`.
17-
*/
18-
extension [T](x: T) def unsafeUnbox: T = x
12+
/** If argument is of type `cs T`, converts to type `box cs T`. This
13+
* avoids the error that would be raised when boxing `*`.
14+
*/
15+
extension [T](x: T) def unsafeBox: T = x
1916

20-
/** If argument is of type `box cs T`, converts to type `cs T`. This
21-
* avoids the error that would be raised when unboxing `*`.
22-
*/
23-
extension [T, U](f: T => U) def unsafeBoxFunArg: T => U = f
17+
/** If argument is of type `box cs T`, converts to type `cs T`. This
18+
* avoids the error that would be raised when unboxing `*`.
19+
*/
20+
extension [T](x: T) def unsafeUnbox: T = x
21+
22+
/** If argument is of type `box cs T`, converts to type `cs T`. This
23+
* avoids the error that would be raised when unboxing `*`.
24+
*/
25+
extension [T, U](f: T => U) def unsafeBoxFunArg: T => U = f
26+
end unsafe
2427

2528
/** Mixing in this trait forces a trait or class to be pure, i.e.
2629
* have no capabilities retained in its self type.

project/MiMaFilters.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ object MiMaFilters {
1010
ProblemFilters.exclude[MissingClassProblem]("scala.runtime.stdLibPatches.language$experimental$captureChecking$"),
1111
ProblemFilters.exclude[MissingClassProblem]("scala.caps"),
1212
ProblemFilters.exclude[MissingClassProblem]("scala.caps$Pure"),
13+
ProblemFilters.exclude[MissingClassProblem]("scala.caps$unsafe$"),
1314
)
1415
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import caps.*
1+
import caps.unsafe.*
22
def test =
33
val tasks = new collection.mutable.ArrayBuffer[() => Unit]
44
val _: Unit = tasks.foreach(((task: () => Unit) => task()).unsafeBoxFunArg)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import caps.*
1+
import caps.unsafe.*
22
def test =
33
var finalizeActions = collection.mutable.ListBuffer[() => Unit]()
44
val action = finalizeActions.remove(0).unsafeUnbox

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import caps.*
1+
import caps.unsafe.*
22

33
object Test:
44
type ErrorHandler = (Int, String) => Unit
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dotty.tools
22
object test {
33

4-
val x = caps.unsafeBox
4+
val x = caps.unsafe.unsafeBox
55

66
}

tests/pos-with-compiler-cc/dotc/Run.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import java.nio.charset.StandardCharsets
3131
import scala.collection.mutable
3232
import scala.util.control.NonFatal
3333
import scala.io.Codec
34-
import caps.unsafeUnbox
34+
import caps.unsafe.unsafeUnbox
3535

3636
/** A compiler run. Exports various methods to compile source files */
3737
class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with ConstraintRunInfo {

tests/pos-with-compiler-cc/dotc/core/OrderingConstraint.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import reflect.ClassTag
1313
import annotation.tailrec
1414
import annotation.internal.sharable
1515
import cc.{CapturingType, derivedCapturingType}
16-
import caps.unsafeUnbox
16+
import caps.unsafe.unsafeUnbox
1717

1818
object OrderingConstraint {
1919

tests/pos-with-compiler-cc/dotc/decompiler/IDEDecompilerDriver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import dotty.tools.dotc.reporting._
1111
import dotty.tools.io.AbstractFile
1212

1313
import scala.quoted.runtime.impl.QuotesImpl
14-
import caps.unsafeUnbox
14+
import caps.unsafe.unsafeUnbox
1515

1616
/**
1717
* Decompiler to be used with IDEs

tests/pos-with-compiler-cc/dotc/reporting/Reporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import core.Decorators.toMessage
1515
import java.io.{BufferedReader, PrintWriter}
1616
import scala.annotation.internal.sharable
1717
import scala.collection.mutable
18-
import scala.caps.unsafeUnbox
18+
import scala.caps.unsafe.unsafeUnbox
1919
import language.experimental.pureFunctions
2020

2121
object Reporter {

tests/pos-with-compiler-cc/dotc/transform/init/Semantic.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import Errors.*
1818

1919
import scala.collection.mutable
2020
import scala.annotation.tailrec
21-
import caps.unsafeBoxFunArg
21+
import caps.unsafe.unsafeBoxFunArg
2222

2323
object Semantic:
2424

0 commit comments

Comments
 (0)