Skip to content

Commit f0af687

Browse files
committed
Systematically use -Yprint-debug for low-level printing
1 parent a041a4c commit f0af687

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import scala.annotation.switch
1616

1717
class PlainPrinter(_ctx: Context) extends Printer {
1818
protected[this] implicit def ctx: Context = _ctx.addMode(Mode.Printing)
19+
protected[this] def printDebug = ctx.settings.YprintDebug.value
1920

2021
private[this] var openRecs: List[RecType] = Nil
2122

@@ -204,13 +205,13 @@ class PlainPrinter(_ctx: Context) extends Printer {
204205
toTextLocal(tpe) ~ " " ~ toText(annot)
205206
case tp: TypeVar =>
206207
if (tp.isInstantiated)
207-
toTextLocal(tp.instanceOpt) ~ (Str("^") provided ctx.settings.YprintDebug.value)
208+
toTextLocal(tp.instanceOpt) ~ (Str("^") provided printDebug)
208209
else {
209210
val constr = ctx.typerState.constraint
210211
val bounds =
211212
if (constr.contains(tp)) ctx.addMode(Mode.Printing).typeComparer.fullBounds(tp.origin)
212213
else TypeBounds.empty
213-
if (bounds.isTypeAlias) toText(bounds.lo) ~ (Str("^") provided ctx.settings.YprintDebug.value)
214+
if (bounds.isTypeAlias) toText(bounds.lo) ~ (Str("^") provided printDebug)
214215
else if (ctx.settings.YshowVarBounds.value) "(" ~ toText(tp.origin) ~ "?" ~ toText(bounds) ~ ")"
215216
else toText(tp.origin)
216217
}
@@ -510,7 +511,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
510511
else
511512
Text()
512513

513-
nodeName ~ "(" ~ elems ~ tpSuffix ~ ")" ~ (Str(tree.sourcePos.toString) provided ctx.settings.YprintPos.value)
514+
nodeName ~ "(" ~ elems ~ tpSuffix ~ ")" ~ (Str(tree.sourcePos.toString) provided printDebug)
514515
}.close // todo: override in refined printer
515516

516517
def toText(pos: SourcePosition): Text = {

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
9191

9292
override def toTextRef(tp: SingletonType): Text = controlled {
9393
tp match {
94-
case tp: ThisType =>
94+
case tp: ThisType if !printDebug =>
9595
if (tp.cls.isAnonymousClass) return keywordStr("this")
9696
if (tp.cls is ModuleClass) return fullNameString(tp.cls.sourceModule)
9797
case _ =>
@@ -101,7 +101,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
101101

102102
override def toTextPrefix(tp: Type): Text = controlled {
103103
def isOmittable(sym: Symbol) =
104-
if (ctx.settings.verbose.value) false
104+
if (printDebug) false
105105
else if (homogenizedView) isEmptyPrefix(sym) // drop <root> and anonymous classes, but not scala, Predef.
106106
else isOmittablePrefix(sym)
107107
tp match {
@@ -182,7 +182,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
182182
val cls = tycon.typeSymbol
183183
if (tycon.isRepeatedParam) return toTextLocal(args.head) ~ "*"
184184
if (defn.isFunctionClass(cls)) return toTextFunction(args, cls.name.isImplicitFunction, cls.name.isErasedFunction)
185-
if (tp.tupleArity >= 2 && !ctx.settings.YprintDebug.value) return toTextTuple(tp.tupleElementTypes)
185+
if (tp.tupleArity >= 2 && !printDebug) return toTextTuple(tp.tupleElementTypes)
186186
if (isInfixType(tp)) {
187187
val l :: r :: Nil = args
188188
val opName = tyconName(tycon)
@@ -197,7 +197,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
197197
case OrType(tp1, tp2) =>
198198
return toTextInfixType(tpnme.raw.BAR, tp1, tp2) { toText(tpnme.raw.BAR) }
199199

200-
case EtaExpansion(tycon) if !ctx.settings.YprintDebug.value =>
200+
case EtaExpansion(tycon) if !printDebug =>
201201
return toText(tycon)
202202
case tp: RefinedType if defn.isFunctionType(tp) =>
203203
return toTextDependentFunction(tp.refinedInfo.asInstanceOf[MethodType])
@@ -237,7 +237,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
237237
}
238238
return "[applied to " ~ (Str("given ") provided tp.isContextualMethod) ~ (Str("erased ") provided tp.isErasedMethod) ~ "(" ~ argsText ~ ") returning " ~ toText(resultType) ~ "]"
239239
case IgnoredProto(ignored) =>
240-
return "?" ~ (("(ignored: " ~ toText(ignored) ~ ")") provided ctx.settings.verbose.value)
240+
return "?" ~ (("(ignored: " ~ toText(ignored) ~ ")") provided printDebug)
241241
case tp @ PolyProto(targs, resType) =>
242242
return "[applied to [" ~ toTextGlobal(targs, ", ") ~ "] returning " ~ toText(resType)
243243
case _ =>
@@ -255,7 +255,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
255255
("{" ~ toText(trees, "\n") ~ "}").close
256256

257257
protected def typeApplyText[T >: Untyped](tree: TypeApply[T]): Text = {
258-
val isQuote = !ctx.settings.YprintDebug.value && tree.fun.hasType && tree.fun.symbol == defn.InternalQuoted_typeQuote
258+
val isQuote = !printDebug && tree.fun.hasType && tree.fun.symbol == defn.InternalQuoted_typeQuote
259259
val (open, close) = if (isQuote) (keywordStr("'["), keywordStr("]")) else ("[", "]")
260260
val funText = toTextLocal(tree.fun).provided(!isQuote)
261261
tree.fun match {
@@ -337,9 +337,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
337337
if (name.isTypeName) typeText(txt)
338338
else txt
339339
case tree @ Select(qual, name) =>
340-
if (!ctx.settings.YprintDebug.value && tree.hasType && tree.symbol == defn.QuotedType_splice) typeText("${") ~ toTextLocal(qual) ~ typeText("}")
340+
if (!printDebug && tree.hasType && tree.symbol == defn.QuotedType_splice) typeText("${") ~ toTextLocal(qual) ~ typeText("}")
341341
else if (qual.isType) toTextLocal(qual) ~ "#" ~ typeText(toText(name))
342-
else toTextLocal(qual) ~ ("." ~ nameIdText(tree) provided (name != nme.CONSTRUCTOR || ctx.settings.YprintDebug.value))
342+
else toTextLocal(qual) ~ ("." ~ nameIdText(tree) provided (name != nme.CONSTRUCTOR || printDebug))
343343
case tree: This =>
344344
optDotPrefix(tree) ~ keywordStr("this") ~ idText(tree)
345345
case Super(qual: This, mix) =>
@@ -349,9 +349,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
349349
changePrec (GlobalPrec) {
350350
keywordStr("throw ") ~ toText(args.head)
351351
}
352-
else if (!ctx.settings.YprintDebug.value && fun.hasType && fun.symbol == defn.InternalQuoted_exprQuote)
352+
else if (!printDebug && fun.hasType && fun.symbol == defn.InternalQuoted_exprQuote)
353353
keywordStr("'{") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
354-
else if (!ctx.settings.YprintDebug.value && fun.hasType && fun.symbol == defn.InternalQuoted_exprSplice)
354+
else if (!printDebug && fun.hasType && fun.symbol == defn.InternalQuoted_exprSplice)
355355
keywordStr("${") ~ toTextGlobal(args, ", ") ~ keywordStr("}")
356356
else if (app.isGivenApply && !homogenizedView)
357357
changePrec(InfixPrec) {
@@ -519,7 +519,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
519519
case EmptyTree =>
520520
"<empty>"
521521
case TypedSplice(t) =>
522-
if (ctx.settings.YprintDebug.value) "[" ~ toText(t) ~ "]#TS#"
522+
if (printDebug) "[" ~ toText(t) ~ "]#TS#"
523523
else toText(t)
524524
case tree @ ModuleDef(name, impl) =>
525525
withEnclosingDef(tree) {
@@ -603,7 +603,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
603603
case Splice(tree) =>
604604
keywordStr("${") ~ toTextGlobal(dropBlock(tree)) ~ keywordStr("}")
605605
case tree: Applications.IntegratedTypeArgs =>
606-
toText(tree.app) ~ Str("(with integrated type args)").provided(ctx.settings.YprintDebug.value)
606+
toText(tree.app) ~ Str("(with integrated type args)").provided(printDebug)
607607
case Thicket(trees) =>
608608
"Thicket {" ~~ toTextGlobal(trees, "\n") ~~ "}"
609609
case _ =>
@@ -785,8 +785,9 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
785785

786786
protected def templateText(tree: TypeDef, impl: Template): Text = {
787787
val decl = modText(tree.mods, tree.symbol, keywordStr(if ((tree).mods is Trait) "trait" else "class"), isType = true)
788-
decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~
789-
(if (tree.hasType && ctx.settings.verbose.value) i"[decls = ${tree.symbol.info.decls}]" else "")
788+
( decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) }
789+
// ~ (if (tree.hasType && printDebug) i"[decls = ${tree.symbol.info.decls}]" else "") // uncomment to enable
790+
)
790791
}
791792

792793
protected def toTextPackageId[T >: Untyped](pid: Tree[T]): Text =

0 commit comments

Comments
 (0)