Skip to content

Commit ffa04cb

Browse files
committed
Bring Mayby back
1 parent 04097cd commit ffa04cb

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
@@ -611,7 +611,7 @@ object Capabilities:
611611
c match
612612
case _: ReadOnly => ReadOnlyCapability(c1)
613613
case _: Reach => ReachCapability(c1)
614-
// TODO: do we need to handle Maybe here?
614+
case _: Maybe => MaybeCapability(c1)
615615
case _ => c1
616616

617617
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
@@ -47,28 +47,6 @@ def ccState(using Context): CCState =
4747

4848
extension (tree: Tree)
4949

50-
/** Map tree with a Capability type to the corresponding capability,
51-
* map CapSet^{refs} to the `refs` references,
52-
* throw IllegalCaptureRef otherwise
53-
*/
54-
// def toCapabilities(using Context): List[Capability] = tree match
55-
// case ReachCapabilityApply(arg) =>
56-
// arg.toCapabilities.map(_.reach)
57-
// case ReadOnlyCapabilityApply(arg) =>
58-
// arg.toCapabilities.map(_.readOnly)
59-
// case CapsOfApply(arg) =>
60-
// arg.toCapabilities
61-
// case _ => tree.tpe.dealiasKeepAnnots match
62-
// case ref: TermRef if ref.isCapRef =>
63-
// GlobalCap :: Nil
64-
// case ref: Capability if ref.isTrackableRef =>
65-
// ref :: Nil
66-
// case AnnotatedType(parent, ann)
67-
// if ann.symbol.isRetains && parent.derivesFrom(defn.Caps_CapSet) =>
68-
// ann.tree.toCaptureSet.elems.toList
69-
// case tpe =>
70-
// throw IllegalCaptureRef(tpe) // if this was compiled from cc syntax, problem should have been reported at Typer
71-
7250
/** Convert a @retains or @retainsByName annotation tree to the capture set it represents.
7351
* For efficience, the result is cached as an Attachment on the tree.
7452
*/
@@ -79,6 +57,7 @@ extension (tree: Tree)
7957
val refs = CaptureSet(tree.retainedSet.retainedElements*)
8058
tree.putAttachment(Captures, refs)
8159
refs
60+
8261
/** The type representing the capture set of retains annotation.
8362
*/
8463
def retainedSet(using Context): Type =
@@ -561,11 +540,16 @@ end AnnotatedCapability
561540
*/
562541
object ReadOnlyCapability extends AnnotatedCapability(defn.ReadOnlyCapabilityAnnot)
563542

564-
/** An extractor for `ref @annotation.internal.reachCapability`, which is used to express
543+
/** An extractor for `ref @reachCapability`, which is used to express
565544
* the reach capability `ref*` as a type.
566545
*/
567546
object ReachCapability extends AnnotatedCapability(defn.ReachCapabilityAnnot)
568547

548+
/** An extractor for `ref @amaybeCapability`, which is used to express
549+
* the maybe capability `ref?` as a type.
550+
*/
551+
object MaybeCapability extends AnnotatedCapability(defn.MaybeCapabilityAnnot)
552+
569553
/** An extractor for all kinds of function types as well as method and poly types.
570554
* It includes aliases of function types such as `=>`. TODO: Can we do without?
571555
* @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")
@@ -2229,7 +2233,8 @@ class Definitions {
22292233
NullClass,
22302234
NothingClass,
22312235
SingletonClass,
2232-
CBCompanion)
2236+
CBCompanion,
2237+
MaybeCapabilityAnnot)
22332238

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

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

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

0 commit comments

Comments
 (0)