Skip to content

Commit 58d7f5e

Browse files
oderskyliufengyun
authored andcommitted
Add -Xprint-suspension option to print info about suspensions
1 parent 38784ab commit 58d7f5e

File tree

5 files changed

+15
-6
lines changed

5 files changed

+15
-6
lines changed

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ class CompilationUnit protected (val source: SourceFile) {
3737

3838
def suspend()(given ctx: Context): Nothing =
3939
if !suspended then
40-
println(i"suspended: $this")
40+
if (ctx.settings.XprintSuspension.value)
41+
ctx.echo(i"suspended: $this")
4142
suspended = true
4243
ctx.run.suspendedUnits += this
4344
throw CompilationUnit.SuspendException()

compiler/src/dotty/tools/dotc/Driver.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import core.{MacroClassLoader, Mode, TypeError}
1010
import dotty.tools.dotc.ast.Positioned
1111
import dotty.tools.io.File
1212
import reporting._
13+
import core.Decorators._
1314

1415
import scala.util.control.NonFatal
1516
import fromtasty.{TASTYCompiler, TastyFileUtil}
@@ -37,9 +38,12 @@ class Driver {
3738
def finish(run: Run): Unit =
3839
run.printSummary()
3940
if !ctx.reporter.errorsReported && run.suspendedUnits.nonEmpty then
41+
val suspendedUnits = run.suspendedUnits.toList
42+
if (ctx.settings.XprintSuspension.value)
43+
ctx.echo(i"compiling suspended $suspendedUnits%, %")
4044
val run1 = compiler.newRun
41-
for unit <- run.suspendedUnits do unit.suspended = false
42-
run1.compileUnits(run.suspendedUnits.toList)
45+
for unit <- suspendedUnits do unit.suspended = false
46+
run1.compileUnits(suspendedUnits)
4347
finish(run1)
4448

4549
finish(run)

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class ScalaSettings extends Settings.SettingGroup {
7777
val XprintDiff: Setting[Boolean] = BooleanSetting("-Xprint-diff", "Print changed parts of the tree since last print.")
7878
val XprintDiffDel: Setting[Boolean] = BooleanSetting("-Xprint-diff-del", "Print changed parts of the tree since last print including deleted parts.")
7979
val XprintInline: Setting[Boolean] = BooleanSetting("-Xprint-inline", "Show where inlined code comes from")
80+
val XprintSuspension: Setting[Boolean] = BooleanSetting("-Xprint-suspension", "Show when code is suspended until macros are compiled")
8081
val Xprompt: Setting[Boolean] = BooleanSetting("-Xprompt", "Display a prompt after each error (debugging option).")
8182
val XnoValueClasses: Setting[Boolean] = BooleanSetting("-Xno-value-classes", "Do not use value classes. Helps debugging.")
8283
val XreplLineWidth: Setting[Int] = IntSetting("-Xrepl-line-width", "Maximal number of columns per line for REPL output", 390)
@@ -200,7 +201,7 @@ class ScalaSettings extends Settings.SettingGroup {
200201
"The source repository of your project",
201202
""
202203
)
203-
204+
204205
val projectLogo: Setting[String] = StringSetting(
205206
"-project-logo",
206207
"project logo filename",

compiler/src/dotty/tools/dotc/typer/FrontEnd.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,9 @@ class FrontEnd extends Phase {
125125
ctx.error(em"""Cyclic macro dependencies $where
126126
|Compilation stopped since no further progress can be made.
127127
|
128-
|To fix this, place macros in one set of files and their callers in another.""")
128+
|To fix this, place macros in one set of files and their callers in another.
129+
|
130+
|Compiling with -XprintSuspension gives more information.""")
129131
newUnits
130132
}
131133

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1243,7 +1243,8 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
12431243
for sym <- dependencies do
12441244
if ctx.compilationUnit.source.file == sym.associatedFile then
12451245
ctx.error(em"Cannot call macro $sym defined in the same source file", body.sourcePos)
1246-
println(i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}")
1246+
if (ctx.settings.XprintSuspension.value)
1247+
ctx.echo(i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}", body.sourcePos)
12471248
ctx.compilationUnit.suspend() // this throws a SuspendException
12481249

12491250
val evaluatedSplice = Splicer.splice(body, inlinedFrom.sourcePos, MacroClassLoader.fromContext)(ctx1)

0 commit comments

Comments
 (0)