Skip to content

Use inline and inline-if to ensure constant folding happened #7202

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

Merged
merged 1 commit into from
Sep 12, 2019
Merged
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
27 changes: 10 additions & 17 deletions compiler/src/dotty/tools/dotc/reporting/trace.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,47 +25,40 @@ object trace extends TraceSyntax {
abstract class TraceSyntax {
val isForced: Boolean

@forceInline
def onDebug[TD](question: => String)(op: => TD)(implicit ctx: Context): TD =
inline def onDebug[TD](question: => String)(op: => TD)(implicit ctx: Context): TD =
conditionally(ctx.settings.YdebugTrace.value, question, false)(op)

@forceInline
def conditionally[TC](cond: Boolean, question: => String, show: Boolean)(op: => TC)(implicit ctx: Context): TC =
if (isForced || Config.tracingEnabled) {
inline def conditionally[TC](cond: Boolean, question: => String, show: Boolean)(op: => TC)(implicit ctx: Context): TC =
inline if (isForced || Config.tracingEnabled) {
def op1 = op
if (cond) apply[TC](question, Printers.default, show)(op1)
else op1
}
else op

@forceInline
def apply[T](question: => String, printer: Printers.Printer, showOp: Any => String)(op: => T)(implicit ctx: Context): T =
if (isForced || Config.tracingEnabled) {
inline def apply[T](question: => String, printer: Printers.Printer, showOp: Any => String)(op: => T)(implicit ctx: Context): T =
inline if (isForced || Config.tracingEnabled) {
def op1 = op
if (!isForced && printer.eq(config.Printers.noPrinter)) op1
else doTrace[T](question, printer, showOp)(op1)
}
else op

@forceInline
def apply[T](question: => String, printer: Printers.Printer, show: Boolean)(op: => T)(implicit ctx: Context): T =
if (isForced || Config.tracingEnabled) {
inline def apply[T](question: => String, printer: Printers.Printer, show: Boolean)(op: => T)(implicit ctx: Context): T =
inline if (isForced || Config.tracingEnabled) {
def op1 = op
if (!isForced && printer.eq(config.Printers.noPrinter)) op1
else doTrace[T](question, printer, if (show) showShowable(_) else alwaysToString)(op1)
}
else op

@forceInline
def apply[T](question: => String, printer: Printers.Printer)(op: => T)(implicit ctx: Context): T =
inline def apply[T](question: => String, printer: Printers.Printer)(op: => T)(implicit ctx: Context): T =
apply[T](question, printer, false)(op)

@forceInline
def apply[T](question: => String, show: Boolean)(op: => T)(implicit ctx: Context): T =
inline def apply[T](question: => String, show: Boolean)(op: => T)(implicit ctx: Context): T =
apply[T](question, Printers.default, show)(op)

@forceInline
def apply[T](question: => String)(op: => T)(implicit ctx: Context): T =
inline def apply[T](question: => String)(op: => T)(implicit ctx: Context): T =
apply[T](question, Printers.default, false)(op)

private def showShowable(x: Any)(implicit ctx: Context) = x match {
Expand Down