@@ -17,6 +17,7 @@ import typer.ErrorReporting.Addenda
17
17
import TypeComparer .linkOK
18
18
import util .common .alwaysTrue
19
19
import scala .collection .mutable
20
+ import CCState .*
20
21
21
22
/** A class for capture sets. Capture sets can be constants or variables.
22
23
* Capture sets support inclusion constraints <:< where <:< is subcapturing.
@@ -56,10 +57,14 @@ sealed abstract class CaptureSet extends Showable:
56
57
*/
57
58
def isAlwaysEmpty : Boolean
58
59
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 .
60
+ /** An optional level limit, or undefinedLevel if none exists. All elements of the set
61
+ * must be at levels equal or smaller than the level of the set, if it is defined .
61
62
*/
62
- def levelLimit : Symbol
63
+ def level : Level
64
+
65
+ /** An optional owner, or NoSymbol if none exists. Used for diagnstics
66
+ */
67
+ def owner : Symbol
63
68
64
69
/** Is this capture set definitely non-empty? */
65
70
final def isNotEmpty : Boolean = ! elems.isEmpty
@@ -242,9 +247,7 @@ sealed abstract class CaptureSet extends Showable:
242
247
if this .subCaptures(that, frozen = true ).isOK then that
243
248
else if that.subCaptures(this , frozen = true ).isOK then this
244
249
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)
250
+ else Var (initialElems = this .elems ++ that.elems)
248
251
.addAsDependentTo(this ).addAsDependentTo(that)
249
252
250
253
/** The smallest superset (via <:<) of this capture set that also contains `ref`.
@@ -414,7 +417,9 @@ object CaptureSet:
414
417
415
418
def withDescription (description : String ): Const = Const (elems, description)
416
419
417
- def levelLimit = NoSymbol
420
+ def level = undefinedLevel
421
+
422
+ def owner = NoSymbol
418
423
419
424
override def toString = elems.toString
420
425
end Const
@@ -434,7 +439,7 @@ object CaptureSet:
434
439
end Fluid
435
440
436
441
/** The subclass of captureset variables with given initial elements */
437
- class Var (directOwner : Symbol , initialElems : Refs = emptySet)(using @ constructorOnly ictx : Context ) extends CaptureSet :
442
+ class Var (override val owner : Symbol = NoSymbol , initialElems : Refs = emptySet, val level : Level = undefinedLevel, underBox : Boolean = false )(using @ constructorOnly ictx : Context ) extends CaptureSet :
438
443
439
444
/** A unique identification number for diagnostics */
440
445
val id =
@@ -443,9 +448,6 @@ object CaptureSet:
443
448
444
449
// assert(id != 40)
445
450
446
- override val levelLimit =
447
- if directOwner.exists then directOwner.levelOwner else NoSymbol
448
-
449
451
/** A variable is solved if it is aproximated to a from-then-on constant set. */
450
452
private var isSolved : Boolean = false
451
453
@@ -519,12 +521,10 @@ object CaptureSet:
519
521
private def levelOK (elem : CaptureRef )(using Context ): Boolean =
520
522
if elem.isRootCapability then ! noUniversal
521
523
else elem match
522
- case elem : TermRef if levelLimit.exists =>
523
- var sym = elem.symbol
524
- if sym.isLevelOwner then sym = sym.owner
525
- levelLimit.isContainedIn(sym.levelOwner)
526
- case elem : ThisType if levelLimit.exists =>
527
- levelLimit.isContainedIn(elem.cls.levelOwner)
524
+ case elem : TermRef if level.isDefined =>
525
+ elem.symbol.ccLevel <= level
526
+ case elem : ThisType if level.isDefined =>
527
+ elem.cls.ccLevel.nextInner <= level
528
528
case ReachCapability (elem1) =>
529
529
levelOK(elem1)
530
530
case MaybeCapability (elem1) =>
@@ -602,8 +602,8 @@ object CaptureSet:
602
602
val debugInfo =
603
603
if ! isConst && ctx.settings.YccDebug .value then ids else " "
604
604
val limitInfo =
605
- if ctx.settings.YprintLevel .value && levelLimit.exists
606
- then i " <in $levelLimit > "
605
+ if ctx.settings.YprintLevel .value && level.isDefined
606
+ then i " <at level ${level.toString} > "
607
607
else " "
608
608
debugInfo ++ limitInfo
609
609
@@ -622,13 +622,6 @@ object CaptureSet:
622
622
override def toString = s " Var $id$elems"
623
623
end Var
624
624
625
- /** Variables that represent refinements of class parameters can have the universal
626
- * capture set, since they represent only what is the result of the constructor.
627
- * Test case: Without that tweak, logger.scala would not compile.
628
- */
629
- class RefiningVar (directOwner : Symbol )(using Context ) extends Var (directOwner):
630
- override def disallowRootCapability (handler : () => Context ?=> Unit )(using Context ) = this
631
-
632
625
/** A variable that is derived from some other variable via a map or filter. */
633
626
abstract class DerivedVar (owner : Symbol , initialElems : Refs )(using @ constructorOnly ctx : Context )
634
627
extends Var (owner, initialElems):
@@ -657,7 +650,7 @@ object CaptureSet:
657
650
*/
658
651
class Mapped private [CaptureSet ]
659
652
(val source : Var , tm : TypeMap , variance : Int , initial : CaptureSet )(using @ constructorOnly ctx : Context )
660
- extends DerivedVar (source.levelLimit , initial.elems):
653
+ extends DerivedVar (source.owner , initial.elems):
661
654
addAsDependentTo(initial) // initial mappings could change by propagation
662
655
663
656
private def mapIsIdempotent = tm.isInstanceOf [IdempotentCaptRefMap ]
@@ -754,7 +747,7 @@ object CaptureSet:
754
747
*/
755
748
final class BiMapped private [CaptureSet ]
756
749
(val source : Var , bimap : BiTypeMap , initialElems : Refs )(using @ constructorOnly ctx : Context )
757
- extends DerivedVar (source.levelLimit , initialElems):
750
+ extends DerivedVar (source.owner , initialElems):
758
751
759
752
override def tryInclude (elem : CaptureRef , origin : CaptureSet )(using Context , VarState ): CompareResult =
760
753
if origin eq source then
@@ -788,7 +781,7 @@ object CaptureSet:
788
781
/** A variable with elements given at any time as { x <- source.elems | p(x) } */
789
782
class Filtered private [CaptureSet ]
790
783
(val source : Var , p : Context ?=> CaptureRef => Boolean )(using @ constructorOnly ctx : Context )
791
- extends DerivedVar (source.levelLimit , source.elems.filter(p)):
784
+ extends DerivedVar (source.owner , source.elems.filter(p)):
792
785
793
786
override def tryInclude (elem : CaptureRef , origin : CaptureSet )(using Context , VarState ): CompareResult =
794
787
if accountsFor(elem) then
@@ -818,7 +811,7 @@ object CaptureSet:
818
811
extends Filtered (source, ! other.accountsFor(_))
819
812
820
813
class Intersected (cs1 : CaptureSet , cs2 : CaptureSet )(using Context )
821
- extends Var (cs1.levelLimit.minNested(cs2.levelLimit), elemIntersection(cs1, cs2)):
814
+ extends Var (initialElems = elemIntersection(cs1, cs2)):
822
815
addAsDependentTo(cs1)
823
816
addAsDependentTo(cs2)
824
817
deps += cs1
@@ -908,7 +901,7 @@ object CaptureSet:
908
901
if ctx.settings.YccDebug .value then printer.toText(trace, " , " )
909
902
else blocking.show
910
903
case LevelError (cs : CaptureSet , elem : CaptureRef ) =>
911
- Str (i " ( $elem at wrong level for $cs in ${cs.levelLimit }) " )
904
+ Str (i " ( $elem at wrong level for $cs at level ${cs.level.toString }) " )
912
905
913
906
/** The result is OK */
914
907
def isOK : Boolean = this == OK
@@ -1151,6 +1144,6 @@ object CaptureSet:
1151
1144
i """
1152
1145
|
1153
1146
|Note that reference ${ref}$levelStr
1154
- |cannot be included in outer capture set $cs which is associated with ${cs.levelLimit} """
1147
+ |cannot be included in outer capture set $cs"""
1155
1148
1156
1149
end CaptureSet
0 commit comments