Skip to content

Commit 1ff73f0

Browse files
committed
Fixes and improvements to trace logging
The String.valueOf is because I somehow ended up with a null. Then I found some docs in the history of trace, as well as a mistake in a commit revert: using the non-StoreReporter logctx! I also added a "log" variant to "force", which is also default enabled but doesn't force the output to the standard out, meaning I can bootstrap the compiler without it taking forever to output all the trace output it generates while bootstrapping the compiler, bottlenecking on console IO)... Also, remove some dead code in Definitions.
1 parent 2ef89b2 commit 1ff73f0

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,13 +1370,6 @@ class Definitions {
13701370
else if arity >= 0 then FunctionType(arity)
13711371
else NoType
13721372

1373-
val predefClassNames: Set[Name] =
1374-
Set("Predef$", "DeprecatedPredef", "LowPriorityImplicits").map(_.toTypeName.unmangleClassName)
1375-
1376-
/** Is `cls` the predef module class, or a class inherited by Predef? */
1377-
def isPredefClass(cls: Symbol): Boolean =
1378-
(cls.owner eq ScalaPackageClass) && predefClassNames.contains(cls.name)
1379-
13801373
private val JavaImportFns: List[RootRef] = List(
13811374
RootRef(() => JavaLangPackageVal.termRef)
13821375
)

compiler/src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ object Formatting {
3636
case _ => ex.getMessage
3737
s"[cannot display due to $msg, raw string = ${arg.toString}]"
3838
}
39-
case _ => arg.toString
39+
case _ => String.valueOf(arg)
4040
}
4141

4242
private def treatArg(arg: Any, suffix: String)(using Context): (Any, String) = arg match {

compiler/src/dotty/tools/dotc/reporting/trace.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,23 @@ import config.Config
77
import config.Printers
88
import core.Mode
99

10+
/** Exposes the {{{ trace("question") { op } }}} syntax.
11+
*
12+
* Traced operations will print indented messages if enabled.
13+
* Tracing depends on [[Config.tracingEnabled]] and [[dotty.tools.dotc.config.ScalaSettings.Ylog]].
14+
* Tracing can be forced by replacing [[trace]] with [[trace.force]] or [[trace.log]] (see below).
15+
*/
1016
object trace extends TraceSyntax:
1117
inline def isEnabled = Config.tracingEnabled
1218
protected val isForced = false
1319

1420
object force extends TraceSyntax:
1521
inline def isEnabled: true = true
1622
protected val isForced = true
23+
24+
object log extends TraceSyntax:
25+
inline def isEnabled: true = true
26+
protected val isForced = false
1727
end trace
1828

1929
/** This module is carefully optimized to give zero overhead if Config.tracingEnabled
@@ -73,7 +83,7 @@ trait TraceSyntax:
7383
var logctx = ctx
7484
while logctx.reporter.isInstanceOf[StoreReporter] do logctx = logctx.outer
7585
def margin = ctx.base.indentTab * ctx.base.indent
76-
def doLog(s: String) = if isForced then println(s) else report.log(s)
86+
def doLog(s: String) = if isForced then println(s) else report.log(s)(using logctx)
7787
def finalize(msg: String) =
7888
if !finalized then
7989
ctx.base.indent -= 1

0 commit comments

Comments
 (0)