From 5c101200a4d4297928865b58d2fdf4e346039bcb Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Fri, 6 Aug 2021 15:22:33 +0100 Subject: [PATCH] Tweak -Xprint output Most importantly, move "unchanged since $phase" to be on the same line as the lead-in. And then I copied over the lead-in from Scala 2, because I like it. It doesn't look as nice because MegaPhases don't have their own trim name, but it starts nicely: [[syntax trees at end of typer]] // a.scala package { class C() extends Object() { def foo: Int = 1 } } [[syntax trees at end of inlinedPositions]] // a.scala: unchanged since typer [[syntax trees at end of posttyper]] // a.scala package { @scala.annotation.internal.SourceFile("a.scala") class C() extends Object() { def foo: Int = 1 } } [[syntax trees at end of pickler]] // a.scala: unchanged since posttyper [[syntax trees at end of inlining]] // a.scala: unchanged since posttyper [[syntax trees at end of postInlining]] // a.scala: unchanged since posttyper [[syntax trees at end of staging]] // a.scala: unchanged since posttyper [[syntax trees at end of pickleQuotes]] // a.scala: unchanged since posttyper [[syntax trees at end of MegaPhase{firstTransform, checkReentrant, elimPackagePrefixes, cookComments, checkStatic, betaReduce, inlineVals, expandSAMs}]] // a.scala: unchanged since posttyper [[syntax trees at end of MegaPhase{elimRepeated, protectedAccessors, extmethods, uncacheGivenAliases, byNameClosures, hoistSuperArgs, specializeApplyMethods, refchecks, tryCatchPatterns, patternMatcher}]] // a.scala: unchanged since posttyper [[syntax trees at end of MegaPhase{elimOpaque, explicitOuter, explicitSelf, elimByName, stringInterpolatorOpt}]] // a.scala: unchanged since posttyper [[syntax trees at end of MegaPhase{pruneErasedDefs, uninitializedDefs, inlinePatterns, vcInlineMethods, seqLiterals, intercepted, getters, specializeFunctions, liftTry, collectNullableFields, elimOuterSelect, resolveSuper, functionXXLForwarders, paramForwarding, genericTuples, letOverApply, arrayConstructors}]] // a.scala: unchanged since posttyper --- compiler/src/dotty/tools/dotc/Run.scala | 29 ++++++++++--------------- tests/printing/i620.check | 3 ++- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/Run.scala b/compiler/src/dotty/tools/dotc/Run.scala index d75042d5a238..66095a77dcc6 100644 --- a/compiler/src/dotty/tools/dotc/Run.scala +++ b/compiler/src/dotty/tools/dotc/Run.scala @@ -268,28 +268,23 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint val unit = ctx.compilationUnit val prevPhase = ctx.phase.prev // can be a mini-phase val fusedPhase = ctx.base.fusedContaining(prevPhase) - val tree = - if (ctx.isAfterTyper) unit.tpdTree - else unit.untpdTree + val echoHeader = f"[[syntax trees at end of $fusedPhase%25s]] // ${unit.source}" + val tree = if ctx.isAfterTyper then unit.tpdTree else unit.untpdTree val treeString = tree.show(using ctx.withProperty(XprintMode, Some(()))) - report.echo(s"result of $unit after $fusedPhase:") - last match { - case SomePrintedTree(phase, lastTreeSting) if lastTreeSting != treeString => - val msg = - if (!ctx.settings.XprintDiff.value && !ctx.settings.XprintDiffDel.value) treeString - else DiffUtil.mkColoredCodeDiff(treeString, lastTreeSting, ctx.settings.XprintDiffDel.value) - report.echo(msg) - SomePrintedTree(fusedPhase.toString, treeString) - - case SomePrintedTree(phase, lastTreeSting) => - report.echo(" Unchanged since " + phase) + case SomePrintedTree(phase, lastTreeString) if lastTreeString == treeString => + report.echo(s"$echoHeader: unchanged since $phase") last - case NoPrintedTree => - report.echo(treeString) - SomePrintedTree(fusedPhase.toString, treeString) + case SomePrintedTree(phase, lastTreeString) if ctx.settings.XprintDiff.value || ctx.settings.XprintDiffDel.value => + val diff = DiffUtil.mkColoredCodeDiff(treeString, lastTreeString, ctx.settings.XprintDiffDel.value) + report.echo(s"$echoHeader\n$diff\n") + SomePrintedTree(fusedPhase.phaseName, treeString) + + case _ => + report.echo(s"$echoHeader\n$treeString\n") + SomePrintedTree(fusedPhase.phaseName, treeString) } } diff --git a/tests/printing/i620.check b/tests/printing/i620.check index 1dedb6d375a7..3780e2cf3045 100644 --- a/tests/printing/i620.check +++ b/tests/printing/i620.check @@ -1,4 +1,4 @@ -result of tests/printing/i620.scala after typer: +[[syntax trees at end of typer]] // tests/printing/i620.scala package O { package O.A { class D() extends Object() { @@ -30,3 +30,4 @@ package O { } } } +