Skip to content

Tweak -Xprint output #13268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 12 additions & 17 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/printing/i620.check
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -30,3 +30,4 @@ package O {
}
}
}