Skip to content

Commit 1b7dcd1

Browse files
committed
Only run inlining phase when needed
1 parent c17e82a commit 1b7dcd1

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ class CompilationUnit protected (val source: SourceFile) {
3838
*/
3939
val freshNames: FreshNameCreator = new FreshNameCreator.Default
4040

41+
/** Will be set to `true` if there are inline call that must be inlined after typer.
42+
* The information is used in phase `Inlining` in order to avoid traversing trees that need no transformations.
43+
*/
44+
var needsInlining: Boolean = false
45+
4146
/** Will be set to `true` if contains `Quote`.
4247
* The information is used in phase `Staging` in order to avoid traversing trees that need no transformations.
4348
*/
@@ -100,6 +105,7 @@ object CompilationUnit {
100105
force.traverse(unit1.tpdTree)
101106
unit1.needsStaging = force.containsQuote
102107
unit1.needsQuotePickling = force.containsQuote
108+
unit1.needsInlining = force.containsInline
103109
}
104110
unit1
105111
}
@@ -126,9 +132,12 @@ object CompilationUnit {
126132
/** Force the tree to be loaded */
127133
private class Force extends TreeTraverser {
128134
var containsQuote = false
135+
var containsInline = false
129136
def traverse(tree: Tree)(using Context): Unit = {
130137
if (tree.symbol.isQuote)
131138
containsQuote = true
139+
if tree.symbol.is(Flags.Inline) then
140+
containsInline = true
132141
traverseChildren(tree)
133142
}
134143
}

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ class Inlining extends MacroTransform {
4040
override def allowsImplicitSearch: Boolean = true
4141

4242
override def run(using Context): Unit =
43-
try super.run
44-
catch case _: CompilationUnit.SuspendException => ()
43+
if ctx.compilationUnit.needsInlining then
44+
try super.run
45+
catch case _: CompilationUnit.SuspendException => ()
4546

4647
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] =
4748
val newUnits = super.runOn(units).filterNot(_.suspended)

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,16 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
258258
override def transform(tree: Tree)(using Context): Tree =
259259
try tree match {
260260
case tree: Ident if !tree.isType =>
261+
if tree.symbol.is(Inline) then
262+
ctx.compilationUnit.needsInlining = true
261263
checkNoConstructorProxy(tree)
262264
tree.tpe match {
263265
case tpe: ThisType => This(tpe.cls).withSpan(tree.span)
264266
case _ => tree
265267
}
266268
case tree @ Select(qual, name) =>
269+
if tree.symbol.is(Inline) then
270+
ctx.compilationUnit.needsInlining = true
267271
if (name.isTypeName) {
268272
Checking.checkRealizable(qual.tpe, qual.srcPos)
269273
withMode(Mode.Type)(super.transform(tree))
@@ -272,6 +276,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
272276
checkNoConstructorProxy(tree)
273277
transformSelect(tree, Nil)
274278
case tree: Apply =>
279+
if tree.symbol.is(Inline) then
280+
ctx.compilationUnit.needsInlining = true
275281
val methType = tree.fun.tpe.widen
276282
val app =
277283
if (methType.isErasedMethod)
@@ -303,6 +309,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
303309
if tree.symbol.isQuote then
304310
ctx.compilationUnit.needsStaging = true
305311
ctx.compilationUnit.needsQuotePickling = true
312+
if tree.symbol.is(Inline) then
313+
ctx.compilationUnit.needsInlining = true
306314
val tree1 @ TypeApply(fn, args) = normalizeTypeArgs(tree)
307315
args.foreach(checkInferredWellFormed)
308316
if (fn.symbol != defn.ChildAnnot.primaryConstructor)

0 commit comments

Comments
 (0)