Skip to content

Commit c49972c

Browse files
committed
Move perRunCaches
1 parent 043e390 commit c49972c

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

compiler/src/dotty/tools/backend/jvm/BTypesFromSymbols.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ package jvm
44

55
import scala.tools.asm
66
import scala.annotation.threadUnsafe
7+
import scala.collection.mutable
8+
import scala.collection.generic.Clearable
79

810
import dotty.tools.dotc.core.Flags
911
import dotty.tools.dotc.core.Symbols._
1012
import dotty.tools.dotc.core.Phases.Phase
1113
import dotty.tools.dotc.transform.SymUtils._
14+
import dotty.tools.dotc.util.WeakHashSet
1215

1316
/**
1417
* This class mainly contains the method classBTypeFromSymbol, which extracts the necessary
@@ -37,6 +40,25 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
3740
coreBTypes.setBTypes(new CoreBTypes[this.type](this))
3841
}
3942

43+
private[this] val perRunCaches: Caches = new Caches {
44+
def newAnyRefMap[K <: AnyRef, V](): mutable.AnyRefMap[K, V] = new mutable.AnyRefMap[K, V]()
45+
def newWeakMap[K, V](): mutable.WeakHashMap[K, V] = new mutable.WeakHashMap[K, V]()
46+
def recordCache[T <: Clearable](cache: T): T = cache
47+
def newWeakSet[K >: Null <: AnyRef](): WeakHashSet[K] = new WeakHashSet[K]()
48+
def newMap[K, V](): mutable.HashMap[K, V] = new mutable.HashMap[K, V]()
49+
def newSet[K](): mutable.Set[K] = new mutable.HashSet[K]
50+
}
51+
52+
// TODO remove abstraction
53+
private abstract class Caches {
54+
def recordCache[T <: Clearable](cache: T): T
55+
def newWeakMap[K, V](): collection.mutable.WeakHashMap[K, V]
56+
def newMap[K, V](): collection.mutable.HashMap[K, V]
57+
def newSet[K](): collection.mutable.Set[K]
58+
def newWeakSet[K >: Null <: AnyRef](): dotty.tools.dotc.util.WeakHashSet[K]
59+
def newAnyRefMap[K <: AnyRef, V](): collection.mutable.AnyRefMap[K, V]
60+
}
61+
4062
@threadUnsafe protected lazy val classBTypeFromInternalNameMap = {
4163
perRunCaches.recordCache(collection.concurrent.TrieMap.empty[String, ClassBType])
4264
}

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,6 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
7575
def sourcePos(pos: Spans.Span)(implicit ctx: Context): util.SourcePosition =
7676
ctx.source.atSpan(pos)
7777

78-
val perRunCaches: Caches = new Caches {
79-
def newAnyRefMap[K <: AnyRef, V](): mutable.AnyRefMap[K, V] = new mutable.AnyRefMap[K, V]()
80-
def newWeakMap[K, V](): mutable.WeakHashMap[K, V] = new mutable.WeakHashMap[K, V]()
81-
def recordCache[T <: Clearable](cache: T): T = cache
82-
def newWeakSet[K >: Null <: AnyRef](): WeakHashSet[K] = new WeakHashSet[K]()
83-
def newMap[K, V](): mutable.HashMap[K, V] = new mutable.HashMap[K, V]()
84-
def newSet[K](): mutable.Set[K] = new mutable.HashSet[K]
85-
}
86-
8778
private val desugared = new java.util.IdentityHashMap[Type, tpd.Select]
8879

8980
def desugarIdentBI(i: Ident): Option[tpd.Select] = {
@@ -211,15 +202,6 @@ class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap
211202
}
212203
}
213204

214-
abstract class Caches {
215-
def recordCache[T <: Clearable](cache: T): T
216-
def newWeakMap[K, V](): collection.mutable.WeakHashMap[K, V]
217-
def newMap[K, V](): collection.mutable.HashMap[K, V]
218-
def newSet[K](): collection.mutable.Set[K]
219-
def newWeakSet[K >: Null <: AnyRef](): dotty.tools.dotc.util.WeakHashSet[K]
220-
def newAnyRefMap[K <: AnyRef, V](): collection.mutable.AnyRefMap[K, V]
221-
}
222-
223205
// Class symbols used in backend.
224206
// Vals because they are to frequent in scala programs so that they are already loaded by backend
225207

0 commit comments

Comments
 (0)