Skip to content

Commit 2a4c496

Browse files
committed
Drop old levelOwner scheme
1 parent 1432634 commit 2a4c496

File tree

6 files changed

+28
-32
lines changed

6 files changed

+28
-32
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

+22-21
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ sealed abstract class CaptureSet extends Showable:
5656
*/
5757
def isAlwaysEmpty: Boolean
5858

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.
6161
*/
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
6367

6468
/** Is this capture set definitely non-empty? */
6569
final def isNotEmpty: Boolean = !elems.isEmpty
@@ -242,9 +246,7 @@ sealed abstract class CaptureSet extends Showable:
242246
if this.subCaptures(that, frozen = true).isOK then that
243247
else if that.subCaptures(this, frozen = true).isOK then this
244248
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)
248250
.addAsDependentTo(this).addAsDependentTo(that)
249251

250252
/** The smallest superset (via <:<) of this capture set that also contains `ref`.
@@ -414,7 +416,9 @@ object CaptureSet:
414416

415417
def withDescription(description: String): Const = Const(elems, description)
416418

417-
def levelLimit = NoSymbol
419+
def level = -1
420+
421+
def owner = NoSymbol
418422

419423
override def toString = elems.toString
420424
end Const
@@ -434,7 +438,7 @@ object CaptureSet:
434438
end Fluid
435439

436440
/** 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:
438442

439443
/** A unique identification number for diagnostics */
440444
val id =
@@ -443,9 +447,6 @@ object CaptureSet:
443447

444448
//assert(id != 40)
445449

446-
override val levelLimit =
447-
if directOwner.exists then directOwner.levelOwner else NoSymbol
448-
449450
/** A variable is solved if it is aproximated to a from-then-on constant set. */
450451
private var isSolved: Boolean = false
451452

@@ -519,9 +520,9 @@ object CaptureSet:
519520
private def levelOK(elem: CaptureRef)(using Context): Boolean =
520521
if elem.isRootCapability then !noUniversal
521522
else elem match
522-
case elem: TermRef if levelLimit.exists =>
523+
case elem: TermRef if level != -1 =>
523524
level == -1 || ccState.level(elem.symbol) <= level
524-
case elem: ThisType if levelLimit.exists =>
525+
case elem: ThisType if level != 1 =>
525526
level == -1 || ccState.level(elem.cls) + 1 <= level
526527
case ReachCapability(elem1) =>
527528
levelOK(elem1)
@@ -600,8 +601,8 @@ object CaptureSet:
600601
val debugInfo =
601602
if !isConst && ctx.settings.YccDebug.value then ids else ""
602603
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>"
605606
else ""
606607
debugInfo ++ limitInfo
607608

@@ -648,7 +649,7 @@ object CaptureSet:
648649
*/
649650
class Mapped private[CaptureSet]
650651
(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):
652653
addAsDependentTo(initial) // initial mappings could change by propagation
653654

654655
private def mapIsIdempotent = tm.isInstanceOf[IdempotentCaptRefMap]
@@ -745,7 +746,7 @@ object CaptureSet:
745746
*/
746747
final class BiMapped private[CaptureSet]
747748
(val source: Var, bimap: BiTypeMap, initialElems: Refs)(using @constructorOnly ctx: Context)
748-
extends DerivedVar(source.levelLimit, initialElems):
749+
extends DerivedVar(source.owner, initialElems):
749750

750751
override def tryInclude(elem: CaptureRef, origin: CaptureSet)(using Context, VarState): CompareResult =
751752
if origin eq source then
@@ -779,7 +780,7 @@ object CaptureSet:
779780
/** A variable with elements given at any time as { x <- source.elems | p(x) } */
780781
class Filtered private[CaptureSet]
781782
(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)):
783784

784785
override def tryInclude(elem: CaptureRef, origin: CaptureSet)(using Context, VarState): CompareResult =
785786
if accountsFor(elem) then
@@ -809,7 +810,7 @@ object CaptureSet:
809810
extends Filtered(source, !other.accountsFor(_))
810811

811812
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)):
813814
addAsDependentTo(cs1)
814815
addAsDependentTo(cs2)
815816
deps += cs1
@@ -899,7 +900,7 @@ object CaptureSet:
899900
if ctx.settings.YccDebug.value then printer.toText(trace, ", ")
900901
else blocking.show
901902
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})")
903904

904905
/** The result is OK */
905906
def isOK: Boolean = this == OK
@@ -1142,6 +1143,6 @@ object CaptureSet:
11421143
i"""
11431144
|
11441145
|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"""
11461147

11471148
end CaptureSet

tests/neg-custom-args/captures/levels.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
| Required: box (x$0: String) ->? String
1313
|
1414
| Note that reference (cap3 : CC^), defined in method scope
15-
| cannot be included in outer capture set ? of value r which is associated with method test2
15+
| cannot be included in outer capture set ? of value r
1616
|
1717
| longer explanation available when compiling with `-explain`

tests/neg-custom-args/captures/outer-var.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
| Required: () ->{p} Unit
3333
|
3434
| Note that reference (q : Proc), defined in method inner
35-
| cannot be included in outer capture set {p} of variable y which is associated with method test
35+
| cannot be included in outer capture set {p} of variable y
3636
|
3737
| longer explanation available when compiling with `-explain`
3838
-- Error: tests/neg-custom-args/captures/outer-var.scala:16:53 ---------------------------------------------------------

tests/neg-custom-args/captures/reaches.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
| Required: box List[box () ->{xs*} Unit]^?
1313
|
1414
| Note that reference (f : File^), defined in method $anonfun
15-
| cannot be included in outer capture set {xs*} of value cur which is associated with method runAll1
15+
| cannot be included in outer capture set {xs*} of value cur
1616
|
1717
| longer explanation available when compiling with `-explain`
1818
-- Error: tests/neg-custom-args/captures/reaches.scala:35:6 ------------------------------------------------------------

tests/neg-custom-args/captures/vars.check

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44
| reference (cap3 : Cap) is not included in the allowed capture set {cap1} of variable a
55
|
66
| Note that reference (cap3 : Cap), defined in method scope
7-
| cannot be included in outer capture set {cap1} of variable a which is associated with method test
7+
| cannot be included in outer capture set {cap1} of variable a
88
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars.scala:23:8 ------------------------------------------
99
23 | a = g // error
1010
| ^
1111
| Found: (x: String) ->{cap3} String
1212
| Required: (x$0: String) ->{cap1} String
1313
|
1414
| Note that reference (cap3 : Cap), defined in method scope
15-
| cannot be included in outer capture set {cap1} of variable a which is associated with method test
15+
| cannot be included in outer capture set {cap1} of variable a
1616
|
1717
| longer explanation available when compiling with `-explain`
1818
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars.scala:25:12 -----------------------------------------

tests/printing/dependent-annot.check

+1-6
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,7 @@ package <empty> {
1111
def f(y: C, z: C): Unit =
1212
{
1313
def g(): C @ann([y,z : Any]*) = ???
14-
val ac:
15-
(C => Array[String])
16-
{
17-
def apply(x: C): Array[String @ann([x : Any]*)]
18-
}
19-
= ???
14+
val ac: (x: C) => Array[String @ann([x : Any]*)] = ???
2015
val dc: Array[String] = ac.apply(g())
2116
()
2217
}

0 commit comments

Comments
 (0)