Skip to content

Commit 8b1320c

Browse files
oderskydwijnand
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 from commit e79b2e9)
1 parent 493a216 commit 8b1320c

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed
Submodule perspective updated 84 files

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

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,28 @@ object Symbols {
108108
}
109109

110110
private def computeDenot(lastd: SymDenotation)(using Context): SymDenotation = {
111+
// Written that way so that it comes in at 32 bytes and is therefore inlineable for
112+
// the JIT (reputedly, cutoff is at 35 bytes)
111113
util.Stats.record("Symbol.computeDenot")
112114
val now = ctx.period
113-
val prev = checkedPeriod
114115
checkedPeriod = now
115-
if lastd.validFor.contains(now) then
116-
lastd
117-
else
118-
val newd = recomputeDenot(lastd)
119-
if newd.exists then
120-
lastDenot = newd
121-
else
122-
checkedPeriod = prev
123-
newd
116+
if lastd.validFor.contains(now) then lastd else recomputeDenot(lastd)
124117
}
125118

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

132135
/** The original denotation of this symbol, without forcing anything */
@@ -761,7 +764,7 @@ object Symbols {
761764
cls: ClassSymbol,
762765
name: TermName = nme.WILDCARD,
763766
selfInfo: Type = NoType)(using Context): TermSymbol =
764-
newSymbol(cls, name, SelfSymFlags, selfInfo orElse cls.classInfo.selfType, coord = cls.coord)
767+
newSymbol(cls, name, SelfSymFlags, selfInfo.orElse(cls.classInfo.selfType), coord = cls.coord)
765768

766769
/** Create new type parameters with given owner, names, and flags.
767770
* @param boundsFn A function that, given type refs to the newly created
@@ -928,7 +931,7 @@ object Symbols {
928931
*/
929932
def getPackageClassIfDefined(path: PreName)(using Context): Symbol =
930933
staticRef(path.toTypeName, isPackage = true, generateStubs = false)
931-
.disambiguate(_ is PackageClass).symbol
934+
.disambiguate(_.is(PackageClass)).symbol
932935

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

0 commit comments

Comments
 (0)