@@ -53,12 +53,12 @@ extension (tree: Tree)
5353 * throw IllegalCaptureRef otherwise
5454 */
5555 def toCaptureRefs (using Context ): List [CaptureRef ] = tree match
56- case ReachCapabilityApply (arg) =>
57- arg.toCaptureRefs.map(_.reach)
58- case ReadOnlyCapabilityApply (arg) =>
59- arg.toCaptureRefs.map(_.readOnly)
60- case CapsOfApply (arg) =>
61- arg.toCaptureRefs
56+ // case ReachCapabilityApply(arg) =>
57+ // arg.toCaptureRefs.map(_.reach)
58+ // case ReadOnlyCapabilityApply(arg) =>
59+ // arg.toCaptureRefs.map(_.readOnly)
60+ // case CapsOfApply(arg) =>
61+ // arg.toCaptureRefs
6262 case _ => tree.tpe.dealiasKeepAnnots match
6363 case ref : CaptureRef if ref.isTrackableRef =>
6464 ref :: Nil
@@ -78,28 +78,20 @@ extension (tree: Tree)
7878 val refs =
7979 tree match
8080 case Apply (_ : TypeApply , _) =>
81- CaptureSet (tree.retainedElemsFromType * )
81+ CaptureSet (tree.retainedSet.retainedElements * )
8282 case _ =>
8383 CaptureSet (tree.retainedElems.flatMap(_.toCaptureRefs)* )
8484 // println(s"toCaptureSet: $tree -> $refs")
8585 tree.putAttachment(Captures , refs)
8686 refs
8787
88- def retainedElemsFromType (using Context ): List [CaptureRef ] =
89- def collectRefs (tp : Type ): List [CaptureRef ] = tp match
90- case tp : CaptureRef if tp.isTrackableRef =>
91- tp :: Nil
92- case tp : TypeRef if tp.symbol.isType && tp.derivesFrom(defn.Caps_CapSet ) =>
93- tp :: Nil
94- case OrType (tp1, tp2) =>
95- collectRefs(tp1) ++ collectRefs(tp2)
96- case _ =>
97- Nil
88+ def retainedSet (using Context ): Type =
9889 tree match
99- case Apply (TypeApply (_, refs :: Nil ), _) =>
100- collectRefs(refs.tpe)
90+ case Apply (TypeApply (_, refs :: Nil ), _) => refs.tpe
10191 case _ =>
102- Nil
92+ if tree.symbol.maybeOwner == defn.RetainsCapAnnot
93+ then root.cap
94+ else NoType
10395
10496 /** The arguments of a @retains, @retainsCap or @retainsByName annotation */
10597 def retainedElems (using Context ): List [Tree ] = tree match
@@ -112,6 +104,21 @@ extension (tree: Tree)
112104
113105extension (tp : Type )
114106
107+ def retainedElements (using Context ): List [CaptureRef ] = tp match
108+ case ReachCapability (tp1) =>
109+ tp1.reach :: Nil
110+ case ReadOnlyCapability (tp1) =>
111+ tp1.readOnly :: Nil
112+ case tp : CaptureRef if tp.isTrackableRef =>
113+ tp :: Nil
114+ case tp : TypeRef if tp.symbol.isType && tp.derivesFrom(defn.Caps_CapSet ) =>
115+ tp :: Nil
116+ case OrType (tp1, tp2) =>
117+ tp1.retainedElements ++ tp2.retainedElements
118+ case _ =>
119+ if tp.isNothingType then Nil
120+ else throw IllegalCaptureRef (tp)
121+
115122 /** Is this type a CaptureRef that can be tracked?
116123 * This is true for
117124 * - all ThisTypes and all TermParamRef,
@@ -543,7 +550,7 @@ extension (cls: ClassSymbol)
543550 || bc.is(CaptureChecked )
544551 && bc.givenSelfType.dealiasKeepAnnots.match
545552 case CapturingType (_, refs) => refs.isAlwaysEmpty
546- case RetainingType (_, refs) => refs.isEmpty
553+ case RetainingType (_, refs) => refs.retainedElements. isEmpty
547554 case selfType =>
548555 isCaptureChecking // At Setup we have not processed self types yet, so
549556 // unless a self type is explicitly given, we can't tell
@@ -661,7 +668,7 @@ class CleanupRetains(using Context) extends TypeMap:
661668 def apply (tp : Type ): Type =
662669 tp match
663670 case AnnotatedType (tp, annot) if annot.symbol == defn.RetainsAnnot || annot.symbol == defn.RetainsByNameAnnot =>
664- RetainingType (tp, Nil , byName = annot.symbol == defn.RetainsByNameAnnot )
671+ RetainingType (tp, defn. NothingType , byName = annot.symbol == defn.RetainsByNameAnnot )
665672 case _ => mapOver(tp)
666673
667674/** A typemap that follows aliases and keeps their transformed results if
@@ -680,18 +687,18 @@ trait FollowAliasesMap(using Context) extends TypeMap:
680687/** An extractor for `caps.reachCapability(ref)`, which is used to express a reach
681688 * capability as a tree in a @retains annotation.
682689 */
683- object ReachCapabilityApply :
684- def unapply (tree : Apply )(using Context ): Option [Tree ] = tree match
685- case Apply (reach, arg :: Nil ) if reach.symbol == defn.Caps_reachCapability => Some (arg)
686- case _ => None
690+ // object ReachCapabilityApply:
691+ // def unapply(tree: Apply)(using Context): Option[Tree] = tree match
692+ // case Apply(reach, arg :: Nil) if reach.symbol == defn.Caps_reachCapability => Some(arg)
693+ // case _ => None
687694
688695/** An extractor for `caps.readOnlyCapability(ref)`, which is used to express a read-only
689696 * capability as a tree in a @retains annotation.
690697 */
691- object ReadOnlyCapabilityApply :
692- def unapply (tree : Apply )(using Context ): Option [Tree ] = tree match
693- case Apply (ro, arg :: Nil ) if ro.symbol == defn.Caps_readOnlyCapability => Some (arg)
694- case _ => None
698+ // object ReadOnlyCapabilityApply:
699+ // def unapply(tree: Apply)(using Context): Option[Tree] = tree match
700+ // case Apply(ro, arg :: Nil) if ro.symbol == defn.Caps_readOnlyCapability => Some(arg)
701+ // case _ => None
695702
696703/** An extractor for `caps.capsOf[X]`, which is used to express a generic capture set
697704 * as a tree in a @retains annotation.
0 commit comments