Skip to content

Commit e916b4a

Browse files
oderskyWojciechMazur
authored andcommitted
Some tweaks to denotation updates
- Be more specific when we go into the special case of not updating checkedPeriod - Always update lastDenotation. - Keep computeDenot small, move work to recomputeDenot [Cherry-picked e79b2e9]
1 parent 3d3d8aa commit e916b4a

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -105,25 +105,28 @@ object Symbols extends SymUtils {
105105
}
106106

107107
private def computeDenot(lastd: SymDenotation)(using Context): SymDenotation = {
108+
// Written that way do that it comes in at 32 bytes and is therefore inlineable for
109+
// the JIT (reputedly, cutoff is at 35 bytes)
108110
util.Stats.record("Symbol.computeDenot")
109111
val now = ctx.period
110-
val prev = checkedPeriod
111112
checkedPeriod = now
112-
if lastd.validFor.contains(now) then
113-
lastd
114-
else
115-
val newd = recomputeDenot(lastd)
116-
if newd.exists then
117-
lastDenot = newd
118-
else
119-
checkedPeriod = prev
120-
newd
113+
if lastd.validFor.contains(now) then lastd else recomputeDenot(lastd)
121114
}
122115

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

129132
/** The original denotation of this symbol, without forcing anything */
@@ -771,7 +774,7 @@ object Symbols extends SymUtils {
771774
cls: ClassSymbol,
772775
name: TermName = nme.WILDCARD,
773776
selfInfo: Type = NoType)(using Context): TermSymbol =
774-
newSymbol(cls, name, SelfSymFlags, selfInfo orElse cls.classInfo.selfType, coord = cls.coord)
777+
newSymbol(cls, name, SelfSymFlags, selfInfo.orElse(cls.classInfo.selfType), coord = cls.coord)
775778

776779
/** Create new type parameters with given owner, names, and flags.
777780
* @param boundsFn A function that, given type refs to the newly created
@@ -938,7 +941,7 @@ object Symbols extends SymUtils {
938941
*/
939942
def getPackageClassIfDefined(path: PreName)(using Context): Symbol =
940943
staticRef(path.toTypeName, isPackage = true, generateStubs = false)
941-
.disambiguate(_ is PackageClass).symbol
944+
.disambiguate(_.is(PackageClass)).symbol
942945

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

0 commit comments

Comments
 (0)