lua-users home
lua-l archive

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


On Sun, May 23, 2010 at 4:42 PM, Mark Hamburg <mark@grubmah.com> wrote:
> Does this mean that the compiler could now detect functions without upvalue references and treat them as constants so that we don't reconstruct them over and over again? (The presence of function environments stood in the way of doing so in the past.)
>
> Today, one could lift such definitions out of the code and explicitly store them in local variables, but doing so can break the flow of the code for reading.
>
> Mark
>
>

It does sound like a pretty good idea. Can anyone think of a realistic
circumstance where functions being identical values where they didn't
used to be would cause a big problem?

To explain what I mean a bit more:

 local t = {}
 for i = 1, 100 do
   local f = function()  return "hi";  end
   t[f] = true
 end
 for func in pairs(t) do
   print(func())
 end

...would print "hi" 100 times at the moment, but only once if we had
this optimisation. But this is obviously a very contrived example, the
question is: is there much real-world code out there that could be
affected in a similar way?

-Duncan