Skip to content

Commit a6419fb

Browse files
oderskyDarkDimius
authored andcommitted
Fix Denotations#current
The logic for dealing with periods in denotation histories did not correctly take into account the case where the current validity period of a denotation ends some phases before the next type transformer starts. And there was an off-by-one error in startPid. And Types#computeDenot erroneously tried to reload denotations even the run did not change.
1 parent 29c876a commit a6419fb

File tree

2 files changed

+35
-20
lines changed

2 files changed

+35
-20
lines changed

src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import printing.Printer
1919
import io.AbstractFile
2020
import config.Config
2121
import util.common._
22+
import collection.mutable.ListBuffer
2223
import Decorators.SymbolIteratorDecorator
2324

2425
/** Denotations represent the meaning of symbols and named types.
@@ -459,7 +460,7 @@ object Denotations {
459460
* 2) the union of all validity periods is a contiguous
460461
* interval.
461462
*/
462-
var nextInRun: SingleDenotation = this
463+
private var nextInRun: SingleDenotation = this
463464

464465
/** The version of this SingleDenotation that was valid in the first phase
465466
* of this run.
@@ -470,6 +471,17 @@ object Denotations {
470471
current
471472
}
472473

474+
def history: List[SingleDenotation] = {
475+
val b = new ListBuffer[SingleDenotation]
476+
var current = initial
477+
do {
478+
b += (current)
479+
current = current.nextInRun
480+
}
481+
while (current ne initial)
482+
b.toList
483+
}
484+
473485
/** Move validity period of this denotation to a new run. Throw a StaleSymbol error
474486
* if denotation is no longer valid.
475487
*/
@@ -518,27 +530,30 @@ object Denotations {
518530
cur = next
519531
cur
520532
} else {
533+
//println(s"might need new denot for $cur, valid for ${cur.validFor} at $currentPeriod")
521534
// not found, cur points to highest existing variant
522-
var startPid = cur.validFor.lastPhaseId + 1
523-
val nextTranformerId = ctx.nextDenotTransformerId(startPid)
524-
val transformer = ctx.denotTransformers(nextTranformerId)
525-
//println(s"transforming with $transformer")
526-
if (currentPeriod.lastPhaseId > transformer.id)
527-
next = transformer.transform(cur)(ctx.withPhase(startPid)).syncWithParents
528-
if (next eq cur)
529-
startPid = cur.validFor.firstPhaseId
535+
val nextTransformerId = ctx.nextDenotTransformerId(cur.validFor.lastPhaseId)
536+
if (currentPeriod.lastPhaseId <= nextTransformerId)
537+
cur.validFor = Period(currentPeriod.runId, cur.validFor.firstPhaseId, nextTransformerId)
530538
else {
531-
next match {
532-
case next: ClassDenotation => next.resetFlag(Frozen)
533-
case _ =>
539+
var startPid = nextTransformerId + 1
540+
val transformer = ctx.denotTransformers(nextTransformerId)
541+
//println(s"transforming $this with $transformer")
542+
next = transformer.transform(cur)(ctx.withPhase(transformer)).syncWithParents
543+
if (next eq cur)
544+
startPid = cur.validFor.firstPhaseId
545+
else {
546+
next match {
547+
case next: ClassDenotation => next.resetFlag(Frozen)
548+
case _ =>
549+
}
550+
next.nextInRun = cur.nextInRun
551+
cur.nextInRun = next
552+
cur = next
534553
}
535-
next.nextInRun = cur.nextInRun
536-
cur.nextInRun = next
537-
cur = next
554+
cur.validFor = Period(currentPeriod.runId, startPid, transformer.lastPhaseId)
555+
//println(s"new denot: $cur, valid for ${cur.validFor}")
538556
}
539-
cur.validFor = Period(
540-
currentPeriod.runId, startPid, transformer.lastPhaseId)
541-
//println(s"new denot: $cur, valid for ${cur.validFor}")
542557
cur.current // multiple transformations could be required
543558
}
544559
} else {
@@ -562,7 +577,7 @@ object Denotations {
562577
case denot: SymDenotation => s"in ${denot.owner}"
563578
case _ => ""
564579
}
565-
def msg = s"stale symbol; $this#${symbol.id}$ownerMsg, defined in run ${myValidFor.runId}, is referred to in run ${ctx.period.runId}"
580+
def msg = s"stale symbol; $this#${symbol.id} $ownerMsg, defined in run ${myValidFor.runId}, is referred to in run ${ctx.runId}"
566581
throw new StaleSymbol(msg)
567582
}
568583

src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ object Types {
10281028
val sym = lastSymbol
10291029
if (sym == null) loadDenot else denotOfSym(sym)
10301030
case d: SymDenotation =>
1031-
if (ctx.stillValid(d)) d.current
1031+
if (d.validFor.runId == ctx.runId || ctx.stillValid(d)) d.current
10321032
else {
10331033
val newd = loadDenot
10341034
if (newd.exists) newd else d.staleSymbolError

0 commit comments

Comments
 (0)