File tree 3 files changed +13
-3
lines changed
compiler/src/dotty/tools/dotc
3 files changed +13
-3
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,11 @@ class CompilationUnit(val source: SourceFile) {
25
25
/** Pickled TASTY binaries, indexed by class. */
26
26
var pickled : Map [ClassSymbol , Array [Byte ]] = Map ()
27
27
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
+
28
33
/** Will be reset to `true` if `untpdTree` contains `Quote` trees. The information
29
34
* is used in phase ReifyQuotes in order to avoid traversing a quote-less tree.
30
35
*/
@@ -48,20 +53,22 @@ object CompilationUnit {
48
53
if (forceTrees) {
49
54
val force = new Force
50
55
force.traverse(unit1.tpdTree)
56
+ unit1.containsInlineCalls = force.containsInline
51
57
unit1.containsQuotesOrSplices = force.containsQuotes
52
58
}
53
59
unit1
54
60
}
55
61
56
62
/** Force the tree to be loaded */
57
63
private class Force extends TreeTraverser {
64
+ var containsInline = false
58
65
var containsQuotes = false
59
66
def traverse (tree : Tree )(implicit ctx : Context ): Unit = {
60
67
if (tree.symbol.isQuote)
61
68
containsQuotes = true
62
69
tree match {
63
70
case _ : tpd.RefTree | _ : Trees .GenericApply [_] if Inliner .isInlineable(tree) =>
64
- containsQuotes = true // May inline a quote
71
+ containsInline = true
65
72
case _ =>
66
73
}
67
74
traverseChildren(tree)
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import dotty.tools.dotc.ast.tpd
5
5
import dotty .tools .dotc .core .Contexts ._
6
6
import dotty .tools .dotc .core .Phases .Phase
7
7
import dotty .tools .dotc .core .Types .MethodicType
8
+ import dotty .tools .dotc .transform .SymUtils ._
8
9
import dotty .tools .dotc .typer .{ConstFold , Inliner }
9
10
10
11
/** β-reduce all calls to inline methods and preform constant folding */
@@ -14,7 +15,7 @@ class InlineCalls extends MacroTransform { thisPhase =>
14
15
override def phaseName : String = InlineCalls .name
15
16
16
17
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
18
19
19
20
override def transformPhase (implicit ctx : Context ): Phase = thisPhase.next
20
21
@@ -31,6 +32,8 @@ class InlineCalls extends MacroTransform { thisPhase =>
31
32
newTree.symbol.defTree = newTree // update tree set in PostTyper or set for inlined members
32
33
newTree
33
34
case _ =>
35
+ if (tree.symbol.isQuote || tree.symbol.isSplice)
36
+ ctx.compilationUnit.containsQuotesOrSplices = true
34
37
ConstFold (super .transform(tree))
35
38
}
36
39
}
Original file line number Diff line number Diff line change @@ -180,7 +180,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
180
180
181
181
private def handleInlineCall (sym : Symbol )(implicit ctx : Context ): Unit = {
182
182
if (sym.is(Inline ))
183
- ctx.compilationUnit.containsQuotesOrSplices = true
183
+ ctx.compilationUnit.containsInlineCalls = true
184
184
}
185
185
186
186
private object dropInlines extends TreeMap {
You can’t perform that action at this time.
0 commit comments