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