Skip to content

Commit 69c8993

Browse files
committed
Revert: Also cache Denotation#validFor in Symbol
Reverted from commit 7587f9c This one seemed to cause a performance regression.
1 parent f70b87f commit 69c8993

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,7 @@ object Denotations {
703703
def validFor = myValidFor
704704
def validFor_=(p: Period) = {
705705
myValidFor = p
706-
symbol.updateValidForCache(this, p)
706+
symbol.invalidateDenotCache()
707707
}
708708

709709
/** The next SingleDenotation in this run, with wrap-around from last to first.

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -434,16 +434,12 @@ object Symbols {
434434
private[this] var lastDenot: SymDenotation = _
435435
private[this] var checkedPeriod: Period = Nowhere
436436

437-
private[this] var cachedValidFor: Period = _
438437
private[this] var cachedName: Name = _
439438
private[this] var cachedOwner: Symbol = _
440439
private[this] var cachedInfo: Type = _
441440
private[this] var cachedFlags: FlagSet = _
442441

443-
private[core] def updateValidForCache(d: Denotation, validFor: Period) = {
444-
if (lastDenot `eq` d) cachedValidFor = validFor
445-
checkedPeriod = Nowhere // this forces recomputeDenot() on next call to denot
446-
}
442+
private[core] def invalidateDenotCache() = { checkedPeriod = Nowhere }
447443

448444
private[core] def updateInfoCache(d: SymDenotation, info: Type) =
449445
if (lastDenot `eq` d) cachedInfo = info
@@ -453,7 +449,6 @@ object Symbols {
453449

454450
private[this] def setLastDenot(d: SymDenotation) = {
455451
lastDenot = d
456-
cachedValidFor = d.validFor
457452
cachedName = d.name
458453
cachedOwner = d.maybeOwner
459454
cachedInfo = d.infoOrCompleter
@@ -469,21 +464,22 @@ object Symbols {
469464
/** The current denotation of this symbol */
470465
final def denot(implicit ctx: Context): SymDenotation = {
471466
Stats.record("Symbol.denot")
472-
if (checkedPeriod == ctx.period) lastDenot
473-
else computeDenot()
467+
val lastd = lastDenot
468+
if (checkedPeriod == ctx.period) lastd
469+
else computeDenot(lastd)
474470
}
475471

476-
private def computeDenot()(implicit ctx: Context): SymDenotation = {
472+
private def computeDenot(lastd: SymDenotation)(implicit ctx: Context): SymDenotation = {
477473
Stats.record("Symbol.computeDenot")
478474
val now = ctx.period
479475
checkedPeriod = now
480-
if (cachedValidFor contains now) lastDenot else recomputeDenot()
476+
if (lastd.validFor contains now) lastd else recomputeDenot(lastd)
481477
}
482478

483479
/** Overridden in NoSymbol */
484-
protected def recomputeDenot()(implicit ctx: Context) = {
480+
protected def recomputeDenot(lastd: SymDenotation)(implicit ctx: Context) = {
485481
Stats.record("Symbol.recomputeDenot")
486-
val newd = lastDenot.current.asInstanceOf[SymDenotation]
482+
val newd = lastd.current.asInstanceOf[SymDenotation]
487483
setLastDenot(newd)
488484
newd
489485
}
@@ -642,7 +638,7 @@ object Symbols {
642638
// -------- Cached SymDenotation facades -----------------------------------------------
643639

644640
private def ensureUpToDate()(implicit ctx: Context) =
645-
if (checkedPeriod != ctx.period) computeDenot()
641+
if (checkedPeriod != ctx.period) computeDenot(lastDenot)
646642

647643
/** The current name of this symbol */
648644
final def name(implicit ctx: Context): ThisName = {
@@ -897,7 +893,7 @@ object Symbols {
897893
@sharable object NoSymbol extends Symbol(NoCoord, 0) {
898894
override def owner(implicit ctx: Context): Symbol = throw new AssertionError("NoSymbol.owner")
899895
override def associatedFile(implicit ctx: Context): AbstractFile = NoSource.file
900-
override def recomputeDenot()(implicit ctx: Context): SymDenotation = NoDenotation
896+
override def recomputeDenot(lastd: SymDenotation)(implicit ctx: Context): SymDenotation = NoDenotation
901897
}
902898

903899
NoDenotation // force it in order to set `denot` field of NoSymbol

0 commit comments

Comments
 (0)