Skip to content

Feature request: Utility to show the layout that a struct definition compiles into when desugared #44943

Open
@NHDaly

Description

@NHDaly

@dpsanders and I were wondering if there is a utility that works similar to @code_typed and friends but works on struct definitions, rather than on methods. We wanted to know how a certain struct will end up represented in memory, in order to improve performance, but it's currently very hard to tell.

One example use case:
For instance, when a struct contains a field x::Union{Nothing,T}, we want to know what kind of struct layout gets generated. Our understanding is that for types where T will be heap-allocated, meaning x will be a pointer, julia can treat the ::Nothing case as essentially a null-pointer check, so it adds 0 space overhead. Whereas for types T that are inline-allocated/stack-allocated, this requires an extra bit somewhere to track whether x should be treated as the nothing case or the T case. (like a tagged union.)

But it would be great to be able to confirm that understanding by running something like @struct_layout S or @struct_llvm S or something like that!

Metadata

Metadata

Assignees

No one assigned

    Labels

    featureIndicates new feature / enhancement requeststooling

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions