Skip to content

Feasibility of supporting #[repr(Rust)] enums #140

@samscott89

Description

@samscott89

Update: as of #157 / #163 this is exclusively about #[repr(Rust)]

Previous description

Currently EnumDef requires an explicit primitive representation for enums to work, and this is enforced by the derive macro (or at least, will be with #139).

Supporting either #[repr(C)] or #[repr(Rust)] (the default representation) would require understanding the layout of the enum, which is non-trivial.

In the case of #[repr(C)], it might be feasible to do a similar trick with using the shadow struct for the enum variants, but also build a shadow struct for the tag, and use the two to compute the layout of the resultant struct as described here: https://doc.rust-lang.org/reference/type-layout.html#r-layout.repr.c.adt

For #[repr(Rust)] doing this layout matching seems entirely infeasible. There are the various "niche" optimizations for enums (nice post here), and there are no offset_of equivalents for enum variants that can get us this information.

I'm not sure if there are any tricks out there to make this work?

(Note: this is not something I'm personally blocked on, just noting it as a potential future issue).

Currently EnumDef requires an explicit primitive or c-style representation for enums to work, and this is enforced by the derive macro.

For #[repr(Rust)] doing this layout matching seems entirely infeasible. There are the various "niche" optimizations for enums (nice post here), and there are no offset_of equivalents for enum variants that can get us this information.

I'm not sure if there are any tricks out there to make this work?

(Note: this is not something I'm personally blocked on, just noting it as a potential future issue).

Metadata

Metadata

Assignees

No one assigned

    Labels

    🙅 blockedblocked on something else

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions