Skip to content

Commit 4a7e576

Browse files
committed
Avoid double traversal of tree
1 parent e483d23 commit 4a7e576

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ class Inlining extends MacroTransform {
8989
case _ if Inliner.isInlineable(tree) && !tree.tpe.widen.isInstanceOf[MethodOrPoly] && StagingContext.level == 0 =>
9090
val tree1 = super.transform(tree)
9191
if tree1.tpe.isError then tree1
92-
else
93-
val inlined = Inliner.inlineCall(tree1)
94-
if tree1 eq inlined then inlined
95-
else transform(inlined) // TODO can this be removed if `needsStaging` is set in `Inliner`?
92+
else Inliner.inlineCall(tree1)
9693
case _: GenericApply if tree.symbol.isQuote =>
9794
ctx.compilationUnit.needsStaging = true
9895
super.transform(tree)(using StagingContext.quoteContext)

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
12841284
super.typedValDef(vdef1, sym)
12851285

12861286
override def typedApply(tree: untpd.Apply, pt: Type)(using Context): Tree =
1287-
constToLiteral(betaReduce(super.typedApply(tree, pt))) match {
1287+
val res = constToLiteral(betaReduce(super.typedApply(tree, pt))) match {
12881288
case res: Apply if res.symbol == defn.QuotedRuntime_exprSplice
12891289
&& level == 0
12901290
&& !suppressInline =>
@@ -1293,6 +1293,12 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(using Context) {
12931293
case res =>
12941294
inlineIfIsNestedInlineCall(res)
12951295
}
1296+
if res.symbol == defn.QuotedRuntime_exprQuote then
1297+
ctx.compilationUnit.needsStaging = true
1298+
res
1299+
1300+
override def typedTypeApply(tree: untpd.TypeApply, pt: Type)(using Context): Tree =
1301+
inlineIfIsNestedInlineCall(constToLiteral(betaReduce(super.typedTypeApply(tree, pt))))
12961302

12971303
override def typedMatchFinish(tree: untpd.Match, sel: Tree, wideSelType: Type, cases: List[untpd.CaseDef], pt: Type)(using Context) =
12981304
if (!tree.isInline || ctx.owner.isInlineMethod) // don't reduce match of nested inline method yet

0 commit comments

Comments
 (0)