Skip to content

Commit 7737555

Browse files
Merge pull request #6 from scala/backport-lts-3.3-21651
Backport "Handle suspension due to macro call in arbitrary phases" to LTS
2 parents ffd7716 + 236cade commit 7737555

File tree

5 files changed

+42
-13
lines changed

5 files changed

+42
-13
lines changed

compiler/src/dotty/tools/dotc/core/Phases.scala

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,15 +333,20 @@ object Phases {
333333
for unit <- units do
334334
given unitCtx: Context = runCtx.fresh.setPhase(this.start).setCompilationUnit(unit).withRootImports
335335
if ctx.run.enterUnit(unit) then
336-
try run
337-
catch case ex: Throwable if !ctx.run.enrichedErrorMessage =>
338-
println(ctx.run.enrichErrorMessage(s"unhandled exception while running $phaseName on $unit"))
339-
throw ex
336+
try
337+
run
338+
buf += unitCtx.compilationUnit
339+
catch
340+
case _: CompilationUnit.SuspendException => // this unit will be run again in `Run#compileSuspendedUnits`
341+
case ex: Throwable if !ctx.run.enrichedErrorMessage =>
342+
println(ctx.run.enrichErrorMessage(s"unhandled exception while running $phaseName on $unit"))
343+
throw ex
340344
finally ctx.run.advanceUnit()
341-
buf += unitCtx.compilationUnit
342345
end if
343346
end for
344-
buf.result()
347+
val res = buf.result()
348+
ctx.run.nn.checkSuspendedUnits(res)
349+
res
345350
end runOn
346351

347352
/** Convert a compilation unit's tree to a string; can be overridden */

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,7 @@ class Inlining extends MacroTransform {
3131

3232
override def run(using Context): Unit =
3333
if ctx.compilationUnit.needsInlining || ctx.compilationUnit.hasMacroAnnotations then
34-
try super.run
35-
catch case _: CompilationUnit.SuspendException => ()
36-
37-
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
38-
val newUnits = super.runOn(units).filterNot(_.suspended)
39-
ctx.run.nn.checkSuspendedUnits(newUnits)
40-
newUnits
34+
super.run
4135

4236
override def checkPostCondition(tree: Tree)(using Context): Unit =
4337
tree match {

tests/pos-macros/i18517/Caller.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dummy
2+
3+
trait BG {
4+
val description: { type Structure }
5+
type Structure = description.Structure
6+
}
7+
8+
abstract class Caller extends BG {
9+
type Foo >: this.type <: this.type
10+
11+
transparent inline def generate2() =
12+
${Macro.impl() }
13+
14+
final val description = {
15+
generate2()
16+
}
17+
}

tests/pos-macros/i18517/Macro.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package dummy
2+
3+
import scala.quoted.*
4+
5+
object Macro:
6+
def impl()(using quotes:Quotes) : Expr[Any] =
7+
'{ null }

tests/pos-macros/i18517/User.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package dummy
2+
3+
trait User:
4+
final def bar(cell:Any) : Unit =
5+
(cell: cell.type) match
6+
case c: (Caller & cell.type) => ()

0 commit comments

Comments
 (0)