mvdan / goreduce

Reduce Go programs
BSD 3-Clause "New" or "Revised" License
216 stars 7 forks source link

Try to replace all exprs by zero values of their types #21

Closed mvdan closed 7 years ago

mvdan commented 7 years ago

Right now we do this with basic literals only. For example, we try to replace "foo" with "" and 123 with 0.

But we could do this with basically all expressions, being more aggressive:

I need to think about this, however. It might not always be a good idea. And sometimes the result might be awkward, since we might need parentheses or type conversions to make it compile properly.

Also worth noting that we could instead go for doing these step-by-step. The third example should be doable by replacing each literal and removing BinaryExpr sides. The second should be done by inlining a variable and zeroing the composite literal.

The first one will also be done, once we're able to inline somewhat complex func calls.

So need to also think whether or not this would make the tool able to reduce more programs. If not, we have to be careful if this is for performance because it may well actually make the tool slower.

mvdan commented 7 years ago

I struggle to imagine a scenario where this would help us reduce more programs. And as said, also hard to tell if this would make the tool faster overall.

And since this adds complexity, deciding against it for now.