@@ -36,22 +36,26 @@ def allowUniversalInBoxed(using Context) =
36
36
/** An exception thrown if a @retains argument is not syntactically a CaptureRef */
37
37
class IllegalCaptureRef (tpe : Type ) extends Exception
38
38
39
- /** Capture checking state, consisting of
40
- * - nestingLevels: A map associating certain symbols (the nesting level owners)
41
- 8 with their ccNestingLevel
42
- * - localRoots: A map associating nesting level owners with the local roots valid
43
- * in their scopes.
44
- * - levelError: Optionally, the last pair of capture reference and capture set where
45
- * the reference could not be added to the set due to a level conflict.
46
- * The capture checking state is stored in a context property.
47
- */
39
+ /** Capture checking state, which is stored in a context property */
48
40
class CCState :
41
+
42
+ /** Associates certain symbols (the nesting level owners) with their ccNestingLevel */
49
43
val nestingLevels : mutable.HashMap [Symbol , Int ] = new mutable.HashMap
44
+
45
+ /** Associates nesting level owners with the local roots valid in their scopes. */
50
46
val localRoots : mutable.HashMap [Symbol , Symbol ] = new mutable.HashMap
47
+
48
+ /** The last pair of capture reference and capture set where
49
+ * the reference could not be added to the set due to a level conflict.
50
+ */
51
51
var levelError : Option [(CaptureRef , CaptureSet )] = None
52
+ end CCState
52
53
53
54
/** Property key for capture checking state */
54
- val ccState : Key [CCState ] = Key ()
55
+ val ccStateKey : Key [CCState ] = Key ()
56
+
57
+ /** The currently valid CCState */
58
+ def ccState (using Context ) = ctx.property(ccStateKey).get
55
59
56
60
trait FollowAliases extends TypeMap :
57
61
def mapOverFollowingAliases (t : Type ): Type = t match
@@ -348,7 +352,7 @@ extension (sym: Symbol)
348
352
else if sym.is(Method ) then
349
353
if sym.isAnonymousFunction then
350
354
// Setup added anonymous functions counting as level owners to nestingLevels
351
- ctx.property( ccState).get .nestingLevels.contains(sym)
355
+ ccState.nestingLevels.contains(sym)
352
356
else
353
357
! sym.isConstructor && ! isCaseClassSynthetic
354
358
else false
@@ -371,21 +375,18 @@ extension (sym: Symbol)
371
375
def ccNestingLevel (using Context ): Int =
372
376
if sym.exists then
373
377
val lowner = sym.levelOwner
374
- val cache = ctx.property(ccState).get.nestingLevels
375
- cache.getOrElseUpdate(lowner,
378
+ ccState.nestingLevels.getOrElseUpdate(lowner,
376
379
if lowner.isRoot then 0 else lowner.owner.ccNestingLevel + 1 )
377
380
else - 1
378
381
379
382
/** Optionally, the nesting level of `sym` for the purposes of `cc`, provided
380
383
* a capture checker is running.
381
384
*/
382
385
def ccNestingLevelOpt (using Context ): Option [Int ] =
383
- if ctx.property(ccState).isDefined then
384
- Some (ccNestingLevel)
385
- else None
386
+ if ctx.property(ccStateKey).isDefined then Some (ccNestingLevel) else None
386
387
387
388
def setNestingLevel (level : Int )(using Context ): Unit =
388
- ctx.property( ccState).get .nestingLevels(sym) = level
389
+ ccState.nestingLevels(sym) = level
389
390
390
391
/** The parameter with type caps.Root in the leading term parameter section,
391
392
* or NoSymbol, if none exists.
@@ -403,7 +404,7 @@ extension (sym: Symbol)
403
404
def lclRoot =
404
405
if owner.isTerm then owner.definedLocalRoot.orElse(newRoot)
405
406
else newRoot
406
- ctx.property( ccState).get .localRoots.getOrElseUpdate(owner, lclRoot)
407
+ ccState.localRoots.getOrElseUpdate(owner, lclRoot)
407
408
408
409
def maxNested (other : Symbol )(using Context ): Symbol =
409
410
if sym.ccNestingLevel < other.ccNestingLevel then other else sym
0 commit comments