Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions compiler/src/dotty/tools/dotc/cc/CaptureAnnotation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Decorators.*
import config.Printers.capt
import printing.Printer
import printing.Texts.Text
import cc.Capabilities.{Capability, RootCapability}

/** An annotation representing a capture set and whether it is boxed.
* It simulates a normal @retains annotation except that it is more efficient,
Expand Down Expand Up @@ -39,10 +40,10 @@ case class CaptureAnnotation(refs: CaptureSet, boxed: Boolean)(cls: Symbol) exte
/** Reconstitute annotation tree from capture set */
override def tree(using Context) =
val elems = refs.elems.toList.map {
case cr: TermRef => ref(cr)
case cr: TermParamRef => untpd.Ident(cr.paramName).withType(cr)
case cr: ThisType => This(cr.cls)
case root(_) => ref(root.cap)
case c: TermRef => ref(c)
case c: TermParamRef => untpd.Ident(c.paramName).withType(c)
case c: ThisType => This(c.cls)
case c: RootCapability => ref(defn.captureRoot)
// TODO: Will crash if the type is an annotated type, for example `cap.rd`
}
val arg = repeated(elems, TypeTree(defn.AnyType))
Expand All @@ -63,10 +64,12 @@ case class CaptureAnnotation(refs: CaptureSet, boxed: Boolean)(cls: Symbol) exte

override def mapWith(tm: TypeMap)(using Context) =
val elems = refs.elems.toList
val elems1 = elems.mapConserve(tm)
val elems1 = elems.mapConserve(tm.mapCapability(_))
if elems1 eq elems then this
else if elems1.forall(_.isTrackableRef)
then derivedAnnotation(CaptureSet(elems1.asInstanceOf[List[CaptureRef]]*), boxed)
else if elems1.forall:
case elem1: Capability => elem1.isWellformed
case _ => false
then derivedAnnotation(CaptureSet(elems1.asInstanceOf[List[Capability]]*), boxed)
else EmptyAnnotation

override def refersToParamOf(tl: TermLambda)(using Context): Boolean =
Expand Down
Loading
Loading