Skip to content

Commit 9150027

Browse files
committed
More fixes for subCapture
1 parent 8eb04c8 commit 9150027

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

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

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,19 @@ sealed abstract class CaptureSet extends Showable:
7272
* @return CompareResult.OK if all unaccounted elements could be added,
7373
* capture set that prevents addition otherwise.
7474
*/
75-
protected def tryInclude(elems: Refs, origin: CaptureSet)(using Context, VarState): CompareResult =
75+
protected final def tryInclude(elems: Refs, origin: CaptureSet)(using Context, VarState): CompareResult =
7676
val unaccounted = elems.filter(!accountsFor(_))
77-
if unaccounted.isEmpty then CompareResult.OK else addNewElems(unaccounted, origin)
77+
if unaccounted.isEmpty then CompareResult.OK
78+
else addNewElems(unaccounted, origin)
79+
80+
protected final def tryInclude(elem: CaptureRef, origin: CaptureSet)(using Context, VarState): CompareResult =
81+
if accountsFor(elem) then CompareResult.OK
82+
else addNewElems(elem.singletonCaptureSet.elems, origin)
7883

7984
/** {x} <:< this where <:< is subcapturing, but treating all variables
8085
* as frozen.
8186
*/
82-
def accountsFor(x: CaptureRef)(using Context): Boolean =
87+
def accountsFor(x: CaptureRef)(using ctx: Context): Boolean =
8388
reporting.trace(i"$this accountsFor $x, ${x.captureSetOfInfo}?", show = true) {
8489
elems.contains(x)
8590
|| !x.isRootCapability
@@ -91,12 +96,19 @@ sealed abstract class CaptureSet extends Showable:
9196
subCaptures(that)(using ctx, if frozen then FrozenState else VarState())
9297

9398
private def subCaptures(that: CaptureSet)(using Context, VarState): CompareResult =
94-
val result = that.tryInclude(elems, this)
95-
if result == CompareResult.OK then
96-
addSuper(that)
97-
else
98-
varState.abort()
99-
result
99+
def recur(elems: List[CaptureRef]): CompareResult = elems match
100+
case elem :: elems1 =>
101+
var result = that.tryInclude(elem, this)
102+
if result != CompareResult.OK && !elem.isRootCapability && summon[VarState] != FrozenState then
103+
result = elem.captureSetOfInfo.subCaptures(that)
104+
if result == CompareResult.OK then
105+
recur(elems1)
106+
else
107+
varState.abort()
108+
result
109+
case Nil =>
110+
addSuper(that)
111+
recur(elems.toList)
100112

101113
def =:= (that: CaptureSet)(using Context): Boolean =
102114
this.subCaptures(that, frozen = true) == CompareResult.OK

0 commit comments

Comments
 (0)