Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes and improvements to trace logging #13984

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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