@@ -434,12 +434,16 @@ object Symbols {
434434 private [this ] var lastDenot : SymDenotation = _
435435 private [this ] var checkedPeriod : Period = Nowhere
436436
437+ private [this ] var cachedValidFor : Period = _
437438 private [this ] var cachedName : Name = _
438439 private [this ] var cachedOwner : Symbol = _
439440 private [this ] var cachedInfo : Type = _
440441 private [this ] var cachedFlags : FlagSet = _
441442
442- private [core] def invalidateDenotCache () = { checkedPeriod = Nowhere }
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+ }
443447
444448 private [core] def updateInfoCache (d : SymDenotation , info : Type ) =
445449 if (lastDenot `eq` d) cachedInfo = info
@@ -449,6 +453,7 @@ object Symbols {
449453
450454 private [this ] def setLastDenot (d : SymDenotation ) = {
451455 lastDenot = d
456+ cachedValidFor = d.validFor
452457 cachedName = d.name
453458 cachedOwner = d.maybeOwner
454459 cachedInfo = d.infoOrCompleter
@@ -464,22 +469,21 @@ object Symbols {
464469 /** The current denotation of this symbol */
465470 final def denot (implicit ctx : Context ): SymDenotation = {
466471 Stats .record(" Symbol.denot" )
467- val lastd = lastDenot
468- if (checkedPeriod == ctx.period) lastd
469- else computeDenot(lastd)
472+ if (checkedPeriod == ctx.period) lastDenot
473+ else computeDenot()
470474 }
471475
472- private def computeDenot (lastd : SymDenotation )(implicit ctx : Context ): SymDenotation = {
476+ private def computeDenot ()(implicit ctx : Context ): SymDenotation = {
473477 Stats .record(" Symbol.computeDenot" )
474478 val now = ctx.period
475479 checkedPeriod = now
476- if (lastd.validFor contains now) lastd else recomputeDenot(lastd )
480+ if (cachedValidFor contains now) lastDenot else recomputeDenot()
477481 }
478482
479483 /** Overridden in NoSymbol */
480- protected def recomputeDenot (lastd : SymDenotation )(implicit ctx : Context ) = {
484+ protected def recomputeDenot ()(implicit ctx : Context ) = {
481485 Stats .record(" Symbol.recomputeDenot" )
482- val newd = lastd .current.asInstanceOf [SymDenotation ]
486+ val newd = lastDenot .current.asInstanceOf [SymDenotation ]
483487 setLastDenot(newd)
484488 newd
485489 }
@@ -638,7 +642,7 @@ object Symbols {
638642// -------- Cached SymDenotation facades -----------------------------------------------
639643
640644 private def ensureUpToDate ()(implicit ctx : Context ) =
641- if (checkedPeriod != ctx.period) computeDenot(lastDenot )
645+ if (checkedPeriod != ctx.period) computeDenot()
642646
643647 /** The current name of this symbol */
644648 final def name (implicit ctx : Context ): ThisName = {
@@ -893,7 +897,7 @@ object Symbols {
893897 @ sharable object NoSymbol extends Symbol (NoCoord , 0 ) {
894898 override def owner (implicit ctx : Context ): Symbol = throw new AssertionError (" NoSymbol.owner" )
895899 override def associatedFile (implicit ctx : Context ): AbstractFile = NoSource .file
896- override def recomputeDenot (lastd : SymDenotation )(implicit ctx : Context ): SymDenotation = NoDenotation
900+ override def recomputeDenot ()(implicit ctx : Context ): SymDenotation = NoDenotation
897901 }
898902
899903 NoDenotation // force it in order to set `denot` field of NoSymbol
0 commit comments