Skip to content

Commit 085df3d

Browse files
committed
Bring Mayby back
1 parent 565e001 commit 085df3d

File tree

4 files changed

+15
-25
lines changed

4 files changed

+15
-25
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ object Capabilities:
599599
c match
600600
case _: ReadOnly => ReadOnlyCapability(c1)
601601
case _: Reach => ReachCapability(c1)
602-
// TODO: do we need to handle Maybe here?
602+
case _: Maybe => MaybeCapability(c1)
603603
case _ => c1
604604

605605
def toText(printer: Printer): Text = printer.toTextCapability(this)

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

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,28 +50,6 @@ def ccState(using Context): CCState =
5050

5151
extension (tree: Tree)
5252

53-
/** Map tree with a Capability type to the corresponding capability,
54-
* map CapSet^{refs} to the `refs` references,
55-
* throw IllegalCaptureRef otherwise
56-
*/
57-
// def toCapabilities(using Context): List[Capability] = tree match
58-
// case ReachCapabilityApply(arg) =>
59-
// arg.toCapabilities.map(_.reach)
60-
// case ReadOnlyCapabilityApply(arg) =>
61-
// arg.toCapabilities.map(_.readOnly)
62-
// case CapsOfApply(arg) =>
63-
// arg.toCapabilities
64-
// case _ => tree.tpe.dealiasKeepAnnots match
65-
// case ref: TermRef if ref.isCapRef =>
66-
// GlobalCap :: Nil
67-
// case ref: Capability if ref.isTrackableRef =>
68-
// ref :: Nil
69-
// case AnnotatedType(parent, ann)
70-
// if ann.symbol.isRetains && parent.derivesFrom(defn.Caps_CapSet) =>
71-
// ann.tree.toCaptureSet.elems.toList
72-
// case tpe =>
73-
// throw IllegalCaptureRef(tpe) // if this was compiled from cc syntax, problem should have been reported at Typer
74-
7553
/** Convert a @retains or @retainsByName annotation tree to the capture set it represents.
7654
* For efficience, the result is cached as an Attachment on the tree.
7755
*/
@@ -82,6 +60,7 @@ extension (tree: Tree)
8260
val refs = CaptureSet(tree.retainedSet.retainedElements*)
8361
tree.putAttachment(Captures, refs)
8462
refs
63+
8564
/** The type representing the capture set of retains annotation.
8665
*/
8766
def retainedSet(using Context): Type =
@@ -584,11 +563,16 @@ end AnnotatedCapability
584563
*/
585564
object ReadOnlyCapability extends AnnotatedCapability(defn.ReadOnlyCapabilityAnnot)
586565

587-
/** An extractor for `ref @annotation.internal.reachCapability`, which is used to express
566+
/** An extractor for `ref @reachCapability`, which is used to express
588567
* the reach capability `ref*` as a type.
589568
*/
590569
object ReachCapability extends AnnotatedCapability(defn.ReachCapabilityAnnot)
591570

571+
/** An extractor for `ref @amaybeCapability`, which is used to express
572+
* the maybe capability `ref?` as a type.
573+
*/
574+
object MaybeCapability extends AnnotatedCapability(defn.MaybeCapabilityAnnot)
575+
592576
/** An extractor for all kinds of function types as well as method and poly types.
593577
* It includes aliases of function types such as `=>`. TODO: Can we do without?
594578
* @return 1st half: The argument types or empty if this is a type function

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,10 @@ class Definitions {
549549
cls
550550
@tu lazy val SingletonType: TypeRef = SingletonClass.typeRef
551551

552+
@tu lazy val MaybeCapabilityAnnot: ClassSymbol =
553+
completeClass(enterCompleteClassSymbol(
554+
ScalaPackageClass, tpnme.maybeCapability, Final, List(StaticAnnotationClass.typeRef)))
555+
552556
@tu lazy val CollectionSeqType: TypeRef = requiredClassRef("scala.collection.Seq")
553557
@tu lazy val SeqType: TypeRef = requiredClassRef("scala.collection.immutable.Seq")
554558
@tu lazy val SeqModule: Symbol = requiredModule("scala.collection.immutable.Seq")
@@ -2224,7 +2228,8 @@ class Definitions {
22242228
NullClass,
22252229
NothingClass,
22262230
SingletonClass,
2227-
CBCompanion)
2231+
CBCompanion,
2232+
MaybeCapabilityAnnot)
22282233

22292234
@tu lazy val syntheticCoreClasses: List[Symbol] = syntheticScalaClasses ++ List(
22302235
EmptyPackageVal,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ object StdNames {
551551
val materializeClassTag: N = "materializeClassTag"
552552
val materializeWeakTypeTag: N = "materializeWeakTypeTag"
553553
val materializeTypeTag: N = "materializeTypeTag"
554+
val maybeCapability: N = "maybeCapability"
554555
val mirror : N = "mirror"
555556
val moduleClass : N = "moduleClass"
556557
val mut: N = "mut"

0 commit comments

Comments
 (0)