@@ -2,14 +2,20 @@ package dotty.tools
22package dotc
33
44import core ._
5- import Contexts ._ , Periods ._ , Symbols ._ , Phases ._ , Decorators ._
5+ import Contexts ._
6+ import Periods ._
7+ import Symbols ._
8+ import Phases ._
9+ import Decorators ._
610import dotty .tools .dotc .transform .TreeTransforms .TreeTransformer
711import io .PlainFile
8- import util .{ SourceFile , NoSource , Stats , SimpleMap }
12+ import util ._
913import reporting .Reporter
1014import transform .TreeChecker
1115import rewrite .Rewrites
1216import java .io .{BufferedWriter , OutputStreamWriter }
17+
18+ import scala .annotation .tailrec
1319import scala .reflect .io .VirtualFile
1420import scala .util .control .NonFatal
1521
@@ -56,26 +62,48 @@ class Run(comp: Compiler)(implicit ctx: Context) {
5662 val phases = ctx.squashPhases(ctx.phasePlan,
5763 ctx.settings.Yskip .value, ctx.settings.YstopBefore .value, ctx.settings.YstopAfter .value, ctx.settings.Ycheck .value)
5864 ctx.usePhases(phases)
65+ var lastPrintedTree : PrintedTree = NoPrintedTree
5966 for (phase <- ctx.allPhases)
6067 if (! ctx.reporter.hasErrors) {
6168 val start = System .currentTimeMillis
6269 units = phase.runOn(units)
63- def foreachUnit (op : Context => Unit )(implicit ctx : Context ): Unit =
64- for (unit <- units) op(ctx.fresh.setPhase(phase.next).setCompilationUnit(unit))
65- if (ctx.settings.Xprint .value.containsPhase(phase))
66- foreachUnit(printTree)
70+ if (ctx.settings.Xprint .value.containsPhase(phase)) {
71+ for (unit <- units) {
72+ lastPrintedTree =
73+ printTree(lastPrintedTree)(ctx.fresh.setPhase(phase.next).setCompilationUnit(unit))
74+ }
75+ }
6776 ctx.informTime(s " $phase " , start)
6877 }
6978 if (! ctx.reporter.hasErrors) Rewrites .writeBack()
7079 }
7180
72- private def printTree (ctx : Context ) = {
81+ private sealed trait PrintedTree
82+ private final case class SomePrintedTree (phase : String , tree : String ) extends PrintedTree
83+ private object NoPrintedTree extends PrintedTree
84+
85+ private def printTree (last : PrintedTree )(implicit ctx : Context ): PrintedTree = {
7386 val unit = ctx.compilationUnit
7487 val prevPhase = ctx.phase.prev // can be a mini-phase
7588 val squashedPhase = ctx.squashed(prevPhase)
89+ val treeString = unit.tpdTree.show
90+
91+ ctx.echo(s " result of $unit after $squashedPhase: " )
7692
77- ctx.echo(s " result of $unit after ${squashedPhase}: " )
78- ctx.echo(unit.tpdTree.show(ctx))
93+ last match {
94+ case SomePrintedTree (phase, lastTreeSting) if lastTreeSting != treeString =>
95+ val diff = DiffUtil .mkColoredCodeDiff(treeString, lastTreeSting, ctx.settings.XprintDiffDel .value)
96+ ctx.echo(diff)
97+ SomePrintedTree (squashedPhase.toString, treeString)
98+
99+ case SomePrintedTree (phase, lastTreeSting) =>
100+ ctx.echo(" Unchanged since " + phase)
101+ last
102+
103+ case NoPrintedTree =>
104+ ctx.echo(treeString)
105+ SomePrintedTree (squashedPhase.toString, treeString)
106+ }
79107 }
80108
81109 def compile (sourceCode : String ): Unit = {
0 commit comments