From 11df014b7fab14999d2de1ce5f86ef860dabfe2e Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 5 Feb 2016 01:57:02 +0100 Subject: [PATCH 1/4] Hide stack traces behind -Ydebug They're not very useful for end users and some tests like tests/neg/selfreq.scala always print these exceptions which makes it harder to read the test logs, Also use Thread.dumpStack() instead of creating an Exception and calling printStackTrace() on it. --- src/dotty/tools/dotc/core/Types.scala | 2 +- .../tools/dotc/core/unpickleScala2/Scala2Unpickler.scala | 4 ++-- src/dotty/tools/dotc/printing/PlainPrinter.scala | 2 +- src/dotty/tools/dotc/reporting/ConsoleReporter.scala | 2 +- src/dotty/tools/dotc/transform/PatternMatcher.scala | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala index e266bab6f482..db5cca90a1cd 100644 --- a/src/dotty/tools/dotc/core/Types.scala +++ b/src/dotty/tools/dotc/core/Types.scala @@ -3386,7 +3386,7 @@ object Types { class MissingType(pre: Type, name: Name)(implicit ctx: Context) extends TypeError( i"""cannot resolve reference to type $pre.$name |the classfile defining the type might be missing from the classpath${otherReason(pre)}""".stripMargin) { - printStackTrace() + if (ctx.debug) printStackTrace() } private def otherReason(pre: Type)(implicit ctx: Context): String = pre match { diff --git a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala index 618e3ceeac43..3b415c9e3922 100644 --- a/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala +++ b/src/dotty/tools/dotc/core/unpickleScala2/Scala2Unpickler.scala @@ -186,7 +186,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas val ex = new BadSignature( sm"""error reading Scala signature of $classRoot from $source: |error occurred at position $readIndex: $msg""") - /*if (debug)*/ original.getOrElse(ex).printStackTrace() // !!! DEBUG + if (ctx.debug) original.getOrElse(ex).printStackTrace() throw ex } @@ -423,7 +423,7 @@ class Scala2Unpickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClas owner.info.decls.checkConsistent() if (slowSearch(name).exists) System.err.println(i"**** slow search found: ${slowSearch(name)}") - new Exception().printStackTrace() + if (ctx.debug) Thread.dumpStack() ctx.newStubSymbol(owner, name, source) } } diff --git a/src/dotty/tools/dotc/printing/PlainPrinter.scala b/src/dotty/tools/dotc/printing/PlainPrinter.scala index 8f9d70d4c4db..6d026dde741b 100644 --- a/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -32,7 +32,7 @@ class PlainPrinter(_ctx: Context) extends Printer { protected def recursionLimitExceeded() = { ctx.warning("Exceeded recursion depth attempting to print.") - (new Throwable).printStackTrace + if (ctx.debug) Thread.dumpStack() } /** If true, tweak output so it is the same before and after pickling */ diff --git a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala index e9b9964c3eb0..8f1fbf797a63 100644 --- a/src/dotty/tools/dotc/reporting/ConsoleReporter.scala +++ b/src/dotty/tools/dotc/reporting/ConsoleReporter.scala @@ -63,7 +63,7 @@ class ConsoleReporter( if (reader != null) { val response = reader.read().asInstanceOf[Char].toLower if (response == 'a' || response == 's') { - (new Exception).printStackTrace() + Thread.dumpStack() if (response == 'a') sys.exit(1) } diff --git a/src/dotty/tools/dotc/transform/PatternMatcher.scala b/src/dotty/tools/dotc/transform/PatternMatcher.scala index 7c8d0a10f41f..4d626c67bd5d 100644 --- a/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -327,7 +327,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans private[TreeMakers] def incorporateOuterRebinding(outerSubst: Rebindings): Unit = { if (currSub ne null) { ctx.debuglog("BUG: incorporateOuterRebinding called more than once for " + ((this, currSub, outerSubst))) - Thread.dumpStack() + if (ctx.debug) Thread.dumpStack() } else currSub = outerSubst >> rebindings } From e177e782ff12c2288d2e5323a0cd1c65447627e0 Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 5 Feb 2016 02:47:08 +0100 Subject: [PATCH 2/4] Do not use println when SingleDenotation#signature fails --- src/dotty/tools/dotc/core/Denotations.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala index 00ad90354553..2af3f463dde6 100644 --- a/src/dotty/tools/dotc/core/Denotations.scala +++ b/src/dotty/tools/dotc/core/Denotations.scala @@ -465,7 +465,7 @@ object Denotations { try info.signature catch { // !!! DEBUG case scala.util.control.NonFatal(ex) => - println(s"cannot take signature of ${info.show}") + ctx.println(s"cannot take signature of ${info.show}") throw ex } case _ => Signature.NotAMethod From 4d988825e41a789383bdb53b5ef4ac68e37ad96d Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Sat, 6 Feb 2016 01:10:55 +0100 Subject: [PATCH 3/4] Do not store context creation trace with -Ydebug This makes the compiler extremely slow. To store the trace, you now need to pass -Ytrace-context-creation --- src/dotty/tools/dotc/config/ScalaSettings.scala | 1 + src/dotty/tools/dotc/core/Contexts.scala | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala index 0c381c077cc9..b925ffa5a2a1 100644 --- a/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -146,6 +146,7 @@ class ScalaSettings extends Settings.SettingGroup { 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.") val Yinvalidate = StringSetting("-Yinvalidate", "classpath-entry", "Invalidate classpath entry before run", "") val noSelfCheck = BooleanSetting("-Yno-self-type-checks", "Suppress check for self-type conformance among inherited members.") + val YtraceContextCreation = BooleanSetting("-Ytrace-context-creation", "Store stack trace of context creations.") val YshowSuppressedErrors = BooleanSetting("-Yshow-suppressed-errors", "Also show follow-on errors and warnings that are normally supressed.") val Yheartbeat = BooleanSetting("-Yheartbeat", "show heartbeat stack trace of compiler operations.") val Yprintpos = BooleanSetting("-Yprintpos", "show tree positions.") diff --git a/src/dotty/tools/dotc/core/Contexts.scala b/src/dotty/tools/dotc/core/Contexts.scala index b205a40f00bd..9ccb03b89d47 100644 --- a/src/dotty/tools/dotc/core/Contexts.scala +++ b/src/dotty/tools/dotc/core/Contexts.scala @@ -255,7 +255,7 @@ object Contexts { private var creationTrace: Array[StackTraceElement] = _ private def setCreationTrace() = - if (this.settings.debug.value) + if (this.settings.YtraceContextCreation.value) creationTrace = (new Throwable).getStackTrace().take(20) /** Print all enclosing context's creation stacktraces */ From b33babc2398e5013820e21568713fdb6c15aa6fa Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 5 Feb 2016 21:21:53 +0100 Subject: [PATCH 4/4] Do not use the plain printer with -Ydebug Instead, a new setting called -Yplain-printer is used for this. After this commit, we can now run all tests with -Ydebug (this was not the case before because using the plain printer breaks -Ytest-pickler) --- src/dotty/tools/dotc/config/ScalaSettings.scala | 1 + src/dotty/tools/dotc/printing/Printers.scala | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dotty/tools/dotc/config/ScalaSettings.scala b/src/dotty/tools/dotc/config/ScalaSettings.scala index b925ffa5a2a1..035b20130fd7 100644 --- a/src/dotty/tools/dotc/config/ScalaSettings.scala +++ b/src/dotty/tools/dotc/config/ScalaSettings.scala @@ -151,6 +151,7 @@ class ScalaSettings extends Settings.SettingGroup { val Yheartbeat = BooleanSetting("-Yheartbeat", "show heartbeat stack trace of compiler operations.") val Yprintpos = BooleanSetting("-Yprintpos", "show tree positions.") val YnoDeepSubtypes = BooleanSetting("-Yno-deep-subtypes", "throw an exception on deep subtyping call stacks.") + val YplainPrinter = BooleanSetting("-Yplain-printer", "Pretty-print using a plain printer.") val YprintSyms = BooleanSetting("-Yprint-syms", "when printing trees print info in symbols instead of corresponding info in trees.") val YtestPickler = BooleanSetting("-Ytest-pickler", "self-test for pickling functionality; should be used with -Ystop-after:pickler") val YcheckReentrant = BooleanSetting("-Ycheck-reentrant", "check that compiled program does not contain vars that can be accessed from a global root.") diff --git a/src/dotty/tools/dotc/printing/Printers.scala b/src/dotty/tools/dotc/printing/Printers.scala index 7107ccb78204..36043a4ff7e2 100644 --- a/src/dotty/tools/dotc/printing/Printers.scala +++ b/src/dotty/tools/dotc/printing/Printers.scala @@ -8,7 +8,7 @@ trait Printers { this: Context => /** A function creating a printer */ def printer = { val pr = printerFn(this) - if (this.debug) pr.plain else pr + if (this.settings.YplainPrinter.value) pr.plain else pr } }