Skip to content

Commit c6d297b

Browse files
committed
Refactor Inliner
Inliner has become a bit of a ball of mud. It was over 2000 lines and handled several aspects that did not have clear boundaries. This commit refactors Inliner into three units in a new package `inlines`. They are: - Inlines.scala: The frontend for querying inline methods and issuing inline calls. - Inliner.scala: This unit does the main job of inlining. It transforms a call with a given right hand side into a list of bindings and an expansion. - InlineReducer.scala: A helper class used by Inliner that does rewriting of inlined code with the aim of optimizing it. The three units are joined by `PrepareInlineable` in package `inlines`.
1 parent 65a86ae commit c6d297b

23 files changed

+2010
-1953
lines changed

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

+12
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,18 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
999999
case _ => None
10001000
case _ => None
10011001
end AssertNotNull
1002+
1003+
object ConstantValue {
1004+
def unapply(tree: Tree)(using Context): Option[Any] =
1005+
tree match
1006+
case Typed(expr, _) => unapply(expr)
1007+
case Inlined(_, Nil, expr) => unapply(expr)
1008+
case Block(Nil, expr) => unapply(expr)
1009+
case _ =>
1010+
tree.tpe.widenTermRefExpr.normalized match
1011+
case ConstantType(Constant(x)) => Some(x)
1012+
case _ => None
1013+
}
10021014
}
10031015

10041016
object TreeInfo {

compiler/src/dotty/tools/dotc/core/Contexts.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ import Uniques._
1414
import ast.Trees._
1515
import ast.untpd
1616
import util.{NoSource, SimpleIdentityMap, SourceFile, HashSet, ReusableInstance}
17-
import typer.{Implicits, ImportInfo, Inliner, SearchHistory, SearchRoot, TypeAssigner, Typer, Nullables}
17+
import typer.{Implicits, ImportInfo, SearchHistory, SearchRoot, TypeAssigner, Typer, Nullables}
18+
import inlines.Inliner
1819
import Nullables._
1920
import Implicits.ContextualImplicits
2021
import config.Settings._

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ class TreeUnpickler(reader: TastyReader,
830830
else if sym.isInlineMethod && !sym.is(Deferred) then
831831
// The body of an inline method is stored in an annotation, so no need to unpickle it again
832832
new Trees.Lazy[Tree] {
833-
def complete(using Context) = typer.Inliner.bodyToInline(sym)
833+
def complete(using Context) = inlines.Inlines.bodyToInline(sym)
834834
}
835835
else
836836
readLater(end, _.readTerm())

0 commit comments

Comments
 (0)