lua-users home
lua-l archive

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


On Wed, Jan 19, 2011 at 21:11, David Manura <dm.lua@math2.org> wrote:
> On Wed, Jan 19, 2011 at 12:04 PM, Alexander Gladysh <agladysh@gmail.com> wrote:
>> ..somehow automagically optimize out tclone() calls for
>> the nodes that are never changed? [clone-on-write]

> Do you mean, for example, if you have code like this:

>  do
>    local t2 = tclone(t1)
>    [...]
>  end

> to optimize away the `tclone(t1)` as just `t1` if the code in "[...]"
> never writes to t2 and never exposes t2 outside of the block?

Yes, for example.

> Careful: tables have unique identity (t2 ~= t1).  Even if you don't
> write to t2, the code in "[...]" might (although unlikely) still
> expect that t2 ~= t1.

Well, I think it is not the major obstacle here. Our automagic
optimizer will create some kind of a "pointer" for the second instance
of our table anyway. When one does t2 == t1 (or similar operation,
like table indexing), that "pointer" would be used.

But, alas, too much automagic, it seems.

Alexander.