@@ -178,12 +178,7 @@ sealed abstract class CaptureSet extends Showable:
178178
179179 /** Try to include all element in `refs` to this capture set. */
180180 protected final def tryInclude (newElems : Refs , origin : CaptureSet )(using Context , VarState ): Boolean =
181- TypeComparer .inNestedLevel:
182- // Run in nested level so that a error notes for a failure here can be
183- // cancelled in case the whole comparison succeeds.
184- // We do this here because all nested tryInclude and subCaptures calls go
185- // through this method.
186- newElems.forall(tryInclude(_, origin))
181+ newElems.forall(tryInclude(_, origin))
187182
188183 protected def mutableToReader (origin : CaptureSet )(using Context ): Boolean =
189184 if mutability == Mutable then toReader() else true
@@ -284,16 +279,14 @@ sealed abstract class CaptureSet extends Showable:
284279
285280 /** The subcapturing test, using a given VarState */
286281 final def subCaptures (that : CaptureSet )(using ctx : Context , vs : VarState = VarState ()): Boolean =
287- val this1 = this .adaptMutability(that)
288- if this1 == null then false
289- else if this1 ne this then
290- capt.println(i " WIDEN ro $this with ${this .mutability} <:< $that with ${that.mutability} to $this1" )
291- this1.subCaptures(that, vs)
292- else if that.tryInclude(elems, this ) then
293- addDependent(that)
294- else
295- varState.rollBack()
296- false
282+ TypeComparer .inNestedLevel:
283+ val this1 = this .adaptMutability(that)
284+ if this1 == null then false
285+ else if this1 ne this then
286+ capt.println(i " WIDEN ro $this with ${this .mutability} <:< $that with ${that.mutability} to $this1" )
287+ this1.subCaptures(that, vs)
288+ else
289+ that.tryInclude(elems, this ) && addDependent(that)
297290
298291 /** Two capture sets are considered =:= equal if they mutually subcapture each other
299292 * in a frozen state.
@@ -662,30 +655,6 @@ object CaptureSet:
662655
663656 var description : String = " "
664657
665- /** Record current elements in given VarState provided it does not yet
666- * contain an entry for this variable.
667- */
668- private def recordElemsState ()(using VarState ): Boolean =
669- varState.getElems(this ) match
670- case None => varState.putElems(this , elems)
671- case _ => true
672-
673- /** Record current dependent sets in given VarState provided it does not yet
674- * contain an entry for this variable.
675- */
676- private [CaptureSet ] def recordDepsState ()(using VarState ): Boolean =
677- varState.getDeps(this ) match
678- case None => varState.putDeps(this , deps)
679- case _ => true
680-
681- /** Reset elements to what was recorded in `state` */
682- def resetElems ()(using state : VarState ): Unit =
683- elems = state.elems(this )
684-
685- /** Reset dependent sets to what was recorded in `state` */
686- def resetDeps ()(using state : VarState ): Unit =
687- deps = state.deps(this )
688-
689658 /** Check that all maps recorded in skippedMaps map `elem` to itself
690659 * or something subsumed by it.
691660 */
@@ -708,7 +677,7 @@ object CaptureSet:
708677 deps -= cs
709678
710679 final def addThisElem (elem : Capability )(using Context , VarState ): Boolean =
711- if isConst || ! recordElemsState() then // Fail if variable is solved or given VarState is frozen
680+ if isConst || ! varState.canRecord then // Fail if variable is solved or given VarState is frozen
712681 addIfHiddenOrFail(elem)
713682 else if ! levelOK(elem) then
714683 failWith(IncludeFailure (this , elem, levelError = true )) // or `elem` is not visible at the level of the set.
@@ -784,7 +753,7 @@ object CaptureSet:
784753 (cs eq this )
785754 || cs.isUniversal
786755 || isConst
787- || recordDepsState() && { includeDep(cs); true }
756+ || varState.canRecord && { includeDep(cs); true }
788757
789758 override def disallowRootCapability (upto : Symbol )(handler : () => Context ?=> Unit )(using Context ): this .type =
790759 rootLimit = upto
@@ -1250,41 +1219,15 @@ object CaptureSet:
12501219 */
12511220 class VarState :
12521221
1253- /** A map from captureset variables to their elements at the time of the snapshot. */
1254- private val elemsMap : util.EqHashMap [Var , Refs ] = new util.EqHashMap
1255-
1256- /** A map from captureset variables to their dependent sets at the time of the snapshot. */
1257- private val depsMap : util.EqHashMap [Var , Deps ] = new util.EqHashMap
1258-
12591222 /** A map from ResultCap values to other ResultCap values. If two result values
12601223 * `a` and `b` are unified, then `eqResultMap(a) = b` and `eqResultMap(b) = a`.
12611224 */
12621225 private var eqResultMap : util.SimpleIdentityMap [ResultCap , ResultCap ] = util.SimpleIdentityMap .empty
12631226
1264- /** A snapshot of the `eqResultMap` value at the start of a VarState transaction */
1265- private var eqResultSnapshot : util.SimpleIdentityMap [ResultCap , ResultCap ] | Null = null
1266-
1267- /** The recorded elements of `v` (it's required that a recording was made) */
1268- def elems (v : Var ): Refs = elemsMap(v)
1269-
1270- /** Optionally the recorded elements of `v`, None if nothing was recorded for `v` */
1271- def getElems (v : Var ): Option [Refs ] = elemsMap.get(v)
1272-
12731227 /** Record elements, return whether this was allowed.
12741228 * By default, recording is allowed in regular but not in frozen states.
12751229 */
1276- def putElems (v : Var , elems : Refs ): Boolean = { elemsMap(v) = elems; true }
1277-
1278- /** The recorded dependent sets of `v` (it's required that a recording was made) */
1279- def deps (v : Var ): Deps = depsMap(v)
1280-
1281- /** Optionally the recorded dependent sets of `v`, None if nothing was recorded for `v` */
1282- def getDeps (v : Var ): Option [Deps ] = depsMap.get(v)
1283-
1284- /** Record dependent sets, return whether this was allowed.
1285- * By default, recording is allowed in regular but not in frozen states.
1286- */
1287- def putDeps (v : Var , deps : Deps ): Boolean = { depsMap(v) = deps; true }
1230+ def canRecord : Boolean = true
12881231
12891232 /** Does this state allow additions of elements to capture set variables? */
12901233 def isOpen = true
@@ -1295,11 +1238,6 @@ object CaptureSet:
12951238 * but the special state VarState.Separate overrides this.
12961239 */
12971240 def addHidden (hidden : HiddenSet , elem : Capability )(using Context ): Boolean =
1298- elemsMap.get(hidden) match
1299- case None =>
1300- elemsMap(hidden) = hidden.elems
1301- depsMap(hidden) = hidden.deps
1302- case _ =>
13031241 hidden.add(elem)(using ctx, this )
13041242 true
13051243
@@ -1323,20 +1261,13 @@ object CaptureSet:
13231261 && eqResultMap(c1) == null
13241262 && eqResultMap(c2) == null
13251263 && {
1326- if eqResultSnapshot == null then eqResultSnapshot = eqResultMap
13271264 eqResultMap = eqResultMap.updated(c1, c2).updated(c2, c1)
13281265 TypeComparer .logUndoAction: () =>
13291266 eqResultMap.remove(c1)
13301267 eqResultMap.remove(c2)
13311268 true
13321269 }
13331270
1334- /** Roll back global state to what was recorded in this VarState */
1335- def rollBack (): Unit =
1336- elemsMap.keysIterator.foreach(_.resetElems()(using this ))
1337- depsMap.keysIterator.foreach(_.resetDeps()(using this ))
1338- if eqResultSnapshot != null then eqResultMap = eqResultSnapshot.nn
1339-
13401271 private var seen : util.EqHashSet [Capability ] = new util.EqHashSet
13411272
13421273 /** Run test `pred` unless `ref` was seen in an enclosing `ifNotSeen` operation */
@@ -1356,8 +1287,7 @@ object CaptureSet:
13561287 * subsume arbitary types, which are then recorded in their hidden sets.
13571288 */
13581289 class Closed extends VarState :
1359- override def putElems (v : Var , refs : Refs ) = false
1360- override def putDeps (v : Var , deps : Deps ) = false
1290+ override def canRecord = false
13611291 override def isOpen = false
13621292 override def toString = " closed varState"
13631293
@@ -1381,13 +1311,10 @@ object CaptureSet:
13811311 */
13821312 def HardSeparate (using Context ): Separating = ccState.HardSeparate
13831313
1384- /** A special state that turns off recording of elements. Used only
1314+ /** A special state that turns off recording of hidden elements. Used only
13851315 * in `addSub` to prevent cycles in recordings. Instantiated in ccState.Unrecorded.
13861316 */
13871317 class Unrecorded extends VarState :
1388- override def putElems (v : Var , refs : Refs ) = true
1389- override def putDeps (v : Var , deps : Deps ) = true
1390- override def rollBack (): Unit = ()
13911318 override def addHidden (hidden : HiddenSet , elem : Capability )(using Context ): Boolean = true
13921319 override def toString = " unrecorded varState"
13931320
0 commit comments