Skip to content

Commit 7987429

Browse files
committed
Hash-cons FreshCaps
Have at most one FreshCap for a given prefix and hidden set.
1 parent efa14d5 commit 7987429

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,11 @@ object Capabilities:
159159

160160
def derivedFreshCap(newPrefix: Type)(using Context): FreshCap =
161161
if newPrefix eq prefix then this
162-
else FreshCap(newPrefix)(owner, origin, hiddenSet)
162+
else if newPrefix eq hiddenSet.owningCap.prefix then
163+
hiddenSet.owningCap
164+
else
165+
hiddenSet.derivedCaps
166+
.getOrElseUpdate(newPrefix, FreshCap(newPrefix)(owner, origin, hiddenSet))
163167

164168
//assert(rootId != 10, i"fresh $prefix, ${ctx.owner}")
165169

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import annotation.internal.sharable
1212
import reporting.trace
1313
import printing.{Showable, Printer}
1414
import printing.Texts.*
15-
import util.{SimpleIdentitySet, Property}
15+
import util.{SimpleIdentitySet, Property, EqHashMap}
1616
import typer.ErrorReporting.Addenda
1717
import scala.collection.{mutable, immutable}
1818
import TypeComparer.ErrorNote
@@ -1168,6 +1168,9 @@ object CaptureSet:
11681168

11691169
override def owner = givenOwner
11701170

1171+
/** The FreshCaps generated by derivedFreshCap, indexed by prefix */
1172+
val derivedCaps = new EqHashMap[Type, FreshCap]()
1173+
11711174
//assert(id != 3)
11721175

11731176
description = i"of elements subsumed by a fresh cap in $initialOwner"

0 commit comments

Comments
 (0)