Skip to content

Commit b9d485a

Browse files
committed
Drop legacy caps.unsafe operations
Retain only caps.unsafe.unsafeAssumePure
1 parent 2b51ee9 commit b9d485a

File tree

4 files changed

+13
-47
lines changed

4 files changed

+13
-47
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,8 +584,6 @@ extension (sym: Symbol)
584584
case _ => false
585585
containsEnclTypeParam(sym.info.finalResultType)
586586
&& !sym.allowsRootCapture
587-
&& sym != defn.Caps_unsafeBox
588-
&& sym != defn.Caps_unsafeUnbox
589587
&& !defn.isPolymorphicAfterErasure(sym)
590588
&& !defn.isTypeTestOrCast(sym)
591589

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

Lines changed: 13 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -607,13 +607,6 @@ class CheckCaptures extends Recheck, SymTransformer:
607607
* otherwise return NoType.
608608
*/
609609
private def recheckUnsafeApply(tree: Apply, pt: Type)(using Context): Type =
610-
611-
def mapArgUsing(f: Type => Type) =
612-
val arg :: Nil = tree.args: @unchecked
613-
val argType0 = f(recheckStart(arg, pt))
614-
val argType = super.recheckFinish(argType0, arg, pt)
615-
super.recheckFinish(argType, tree, pt)
616-
617610
val meth = tree.fun.symbol
618611
if meth == defn.Caps_unsafeAssumePure then
619612
val arg :: Nil = tree.args: @unchecked
@@ -623,31 +616,25 @@ class CheckCaptures extends Recheck, SymTransformer:
623616
else argType0.widen.stripCapturing
624617
capt.println(i"rechecking $arg with $pt: $argType")
625618
super.recheckFinish(argType, tree, pt)
626-
else if meth == defn.Caps_unsafeBox then
627-
mapArgUsing(_.forceBoxStatus(true))
628-
else if meth == defn.Caps_unsafeUnbox then
629-
mapArgUsing(_.forceBoxStatus(false))
630-
else if meth == defn.Caps_unsafeBoxFunArg then
631-
def forceBox(tp: Type): Type = tp.strippedDealias match
632-
case defn.FunctionOf(paramtpe :: Nil, restpe, isContextual) =>
633-
defn.FunctionOf(paramtpe.forceBoxStatus(true) :: Nil, restpe, isContextual)
634-
case tp @ RefinedType(parent, rname, rinfo: MethodType) =>
635-
tp.derivedRefinedType(parent, rname,
636-
rinfo.derivedLambdaType(
637-
paramInfos = rinfo.paramInfos.map(_.forceBoxStatus(true))))
638-
case tp @ CapturingType(parent, refs) =>
639-
tp.derivedCapturingType(forceBox(parent), refs)
640-
mapArgUsing(forceBox)
641619
else NoType
642620
end recheckUnsafeApply
643621

644-
/** Recheck applications. More work is done in `recheckApplication`,
645-
* `recheckArg` and `instantiate` below.
622+
/** Recheck applications, with special handling of unsafeAssumePure.
623+
* More work is done in `recheckApplication`, `recheckArg` and `instantiate` below.
646624
*/
647625
override def recheckApply(tree: Apply, pt: Type)(using Context): Type =
648-
recheckUnsafeApply(tree, pt).orElse:
626+
val meth = tree.fun.symbol
627+
if meth == defn.Caps_unsafeAssumePure then
628+
val arg :: Nil = tree.args: @unchecked
629+
val argType0 = recheck(arg, pt.capturing(CaptureSet.universal))
630+
val argType =
631+
if argType0.captureSet.isAlwaysEmpty then argType0
632+
else argType0.widen.stripCapturing
633+
capt.println(i"rechecking $arg with $pt: $argType")
634+
super.recheckFinish(argType, tree, pt)
635+
else
649636
val res = super.recheckApply(tree, pt)
650-
includeCallCaptures(tree.symbol, res, tree.srcPos)
637+
includeCallCaptures(meth, res, tree.srcPos)
651638
res
652639

653640
/** Recheck argument, and, if formal parameter carries a `@use`,

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -999,9 +999,6 @@ class Definitions {
999999
@tu lazy val Caps_Exists: ClassSymbol = requiredClass("scala.caps.Exists")
10001000
@tu lazy val CapsUnsafeModule: Symbol = requiredModule("scala.caps.unsafe")
10011001
@tu lazy val Caps_unsafeAssumePure: Symbol = CapsUnsafeModule.requiredMethod("unsafeAssumePure")
1002-
@tu lazy val Caps_unsafeBox: Symbol = CapsUnsafeModule.requiredMethod("unsafeBox")
1003-
@tu lazy val Caps_unsafeUnbox: Symbol = CapsUnsafeModule.requiredMethod("unsafeUnbox")
1004-
@tu lazy val Caps_unsafeBoxFunArg: Symbol = CapsUnsafeModule.requiredMethod("unsafeBoxFunArg")
10051002
@tu lazy val Caps_ContainsTrait: TypeSymbol = CapsModule.requiredType("Contains")
10061003
@tu lazy val Caps_containsImpl: TermSymbol = CapsModule.requiredMethod("containsImpl")
10071004

library/src/scala/caps.scala

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,4 @@ import annotation.{experimental, compileTimeOnly, retainsCap}
6666
*/
6767
def unsafeAssumePure: T = x
6868

69-
/** If argument is of type `cs T`, converts to type `box cs T`. This
70-
* avoids the error that would be raised when boxing `cap`.
71-
*/
72-
def unsafeBox: T = x
73-
74-
/** If argument is of type `box cs T`, converts to type `cs T`. This
75-
* avoids the error that would be raised when unboxing `cap`.
76-
*/
77-
def unsafeUnbox: T = x
78-
79-
extension [T, U](f: T => U)
80-
/** If argument is of type `box cs T`, converts to type `cs T`. This
81-
* avoids the error that would be raised when unboxing `cap`.
82-
*/
83-
def unsafeBoxFunArg: T => U = f
84-
8569
end unsafe

0 commit comments

Comments
 (0)