Skip to content

Commit f28e2e1

Browse files
committed
Only run InlineCalls if the tree contains an inline call
1 parent 9e14dee commit f28e2e1

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

compiler/src/dotty/tools/dotc/CompilationUnit.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ class CompilationUnit(val source: SourceFile) {
2525
/** Pickled TASTY binaries, indexed by class. */
2626
var pickled: Map[ClassSymbol, Array[Byte]] = Map()
2727

28+
/** Will be reset to `true` if `tpdTree` contains a call to an inline method. The information
29+
* is used in phase InlineCalls in order to avoid traversing an inline-less tree.
30+
*/
31+
var containsInlineCalls: Boolean = false
32+
2833
/** Will be reset to `true` if `untpdTree` contains `Quote` trees. The information
2934
* is used in phase ReifyQuotes in order to avoid traversing a quote-less tree.
3035
*/
@@ -48,20 +53,22 @@ object CompilationUnit {
4853
if (forceTrees) {
4954
val force = new Force
5055
force.traverse(unit1.tpdTree)
56+
unit1.containsInlineCalls = force.containsInline
5157
unit1.containsQuotesOrSplices = force.containsQuotes
5258
}
5359
unit1
5460
}
5561

5662
/** Force the tree to be loaded */
5763
private class Force extends TreeTraverser {
64+
var containsInline = false
5865
var containsQuotes = false
5966
def traverse(tree: Tree)(implicit ctx: Context): Unit = {
6067
if (tree.symbol.isQuote)
6168
containsQuotes = true
6269
tree match {
6370
case _: tpd.RefTree | _: Trees.GenericApply[_] if Inliner.isInlineable(tree) =>
64-
containsQuotes = true // May inline a quote
71+
containsInline = true
6572
case _ =>
6673
}
6774
traverseChildren(tree)

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import dotty.tools.dotc.ast.tpd
55
import dotty.tools.dotc.core.Contexts._
66
import dotty.tools.dotc.core.Phases.Phase
77
import dotty.tools.dotc.core.Types.MethodicType
8+
import dotty.tools.dotc.transform.SymUtils._
89
import dotty.tools.dotc.typer.{ConstFold, Inliner}
910

1011
/** β-reduce all calls to inline methods and preform constant folding */
@@ -14,7 +15,7 @@ class InlineCalls extends MacroTransform { thisPhase =>
1415
override def phaseName: String = InlineCalls.name
1516

1617
override def run(implicit ctx: Context): Unit =
17-
if (!ctx.settings.YnoInline.value) super.run
18+
if (ctx.compilationUnit.containsInlineCalls && !ctx.settings.YnoInline.value) super.run
1819

1920
override def transformPhase(implicit ctx: Context): Phase = thisPhase.next
2021

@@ -31,6 +32,8 @@ class InlineCalls extends MacroTransform { thisPhase =>
3132
newTree.symbol.defTree = newTree // update tree set in PostTyper or set for inlined members
3233
newTree
3334
case _ =>
35+
if (tree.symbol.isQuote || tree.symbol.isSplice)
36+
ctx.compilationUnit.containsQuotesOrSplices = true
3437
ConstFold(super.transform(tree))
3538
}
3639
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
180180

181181
private def handleInlineCall(sym: Symbol)(implicit ctx: Context): Unit = {
182182
if (sym.is(Inline))
183-
ctx.compilationUnit.containsQuotesOrSplices = true
183+
ctx.compilationUnit.containsInlineCalls = true
184184
}
185185

186186
private object dropInlines extends TreeMap {

0 commit comments

Comments
 (0)