@@ -4,11 +4,14 @@ package jvm
4
4
5
5
import scala .tools .asm
6
6
import scala .annotation .threadUnsafe
7
+ import scala .collection .mutable
8
+ import scala .collection .generic .Clearable
7
9
8
10
import dotty .tools .dotc .core .Flags
9
11
import dotty .tools .dotc .core .Symbols ._
10
12
import dotty .tools .dotc .core .Phases .Phase
11
13
import dotty .tools .dotc .transform .SymUtils ._
14
+ import dotty .tools .dotc .util .WeakHashSet
12
15
13
16
/**
14
17
* This class mainly contains the method classBTypeFromSymbol, which extracts the necessary
@@ -37,6 +40,25 @@ class BTypesFromSymbols[I <: DottyBackendInterface](val int: I) extends BTypes {
37
40
coreBTypes.setBTypes(new CoreBTypes [this .type ](this ))
38
41
}
39
42
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
+
40
62
@ threadUnsafe protected lazy val classBTypeFromInternalNameMap = {
41
63
perRunCaches.recordCache(collection.concurrent.TrieMap .empty[String , ClassBType ])
42
64
}
0 commit comments