Skip to content

Commit 9f13e56

Browse files
committed
Make validFor monomorphic
Profiles showed that it accounted for a significant percentage of vtable_stub time.
1 parent 50c1595 commit 9f13e56

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,6 @@ object Denotations {
194194
*/
195195
def infoOrCompleter: Type
196196

197-
/** The period during which this denotation is valid. */
198-
def validFor: Period
199-
200197
/** Is this a reference to a type symbol? */
201198
def isType: Boolean
202199

@@ -229,6 +226,15 @@ object Denotations {
229226
*/
230227
def current(using Context): Denotation
231228

229+
/** The period during which this denotation is valid. */
230+
private var myValidFor: Period = Nowhere
231+
232+
final def validFor: Period = myValidFor
233+
final def validFor_=(p: Period): Unit = {
234+
myValidFor = p
235+
symbol.invalidateDenotCache()
236+
}
237+
232238
/** Is this denotation different from NoDenotation or an ErrorDenotation? */
233239
def exists: Boolean = true
234240

@@ -664,14 +670,6 @@ object Denotations {
664670

665671
// ------ Transformations -----------------------------------------
666672

667-
private var myValidFor: Period = Nowhere
668-
669-
def validFor: Period = myValidFor
670-
def validFor_=(p: Period): Unit = {
671-
myValidFor = p
672-
symbol.invalidateDenotCache()
673-
}
674-
675673
/** The next SingleDenotation in this run, with wrap-around from last to first.
676674
*
677675
* There may be several `SingleDenotation`s with different validity
@@ -695,7 +693,7 @@ object Denotations {
695693
if (validFor.firstPhaseId <= 1) this
696694
else {
697695
var current = nextInRun
698-
while (current.validFor.code > this.myValidFor.code) current = current.nextInRun
696+
while (current.validFor.code > this.validFor.code) current = current.nextInRun
699697
current
700698
}
701699

@@ -776,7 +774,7 @@ object Denotations {
776774
* are otherwise undefined.
777775
*/
778776
def skipRemoved(using Context): SingleDenotation =
779-
if (myValidFor.code <= 0) nextDefined else this
777+
if (validFor.code <= 0) nextDefined else this
780778

781779
/** Produce a denotation that is valid for the given context.
782780
* Usually called when !(validFor contains ctx.period)
@@ -793,7 +791,7 @@ object Denotations {
793791
def current(using Context): SingleDenotation =
794792
util.Stats.record("current")
795793
val currentPeriod = ctx.period
796-
val valid = myValidFor
794+
val valid = validFor
797795

798796
def assertNotPackage(d: SingleDenotation, transformer: DenotTransformer) = d match
799797
case d: ClassDenotation =>
@@ -963,7 +961,7 @@ object Denotations {
963961
case denot: SymDenotation => s"in ${denot.owner}"
964962
case _ => ""
965963
}
966-
s"stale symbol; $this#${symbol.id} $ownerMsg, defined in ${myValidFor}, is referred to in run ${ctx.period}"
964+
s"stale symbol; $this#${symbol.id} $ownerMsg, defined in ${validFor}, is referred to in run ${ctx.period}"
967965
}
968966

969967
/** The period (interval of phases) for which there exists
@@ -1248,8 +1246,9 @@ object Denotations {
12481246
/** An overloaded denotation consisting of the alternatives of both given denotations.
12491247
*/
12501248
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType) with MultiPreDenotation {
1249+
validFor = denot1.validFor & denot2.validFor
1250+
12511251
final def infoOrCompleter: Type = multiHasNot("info")
1252-
final def validFor: Period = denot1.validFor & denot2.validFor
12531252
final def isType: Boolean = false
12541253
final def hasUniqueSym: Boolean = false
12551254
final def name(using Context): Name = denot1.name

0 commit comments

Comments
 (0)