Skip to content

Commit

Permalink
Handle suspension due to macro call in late phases
Browse files Browse the repository at this point in the history
In the added test case this happens in PostTyper, but I've seen it happen in
Mixin too.

Fixes #18517.
  • Loading branch information
smarter committed Sep 26, 2024
1 parent 9ec99c7 commit 1373192
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
14 changes: 9 additions & 5 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -378,14 +378,18 @@ object Phases {
()
else
run
catch case ex: Throwable if !ctx.run.enrichedErrorMessage =>
println(ctx.run.enrichErrorMessage(s"unhandled exception while running $phaseName on $unit"))
throw ex
buf += unitCtx.compilationUnit
catch
case _: CompilationUnit.SuspendException => // this unit will be run again in `Run#compileSuspendedUnits`
case ex: Throwable if !ctx.run.enrichedErrorMessage =>
println(ctx.run.enrichErrorMessage(s"unhandled exception while running $phaseName on $unit"))
throw ex
finally ctx.run.advanceUnit()
buf += unitCtx.compilationUnit
end if
end for
buf.result()
val res = buf.result()
ctx.run.nn.checkSuspendedUnits(res)
res
end runOn

/** Convert a compilation unit's tree to a string; can be overridden */
Expand Down
8 changes: 1 addition & 7 deletions compiler/src/dotty/tools/dotc/transform/Inlining.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,7 @@ class Inlining extends MacroTransform, IdentityDenotTransformer {

override def run(using Context): Unit =
if ctx.compilationUnit.needsInlining || ctx.compilationUnit.hasMacroAnnotations then
try super.run
catch case _: CompilationUnit.SuspendException => ()

override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
val newUnits = super.runOn(units).filterNot(_.suspended)
ctx.run.nn.checkSuspendedUnits(newUnits)
newUnits
super.run

override def checkPostCondition(tree: Tree)(using Context): Unit =
tree match {
Expand Down
17 changes: 17 additions & 0 deletions tests/pos-macros/i18517/Caller.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package dummy

trait BG {
val description: { type Structure }
type Structure = description.Structure
}

abstract class Caller extends BG {
type Foo >: this.type <: this.type

transparent inline def generate2() =
${Macro.impl() }

final val description = {
generate2()
}
}
7 changes: 7 additions & 0 deletions tests/pos-macros/i18517/Macro.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dummy

import scala.quoted.*

object Macro:
def impl()(using quotes:Quotes) : Expr[Any] =
'{ null }
6 changes: 6 additions & 0 deletions tests/pos-macros/i18517/User.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package dummy

trait User:
final def bar(cell:Any) : Unit =
(cell: cell.type) match
case c: (Caller & cell.type) => ()

0 comments on commit 1373192

Please sign in to comment.