Re:Zig self hosted compiler is now capable of building itself
by Karliss on Saturday April 16, 2022 @12:58PM
(#31053937)
Can you clarify about the union part? Did you meant that zig allowed you replacing what would be untagged union in C++ with tagged union in zig? Or does the zig compiler has some kind of debug sanitizer mode which automatically turns untagged unions into tagged unions with checks?
[ Parent
| on HN ]
Re:Zig self hosted compiler is now capable of building itself
by dralley on Saturday April 16, 2022 @01:29PM
(#31054210)
In the past they've talked about the speed and memory improvements they've gotten from using MultiArrayList in the compiler, storing tags separately from the unions themselves. If you have a union with a size of 16 bytes and you add a tag to that which is 1 byte, a lot of space is wasted due to padding. If you keep the tags in a separate array, both arrays are individually densely packed. Less memory wasted due to padding == less memory use overall and better utilization of cache.
But in terms of the implementation, this means working with untagged unions, because the tags are maintained externally.
Re:Zig self hosted compiler is now capable of building itself
by tristan957 on Monday April 18, 2022 @01:13PM
(#31073592)
In debug builds, untagged unions become tagged behind the scenes as you described.