From a9a2fd7c479eb8d68bf7e58cd0f6084a2106ca7d Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 12 May 2012 07:30:19 -0700 Subject: [PATCH 1/2] Clutch modification to tree printing. Don't print trees under -Xprint:all if they're identical to the tree printed at the previous phase. It only works for a single compilation unit but that is a huge step forward for us debuggers. For instance this file: trait Foo { def f = 5 } used to produce 332 lines of output and now produces 92, with zero loss of information. It ends with: [[syntax trees at end of cleanup]] // a.scala: tree is unchanged since mixin [[syntax trees at end of icode]] // a.scala: tree is unchanged since mixin [[syntax trees at end of inliner]] // a.scala: tree is unchanged since mixin [[syntax trees at end of inlineExceptionHandlers]] // a.scala: tree is unchanged since mixin [[syntax trees at end of closelim]] // a.scala: tree is unchanged since mixin [[syntax trees at end of dce]] // a.scala: tree is unchanged since mixin [[syntax trees at end of jvm]] // a.scala: tree is unchanged since mixin --- src/compiler/scala/tools/nsc/Global.scala | 27 +++++++++++++++++++++-- test/files/run/t5527.check | 2 +- test/files/specialized/SI-5005.check | 2 +- 3 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index de270a76f102..49a644ba3a2c 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -130,7 +130,28 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb object nodePrinters extends { val global: Global.this.type = Global.this } with NodePrinters { + var lastPrintedPhase: Phase = NoPhase + var lastPrintedSource: String = "" infolevel = InfoLevel.Verbose + + def showUnit(unit: CompilationUnit) { + print(" // " + unit.source) + if (unit.body == null) println(": tree is null") + else { + val source = util.stringFromWriter(w => newTreePrinter(w) print unit.body) + + // treePrinter show unit.body + if (lastPrintedSource == source) + println(": tree is unchanged since " + lastPrintedPhase) + else { + lastPrintedPhase = phase.prev // since we're running inside "afterPhase" + lastPrintedSource = source + println("") + println(source) + println("") + } + } + } } def withInfoLevel[T](infolevel: nodePrinters.InfoLevel.Value)(op: => T) = { @@ -1588,8 +1609,10 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb } // class Run def printAllUnits() { - print("[[syntax trees at end of " + phase + "]]") - afterPhase(phase) { currentRun.units foreach (treePrinter.print(_)) } + print("[[syntax trees at end of %25s]]".format(phase)) + afterPhase(phase)(currentRun.units foreach { unit => + nodePrinters showUnit unit + }) } /** We resolve the class/object ambiguity by passing a type/term name. diff --git a/test/files/run/t5527.check b/test/files/run/t5527.check index bb13928fd870..1518168c5115 100644 --- a/test/files/run/t5527.check +++ b/test/files/run/t5527.check @@ -1,4 +1,4 @@ -[[syntax trees at end of parser]]// Scala source: newSource1 +[[syntax trees at end of parser]] // newSource1 package { object UselessComments extends scala.AnyRef { def () = { diff --git a/test/files/specialized/SI-5005.check b/test/files/specialized/SI-5005.check index 9fc63a2b1d4d..81e8342dad82 100644 --- a/test/files/specialized/SI-5005.check +++ b/test/files/specialized/SI-5005.check @@ -1,4 +1,4 @@ -[[syntax trees at end of specialize]]// Scala source: newSource1 +[[syntax trees at end of specialize]] // newSource1 package { class C2[@specialized(scala.Boolean) U >: Nothing <: Any] extends Object { def (): C2[U] = { From f1d81c9b9b300b2f526c03a27600e6fe481fc7c6 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 12 May 2012 08:03:08 -0700 Subject: [PATCH 2/2] Test case closes SI-5037. --- test/files/run/t5037.check | 2 ++ test/files/run/t5037.scala | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 test/files/run/t5037.check create mode 100644 test/files/run/t5037.scala diff --git a/test/files/run/t5037.check b/test/files/run/t5037.check new file mode 100644 index 000000000000..da29283aaa47 --- /dev/null +++ b/test/files/run/t5037.check @@ -0,0 +1,2 @@ +true +false diff --git a/test/files/run/t5037.scala b/test/files/run/t5037.scala new file mode 100644 index 000000000000..7b1fce7a82ff --- /dev/null +++ b/test/files/run/t5037.scala @@ -0,0 +1,18 @@ +object Test { + def main(args: Array[String]) { + val t = new Test + t.inner.foo() + } +} + +class Test { + class Inner { + def foo() { + println(bar) + bar = false + println(bar) + } + } + val inner = new Inner + private[this] final var bar = true +}