Skip to content

Commit

Permalink
Improve subsumes test
Browse files Browse the repository at this point in the history
Don't add elements to hidden sets if they were subsumed previously.
  • Loading branch information
odersky committed Dec 16, 2024
1 parent 1df15b1 commit 90d9fed
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/cc/CaptureRef.scala
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,7 @@ trait CaptureRef extends TypeProxy, ValueType:
|| this.isCap
|| this.match
case Fresh.Cap(hidden) =>
if hidden.elems.contains(y) then true
//if hidden.elems.exists(_.subsumes(y)) then true
if vs.ifNotSeen(this)(hidden.elems.exists(_.subsumes(y))) then true
else if !hidden.recordElemsState() || y.stripReadOnly.isCap then false
else
hidden.elems += y
Expand Down
8 changes: 8 additions & 0 deletions compiler/src/dotty/tools/dotc/cc/CaptureSet.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,14 @@ object CaptureSet:
def rollBack(): Unit =
elemsMap.keysIterator.foreach(_.resetElems()(using this))
depsMap.keysIterator.foreach(_.resetDeps()(using this))

private var seen: util.EqHashSet[CaptureRef] = new util.EqHashSet

/** Run test `pred` unless `ref` was seen in an enclosing `ifNotSeen` operation */
def ifNotSeen(ref: CaptureRef)(pred: => Boolean): Boolean =
if seen.add(ref) then
try pred finally seen -= ref
else false
end VarState

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

0 comments on commit 90d9fed

Please sign in to comment.