Skip to content

Commit 1b7e08c

Browse files
committed
Refactoring: Capabilities as a separate type
Split out Capability from Type. For now we keep most of the overall structure. E.g. capability handling code is in file CaptureRef.scala. We will change this afterwards in separate refactorings.
1 parent 4b6dc5b commit 1b7e08c

18 files changed

+728
-883
lines changed

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

+7-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Decorators.*
1010
import config.Printers.capt
1111
import printing.Printer
1212
import printing.Texts.Text
13+
import cc.Capabilities.{Capability, RootCapability}
1314

1415
/** An annotation representing a capture set and whether it is boxed.
1516
* It simulates a normal @retains annotation except that it is more efficient,
@@ -39,10 +40,10 @@ case class CaptureAnnotation(refs: CaptureSet, boxed: Boolean)(cls: Symbol) exte
3940
/** Reconstitute annotation tree from capture set */
4041
override def tree(using Context) =
4142
val elems = refs.elems.toList.map {
42-
case cr: TermRef => ref(cr)
43-
case cr: TermParamRef => untpd.Ident(cr.paramName).withType(cr)
44-
case cr: ThisType => This(cr.cls)
45-
case root(_) => ref(root.cap)
43+
case c: TermRef => ref(c)
44+
case c: TermParamRef => untpd.Ident(c.paramName).withType(c)
45+
case c: ThisType => This(c.cls)
46+
case c: RootCapability => ref(defn.captureRoot)
4647
// TODO: Will crash if the type is an annotated type, for example `cap.rd`
4748
}
4849
val arg = repeated(elems, TypeTree(defn.AnyType))
@@ -66,9 +67,9 @@ case class CaptureAnnotation(refs: CaptureSet, boxed: Boolean)(cls: Symbol) exte
6667
val elems1 = elems.mapConserve(tm.mapCapability(_))
6768
if elems1 eq elems then this
6869
else if elems1.forall:
69-
case elem1: CaptureRef => elem1.isTrackableRef
70+
case elem1: Capability => elem1.isWellformed
7071
case _ => false
71-
then derivedAnnotation(CaptureSet(elems1.asInstanceOf[List[CaptureRef]]*), boxed)
72+
then derivedAnnotation(CaptureSet(elems1.asInstanceOf[List[Capability]]*), boxed)
7273
else EmptyAnnotation
7374

7475
override def refersToParamOf(tl: TermLambda)(using Context): Boolean =

0 commit comments

Comments
 (0)