Question about SETFIELD nil emission in table constructor codegen

重归混沌 <[email protected]>
Newsgroups gmane.comp.lang.lua.general
Message-ID <CABugeg9rp54TBAfHspEYNzVp2GfXD=jN4+=A16+evox1_hqQTg@mail.gmail.com>
Hi all,

I’m looking at table constructor codegen in Lua 5.5.

For code like:

local t = {
  a = nil,
  b = nil,
  c = nil,
}

luac -l -p outputs:

1       [1]     VARARGPREP      0
2       [1]     NEWTABLE        0 3 0   ; 0
3       [1]     EXTRAARG        0
4       [2]     SETFIELD        0 0 1k  ; "a" nil
5       [3]     SETFIELD        0 2 1k  ; "b" nil
6       [4]     SETFIELD        0 3 1k  ; "c" nil
7       [5]     RETURN          1 1 1   ; 0 out

From ltable.c, luaH_newkey does not insert a new entry when the value is
nil (if (!ttisnil(value)) ...), so these writes do not seem to result in
actual table entries.

My question is more about semantics:
for constructor fields that are statically unique and explicitly nil, is
there any specific semantic reason these SETFIELD instructions must still
be emitted? Or is this mainly a simplicity / uniformity choice in the code
generator?

Thanks.

-- 
You received this message because you are subscribed to the Google Groups "lua-l" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/lua-l/CABugeg9rp54TBAfHspEYNzVp2GfXD%3DjN4%2B%3DA16%2Bevox1_hqQTg%40mail.gmail.com.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.