Skip to content

Commit

Permalink
better ergnomics for -Yno-suspended-units
Browse files Browse the repository at this point in the history
  • Loading branch information
bishabosha committed Apr 8, 2024
1 parent 2e956f8 commit be0fb7c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
15 changes: 6 additions & 9 deletions compiler/src/dotty/tools/dotc/CompilationUnit.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,12 @@ class CompilationUnit protected (val source: SourceFile, val info: CompilationUn
// when this unit is unsuspended.
depRecorder.clear()
if !suspended then
if ctx.settings.YnoSuspendedUnits.value then
report.error(i"Compilation unit suspended $this (-Yno-suspended-units is set)")
else
if (ctx.settings.XprintSuspension.value)
report.echo(i"suspended: $this")
suspended = true
ctx.run.nn.suspendedUnits += this
if ctx.phase == Phases.inliningPhase then
suspendedAtInliningPhase = true
if ctx.settings.XprintSuspension.value then
report.echo(i"suspended: $this")
suspended = true
ctx.run.nn.suspendedUnits += this
if ctx.phase == Phases.inliningPhase then
suspendedAtInliningPhase = true
throw CompilationUnit.SuspendException()

private var myAssignmentSpans: Map[Int, List[Span]] | Null = null
Expand Down
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ class Inliner(val call: tpd.Tree)(using Context):
}
}

private def expandMacro(body: Tree, splicePos: SrcPos)(using Context) = {
private def expandMacro(body: Tree, splicePos: SrcPos)(using Context): Tree = {
assert(level == 0)
val inlinedFrom = enclosingInlineds.last
val dependencies = macroDependencies(body)(using spliceContext)
Expand All @@ -1048,7 +1048,12 @@ class Inliner(val call: tpd.Tree)(using Context):
if (suspendable && ctx.settings.XprintSuspension.value)
report.echo(i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}", call.srcPos)
if suspendable then
ctx.compilationUnit.suspend() // this throws a SuspendException
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

val evaluatedSplice = inContext(quoted.MacroExpansion.context(inlinedFrom)) {
Splicer.splice(body, splicePos, inlinedFrom.srcPos, MacroClassLoader.fromContext)
Expand Down
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/quoted/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,9 @@ object Interpreter:
}

def suspendOnMissing(sym: Symbol, pos: SrcPos)(using Context): Nothing =
if ctx.settings.XprintSuspension.value then
report.echo(i"suspension triggered by a dependency on $sym", pos)
ctx.compilationUnit.suspend() // this throws a SuspendException
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

0 comments on commit be0fb7c

Please sign in to comment.