-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #9246 and #6800: Remove pure statements #9263
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
Conversation
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) |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That variant works well
case stat if !stat.symbol.isConstructor && isPureExpr(stat) => EmptyTree | ||
case stat => stat | ||
}) | ||
cpy.Block(tree)(stats, tree.expr) |
There was a problem hiding this comment.
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)
No description provided.