Skip to content

Commit

Permalink
Merge pull request #6 from scala/backport-lts-3.3-21651
Browse files Browse the repository at this point in the history
Backport "Handle suspension due to macro call in arbitrary phases" to LTS
  • Loading branch information
WojciechMazur authored Dec 6, 2024
2 parents ffd7716 + 236cade commit 7737555
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
17 changes: 11 additions & 6 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -333,15 +333,20 @@ object Phases {
for unit <- units do
given unitCtx: Context = runCtx.fresh.setPhase(this.start).setCompilationUnit(unit).withRootImports
if ctx.run.enterUnit(unit) then
try run
catch case ex: Throwable if !ctx.run.enrichedErrorMessage =>
println(ctx.run.enrichErrorMessage(s"unhandled exception while running $phaseName on $unit"))
throw ex
try
run
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 @@ -31,13 +31,7 @@ class Inlining extends MacroTransform {

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 7737555

Please sign in to comment.