Skip to content

Commit 03e6cab

Browse files
committed
Add caches for hot SymDenotations fields to Symbol
1 parent 698577e commit 03e6cab

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ object SymDenotations {
164164
private def adaptFlags(flags: FlagSet) = if (isType) flags.toTypeFlags else flags.toTermFlags
165165

166166
/** Update the flag set */
167-
final def flags_=(flags: FlagSet): Unit =
167+
final def flags_=(flags: FlagSet): Unit = {
168168
myFlags = adaptFlags(flags)
169+
symbol.updateFlagsCache(this, myFlags)
170+
}
169171

170172
/** Set given flags(s) of this denotation */
171173
final def setFlag(flags: FlagSet): Unit = { myFlags |= flags }
@@ -263,6 +265,7 @@ object SymDenotations {
263265
*/
264266
if (Config.checkNoSkolemsInInfo) assertNoSkolems(tp)
265267
myInfo = tp
268+
symbol.updateInfoCache(this, tp)
266269
}
267270

268271
/** The name, except

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

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

437+
private[this] var cachedName: Name = _
438+
private[this] var cachedOwner: Symbol = _
439+
private[this] var cachedInfo: Type = _
440+
private[this] var cachedFlags: FlagSet = _
441+
437442
private[core] def invalidateDenotCache() = { checkedPeriod = Nowhere }
438443

444+
private[core] def updateInfoCache(d: SymDenotation, info: Type) =
445+
if (lastDenot `eq` d) cachedInfo = info
446+
447+
private[core] def updateFlagsCache(d: SymDenotation, flags: FlagSet) =
448+
if (lastDenot `eq` d) cachedFlags = flags
449+
450+
private[this] def setLastDenot(d: SymDenotation) = {
451+
lastDenot = d
452+
cachedName = d.name
453+
cachedOwner = d.owner
454+
cachedInfo = d.infoOrCompleter
455+
cachedFlags = d.flagsUNSAFE
456+
}
457+
439458
/** Set the denotation of this symbol */
440459
private[core] def denot_=(d: SymDenotation) = {
441-
lastDenot = d
460+
setLastDenot(d)
442461
checkedPeriod = Nowhere
443462
}
444463

@@ -461,7 +480,7 @@ object Symbols {
461480
protected def recomputeDenot(lastd: SymDenotation)(implicit ctx: Context) = {
462481
Stats.record("Symbol.recomputeDenot")
463482
val newd = lastd.current.asInstanceOf[SymDenotation]
464-
lastDenot = newd
483+
setLastDenot(newd)
465484
newd
466485
}
467486

0 commit comments

Comments
 (0)