Skip to content

Commit d005613

Browse files
committed
Merge pull request #1057 from dotty-staging/fix/hide-stacktraces
Hide stack traces behind -Ydebug
2 parents ffcc27b + b33babc commit d005613

File tree

9 files changed

+11
-9
lines changed

9 files changed

+11
-9
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,12 @@ class ScalaSettings extends Settings.SettingGroup {
146146
val etaExpandKeepsStar = BooleanSetting("-Yeta-expand-keeps-star", "Eta-expand varargs methods to T* rather than Seq[T]. This is a temporary option to ease transition.")
147147
val Yinvalidate = StringSetting("-Yinvalidate", "classpath-entry", "Invalidate classpath entry before run", "")
148148
val noSelfCheck = BooleanSetting("-Yno-self-type-checks", "Suppress check for self-type conformance among inherited members.")
149+
val YtraceContextCreation = BooleanSetting("-Ytrace-context-creation", "Store stack trace of context creations.")
149150
val YshowSuppressedErrors = BooleanSetting("-Yshow-suppressed-errors", "Also show follow-on errors and warnings that are normally supressed.")
150151
val Yheartbeat = BooleanSetting("-Yheartbeat", "show heartbeat stack trace of compiler operations.")
151152
val Yprintpos = BooleanSetting("-Yprintpos", "show tree positions.")
152153
val YnoDeepSubtypes = BooleanSetting("-Yno-deep-subtypes", "throw an exception on deep subtyping call stacks.")
154+
val YplainPrinter = BooleanSetting("-Yplain-printer", "Pretty-print using a plain printer.")
153155
val YprintSyms = BooleanSetting("-Yprint-syms", "when printing trees print info in symbols instead of corresponding info in trees.")
154156
val YtestPickler = BooleanSetting("-Ytest-pickler", "self-test for pickling functionality; should be used with -Ystop-after:pickler")
155157
val YcheckReentrant = BooleanSetting("-Ycheck-reentrant", "check that compiled program does not contain vars that can be accessed from a global root.")

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ object Contexts {
255255
private var creationTrace: Array[StackTraceElement] = _
256256

257257
private def setCreationTrace() =
258-
if (this.settings.debug.value)
258+
if (this.settings.YtraceContextCreation.value)
259259
creationTrace = (new Throwable).getStackTrace().take(20)
260260

261261
/** Print all enclosing context's creation stacktraces */

src/dotty/tools/dotc/core/Denotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ object Denotations {
465465
try info.signature
466466
catch { // !!! DEBUG
467467
case scala.util.control.NonFatal(ex) =>
468-
println(s"cannot take signature of ${info.show}")
468+
ctx.println(s"cannot take signature of ${info.show}")
469469
throw ex
470470
}
471471
case _ => Signature.NotAMethod

src/dotty/tools/dotc/core/Types.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3387,7 +3387,7 @@ object Types {
33873387
class MissingType(pre: Type, name: Name)(implicit ctx: Context) extends TypeError(
33883388
i"""cannot resolve reference to type $pre.$name
33893389
|the classfile defining the type might be missing from the classpath${otherReason(pre)}""".stripMargin) {
3390-
printStackTrace()
3390+
if (ctx.debug) printStackTrace()
33913391
}
33923392

33933393
private def otherReason(pre: Type)(implicit ctx: Context): String = pre match {

src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
188188
val ex = new BadSignature(
189189
sm"""error reading Scala signature of $classRoot from $source:
190190
|error occurred at position $readIndex: $msg""")
191-
/*if (debug)*/ original.getOrElse(ex).printStackTrace() // !!! DEBUG
191+
if (ctx.debug) original.getOrElse(ex).printStackTrace()
192192
throw ex
193193
}
194194

@@ -425,7 +425,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas
425425
owner.info.decls.checkConsistent()
426426
if (slowSearch(name).exists)
427427
System.err.println(i"**** slow search found: ${slowSearch(name)}")
428-
new Exception().printStackTrace()
428+
if (ctx.debug) Thread.dumpStack()
429429
ctx.newStubSymbol(owner, name, source)
430430
}
431431
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
3232

3333
protected def recursionLimitExceeded() = {
3434
ctx.warning("Exceeded recursion depth attempting to print.")
35-
(new Throwable).printStackTrace
35+
if (ctx.debug) Thread.dumpStack()
3636
}
3737

3838
/** If true, tweak output so it is the same before and after pickling */

src/dotty/tools/dotc/printing/Printers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ trait Printers { this: Context =>
88
/** A function creating a printer */
99
def printer = {
1010
val pr = printerFn(this)
11-
if (this.debug) pr.plain else pr
11+
if (this.settings.YplainPrinter.value) pr.plain else pr
1212
}
1313
}
1414

src/dotty/tools/dotc/reporting/ConsoleReporter.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class ConsoleReporter(
6363
if (reader != null) {
6464
val response = reader.read().asInstanceOf[Char].toLower
6565
if (response == 'a' || response == 's') {
66-
(new Exception).printStackTrace()
66+
Thread.dumpStack()
6767
if (response == 'a')
6868
sys.exit(1)
6969
}

src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans
327327
private[TreeMakers] def incorporateOuterRebinding(outerSubst: Rebindings): Unit = {
328328
if (currSub ne null) {
329329
ctx.debuglog("BUG: incorporateOuterRebinding called more than once for " + ((this, currSub, outerSubst)))
330-
Thread.dumpStack()
330+
if (ctx.debug) Thread.dumpStack()
331331
}
332332
else currSub = outerSubst >> rebindings
333333
}

0 commit comments

Comments
 (0)