Skip to content

Commit

Permalink
Some tweaks to denotation updates
Browse files Browse the repository at this point in the history
 - Be more specific when we go into the special case of not
   updating checkedPeriod
 - Always update lastDenotation.
 - Keep computeDenot small, move work to recomputeDenot
  • Loading branch information
odersky committed Feb 26, 2024
1 parent 4615a9c commit e79b2e9
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions compiler/src/dotty/tools/dotc/core/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -110,25 +110,28 @@ object Symbols extends SymUtils {
}

private def computeDenot(lastd: SymDenotation)(using Context): SymDenotation = {
// Written that way do that it comes in at 32 bytes and is therefore inlineable for
// the JIT (reputedly, cutoff is at 35 bytes)
util.Stats.record("Symbol.computeDenot")
val now = ctx.period
val prev = checkedPeriod
checkedPeriod = now
if lastd.validFor.contains(now) then
lastd
else
val newd = recomputeDenot(lastd)
if newd.exists then
lastDenot = newd
else
checkedPeriod = prev
newd
if lastd.validFor.contains(now) then lastd else recomputeDenot(lastd)
}

/** Overridden in NoSymbol */
protected def recomputeDenot(lastd: SymDenotation)(using Context): SymDenotation = {
util.Stats.record("Symbol.recomputeDenot")
lastd.current.asSymDenotation
val newd = lastd.current.asInstanceOf[SymDenotation]
lastDenot = newd
if !newd.exists && lastd.initial.validFor.firstPhaseId > ctx.phaseId then
// We are trying to bring forward a symbol that is defined only at a later phase
// (typically, a nested Java class, invisible before erasure).
// In that case, keep the checked period to the previous validity, which
// means we will try another bring forward when the symbol is referenced
// at a later phase. Otherwise we'd get stuck on NoDenotation here.
// See #15562 and test i15562b in ReplCompilerTests
checkedPeriod = lastd.initial.validFor
newd
}

/** The original denotation of this symbol, without forcing anything */
Expand Down Expand Up @@ -798,7 +801,7 @@ object Symbols extends SymUtils {
cls: ClassSymbol,
name: TermName = nme.WILDCARD,
selfInfo: Type = NoType)(using Context): TermSymbol =
newSymbol(cls, name, SelfSymFlags, selfInfo orElse cls.classInfo.selfType, coord = cls.coord)
newSymbol(cls, name, SelfSymFlags, selfInfo.orElse(cls.classInfo.selfType), coord = cls.coord)

/** Create new type parameters with given owner, names, and flags.
* @param boundsFn A function that, given type refs to the newly created
Expand Down Expand Up @@ -965,7 +968,7 @@ object Symbols extends SymUtils {
*/
def getPackageClassIfDefined(path: PreName)(using Context): Symbol =
staticRef(path.toTypeName, isPackage = true, generateStubs = false)
.disambiguate(_ is PackageClass).symbol
.disambiguate(_.is(PackageClass)).symbol

def requiredModule(path: PreName)(using Context): TermSymbol = {
val name = path.toTermName
Expand Down

0 comments on commit e79b2e9

Please sign in to comment.