Skip to content

Commit 09d0cb0

Browse files
committed
Use a util.EqHashMap for BaseTypeCache
1 parent 33b1098 commit 09d0cb0

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ object SymDenotations {
15751575
private var myMemberCachePeriod: Period = Nowhere
15761576

15771577
/** A cache from types T to baseType(T, C) */
1578-
type BaseTypeMap = java.util.IdentityHashMap[CachedType, Type]
1578+
type BaseTypeMap = EqHashMap[CachedType, Type]
15791579
private var myBaseTypeCache: BaseTypeMap = null
15801580
private var myBaseTypeCachePeriod: Period = Nowhere
15811581

@@ -1592,7 +1592,7 @@ object SymDenotations {
15921592

15931593
private def baseTypeCache(using Context): BaseTypeMap = {
15941594
if !currentHasSameBaseTypesAs(myBaseTypeCachePeriod) then
1595-
myBaseTypeCache = new BaseTypeMap
1595+
myBaseTypeCache = BaseTypeMap()
15961596
myBaseTypeCachePeriod = ctx.period
15971597
myBaseTypeCache
15981598
}
@@ -1906,14 +1906,16 @@ object SymDenotations {
19061906
/** Compute tp.baseType(this) */
19071907
final def baseTypeOf(tp: Type)(using Context): Type = {
19081908
val btrCache = baseTypeCache
1909-
def inCache(tp: Type) = btrCache.get(tp) != null
1909+
def inCache(tp: Type) = tp match
1910+
case tp: CachedType => btrCache.contains(tp)
1911+
case _ => false
19101912
def record(tp: CachedType, baseTp: Type) = {
19111913
if (Stats.monitored) {
19121914
Stats.record("basetype cache entries")
19131915
if (!baseTp.exists) Stats.record("basetype cache NoTypes")
19141916
}
19151917
if (!tp.isProvisional)
1916-
btrCache.put(tp, baseTp)
1918+
btrCache(tp) = baseTp
19171919
else
19181920
btrCache.remove(tp) // Remove any potential sentinel value
19191921
}
@@ -1926,7 +1928,7 @@ object SymDenotations {
19261928
def recur(tp: Type): Type = try {
19271929
tp match {
19281930
case tp: CachedType =>
1929-
val baseTp = btrCache.get(tp)
1931+
val baseTp = btrCache.lookup(tp)
19301932
if (baseTp != null) return ensureAcyclic(baseTp)
19311933
case _ =>
19321934
}
@@ -1945,7 +1947,7 @@ object SymDenotations {
19451947
}
19461948

19471949
def computeTypeRef = {
1948-
btrCache.put(tp, NoPrefix)
1950+
btrCache(tp) = NoPrefix
19491951
val tpSym = tp.symbol
19501952
tpSym.denot match {
19511953
case clsd: ClassDenotation =>
@@ -1980,7 +1982,7 @@ object SymDenotations {
19801982

19811983
case tp @ AppliedType(tycon, args) =>
19821984
def computeApplied = {
1983-
btrCache.put(tp, NoPrefix)
1985+
btrCache(tp) = NoPrefix
19841986
val baseTp =
19851987
if (tycon.typeSymbol eq symbol) tp
19861988
else (tycon.typeParams: @unchecked) match {
@@ -2041,7 +2043,9 @@ object SymDenotations {
20412043
}
20422044
catch {
20432045
case ex: Throwable =>
2044-
btrCache.remove(tp)
2046+
tp match
2047+
case tp: CachedType => btrCache.remove(tp)
2048+
case _ =>
20452049
throw ex
20462050
}
20472051

0 commit comments

Comments
 (0)