lua-users home
lua-l archive

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


> Also, whenever a function returns it closes all upvalues down to reg 0. 
> So there won't be a OP_CLOSE on your example, it's implicit. This is only 
> done if lua has any open upvalues, but one thing I've noticed is that 
> performance can be further improved (quite noticeably in synthetic 
> compiler shootout benchmarks) by only doing it if the function returning 
> has sub-protos. (As there's nearly always an open upvalue somewhere, yet 
> few functions actually create closures).

Unfortunately, with a one-pass compiler, by the time a return is compiled
we cannot be sure that there won't be a sub-proto later. For instance,
consider a code like this:

function foo (x)
  while true do
    if something then return end   --<<< 1
    b = function () return x end
  end
end

When the return at (1) is compiled, Lua still thinks that the function
does not have a sub-proto. But that return may need to close the upvalues
used by 'b' (if 'something' is true only after some iterations).

-- Roberto