Skip to content

Track levels in Inlining phase #11142

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

Merged
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
21 changes: 17 additions & 4 deletions compiler/src/dotty/tools/dotc/transform/Inlining.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,19 @@ class Inlining extends MacroTransform {

override def checkPostCondition(tree: Tree)(using Context): Unit =
tree match {
case tree: RefTree if !Inliner.inInlineMethod && StagingContext.level == 0 =>
assert(!tree.symbol.isInlineMethod)
case PackageDef(pid, _) if tree.symbol.owner == defn.RootClass =>
new TreeTraverser {
def traverse(tree: Tree)(using Context): Unit =
tree match
case _: GenericApply if tree.symbol.isQuote =>
traverseChildren(tree)(using StagingContext.quoteContext)
case _: GenericApply if tree.symbol.isExprSplice =>
traverseChildren(tree)(using StagingContext.spliceContext)
case tree: RefTree if !Inliner.inInlineMethod && StagingContext.level == 0 =>
assert(!tree.symbol.isInlineMethod, tree.show)
case _ =>
traverseChildren(tree)
}.traverse(tree)
case _ =>
}

Expand All @@ -57,9 +68,11 @@ class Inlining extends MacroTransform {
val inlined = Inliner.inlineCall(tree1)
if tree1 eq inlined then inlined
else transform(inlined)
case _: TypeApply if tree.symbol.isQuote =>
case _: GenericApply if tree.symbol.isQuote =>
ctx.compilationUnit.needsStaging = true
super.transform(tree)
super.transform(tree)(using StagingContext.quoteContext)
case _: GenericApply if tree.symbol.isExprSplice =>
super.transform(tree)(using StagingContext.spliceContext)
case _ =>
super.transform(tree)

Expand Down
20 changes: 20 additions & 0 deletions tests/run-staging/inline-at-level-2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

import scala.quoted._
import scala.quoted.staging._

object Test {

given Toolbox = Toolbox.make(getClass.getClassLoader)

def main(args: Array[String]): Unit = run {
'{
def m(using Quotes) = '{
errorOnceInlined() // Should not be inlined while `run` is executed. It would be inlined in the next stage.
}
()
}
}

inline def errorOnceInlined() = compiletime.error("Error")

}