Skip to content

Commit

Permalink
Refactor Inliner
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
odersky committed Jun 29, 2022
1 parent 65a86ae commit c6d297b
Show file tree
Hide file tree
Showing 23 changed files with 2,010 additions and 1,953 deletions.
12 changes: 12 additions & 0 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,18 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
case _ => None
case _ => None
end AssertNotNull

object ConstantValue {
def unapply(tree: Tree)(using Context): Option[Any] =
tree match
case Typed(expr, _) => unapply(expr)
case Inlined(_, Nil, expr) => unapply(expr)
case Block(Nil, expr) => unapply(expr)
case _ =>
tree.tpe.widenTermRefExpr.normalized match
case ConstantType(Constant(x)) => Some(x)
case _ => None
}
}

object TreeInfo {
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import Uniques._
import ast.Trees._
import ast.untpd
import util.{NoSource, SimpleIdentityMap, SourceFile, HashSet, ReusableInstance}
import typer.{Implicits, ImportInfo, Inliner, SearchHistory, SearchRoot, TypeAssigner, Typer, Nullables}
import typer.{Implicits, ImportInfo, SearchHistory, SearchRoot, TypeAssigner, Typer, Nullables}
import inlines.Inliner
import Nullables._
import Implicits.ContextualImplicits
import config.Settings._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,7 @@ class TreeUnpickler(reader: TastyReader,
else if sym.isInlineMethod && !sym.is(Deferred) then
// The body of an inline method is stored in an annotation, so no need to unpickle it again
new Trees.Lazy[Tree] {
def complete(using Context) = typer.Inliner.bodyToInline(sym)
def complete(using Context) = inlines.Inlines.bodyToInline(sym)
}
else
readLater(end, _.readTerm())
Expand Down
Loading

0 comments on commit c6d297b

Please sign in to comment.