Skip to content

Commit fd6ac0a

Browse files
committed
More accurate or postcondition conchecking in TreeChecker
Previous postcondition checking did not take into account that phases are not flat - they consist in part of macro phases that contain miniphases. In fact the whole set up in Run is dubiuos - we should eliminate the problem at the root, as described in the TODO in run.
1 parent 7d51d27 commit fd6ac0a

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/dotty/tools/dotc/Run.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ class Run(comp: Compiler)(implicit ctx: Context) {
2828
compileSources(sources)
2929
}
3030

31+
/** TODO: There's a fundamental design problem here: We assmble phases using `squash`
32+
* when we first build the compiler. But we modify them with -Yskip, -Ystop
33+
* on each run. That modification needs to either trasnform the tree structure,
34+
* or we need to assmeble phases on each run, and take -Yskip, -Ystop into
35+
* account. I think the latter would be preferable.
36+
*/
3137
def compileSources(sources: List[SourceFile]) = Stats.monitorHeartBeat {
3238
if (sources forall (_.exists)) {
3339
units = sources map (new CompilationUnit(_))
@@ -36,7 +42,7 @@ class Run(comp: Compiler)(implicit ctx: Context) {
3642
ctx.settings.YstopAfter.value.containsPhase(phase.prev)
3743
val phasesToRun = ctx.allPhases.init
3844
.takeWhile(!stoppedBefore(_))
39-
.filterNot(ctx.settings.Yskip.value.containsPhase(_))
45+
.filterNot(ctx.settings.Yskip.value.containsPhase(_)) // TODO: skip only subphase
4046
for (phase <- phasesToRun)
4147
if (!ctx.reporter.hasErrors) {
4248
phase.runOn(units)

src/dotty/tools/dotc/transform/TreeChecker.scala

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,23 @@ import java.lang.AssertionError
3535
class TreeChecker {
3636
import ast.tpd._
3737

38+
private def previousPhases(phases: List[Phase])(implicit ctx: Context): List[Phase] = phases match {
39+
case (phase: TreeTransformer) :: phases1 =>
40+
val subPhases = phase.transformations.map(_.phase)
41+
val previousSubPhases = previousPhases(subPhases.toList)
42+
if (previousSubPhases.length == subPhases.length) previousSubPhases ::: previousPhases(phases1)
43+
else previousSubPhases
44+
case phase :: phases1 if phase ne ctx.phase =>
45+
phase :: previousPhases(phases1)
46+
case _ =>
47+
Nil
48+
}
49+
3850
def check(phasesToRun: Seq[Phase], ctx: Context) = {
3951
println(s"checking ${ctx.compilationUnit} after phase ${ctx.phase.prev}")
4052
val checkingCtx = ctx.fresh
4153
.setTyperState(ctx.typerState.withReporter(new ThrowingReporter(ctx.typerState.reporter)))
42-
val checker = new Checker(phasesToRun.takeWhile(_ ne ctx.phase))
54+
val checker = new Checker(previousPhases(phasesToRun.toList)(ctx))
4355
checker.typedExpr(ctx.compilationUnit.tpdTree)(checkingCtx)
4456
}
4557

0 commit comments

Comments
 (0)