Skip to content

Commit 5aca2da

Browse files
committed
actually print suspension hints, report.echo was swallowed
1 parent be0fb7c commit 5aca2da

File tree

6 files changed

+16
-11
lines changed

6 files changed

+16
-11
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,17 +90,17 @@ class CompilationUnit protected (val source: SourceFile, val info: CompilationUn
9090
/** Suspends the compilation unit by thowing a SuspendException
9191
* and recording the suspended compilation unit
9292
*/
93-
def suspend()(using Context): Nothing =
93+
def suspend(hint: => String)(using Context): Nothing =
9494
assert(isSuspendable)
9595
// Clear references to symbols that may become stale. No need to call
9696
// `depRecorder.sendToZinc()` since all compilation phases will be rerun
9797
// when this unit is unsuspended.
9898
depRecorder.clear()
9999
if !suspended then
100-
if ctx.settings.XprintSuspension.value then
101-
report.echo(i"suspended: $this")
102100
suspended = true
103101
ctx.run.nn.suspendedUnits += this
102+
if ctx.settings.XprintSuspension.value then
103+
ctx.run.nn.suspendedHints += (this -> hint)
104104
if ctx.phase == Phases.inliningPhase then
105105
suspendedAtInliningPhase = true
106106
throw CompilationUnit.SuspendException()
@@ -120,7 +120,7 @@ class CompilationUnit protected (val source: SourceFile, val info: CompilationUn
120120

121121
override def isJava: Boolean = false
122122

123-
override def suspend()(using Context): Nothing =
123+
override def suspend(hint: => String)(using Context): Nothing =
124124
throw CompilationUnit.SuspendException()
125125

126126
override def assignmentSpans(using Context): Map[Int, List[Span]] = Map.empty

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

+3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ class Driver {
5252
if !ctx.reporter.errorsReported && run.suspendedUnits.nonEmpty then
5353
val suspendedUnits = run.suspendedUnits.toList
5454
if (ctx.settings.XprintSuspension.value)
55+
val suspendedHints = run.suspendedHints.toList
5556
report.echo(i"compiling suspended $suspendedUnits%, %")
57+
for (unit, hint) <- suspendedHints do
58+
report.echo(s" $unit: $hint")
5659
val run1 = compiler.newRun
5760
run1.compileSuspendedUnits(suspendedUnits)
5861
finish(compiler, run1)(using MacroClassLoader.init(ctx.fresh))

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

+1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
130130
myUnits = us
131131

132132
var suspendedUnits: mutable.ListBuffer[CompilationUnit] = mutable.ListBuffer()
133+
var suspendedHints: mutable.Map[CompilationUnit, String] = mutable.HashMap()
133134

134135
def checkSuspendedUnits(newUnits: List[CompilationUnit])(using Context): Unit =
135136
if newUnits.isEmpty && suspendedUnits.nonEmpty && !ctx.reporter.errorsReported then

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -1038,22 +1038,25 @@ class Inliner(val call: tpd.Tree)(using Context):
10381038
val inlinedFrom = enclosingInlineds.last
10391039
val dependencies = macroDependencies(body)(using spliceContext)
10401040
val suspendable = ctx.compilationUnit.isSuspendable
1041+
val printSuspensions = ctx.settings.XprintSuspension.value
10411042
if dependencies.nonEmpty && !ctx.reporter.errorsReported then
1043+
val hints: mutable.ListBuffer[String] | Null =
1044+
if printSuspensions then mutable.ListBuffer.empty[String] else null
10421045
for sym <- dependencies do
10431046
if ctx.compilationUnit.source.file == sym.associatedFile then
10441047
report.error(em"Cannot call macro $sym defined in the same source file", call.srcPos)
10451048
else if ctx.settings.YnoSuspendedUnits.value then
10461049
val addendum = ", suspension prevented by -Yno-suspended-units"
10471050
report.error(em"Cannot call macro $sym defined in the same compilation run$addendum", call.srcPos)
1048-
if (suspendable && ctx.settings.XprintSuspension.value)
1049-
report.echo(i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}", call.srcPos)
1051+
if suspendable && printSuspensions then
1052+
hints.nn += i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}"
10501053
if suspendable then
10511054
if ctx.settings.YnoSuspendedUnits.value then
10521055
return ref(defn.Predef_undefined)
10531056
.withType(ErrorType(em"could not expand macro, suspended units are disabled by -Yno-suspended-units"))
10541057
.withSpan(splicePos.span)
10551058
else
1056-
ctx.compilationUnit.suspend() // this throws a SuspendException
1059+
ctx.compilationUnit.suspend(hints.nn.toList.mkString(", ")) // this throws a SuspendException
10571060

10581061
val evaluatedSplice = inContext(quoted.MacroExpansion.context(inlinedFrom)) {
10591062
Splicer.splice(body, splicePos, inlinedFrom.srcPos, MacroClassLoader.fromContext)

compiler/src/dotty/tools/dotc/quoted/Interpreter.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,4 @@ object Interpreter:
371371
if ctx.settings.YnoSuspendedUnits.value then
372372
throw StopInterpretation(em"suspension triggered by a dependency on missing $sym not allowed with -Yno-suspended-units", pos)
373373
else
374-
if ctx.settings.XprintSuspension.value then
375-
report.echo(i"suspension triggered by a dependency on missing $sym", pos)
376-
ctx.compilationUnit.suspend() // this throws a SuspendException
374+
ctx.compilationUnit.suspend(i"suspension triggered by a dependency on missing $sym") // this throws a SuspendException

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ class Namer { typer: Typer =>
16671667

16681668
final override def complete(denot: SymDenotation)(using Context): Unit =
16691669
denot.resetFlag(Touched) // allow one more completion
1670-
ctx.compilationUnit.suspend()
1670+
ctx.compilationUnit.suspend(i"reset $denot")
16711671
}
16721672

16731673
/** Typecheck `tree` during completion using `typed`, and remember result in TypedAhead map */

0 commit comments

Comments
 (0)