Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle suspension due to macro call in arbitrary phases #21651

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => ()