[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Eleminate unused functions from luac
- From: Shaun McVey <shaun.mcvey@...>
- Date: Sun, 4 Apr 2010 20:02:52 +0100
On Sun, Apr 4, 2010 at 6:08 PM, steve donovan <steve.j.donovan@gmail.com> wrote:
> 2010/4/4 "J.Jørgen von Bargen" <jjvb.primus@gmx.de>:
>> Now I have a lot of code in the luac, which is never called, thus could be
>> eleminated.
>>
>> Is there a tool for this? (Assuming, no function calls are constructed at
>> runtime)
>> Would it be possible?
>
> I think the answers are no, and yes. In fact I was idly considering
> writing such a tool, and wondering if there was any interest in it.
> It would work rather like the 'link' phase of compiled languages and
> would be useful to make self-contained scripts (which then could be
> easily make into an executable with srlua.)
>
The problem is, how can you guarantee any particular function is never used?
For example:
os.clock()
and
os["clock"]()
produce the same bytecodes, however you could write code like this:
local x = "clock"
os[x]()
and get different bytecodes.
It could be taken further:
local x = <some input from a file or a user, or generated in some other way>
os[x]()
So I don't think there is a way for a tool to know if a function will
never be used in any generic piece of code, not without further
information given to that tool.
Wouldn't a safer approach be to be able to specify which functions
from a module are loaded when you load the module?