Skip to content

Commit 6acaf31

Browse files
committed
Move inline β-reduction out of typer
1 parent 85f109f commit 6acaf31

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Compiler {
3737
protected def frontendPhases: List[List[Phase]] =
3838
List(new FrontEnd) :: // Compiler frontend: scanner, parser, namer, typer
3939
List(new sbt.ExtractDependencies) :: // Sends information on classes' dependencies to sbt via callbacks
40+
List(new InlineCalls) :: // β-reduce inline calls
4041
List(new PostTyper) :: // Additional checks and cleanups after type checking
4142
List(new sbt.ExtractAPI) :: // Sends a representation of the API of classes to sbt via callbacks
4243
Nil
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package dotty.tools.dotc.transform
2+
3+
import dotty.tools.dotc.ast.Trees._
4+
import dotty.tools.dotc.ast.tpd
5+
import dotty.tools.dotc.core.Contexts._
6+
import dotty.tools.dotc.core.Phases.Phase
7+
import dotty.tools.dotc.typer.Inliner
8+
9+
10+
class InlineCalls extends MacroTransform { thisPhase =>
11+
import tpd._
12+
13+
override def phaseName: String = InlineCalls.name
14+
15+
override def run(implicit ctx: Context): Unit =
16+
if (!ctx.settings.YnoInline.value) super.run
17+
18+
override def transformPhase(implicit ctx: Context): Phase = thisPhase.next
19+
20+
protected def newTransformer(implicit ctx: Context): Transformer =
21+
new InlineCallsTransformer
22+
23+
class InlineCallsTransformer extends Transformer {
24+
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
25+
case _: RefTree | _: GenericApply[_] if Inliner.isInlineable(tree) && !ctx.reporter.hasErrors =>
26+
transform(Inliner.inlineCall(tree, tree.tpe.widen))
27+
case _ =>
28+
super.transform(tree)
29+
}
30+
31+
}
32+
}
33+
34+
object InlineCalls {
35+
final val name = "inlineCalls"
36+
}

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

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2441,13 +2441,6 @@ class Typer extends Namer
24412441
checkEqualityEvidence(tree, pt)
24422442
tree
24432443
}
2444-
else if (Inliner.isInlineable(tree) &&
2445-
!ctx.settings.YnoInline.value &&
2446-
!ctx.isAfterTyper &&
2447-
!ctx.reporter.hasErrors &&
2448-
tree.tpe <:< pt) {
2449-
readaptSimplified(Inliner.inlineCall(tree, pt))
2450-
}
24512444
else if (tree.tpe <:< pt) {
24522445
if (pt.hasAnnotation(defn.InlineParamAnnot))
24532446
checkInlineConformant(tree, isFinal = false, "argument to inline parameter")

0 commit comments

Comments
 (0)