diff options
author | Martin Odersky <odersky@gmail.com> | 2016-09-05 18:06:36 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-10-02 16:11:21 +0200 |
commit | 5a345e7100450d39edf0034cc5b83bdb9a851cfa (patch) | |
tree | 086057223057ac267dee771e89a189c92cc150fd /src | |
parent | 5396a6b3a4cb152d93dbb4947af688fdad1e2508 (diff) | |
download | dotty-5a345e7100450d39edf0034cc5b83bdb9a851cfa.tar.gz dotty-5a345e7100450d39edf0034cc5b83bdb9a851cfa.tar.bz2 dotty-5a345e7100450d39edf0034cc5b83bdb9a851cfa.zip |
Inline key operations in dotty
Inlined operations are: Stats.track and all variants
of Reporter.traceIndented.
Diffstat (limited to 'src')
-rw-r--r-- | src/dotty/tools/dotc/core/SymbolLoaders.scala | 2 | ||||
-rw-r--r-- | src/dotty/tools/dotc/reporting/Reporter.scala | 28 | ||||
-rw-r--r-- | src/dotty/tools/dotc/util/Stats.scala | 17 |
3 files changed, 29 insertions, 18 deletions
diff --git a/src/dotty/tools/dotc/core/SymbolLoaders.scala b/src/dotty/tools/dotc/core/SymbolLoaders.scala index 3f801bda5..4ae28c10b 100644 --- a/src/dotty/tools/dotc/core/SymbolLoaders.scala +++ b/src/dotty/tools/dotc/core/SymbolLoaders.scala @@ -198,7 +198,7 @@ abstract class SymbolLoader extends LazyType { try { val start = currentTime if (ctx.settings.debugTrace.value) - ctx.traceIndented(s">>>> loading ${root.debugString}", _ => s"<<<< loaded ${root.debugString}") { + ctx.doTraceIndented(s">>>> loading ${root.debugString}", _ => s"<<<< loaded ${root.debugString}") { doComplete(root) } else diff --git a/src/dotty/tools/dotc/reporting/Reporter.scala b/src/dotty/tools/dotc/reporting/Reporter.scala index b3d173a42..68ed972e1 100644 --- a/src/dotty/tools/dotc/reporting/Reporter.scala +++ b/src/dotty/tools/dotc/reporting/Reporter.scala @@ -140,28 +140,32 @@ trait Reporting { this: Context => def debugwarn(msg: => String, pos: SourcePosition = NoSourcePosition): Unit = if (this.settings.debug.value) warning(msg, pos) - def debugTraceIndented[T](question: => String, printer: Printers.Printer = Printers.default, show: Boolean = false)(op: => T): T = + @dotty.annotation.inline + def debugTraceIndented[TD](question: => String, printer: Printers.Printer = Printers.default, show: Boolean = false)(op: => TD): TD = conditionalTraceIndented(this.settings.debugTrace.value, question, printer, show)(op) - def conditionalTraceIndented[T](cond: Boolean, question: => String, printer: Printers.Printer = Printers.default, show: Boolean = false)(op: => T): T = - if (cond) traceIndented(question, printer, show)(op) + @dotty.annotation.inline + def conditionalTraceIndented[TC](cond: Boolean, question: => String, printer: Printers.Printer = Printers.default, show: Boolean = false)(op: => TC): TC = + if (cond) traceIndented[TC](question, printer, show)(op) else op - def traceIndented[T](question: => String, printer: Printers.Printer = Printers.default, show: Boolean = false)(op: => T): T = { + @dotty.annotation.inline + def traceIndented[T](question: => String, printer: Printers.Printer = Printers.default, show: Boolean = false)(op: => T): T = + if (printer eq config.Printers.noPrinter) op + else doTraceIndented[T](question, printer, show)(op) + + def doTraceIndented[T](question: => String, printer: Printers.Printer = Printers.default, show: Boolean = false)(op: => T): T = { def resStr(res: Any): String = res match { case res: printing.Showable if show => res.show case _ => String.valueOf(res) } - if (printer eq config.Printers.noPrinter) op - else { - // Avoid evaluating question multiple time, since each evaluation - // may cause some extra logging output. - lazy val q: String = question - traceIndented[T](s"==> $q?", (res: Any) => s"<== $q = ${resStr(res)}")(op) - } + // Avoid evaluating question multiple time, since each evaluation + // may cause some extra logging output. + lazy val q: String = question + doTraceIndented[T](s"==> $q?", (res: Any) => s"<== $q = ${resStr(res)}")(op) } - def traceIndented[T](leading: => String, trailing: Any => String)(op: => T): T = + def doTraceIndented[T](leading: => String, trailing: Any => String)(op: => T): T = if (ctx.mode.is(Mode.Printing)) op else { var finalized = false diff --git a/src/dotty/tools/dotc/util/Stats.scala b/src/dotty/tools/dotc/util/Stats.scala index fdd3602c9..f5e711348 100644 --- a/src/dotty/tools/dotc/util/Stats.scala +++ b/src/dotty/tools/dotc/util/Stats.scala @@ -7,27 +7,34 @@ import collection.mutable @sharable object Stats { - final val enabled = true + final val enabled = false /** The period in ms in which stack snapshots are displayed */ final val HeartBeatPeriod = 250 + var monitored = false + @volatile private var stack: List[String] = Nil val hits = new mutable.HashMap[String, Int] { override def default(key: String): Int = 0 } - def record(fn: String, n: Int = 1) = { + @dotty.annotation.inline + def record(fn: String, n: Int = 1) = + if (enabled) doRecord(fn, n) + + def doRecord(fn: String, n: Int) = if (monitored) { val name = if (fn.startsWith("member-")) "member" else fn hits(name) += n } - } - - var monitored = false + @dotty.annotation.inline def track[T](fn: String)(op: => T) = + if (enabled) doTrack(fn)(op) else op + + def doTrack[T](fn: String)(op: => T) = if (monitored) { stack = fn :: stack record(fn) |