@@ -72,14 +72,19 @@ sealed abstract class CaptureSet extends Showable:
72
72
* @return CompareResult.OK if all unaccounted elements could be added,
73
73
* capture set that prevents addition otherwise.
74
74
*/
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 =
76
76
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)
78
83
79
84
/** {x} <:< this where <:< is subcapturing, but treating all variables
80
85
* as frozen.
81
86
*/
82
- def accountsFor (x : CaptureRef )(using Context ): Boolean =
87
+ def accountsFor (x : CaptureRef )(using ctx : Context ): Boolean =
83
88
reporting.trace(i " $this accountsFor $x, ${x.captureSetOfInfo}? " , show = true ) {
84
89
elems.contains(x)
85
90
|| ! x.isRootCapability
@@ -91,12 +96,19 @@ sealed abstract class CaptureSet extends Showable:
91
96
subCaptures(that)(using ctx, if frozen then FrozenState else VarState ())
92
97
93
98
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)
100
112
101
113
def =:= (that : CaptureSet )(using Context ): Boolean =
102
114
this .subCaptures(that, frozen = true ) == CompareResult .OK
0 commit comments