about
shows the wrong representation for small unions (Julia doesn't expose the needed information)
#35
Labels
about
shows the wrong representation for small unions (Julia doesn't expose the needed information)
#35
Here is an example of a small union in a struct.
For isbits types, this does not turn into a pointer. Instead, what happens is that the Union is essentially expanded into a tuple of
(T, Int8)
, where the Int8 is a type tag that indicates whethery
is aNothing
or aT
.But if
T
is a mutable value,y
is going to need a pointer for T anyway, and so it can use only a single pointer for the whole union. If the pointer points to the singleton address fornothing
, y is a Nothing, otherwise it's aT
.This basically compiles down to a "null-check" on the pointer, but instead of checking for "null," it checks for the singleton address for "nothing," which could be e.g.
0xaabbc123
or something.Instead, this currently incorrectly marks the union as always a Ptr:
However, unfortunately, I think that currently julia doesn't expose enough information to answer this correctly. I'm not positive, but i think so.
See this feature request to expose it: JuliaLang/julia#44943 (comment)
The text was updated successfully, but these errors were encountered: