[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [proposal] a new keyword : final
- From: David Manura <dm.lua@...>
- Date: Tue, 23 Mar 2010 19:54:15 -0400
On Tue, Mar 23, 2010 at 2:27 PM, David Given wrote:
> On 23/03/10 16:56, "J.Jørgen von Bargen" wrote:
>> A smart compiler could eliminate the debug code, when DEBUG is set to false
>
> Of course, a smart compiler should be able to tell that the local is
> never being assigned to in the chunk, and is therefore read-only, and do
> the optimisation anyway, without needing the new keyword!
My source optimizer [1] uses a function named "mark_const_locals" that
walks the AST and marks any local variables that are assigned to as
non-const. It would not be difficult to extend the program to use
this function to support dead code elimination more generally.
Note that even mutable mutable can be used in dead-code elimination.
In the code "local x = false; if x then print(1) end; x = 3", the
conditional block can be eliminated even though you cannot declare x
as "final".
[1] http://lua-users.org/wiki/SourceOptimizer