@@ -56,10 +56,14 @@ sealed abstract class CaptureSet extends Showable:
56
56
*/
57
57
def isAlwaysEmpty : Boolean
58
58
59
- /** An optional level limit, or NoSymbol if none exists. All elements of the set
60
- * must be in scopes visible from the level limit .
59
+ /** An optional level limit, or -1 if none exists. All elements of the set
60
+ * must be at levels equal or smaller than the level of the set .
61
61
*/
62
- def levelLimit : Symbol
62
+ def level : Int
63
+
64
+ /** An optional owner, or NoSymbol if none exists. Used for diagnstics
65
+ */
66
+ def owner : Symbol
63
67
64
68
/** Is this capture set definitely non-empty? */
65
69
final def isNotEmpty : Boolean = ! elems.isEmpty
@@ -242,9 +246,7 @@ sealed abstract class CaptureSet extends Showable:
242
246
if this .subCaptures(that, frozen = true ).isOK then that
243
247
else if that.subCaptures(this , frozen = true ).isOK then this
244
248
else if this .isConst && that.isConst then Const (this .elems ++ that.elems)
245
- else Var (
246
- this .levelLimit.maxNested(that.levelLimit, onConflict = (sym1, sym2) => sym1),
247
- this .elems ++ that.elems)
249
+ else Var (initialElems = this .elems ++ that.elems)
248
250
.addAsDependentTo(this ).addAsDependentTo(that)
249
251
250
252
/** The smallest superset (via <:<) of this capture set that also contains `ref`.
@@ -414,7 +416,9 @@ object CaptureSet:
414
416
415
417
def withDescription (description : String ): Const = Const (elems, description)
416
418
417
- def levelLimit = NoSymbol
419
+ def level = - 1
420
+
421
+ def owner = NoSymbol
418
422
419
423
override def toString = elems.toString
420
424
end Const
@@ -434,7 +438,7 @@ object CaptureSet:
434
438
end Fluid
435
439
436
440
/** The subclass of captureset variables with given initial elements */
437
- class Var (directOwner : Symbol , initialElems : Refs = emptySet, level : Int = - 1 , underBox : Boolean = false )(using @ constructorOnly ictx : Context ) extends CaptureSet :
441
+ class Var (override val owner : Symbol = NoSymbol , initialElems : Refs = emptySet, val level : Int = - 1 , underBox : Boolean = false )(using @ constructorOnly ictx : Context ) extends CaptureSet :
438
442
439
443
/** A unique identification number for diagnostics */
440
444
val id =
@@ -443,9 +447,6 @@ object CaptureSet:
443
447
444
448
// assert(id != 40)
445
449
446
- override val levelLimit =
447
- if directOwner.exists then directOwner.levelOwner else NoSymbol
448
-
449
450
/** A variable is solved if it is aproximated to a from-then-on constant set. */
450
451
private var isSolved : Boolean = false
451
452
@@ -519,9 +520,9 @@ object CaptureSet:
519
520
private def levelOK (elem : CaptureRef )(using Context ): Boolean =
520
521
if elem.isRootCapability then ! noUniversal
521
522
else elem match
522
- case elem : TermRef if levelLimit.exists =>
523
+ case elem : TermRef if level != - 1 =>
523
524
level == - 1 || ccState.level(elem.symbol) <= level
524
- case elem : ThisType if levelLimit.exists =>
525
+ case elem : ThisType if level != 1 =>
525
526
level == - 1 || ccState.level(elem.cls) + 1 <= level
526
527
case ReachCapability (elem1) =>
527
528
levelOK(elem1)
@@ -600,8 +601,8 @@ object CaptureSet:
600
601
val debugInfo =
601
602
if ! isConst && ctx.settings.YccDebug .value then ids else " "
602
603
val limitInfo =
603
- if ctx.settings.YprintLevel .value && levelLimit.exists
604
- then i " <in $levelLimit > "
604
+ if ctx.settings.YprintLevel .value && level != - 1
605
+ then i " <at level $level > "
605
606
else " "
606
607
debugInfo ++ limitInfo
607
608
@@ -648,7 +649,7 @@ object CaptureSet:
648
649
*/
649
650
class Mapped private [CaptureSet ]
650
651
(val source : Var , tm : TypeMap , variance : Int , initial : CaptureSet )(using @ constructorOnly ctx : Context )
651
- extends DerivedVar (source.levelLimit , initial.elems):
652
+ extends DerivedVar (source.owner , initial.elems):
652
653
addAsDependentTo(initial) // initial mappings could change by propagation
653
654
654
655
private def mapIsIdempotent = tm.isInstanceOf [IdempotentCaptRefMap ]
@@ -745,7 +746,7 @@ object CaptureSet:
745
746
*/
746
747
final class BiMapped private [CaptureSet ]
747
748
(val source : Var , bimap : BiTypeMap , initialElems : Refs )(using @ constructorOnly ctx : Context )
748
- extends DerivedVar (source.levelLimit , initialElems):
749
+ extends DerivedVar (source.owner , initialElems):
749
750
750
751
override def tryInclude (elem : CaptureRef , origin : CaptureSet )(using Context , VarState ): CompareResult =
751
752
if origin eq source then
@@ -779,7 +780,7 @@ object CaptureSet:
779
780
/** A variable with elements given at any time as { x <- source.elems | p(x) } */
780
781
class Filtered private [CaptureSet ]
781
782
(val source : Var , p : Context ?=> CaptureRef => Boolean )(using @ constructorOnly ctx : Context )
782
- extends DerivedVar (source.levelLimit , source.elems.filter(p)):
783
+ extends DerivedVar (source.owner , source.elems.filter(p)):
783
784
784
785
override def tryInclude (elem : CaptureRef , origin : CaptureSet )(using Context , VarState ): CompareResult =
785
786
if accountsFor(elem) then
@@ -809,7 +810,7 @@ object CaptureSet:
809
810
extends Filtered (source, ! other.accountsFor(_))
810
811
811
812
class Intersected (cs1 : CaptureSet , cs2 : CaptureSet )(using Context )
812
- extends Var (cs1.levelLimit.minNested(cs2.levelLimit), elemIntersection(cs1, cs2)):
813
+ extends Var (initialElems = elemIntersection(cs1, cs2)):
813
814
addAsDependentTo(cs1)
814
815
addAsDependentTo(cs2)
815
816
deps += cs1
@@ -899,7 +900,7 @@ object CaptureSet:
899
900
if ctx.settings.YccDebug .value then printer.toText(trace, " , " )
900
901
else blocking.show
901
902
case LevelError (cs : CaptureSet , elem : CaptureRef ) =>
902
- Str (i " ( $elem at wrong level for $cs in ${cs.levelLimit }) " )
903
+ Str (i " ( $elem at wrong level for $cs at level ${cs.level }) " )
903
904
904
905
/** The result is OK */
905
906
def isOK : Boolean = this == OK
@@ -1142,6 +1143,6 @@ object CaptureSet:
1142
1143
i """
1143
1144
|
1144
1145
|Note that reference ${ref}$levelStr
1145
- |cannot be included in outer capture set $cs which is associated with ${cs.levelLimit} """
1146
+ |cannot be included in outer capture set $cs"""
1146
1147
1147
1148
end CaptureSet
0 commit comments