Skip to content

Commit

Permalink
Merge pull request #13984 from dwijnand/log-fixes-and-other
Browse files Browse the repository at this point in the history
Fixes and improvements to trace logging
  • Loading branch information
nicolasstucki authored Nov 24, 2021
2 parents b735803 + 1ff73f0 commit 1f48de1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
7 changes: 0 additions & 7 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1370,13 +1370,6 @@ class Definitions {
else if arity >= 0 then FunctionType(arity)
else NoType

val predefClassNames: Set[Name] =
Set("Predef$", "DeprecatedPredef", "LowPriorityImplicits").map(_.toTypeName.unmangleClassName)

/** Is `cls` the predef module class, or a class inherited by Predef? */
def isPredefClass(cls: Symbol): Boolean =
(cls.owner eq ScalaPackageClass) && predefClassNames.contains(cls.name)

private val JavaImportFns: List[RootRef] = List(
RootRef(() => JavaLangPackageVal.termRef)
)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/printing/Formatting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object Formatting {
case _ => ex.getMessage
s"[cannot display due to $msg, raw string = ${arg.toString}]"
}
case _ => arg.toString
case _ => String.valueOf(arg)
}

private def treatArg(arg: Any, suffix: String)(using Context): (Any, String) = arg match {
Expand Down
12 changes: 11 additions & 1 deletion compiler/src/dotty/tools/dotc/reporting/trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,23 @@ import config.Config
import config.Printers
import core.Mode

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

object force extends TraceSyntax:
inline def isEnabled: true = true
protected val isForced = true

object log extends TraceSyntax:
inline def isEnabled: true = true
protected val isForced = false
end trace

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

0 comments on commit 1f48de1

Please sign in to comment.