Skip to content

Splitter: Avoid unnecessary allocations (20% fewer Apply nodes) #3942

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 30, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Splitter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,22 @@ class Splitter extends MiniPhase {
recur(tree.fun)
}

private def needsDistribution(fun: Tree) = fun match {
case _: Block | _: If => true
case _ => false
}

override def transformTypeApply(tree: TypeApply)(implicit ctx: Context) =
distribute(tree, typeApply)
if (needsDistribution(tree.fun))
distribute(tree, typeApply)
else
tree

override def transformApply(tree: Apply)(implicit ctx: Context) =
distribute(tree, apply)
if (needsDistribution(tree.fun))
distribute(tree, apply)
else
tree

private val typeApply = (fn: Tree, args: List[Tree]) => (ctx: Context) => TypeApply(fn, args)(ctx)
private val apply = (fn: Tree, args: List[Tree]) => (ctx: Context) => Apply(fn, args)(ctx)
Expand Down