Skip to content

Commit

Permalink
actually print suspension hints, report.echo was swallowed
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Apr 8, 2024
1 parent be0fb7c commit 5aca2da
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 11 deletions.
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/CompilationUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,17 @@ class CompilationUnit protected (val source: SourceFile, val info: CompilationUn
/** Suspends the compilation unit by thowing a SuspendException
* and recording the suspended compilation unit
*/
def suspend()(using Context): Nothing =
def suspend(hint: => String)(using Context): Nothing =
assert(isSuspendable)
// Clear references to symbols that may become stale. No need to call
// `depRecorder.sendToZinc()` since all compilation phases will be rerun
// when this unit is unsuspended.
depRecorder.clear()
if !suspended then
if ctx.settings.XprintSuspension.value then
report.echo(i"suspended: $this")
suspended = true
ctx.run.nn.suspendedUnits += this
if ctx.settings.XprintSuspension.value then
ctx.run.nn.suspendedHints += (this -> hint)
if ctx.phase == Phases.inliningPhase then
suspendedAtInliningPhase = true
throw CompilationUnit.SuspendException()
Expand All @@ -120,7 +120,7 @@ class CompilationUnit protected (val source: SourceFile, val info: CompilationUn

override def isJava: Boolean = false

override def suspend()(using Context): Nothing =
override def suspend(hint: => String)(using Context): Nothing =
throw CompilationUnit.SuspendException()

override def assignmentSpans(using Context): Map[Int, List[Span]] = Map.empty
Expand Down
3 changes: 3 additions & 0 deletions compiler/src/dotty/tools/dotc/Driver.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ class Driver {
if !ctx.reporter.errorsReported && run.suspendedUnits.nonEmpty then
val suspendedUnits = run.suspendedUnits.toList
if (ctx.settings.XprintSuspension.value)
val suspendedHints = run.suspendedHints.toList
report.echo(i"compiling suspended $suspendedUnits%, %")
for (unit, hint) <- suspendedHints do
report.echo(s" $unit: $hint")
val run1 = compiler.newRun
run1.compileSuspendedUnits(suspendedUnits)
finish(compiler, run1)(using MacroClassLoader.init(ctx.fresh))
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/Run.scala
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class Run(comp: Compiler, ictx: Context) extends ImplicitRunInfo with Constraint
myUnits = us

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

def checkSuspendedUnits(newUnits: List[CompilationUnit])(using Context): Unit =
if newUnits.isEmpty && suspendedUnits.nonEmpty && !ctx.reporter.errorsReported then
Expand Down
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1038,22 +1038,25 @@ class Inliner(val call: tpd.Tree)(using Context):
val inlinedFrom = enclosingInlineds.last
val dependencies = macroDependencies(body)(using spliceContext)
val suspendable = ctx.compilationUnit.isSuspendable
val printSuspensions = ctx.settings.XprintSuspension.value
if dependencies.nonEmpty && !ctx.reporter.errorsReported then
val hints: mutable.ListBuffer[String] | Null =
if printSuspensions then mutable.ListBuffer.empty[String] else null
for sym <- dependencies do
if ctx.compilationUnit.source.file == sym.associatedFile then
report.error(em"Cannot call macro $sym defined in the same source file", call.srcPos)
else if ctx.settings.YnoSuspendedUnits.value then
val addendum = ", suspension prevented by -Yno-suspended-units"
report.error(em"Cannot call macro $sym defined in the same compilation run$addendum", call.srcPos)
if (suspendable && ctx.settings.XprintSuspension.value)
report.echo(i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}", call.srcPos)
if suspendable && printSuspensions then
hints.nn += i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}"
if suspendable then
if ctx.settings.YnoSuspendedUnits.value then
return ref(defn.Predef_undefined)
.withType(ErrorType(em"could not expand macro, suspended units are disabled by -Yno-suspended-units"))
.withSpan(splicePos.span)
else
ctx.compilationUnit.suspend() // this throws a SuspendException
ctx.compilationUnit.suspend(hints.nn.toList.mkString(", ")) // this throws a SuspendException

val evaluatedSplice = inContext(quoted.MacroExpansion.context(inlinedFrom)) {
Splicer.splice(body, splicePos, inlinedFrom.srcPos, MacroClassLoader.fromContext)
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/quoted/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,4 @@ object Interpreter:
if ctx.settings.YnoSuspendedUnits.value then
throw StopInterpretation(em"suspension triggered by a dependency on missing $sym not allowed with -Yno-suspended-units", pos)
else
if ctx.settings.XprintSuspension.value then
report.echo(i"suspension triggered by a dependency on missing $sym", pos)
ctx.compilationUnit.suspend() // this throws a SuspendException
ctx.compilationUnit.suspend(i"suspension triggered by a dependency on missing $sym") // this throws a SuspendException
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1667,7 +1667,7 @@ class Namer { typer: Typer =>

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

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

0 comments on commit 5aca2da

Please sign in to comment.