-
Notifications
You must be signed in to change notification settings - Fork 382
Open
Milestone
Description
Next perhaps to lambdas, array creation is one of the more verbose bits of output that the compiler creates, so that it can correctly emit the class literal, castable type map, the length of the array, and the type of the elements. The DeadCodeElimination pass doesn't consider array creation at all, except that creating an array has side effects if either the size expressions have side effects, or if the initializers have side effects (as you can't specify both size and initializers at once). This seems like an easy pass to improve: given array expressions where the value is unused
new int[hasSideEffects()]
or
new int[]{has(), side(), effects()]
we can instead emit
hasSideEffects()
or
(has(), side(), effects())
respectively. A quick sketch might look like this:
/**
* Simplify new array expressions whose output is ignored.
*/
@Override
public void endVisit(JNewArray x, Context ctx) {
if (ignoringExpressionOutput.contains(x)) {
if (x.getDimensionExpressions() != null) {
ctx.replaceMe(new JMultiExpression(x.getSourceInfo(), x.getDimensionExpressions()));
} else {
assert x.getInitializers() != null;
ctx.replaceMe(new JMultiExpression(x.getSourceInfo(), x.getInitializers()));
}
ignoringExpressionOutput.remove(x);
}
}Metadata
Metadata
Assignees
Labels
No labels