Re: No warnings for unreferenced code in eu40b2 build r3025
- Posted by Spock Jan 03, 2010
- 960 views
Hmm...
But what about the linker when the object code is compiled and linked...
Its job is make sure a jump/goto/branch target is valid?
Else it must be a self modifying program to know where to branch to..
If all possible entry points (procedure / function) are compared with all branches, won't this show what is redundant?
It would be possible to add a warning for this, but if the application contains just one routine_id() whose argument is not a literal, then all bets are off - any routine could be called and the parser would not know if an unreferenced routine is not being indirectly called via the routine_id() facility.
For example...
procedure notcalled() puts(1, "I wasn't called\n") end procedure sequence cmd cmd = command_line() for i = 3 to length(cmd) do r = routine_id(cmd[i]) if r != -1 then call_proc(r,{}) end if end for
Given this program, the routine notcalled is not directly referenced, but it might still be called if the user runs the program as ...
eui myapp notcalled
Thanks Derek, I'll use the bind -list to find unreferenced code, when I am suspicious that there may be some.
Can I request a new interpreter feature to issue a warning for where a code block is not explicitly referenced,
that that code is possibly never executed?
Im more interested in the "show me redundant code" angle than the "your call may be branching to nowhere" side.
It does not have to be smart, like should a call be within an if statement, will it be called. That would be impossible I think. ;)
A simple comparison of callable targets with calls (within the global scope) to reveal unreachable code.
Writing code, and debugging it is normally done using the interpreter (not the binder) after all.
Regards, Alan
Hi Alan,
I'm not sure that I agree with Derek that even "one routine_id() whose argument is not a literal" automatically means that "any routine could be called" thus defeating a check for unreferenced code. This is because routine_id() can only reach as far as it's scope allows - anything outside that is fair game for analysis.
I wrote the Orac compiler as a way of overcoming certain problems in Euphoria. To be honest, I don't know how routine_id functions under the 4.0 environment but what I did with Orac was simply to decree that the scope of routine_id() be limited to those modules visible at that point. That way I can be sure that any modules outside that scope could be optimized.
When I run the compiler using itself as the target I can analyse the source to see that there are scores of routines not directly referenced in the code and could delete these if so desired. The compiler has an option to ignore these in the output anyway.
Probably most Euphoria programmers would consider it too much trouble to use Orac because of the conversion step required and incompatibility issues (and a few compiler bugs). Still, ..
regards,
Mike