Skip to content

Commit 986c57d

Browse files
committed
Drop legacy caps.unsafe operations
Retain only caps.unsafe.unsafeAssumePure
1 parent 37a8794 commit 986c57d

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
@@ -602,13 +602,6 @@ class CheckCaptures extends Recheck, SymTransformer:
602602
* otherwise return NoType.
603603
*/
604604
private def recheckUnsafeApply(tree: Apply, pt: Type)(using Context): Type =
605-
606-
def mapArgUsing(f: Type => Type) =
607-
val arg :: Nil = tree.args: @unchecked
608-
val argType0 = f(recheckStart(arg, pt))
609-
val argType = super.recheckFinish(argType0, arg, pt)
610-
super.recheckFinish(argType, tree, pt)
611-
612605
val meth = tree.fun.symbol
613606
if meth == defn.Caps_unsafeAssumePure then
614607
val arg :: Nil = tree.args: @unchecked
@@ -618,31 +611,25 @@ class CheckCaptures extends Recheck, SymTransformer:
618611
else argType0.widen.stripCapturing
619612
capt.println(i"rechecking $arg with $pt: $argType")
620613
super.recheckFinish(argType, tree, pt)
621-
else if meth == defn.Caps_unsafeBox then
622-
mapArgUsing(_.forceBoxStatus(true))
623-
else if meth == defn.Caps_unsafeUnbox then
624-
mapArgUsing(_.forceBoxStatus(false))
625-
else if meth == defn.Caps_unsafeBoxFunArg then
626-
def forceBox(tp: Type): Type = tp.strippedDealias match
627-
case defn.FunctionOf(paramtpe :: Nil, restpe, isContextual) =>
628-
defn.FunctionOf(paramtpe.forceBoxStatus(true) :: Nil, restpe, isContextual)
629-
case tp @ RefinedType(parent, rname, rinfo: MethodType) =>
630-
tp.derivedRefinedType(parent, rname,
631-
rinfo.derivedLambdaType(
632-
paramInfos = rinfo.paramInfos.map(_.forceBoxStatus(true))))
633-
case tp @ CapturingType(parent, refs) =>
634-
tp.derivedCapturingType(forceBox(parent), refs)
635-
mapArgUsing(forceBox)
636614
else NoType
637615
end recheckUnsafeApply
638616

639-
/** Recheck applications. More work is done in `recheckApplication`,
640-
* `recheckArg` and `instantiate` below.
617+
/** Recheck applications, with special handling of unsafeAssumePure.
618+
* More work is done in `recheckApplication`, `recheckArg` and `instantiate` below.
641619
*/
642620
override def recheckApply(tree: Apply, pt: Type)(using Context): Type =
643-
recheckUnsafeApply(tree, pt).orElse:
621+
val meth = tree.fun.symbol
622+
if meth == defn.Caps_unsafeAssumePure then
623+
val arg :: Nil = tree.args: @unchecked
624+
val argType0 = recheck(arg, pt.capturing(CaptureSet.universal))
625+
val argType =
626+
if argType0.captureSet.isAlwaysEmpty then argType0
627+
else argType0.widen.stripCapturing
628+
capt.println(i"rechecking $arg with $pt: $argType")
629+
super.recheckFinish(argType, tree, pt)
630+
else
644631
val res = super.recheckApply(tree, pt)
645-
includeCallCaptures(tree.symbol, res, tree.srcPos)
632+
includeCallCaptures(meth, res, tree.srcPos)
646633
res
647634

648635
/** 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)