Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

about shows the wrong representation for small unions (Julia doesn't expose the needed information) #35

Open
NHDaly opened this issue Oct 9, 2024 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@NHDaly
Copy link

NHDaly commented Oct 9, 2024

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 whether y is a Nothing or a T.

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 for nothing, y is a Nothing, otherwise it's a T.

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:

julia> struct MyStruct32{T}
           x::Int32
           y::Union{T,Nothing}
       end
Screenshot 2024-10-09 at 12 52 46 PM

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)

@tecosaur tecosaur added bug Something isn't working enhancement New feature or request labels Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants