Skip to content

Commit a1f182b

Browse files
committed
Improve subsumes test
Don't add elements to hidden sets if they were subsumed previously.
1 parent ef252f2 commit a1f182b

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ trait CaptureRef extends TypeProxy, ValueType:
168168
|| this.isCap
169169
|| this.match
170170
case Fresh.Cap(hidden) =>
171-
if hidden.elems.contains(y) then true
172-
//if hidden.elems.exists(_.subsumes(y)) then true
171+
if vs.ifNotSeen(this)(hidden.elems.exists(_.subsumes(y))) then true
173172
else if !hidden.recordElemsState() || y.stripReadOnly.isCap then false
174173
else
175174
hidden.elems += y

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,14 @@ object CaptureSet:
10701070
def rollBack(): Unit =
10711071
elemsMap.keysIterator.foreach(_.resetElems()(using this))
10721072
depsMap.keysIterator.foreach(_.resetDeps()(using this))
1073+
1074+
private var seen: util.EqHashSet[CaptureRef] = new util.EqHashSet
1075+
1076+
/** Run test `pred` unless `ref` was seen in an enclosing `ifNotSeen` operation */
1077+
def ifNotSeen(ref: CaptureRef)(pred: => Boolean): Boolean =
1078+
if seen.add(ref) then
1079+
try pred finally seen -= ref
1080+
else false
10731081
end VarState
10741082

10751083
/** A special state that does not allow to record elements or dependent sets.

0 commit comments

Comments
 (0)