diff options
author | Nicolas Stucki <nicolas.stucki@gmail.com> | 2016-06-30 14:47:54 +0200 |
---|---|---|
committer | Nicolas Stucki <nicolas.stucki@gmail.com> | 2016-07-15 14:02:29 +0200 |
commit | f359953e0437c0b9b2205bf30c53c6206c6c0249 (patch) | |
tree | 2b49d9ead3bb6441fec62d8170845f37b4bff833 /src/dotty/tools/dotc/Run.scala | |
parent | 409c6c30c8496529aace68967acccf88850145da (diff) | |
download | dotty-f359953e0437c0b9b2205bf30c53c6206c6c0249.tar.gz dotty-f359953e0437c0b9b2205bf30c53c6206c6c0249.tar.bz2 dotty-f359953e0437c0b9b2205bf30c53c6206c6c0249.zip |
Fix #1312: Improve Xprint
* Do not reprint a tree that has not changed.
* Highlight changes with yellow and insertions in green.
* -Xprint-diff-del: Inserts the deleted parts of the tree in red
and the parts that where changed in magenta.
Diffstat (limited to 'src/dotty/tools/dotc/Run.scala')
-rw-r--r-- | src/dotty/tools/dotc/Run.scala | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/src/dotty/tools/dotc/Run.scala b/src/dotty/tools/dotc/Run.scala index 928a59214..1c500c913 100644 --- a/src/dotty/tools/dotc/Run.scala +++ b/src/dotty/tools/dotc/Run.scala @@ -2,14 +2,20 @@ package dotty.tools package dotc import core._ -import Contexts._, Periods._, Symbols._, Phases._, Decorators._ +import Contexts._ +import Periods._ +import Symbols._ +import Phases._ +import Decorators._ import dotty.tools.dotc.transform.TreeTransforms.TreeTransformer import io.PlainFile -import util.{SourceFile, NoSource, Stats, SimpleMap} +import util._ import reporting.Reporter import transform.TreeChecker import rewrite.Rewrites import java.io.{BufferedWriter, OutputStreamWriter} + +import scala.annotation.tailrec import scala.reflect.io.VirtualFile import scala.util.control.NonFatal @@ -56,26 +62,48 @@ class Run(comp: Compiler)(implicit ctx: Context) { val phases = ctx.squashPhases(ctx.phasePlan, ctx.settings.Yskip.value, ctx.settings.YstopBefore.value, ctx.settings.YstopAfter.value, ctx.settings.Ycheck.value) ctx.usePhases(phases) + var lastPrintedTree: PrintedTree = NoPrintedTree for (phase <- ctx.allPhases) if (!ctx.reporter.hasErrors) { val start = System.currentTimeMillis units = phase.runOn(units) - def foreachUnit(op: Context => Unit)(implicit ctx: Context): Unit = - for (unit <- units) op(ctx.fresh.setPhase(phase.next).setCompilationUnit(unit)) - if (ctx.settings.Xprint.value.containsPhase(phase)) - foreachUnit(printTree) + if (ctx.settings.Xprint.value.containsPhase(phase)) { + for (unit <- units) { + lastPrintedTree = + printTree(lastPrintedTree)(ctx.fresh.setPhase(phase.next).setCompilationUnit(unit)) + } + } ctx.informTime(s"$phase ", start) } if (!ctx.reporter.hasErrors) Rewrites.writeBack() } - private def printTree(ctx: Context) = { + private sealed trait PrintedTree + private final case class SomePrintedTree(phase: String, tree: String) extends PrintedTree + private object NoPrintedTree extends PrintedTree + + private def printTree(last: PrintedTree)(implicit ctx: Context): PrintedTree = { val unit = ctx.compilationUnit val prevPhase = ctx.phase.prev // can be a mini-phase val squashedPhase = ctx.squashed(prevPhase) + val treeString = unit.tpdTree.show + + ctx.echo(s"result of $unit after $squashedPhase:") - ctx.echo(s"result of $unit after ${squashedPhase}:") - ctx.echo(unit.tpdTree.show(ctx)) + last match { + case SomePrintedTree(phase, lastTreeSting) if lastTreeSting != treeString => + val diff = DiffUtil.mkColoredCodeDiff(treeString, lastTreeSting, ctx.settings.XprintDiffDel.value) + ctx.echo(diff) + SomePrintedTree(squashedPhase.toString, treeString) + + case SomePrintedTree(phase, lastTreeSting) => + ctx.echo(" Unchanged since " + phase) + last + + case NoPrintedTree => + ctx.echo(treeString) + SomePrintedTree(squashedPhase.toString, treeString) + } } def compile(sourceCode: String): Unit = { |