Skip to content

Commit 40d2d5d

Browse files
committed
Cache staticRef
Per-run cache of what is returned for a staticRef
1 parent 0f31e85 commit 40d2d5d

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import Periods._
77
import Symbols._
88
import Types._
99
import Scopes._
10+
import Names.Name
11+
import Denotations.Denotation
1012
import typer.Typer
1113
import typer.ImportInfo._
1214
import Decorators._
@@ -116,6 +118,9 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
116118
/** The source files of all late entered symbols, as a set */
117119
private var lateFiles = mutable.Set[AbstractFile]()
118120

121+
/** A cache for static references to packages and classes */
122+
val staticRefs = util.IdentityHashMap[Name, Denotation](initialCapacity = 1024)
123+
119124
/** Actions that need to be performed at the end of the current compilation run */
120125
private var finalizeActions = mutable.ListBuffer[() => Unit]()
121126

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1259,7 +1259,8 @@ object Denotations {
12591259
}
12601260
recurSimple(path.length, wrap)
12611261
}
1262-
recur(path)
1262+
if ctx.run == null then recur(path)
1263+
else ctx.run.staticRefs.getOrElseUpdate(path, recur(path))
12631264
}
12641265

12651266

compiler/src/dotty/tools/dotc/util/GenericHashMap.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,11 @@ abstract class GenericHashMap[Key <: AnyRef, Value >: Null <: AnyRef]
117117
idx = nextIndex(idx)
118118
k = keyAt(idx)
119119

120+
def getOrElseUpdate(key: Key, value: => Value): Value =
121+
var v = lookup(key)
122+
if v == null then v = value
123+
v
124+
120125
private def addOld(key: Key, value: AnyRef): Unit =
121126
Stats.record(statsItem("re-enter"))
122127
var idx = firstIndex(key)

0 commit comments

Comments
 (0)