lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi,

Roberto Ierusalimschy wrote:
> Currently, I am not sure constant folding is worth the trouble.

Maybe, maybe not. Where I've previously used variables to store
precomputed constants, I've relied on constant folding quite a
bit since it has been introduced. Some cases are no longer needed
due to the introduction of hex literals.

So it really depends on how much developers rely on the (limited)
constant folding. E.g. x+1+1 is _not_ folded (FP arithmetics are
not associative), but x+(1+1) is. So how often does everyone
write x+(3*12+7) and rely on this being the same speed as x+43?

[Well, the partial-sums benchmark in the shootout relies on it ...]

Another data point: LuaJIT currently relies on the constant
folding in the parser. But I'm planning to switch over to delayed
code generation, anyway. This would enable much more extensive
constant folding as a side-effect. E.g. 'local x=2; y=3*x' would
be folded, too.

> ... remove constant folding optimization from Lua 5.1.

Well, I would be a little bit worried doing this in the 5.1.x
branch, though.

Bye,
     Mike