Skip to content

Commit 19dab9d

Browse files
committed
Make validFor monomorphic
Profiles showed that it accounted for a significant percentage of vtable_stub time.
1 parent 128a5f9 commit 19dab9d

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

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

Lines changed: 15 additions & 17 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

@@ -667,14 +673,6 @@ object Denotations {
667673

668674
// ------ Transformations -----------------------------------------
669675

670-
private var myValidFor: Period = Nowhere
671-
672-
def validFor: Period = myValidFor
673-
def validFor_=(p: Period): Unit = {
674-
myValidFor = p
675-
symbol.invalidateDenotCache()
676-
}
677-
678676
/** The next SingleDenotation in this run, with wrap-around from last to first.
679677
*
680678
* There may be several `SingleDenotation`s with different validity
@@ -698,7 +696,7 @@ object Denotations {
698696
if (validFor.firstPhaseId <= 1) this
699697
else {
700698
var current = nextInRun
701-
while (current.validFor.code > this.myValidFor.code) current = current.nextInRun
699+
while (current.validFor.code > this.validFor.code) current = current.nextInRun
702700
current
703701
}
704702

@@ -779,7 +777,7 @@ object Denotations {
779777
* are otherwise undefined.
780778
*/
781779
def skipRemoved(using Context): SingleDenotation =
782-
if (myValidFor.code <= 0) nextDefined else this
780+
if (validFor.code <= 0) nextDefined else this
783781

784782
/** Produce a denotation that is valid for the given context.
785783
* Usually called when !(validFor contains ctx.period)
@@ -796,7 +794,7 @@ object Denotations {
796794
def current(using Context): SingleDenotation =
797795
util.Stats.record("current")
798796
val currentPeriod = ctx.period
799-
val valid = myValidFor
797+
val valid = validFor
800798

801799
def assertNotPackage(d: SingleDenotation, transformer: DenotTransformer) = d match
802800
case d: ClassDenotation =>
@@ -833,7 +831,6 @@ object Denotations {
833831
val savedPeriod = ctx.period
834832
val mutCtx = ctx.asInstanceOf[FreshContext]
835833
try
836-
util.Stats.record("current.transform")
837834
mutCtx.setPhase(transformer)
838835
next = transformer.transform(cur)
839836
// We temporarily update the context with the new phase instead of creating a
@@ -967,7 +964,7 @@ object Denotations {
967964
case denot: SymDenotation => s"in ${denot.owner}"
968965
case _ => ""
969966
}
970-
s"stale symbol; $this#${symbol.id} $ownerMsg, defined in ${myValidFor}, is referred to in run ${ctx.period}"
967+
s"stale symbol; $this#${symbol.id} $ownerMsg, defined in ${validFor}, is referred to in run ${ctx.period}"
971968
}
972969

973970
/** The period (interval of phases) for which there exists
@@ -1252,8 +1249,9 @@ object Denotations {
12521249
/** An overloaded denotation consisting of the alternatives of both given denotations.
12531250
*/
12541251
case class MultiDenotation(denot1: Denotation, denot2: Denotation) extends Denotation(NoSymbol, NoType) with MultiPreDenotation {
1252+
validFor = denot1.validFor & denot2.validFor
1253+
12551254
final def infoOrCompleter: Type = multiHasNot("info")
1256-
final def validFor: Period = denot1.validFor & denot2.validFor
12571255
final def isType: Boolean = false
12581256
final def hasUniqueSym: Boolean = false
12591257
final def name(using Context): Name = denot1.name

0 commit comments

Comments
 (0)