Skip to content

Commit be0fb7c

Browse files
committed
better ergnomics for -Yno-suspended-units
1 parent 2e956f8 commit be0fb7c

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

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

+6-9
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,12 @@ class CompilationUnit protected (val source: SourceFile, val info: CompilationUn
9797
// when this unit is unsuspended.
9898
depRecorder.clear()
9999
if !suspended then
100-
if ctx.settings.YnoSuspendedUnits.value then
101-
report.error(i"Compilation unit suspended $this (-Yno-suspended-units is set)")
102-
else
103-
if (ctx.settings.XprintSuspension.value)
104-
report.echo(i"suspended: $this")
105-
suspended = true
106-
ctx.run.nn.suspendedUnits += this
107-
if ctx.phase == Phases.inliningPhase then
108-
suspendedAtInliningPhase = true
100+
if ctx.settings.XprintSuspension.value then
101+
report.echo(i"suspended: $this")
102+
suspended = true
103+
ctx.run.nn.suspendedUnits += this
104+
if ctx.phase == Phases.inliningPhase then
105+
suspendedAtInliningPhase = true
109106
throw CompilationUnit.SuspendException()
110107

111108
private var myAssignmentSpans: Map[Int, List[Span]] | Null = null

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

+7-2
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ class Inliner(val call: tpd.Tree)(using Context):
10331033
}
10341034
}
10351035

1036-
private def expandMacro(body: Tree, splicePos: SrcPos)(using Context) = {
1036+
private def expandMacro(body: Tree, splicePos: SrcPos)(using Context): Tree = {
10371037
assert(level == 0)
10381038
val inlinedFrom = enclosingInlineds.last
10391039
val dependencies = macroDependencies(body)(using spliceContext)
@@ -1048,7 +1048,12 @@ class Inliner(val call: tpd.Tree)(using Context):
10481048
if (suspendable && ctx.settings.XprintSuspension.value)
10491049
report.echo(i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}", call.srcPos)
10501050
if suspendable then
1051-
ctx.compilationUnit.suspend() // this throws a SuspendException
1051+
if ctx.settings.YnoSuspendedUnits.value then
1052+
return ref(defn.Predef_undefined)
1053+
.withType(ErrorType(em"could not expand macro, suspended units are disabled by -Yno-suspended-units"))
1054+
.withSpan(splicePos.span)
1055+
else
1056+
ctx.compilationUnit.suspend() // this throws a SuspendException
10521057

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

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ object Interpreter:
368368
}
369369

370370
def suspendOnMissing(sym: Symbol, pos: SrcPos)(using Context): Nothing =
371-
if ctx.settings.XprintSuspension.value then
372-
report.echo(i"suspension triggered by a dependency on $sym", pos)
373-
ctx.compilationUnit.suspend() // this throws a SuspendException
371+
if ctx.settings.YnoSuspendedUnits.value then
372+
throw StopInterpretation(em"suspension triggered by a dependency on missing $sym not allowed with -Yno-suspended-units", pos)
373+
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

0 commit comments

Comments
 (0)