Skip to content

Commit c73a21b

Browse files
committed
More debug options for printing
- Mark splices in code under -print-debug - Print owners of all definitions under -print-debug-owners
1 parent 9733479 commit c73a21b

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class ScalaSettings extends Settings.SettingGroup {
8787
val YdebugFlags = BooleanSetting("-Ydebug-flags", "Print all flags of definitions")
8888
val YdebugMissingRefs = BooleanSetting("-Ydebug-missing-refs", "Print a stacktrace when a required symbol is missing")
8989
val YdebugNames = BooleanSetting("-Ydebug-names", "Show internal representation of names")
90-
val YdebugOwners = BooleanSetting("-Ydebug-owners", "Print all owners of definitions (requires -Yprint-syms)")
9190
val YtermConflict = ChoiceSetting("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", List("package", "object", "error"), "error")
9291
val Ylog = PhasesSetting("-Ylog", "Log operations during")
9392
val YemitTasty = BooleanSetting("-Yemit-tasty", "Generate tasty in separate *.tasty file.")
@@ -113,6 +112,7 @@ class ScalaSettings extends Settings.SettingGroup {
113112
val YplainPrinter = BooleanSetting("-Yplain-printer", "Pretty-print using a plain printer.")
114113
val YprintSyms = BooleanSetting("-Yprint-syms", "when printing trees print info in symbols instead of corresponding info in trees.")
115114
val YprintDebug = BooleanSetting("-Yprint-debug", "when printing trees, print some extra information useful for debugging.")
115+
val YprintDebugOwners = BooleanSetting("-Yprint-debug-owners", "when printing trees, print owners of definitions.")
116116
val YshowPrintErrors = BooleanSetting("-Yshow-print-errors", "don't suppress exceptions thrown during tree printing.")
117117
val YtestPickler = BooleanSetting("-Ytest-pickler", "self-test for pickling functionality; should be used with -Ystop-after:pickler")
118118
val YcheckReentrant = BooleanSetting("-Ycheck-reentrant", "check that compiled program does not contain vars that can be accessed from a global root.")

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
444444
case EmptyTree =>
445445
"<empty>"
446446
case TypedSplice(t) =>
447-
toText(t)
447+
if (ctx.settings.YprintDebug.value) "[" ~ toText(t) ~ "]#TS#"
448+
else toText(t)
448449
case tree @ ModuleDef(name, impl) =>
449450
withEnclosingDef(tree) {
450451
modText(tree.mods, NoSymbol, keywordStr("object")) ~~ nameIdText(tree) ~ toTextTemplate(impl)
@@ -610,11 +611,14 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
610611
else toText(tree.name) ~ idText(tree)
611612
}
612613

614+
private def toTextOwner(tree: Tree[_]) =
615+
"[owner = " ~ tree.symbol.owner.show ~ "]" provided ctx.settings.YprintDebugOwners.value
616+
613617
protected def dclTextOr[T >: Untyped](tree: Tree[T])(treeText: => Text) =
614-
if (useSymbol(tree))
615-
annotsText(tree.symbol) ~~ dclText(tree.symbol) ~
616-
( " <in " ~ toText(tree.symbol.owner) ~ ">" provided ctx.settings.YdebugOwners.value)
617-
else treeText
618+
toTextOwner(tree) ~ {
619+
if (useSymbol(tree)) annotsText(tree.symbol) ~~ dclText(tree.symbol)
620+
else treeText
621+
}
618622

619623
def tparamsText[T >: Untyped](params: List[Tree[T]]): Text =
620624
"[" ~ toText(params, ", ") ~ "]" provided params.nonEmpty

0 commit comments

Comments
 (0)