@@ -398,19 +398,34 @@ object Symbols {
398
398
399
399
/** The last denotation of this symbol */
400
400
private [this ] var lastDenot : SymDenotation = _
401
+ private [this ] var checkedPeriod : Period = Nowhere
402
+
403
+ private [core] def invalidateDenotCache () = { checkedPeriod = Nowhere }
401
404
402
405
/** Set the denotation of this symbol */
403
- private [core] def denot_= (d : SymDenotation ) =
406
+ private [core] def denot_= (d : SymDenotation ) = {
404
407
lastDenot = d
408
+ checkedPeriod = Nowhere
409
+ }
405
410
406
411
/** The current denotation of this symbol */
407
412
final def denot (implicit ctx : Context ): SymDenotation = {
408
- var denot = lastDenot
409
- if (! (denot.validFor contains ctx.period)) {
410
- denot = denot.current.asInstanceOf [SymDenotation ]
411
- lastDenot = denot
412
- }
413
- denot
413
+ val lastd = lastDenot
414
+ if (checkedPeriod == ctx.period) lastd
415
+ else computeDenot(lastd)
416
+ }
417
+
418
+ private def computeDenot (lastd : SymDenotation )(implicit ctx : Context ): SymDenotation = {
419
+ val now = ctx.period
420
+ checkedPeriod = now
421
+ if (lastd.validFor contains now) lastd else recomputeDenot(lastd)
422
+ }
423
+
424
+ /** Overridden in NoSymbol */
425
+ protected def recomputeDenot (lastd : SymDenotation )(implicit ctx : Context ) = {
426
+ val newd = lastd.current.asInstanceOf [SymDenotation ]
427
+ lastDenot = newd
428
+ newd
414
429
}
415
430
416
431
/** The initial denotation of this symbol, without going through `current` */
@@ -631,8 +646,8 @@ object Symbols {
631
646
632
647
@ sharable object NoSymbol extends Symbol (NoCoord , 0 ) {
633
648
denot = NoDenotation
634
-
635
649
override def associatedFile (implicit ctx : Context ): AbstractFile = NoSource .file
650
+ override def recomputeDenot (lastd : SymDenotation )(implicit ctx : Context ): SymDenotation = NoDenotation
636
651
}
637
652
638
653
implicit class Copier [N <: Name ](sym : Symbol { type ThisName = N })(implicit ctx : Context ) {
0 commit comments