Skip to content

Commit

Permalink
Compute debug messages lazily in safe init
Browse files Browse the repository at this point in the history
I noticed that a significant amount of time was spent pretty-printing
Strings that were never displayed when compiling scalatest in the
community-build, fixed by making the message parameter of traceIndented
and traceOp by-name, just like printer.println itself already is.
  • Loading branch information
smarter committed May 14, 2021
1 parent b9773d6 commit cfa8db7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions compiler/src/dotty/tools/dotc/transform/init/Util.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ import config.Printers.Printer
import annotation.tailrec

object Util {
def traceIndented(msg: String, printer: Printer)(using Context): Unit =
def traceIndented(msg: => String, printer: Printer)(using Context): Unit =
printer.println(s"${ctx.base.indentTab * ctx.base.indent} $msg")

def traceOp(msg: String, printer: Printer)(op: => Unit)(using Context): Unit = {
traceIndented(s"==> ${msg}", printer)
def traceOp(msg: => String, printer: Printer)(op: => Unit)(using Context): Unit = {
lazy val computedMsg = msg
traceIndented(s"==> ${computedMsg}", printer)
op
traceIndented(s"<== ${msg}", printer)
traceIndented(s"<== ${computedMsg}", printer)
}

extension (symbol: Symbol) def hasSource(using Context): Boolean =
Expand All @@ -38,4 +39,4 @@ object Util {
}
loop(cls.info.baseClasses.dropWhile(sym.owner != _))
}
}
}

0 comments on commit cfa8db7

Please sign in to comment.