Skip to content

Commit 5c10120

Browse files
committed
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 <empty> { 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 <empty> { @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
1 parent 58d1b10 commit 5c10120

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -268,28 +268,23 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
268268
val unit = ctx.compilationUnit
269269
val prevPhase = ctx.phase.prev // can be a mini-phase
270270
val fusedPhase = ctx.base.fusedContaining(prevPhase)
271-
val tree =
272-
if (ctx.isAfterTyper) unit.tpdTree
273-
else unit.untpdTree
271+
val echoHeader = f"[[syntax trees at end of $fusedPhase%25s]] // ${unit.source}"
272+
val tree = if ctx.isAfterTyper then unit.tpdTree else unit.untpdTree
274273
val treeString = tree.show(using ctx.withProperty(XprintMode, Some(())))
275274

276-
report.echo(s"result of $unit after $fusedPhase:")
277-
278275
last match {
279-
case SomePrintedTree(phase, lastTreeSting) if lastTreeSting != treeString =>
280-
val msg =
281-
if (!ctx.settings.XprintDiff.value && !ctx.settings.XprintDiffDel.value) treeString
282-
else DiffUtil.mkColoredCodeDiff(treeString, lastTreeSting, ctx.settings.XprintDiffDel.value)
283-
report.echo(msg)
284-
SomePrintedTree(fusedPhase.toString, treeString)
285-
286-
case SomePrintedTree(phase, lastTreeSting) =>
287-
report.echo(" Unchanged since " + phase)
276+
case SomePrintedTree(phase, lastTreeString) if lastTreeString == treeString =>
277+
report.echo(s"$echoHeader: unchanged since $phase")
288278
last
289279

290-
case NoPrintedTree =>
291-
report.echo(treeString)
292-
SomePrintedTree(fusedPhase.toString, treeString)
280+
case SomePrintedTree(phase, lastTreeString) if ctx.settings.XprintDiff.value || ctx.settings.XprintDiffDel.value =>
281+
val diff = DiffUtil.mkColoredCodeDiff(treeString, lastTreeString, ctx.settings.XprintDiffDel.value)
282+
report.echo(s"$echoHeader\n$diff\n")
283+
SomePrintedTree(fusedPhase.phaseName, treeString)
284+
285+
case _ =>
286+
report.echo(s"$echoHeader\n$treeString\n")
287+
SomePrintedTree(fusedPhase.phaseName, treeString)
293288
}
294289
}
295290

tests/printing/i620.check

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
result of tests/printing/i620.scala after typer:
1+
[[syntax trees at end of typer]] // tests/printing/i620.scala
22
package O {
33
package O.A {
44
class D() extends Object() {
@@ -30,3 +30,4 @@ package O {
3030
}
3131
}
3232
}
33+

0 commit comments

Comments
 (0)