@@ -17,6 +17,7 @@ import util.common.alwaysTrue
1717import scala .collection .mutable
1818import config .Config .ccAllowUnsoundMaps
1919import language .experimental .pureFunctions
20+ import annotation .retains
2021
2122/** A class for capture sets. Capture sets can be constants or variables.
2223 * Capture sets support inclusion constraints <:< where <:< is subcapturing.
@@ -176,7 +177,7 @@ sealed abstract class CaptureSet extends Showable, caps.Pure:
176177 case Nil =>
177178 addDependent(that)
178179 recur(elems.toList)
179- .showing(i " subcaptures $this <:< $that = ${ result.show} " , capt)
180+ .showing(i " subcaptures $this <:< $that = $result" , capt)( using null )
180181
181182 /** Two capture sets are considered =:= equal if they mutually subcapture each other
182183 * in a frozen state.
@@ -223,7 +224,7 @@ sealed abstract class CaptureSet extends Showable, caps.Pure:
223224 /** The largest subset (via <:<) of this capture set that only contains elements
224225 * for which `p` is true.
225226 */
226- def filter (p : CaptureRef -> Boolean )(using Context ): CaptureSet =
227+ def filter (p : ( c : Context ) ?-> ( CaptureRef -> Boolean ) @ retains(c) )(using Context ): CaptureSet =
227228 if this .isConst then
228229 val elems1 = elems.filter(p)
229230 if elems1 == elems then this
@@ -269,7 +270,7 @@ sealed abstract class CaptureSet extends Showable, caps.Pure:
269270
270271 /** A mapping resulting from substituting parameters of a BindingType to a list of types */
271272 def substParams (tl : BindingType , to : List [Type ])(using Context ) =
272- map(Substituters .SubstParamsMap (tl, to))
273+ map(Substituters .SubstParamsMap (tl, to).detach )
273274
274275 /** Invoke handler if this set has (or later aquires) the root capability `*` */
275276 def disallowRootCapability (handler : () => Context ?=> Unit )(using Context ): this .type =
@@ -596,7 +597,7 @@ object CaptureSet:
596597 super .addNewElems(newElems, origin)
597598 .andAlso {
598599 source.tryInclude(newElems.map(bimap.backward), this )
599- .showing(i " propagating new elems ${CaptureSet (newElems)} backward from $this to $source" , capt)
600+ .showing(i " propagating new elems ${CaptureSet (newElems)} backward from $this to $source" , capt)( using null )
600601 }
601602
602603 /** For a BiTypeMap, supertypes of the mapped type also constrain
@@ -608,15 +609,15 @@ object CaptureSet:
608609 */
609610 override def computeApprox (origin : CaptureSet )(using Context ): CaptureSet =
610611 val supApprox = super .computeApprox(this )
611- if source eq origin then supApprox.map(bimap.inverseTypeMap)
612+ if source eq origin then supApprox.map(bimap.inverseTypeMap.detach )
612613 else source.upperApprox(this ).map(bimap) ** supApprox
613614
614615 override def toString = s " BiMapped $id( $source, elems = $elems) "
615616 end BiMapped
616617
617618 /** A variable with elements given at any time as { x <- source.elems | p(x) } */
618619 class Filtered private [CaptureSet ]
619- (val source : Var , p : CaptureRef -> Boolean )(using @ constructorOnly ctx : Context )
620+ (val source : Var , p : ( c : Context ) ?-> ( CaptureRef -> Boolean ) @ retains(c) )(using @ constructorOnly ctx : Context )
620621 extends DerivedVar (source.elems.filter(p)):
621622
622623 override def addNewElems (newElems : Refs , origin : CaptureSet )(using Context , VarState ): CompareResult =
@@ -644,10 +645,10 @@ object CaptureSet:
644645 end Filtered
645646
646647 /** A variable with elements given at any time as { x <- source.elems | !other.accountsFor(x) } */
647- class Diff (source : Var , other : Const )(using Context )
648+ class Diff (source : Var , other : Const )(using @ constructorOnly ctx : Context )
648649 extends Filtered (source, ! other.accountsFor(_))
649650
650- class Intersected (cs1 : CaptureSet , cs2 : CaptureSet )(using Context )
651+ class Intersected (cs1 : CaptureSet , cs2 : CaptureSet )(using @ constructorOnly ctx : Context )
651652 extends Var (elemIntersection(cs1, cs2)):
652653 addAsDependentTo(cs1)
653654 addAsDependentTo(cs2)
0 commit comments