Is the "isbits union" optimization enabled in Julia 1.1?

According to the documentation, the so-called “isbits Union optimization” should apply to the following type definition:

struct S
  x :: Union{UInt8, Int16}

Therefore, I would expect isbitstype(S) to be true. However, using Julia 1.1, I get:

julia> isbitstype(S)

Does it mean that the isbits union type optimization does not apply in this case or am I misunderstanding the semantics of isbitstype? (I am using Julia 1.1)

So the isbits Union optimizations didn’t affect the query of isbitstype directly; it’s a more internal optimization to treat these types of Unions as isbits in places where they can be optimized like Array and struct storage. Base defines internally a Base.isbitsunion function that returns if a specific Union type contains all isbitstype components.


I see. In practice, is there any easy way to check whether or not the layout of a type features heap-allocated boxed values?

Can you clarify what you’re trying to do?

Oh, I see you edited your message. So there’s an open PR that will simplify things by having a single property of a DataType that indicates if it can be stored inline. Currently, you would just check if each field of a struct is isbitstype or Base.isbitsunion.



Yeah, that might be helpful, although it doesn’t address the Union case for the fields. That can be queried with datatype_pointerfree (although as you might guess from the long name, it’s not something we usually expect user code to care about frequently)