Skip to content

Commit dbbc21c

Browse files
Merge pull request #11142 from dotty-staging/track-levels-in-inlining-transform
Track levels in Inlining phase
2 parents 65b17af + 0f1d24d commit dbbc21c

File tree

2 files changed

+37
-4
lines changed

2 files changed

+37
-4
lines changed

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

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,19 @@ class Inlining extends MacroTransform {
3939

4040
override def checkPostCondition(tree: Tree)(using Context): Unit =
4141
tree match {
42-
case tree: RefTree if !Inliner.inInlineMethod && StagingContext.level == 0 =>
43-
assert(!tree.symbol.isInlineMethod)
42+
case PackageDef(pid, _) if tree.symbol.owner == defn.RootClass =>
43+
new TreeTraverser {
44+
def traverse(tree: Tree)(using Context): Unit =
45+
tree match
46+
case _: GenericApply if tree.symbol.isQuote =>
47+
traverseChildren(tree)(using StagingContext.quoteContext)
48+
case _: GenericApply if tree.symbol.isExprSplice =>
49+
traverseChildren(tree)(using StagingContext.spliceContext)
50+
case tree: RefTree if !Inliner.inInlineMethod && StagingContext.level == 0 =>
51+
assert(!tree.symbol.isInlineMethod, tree.show)
52+
case _ =>
53+
traverseChildren(tree)
54+
}.traverse(tree)
4455
case _ =>
4556
}
4657

@@ -57,9 +68,11 @@ class Inlining extends MacroTransform {
5768
val inlined = Inliner.inlineCall(tree1)
5869
if tree1 eq inlined then inlined
5970
else transform(inlined)
60-
case _: TypeApply if tree.symbol.isQuote =>
71+
case _: GenericApply if tree.symbol.isQuote =>
6172
ctx.compilationUnit.needsStaging = true
62-
super.transform(tree)
73+
super.transform(tree)(using StagingContext.quoteContext)
74+
case _: GenericApply if tree.symbol.isExprSplice =>
75+
super.transform(tree)(using StagingContext.spliceContext)
6376
case _ =>
6477
super.transform(tree)
6578

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
import scala.quoted._
3+
import scala.quoted.staging._
4+
5+
object Test {
6+
7+
given Toolbox = Toolbox.make(getClass.getClassLoader)
8+
9+
def main(args: Array[String]): Unit = run {
10+
'{
11+
def m(using Quotes) = '{
12+
errorOnceInlined() // Should not be inlined while `run` is executed. It would be inlined in the next stage.
13+
}
14+
()
15+
}
16+
}
17+
18+
inline def errorOnceInlined() = compiletime.error("Error")
19+
20+
}

0 commit comments

Comments
 (0)