lua-users home
lua-l archive

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


I haven't started using LuaJIT yet, but I have been working with some
design patterns that I wonder whether could still be relied on there.

For instance, if I do this:

local bar

local function foo()
    local U = newproxy(true)
    getmetatable(U).__gc = function(self) print "goodbye world" end
    return bar(U)
end

function bar(U)
    ...lots of processing that might force a garbage-collection...
    ...nowhere here do we do anything with U...
end

In straight Lua, U will still be alive during the execution of bar, so
it won't be gc'd until after bar returns. Could that still be relied on
in LuaJIT? Or might the JIT compiler see that U is never touched inside bar,
and optimize foo's tail-call in such a way that U is no longer
referenced by anybody once control switches to bar?

I realize there are work-arounds. For instance, one could change foo so
that the call to bar was no longer a tail-call. Or one could keep U
alive during bar's execution in another way (what I ended up doing). I
just suspected this might be something I'd need to attend to when using
n optimizing compiler.

-- 
Profjim
profjim@jimpryor.net