lua-users home
lua-l archive

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

Personally I would much prefer trading hypothetical speed loss against
bug risks... Because this bug really frightens me. It is very easy
building large configuration, but hard to notice that some numbers are
totally wrong.

I guess constant folding only occurs when you have code like this: 
A = 2 * (2+4) => A = 12
A = (2 + 4) * B => A = 6 * B
So it may generate more opcodes if not folded and it may embed fewer
constants in the instructions, but I guess such a code is most likely to
be executed once when you declare constants. So it has almost no impact
on performances if you are used to name constants.
-----Original Message-----
[] On Behalf Of Jerome Vuarand
Sent: Friday, February 09, 2007 5:44 PM
To: Lua list
Subject: RE: bug report

Roberto Ierusalimschy write:
> > Thierry Grellier reported a bug in Lua 5.1.1.  The bug only 
> happens in 
> > functions with more than 255 names/constants.  Then, the 
> interaction 
> > between contants and table accesses (e.g., "2*a.x") may 
> produce weird 
> > results. Bellow is an example (all results should be 2).
> > [...]
> We could write a quick patch for this bug. However, we are 
> considering a more drastic measure: maybe it would be simpler 
> to remove constant folding optimization from Lua 5.1.
> Currently, I am not sure constant folding is worth the 
> trouble. We had all kinds of problems with it: division and 
> module by zero, NaN results, problems with exotic lua_Number 
> types (which may need a state to create new values), etc. And 
> it adds very little to the language: it is very easy for the 
> programmer to define suitable local "constants" to avoid 
> recomputing constant expressions, when needed.

Consider the following hypothesis: "I'm not sure exactly when constant
folding happens, and if removing it would have a big impact on my
project". Could you present briefly general cases/conditions when
constant folding is extensively used by the compiler, when it works
gracefully, when compiler can't use it, and a simple patch that
desactivate it for worried people to test and benchmark in real world
situation ? That would give you valuable feedback on whether or not
applying your 'drastic' measure would have a negative impact.