Skip to content

Commit e0f56b7

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 b6946f3 commit e0f56b7

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
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: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -446,9 +446,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
446446
case EmptyTree =>
447447
"<empty>"
448448
case TypedSplice(t) =>
449-
toText(t)
449+
if (ctx.settings.YprintDebug.value) "[" ~ toText(t) ~ "]#TS#"
450+
else toText(t)
450451
case tpd.UntypedSplice(t) =>
451-
toText(t)
452+
if (ctx.settings.YprintDebug.value) "[" ~ toText(t) ~ ":" ~ toText(tree.typeOpt) ~ "]#US#"
453+
else toText(t)
452454
case tree @ ModuleDef(name, impl) =>
453455
withEnclosingDef(tree) {
454456
modText(tree.mods, NoSymbol, keywordStr("object")) ~~ nameIdText(tree) ~ toTextTemplate(impl)
@@ -605,11 +607,14 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
605607
else toText(tree.name) ~ idText(tree)
606608
}
607609

610+
private def toTextOwner(tree: Tree[_]) =
611+
"[owner = " ~ tree.symbol.owner.show ~ "]" provided ctx.settings.YprintDebugOwners.value
612+
608613
protected def dclTextOr[T >: Untyped](tree: Tree[T])(treeText: => Text) =
609-
if (useSymbol(tree))
610-
annotsText(tree.symbol) ~~ dclText(tree.symbol) ~
611-
( " <in " ~ toText(tree.symbol.owner) ~ ">" provided ctx.settings.YdebugOwners.value)
612-
else treeText
614+
toTextOwner(tree) ~ {
615+
if (useSymbol(tree)) annotsText(tree.symbol) ~~ dclText(tree.symbol)
616+
else treeText
617+
}
613618

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

0 commit comments

Comments
 (0)