From cfa8db7d98d56acc91f835e150a7cca74e992adf Mon Sep 17 00:00:00 2001 From: Guillaume Martres Date: Fri, 14 May 2021 21:50:58 +0200 Subject: [PATCH] Compute debug messages lazily in safe init 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. --- .../src/dotty/tools/dotc/transform/init/Util.scala | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/init/Util.scala b/compiler/src/dotty/tools/dotc/transform/init/Util.scala index 41d77a8fe608..3673b75ec42c 100644 --- a/compiler/src/dotty/tools/dotc/transform/init/Util.scala +++ b/compiler/src/dotty/tools/dotc/transform/init/Util.scala @@ -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 = @@ -38,4 +39,4 @@ object Util { } loop(cls.info.baseClasses.dropWhile(sym.owner != _)) } -} \ No newline at end of file +}