Skip to content

Conversation

@nicolasstucki
Copy link
Contributor

No description provided.

@smarter smarter requested a review from odersky June 30, 2020 19:15
@smarter smarter assigned odersky and unassigned smarter Jun 30, 2020
case Typed(Block(stats, expr), _) if isPureExpr(expr) => stats
case stat => if !stat.symbol.isConstructor && isPureExpr(stat) then Nil else List(stat)
}
cpy.Block(tree)(stats, tree.expr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This implementation copies all blocks which leads in practice to large scale tree rewriting & allocation even if there are no pure statements. I'd try this instead:

val stats = Trees.flatten(
  tree.stats.mapConserve {
    case Typed(Block(stats, expr), _) if isPureExpr(expr) => Thicket(stats)
    case stat if !stat.symbol.isConstructor && isPureExpr(stat) => EmptyTree
    case stat => stat
  })

(flatten avoids tree copying if possible).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That variant works well

@odersky odersky assigned nicolasstucki and unassigned odersky Jul 1, 2020
case stat if !stat.symbol.isConstructor && isPureExpr(stat) => EmptyTree
case stat => stat
})
cpy.Block(tree)(stats, tree.expr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since you're using mapConserve you may not need to call Trees.flatten and cpy.Block:

val stats = tree.stats.mapConserve { ... }
if stats eq tree.stats then tree
else cpy.Block(tree)(Trees.flatten(stats), tree.expr)

@nicolasstucki nicolasstucki merged commit 3410426 into scala:master Jul 1, 2020
@nicolasstucki nicolasstucki deleted the fix-#9246 branch July 1, 2020 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Inlined methods of type Unit produce unnesesary code Inline code leads to a lot of Unit load + discard bytecode

4 participants