Skip to content

Commit 8497e46

Browse files
committed
Add CompilationUnit.isSuspendable
1 parent ae68ec7 commit 8497e46

File tree

3 files changed

+13
-4
lines changed

3 files changed

+13
-4
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ class CompilationUnit protected (val source: SourceFile) {
2424

2525
var tpdTree: tpd.Tree = tpd.EmptyTree
2626

27+
/** Is this the compilation unit of a Java file */
2728
def isJava: Boolean = source.file.name.endsWith(".java")
2829

30+
/** Is this the compilation unit of a REPL input */
2931
def isREPL: Boolean = source.file.name.startsWith(str.REPL_SESSION_LINE)
3032

3133
/** The source version for this unit, as determined by a language import */
@@ -50,7 +52,14 @@ class CompilationUnit protected (val source: SourceFile) {
5052

5153
var suspended: Boolean = false
5254

55+
/** Can this compilation unit be suspended */
56+
def isSuspendable: Boolean = !isREPL
57+
58+
/** Suspends the compilation unit by thowing a SuspendException
59+
* and recoring the suspended compilation unit
60+
*/
5361
def suspend()(using Context): Nothing =
62+
assert(isSuspendable)
5463
if !suspended then
5564
if (ctx.settings.XprintSuspension.value)
5665
ctx.echo(i"suspended: $this")

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ object Splicer {
393393
ex.getTargetException match {
394394
case ex: scala.quoted.Reporting.StopQuotedContext =>
395395
throw ex
396-
case MissingClassDefinedInCurrentRun(sym) =>
396+
case MissingClassDefinedInCurrentRun(sym) if ctx.compilationUnit.isSuspendable =>
397397
if (ctx.settings.XprintSuspension.value)
398398
ctx.echo(i"suspension triggered by a dependency on $sym", pos)
399399
ctx.compilationUnit.suspend() // this throws a SuspendException

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,14 +1407,14 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
14071407
assert(level == 0)
14081408
val inlinedFrom = enclosingInlineds.last
14091409
val dependencies = macroDependencies(body)
1410-
val inREPL = ctx.compilationUnit.isREPL
1410+
val suspendable = ctx.compilationUnit.isSuspendable
14111411
if dependencies.nonEmpty && !ctx.reporter.errorsReported then
14121412
for sym <- dependencies do
14131413
if ctx.compilationUnit.source.file == sym.associatedFile then
14141414
ctx.error(em"Cannot call macro $sym defined in the same source file", call.sourcePos)
1415-
if (ctx.settings.XprintSuspension.value && !inREPL)
1415+
if (suspendable && ctx.settings.XprintSuspension.value)
14161416
ctx.echo(i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}", call.sourcePos)
1417-
if !inREPL then
1417+
if suspendable then
14181418
ctx.compilationUnit.suspend() // this throws a SuspendException
14191419

14201420
val evaluatedSplice = inContext(tastyreflect.MacroExpansion.context(inlinedFrom)) {

0 commit comments

Comments
 (0)