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

Layout for enums does not match MIR (and types) very well #70399

Open
RalfJung opened this issue Mar 25, 2020 · 0 comments
Open

Layout for enums does not match MIR (and types) very well #70399

RalfJung opened this issue Mar 25, 2020 · 0 comments
Labels
A-layout Area: Memory layout of types A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented Mar 25, 2020

Enum layout computation entirely ignores ZST uninhabited ("absent") variants, which can lead to the layout being quite different in structure from the user-visible enum:

  • if there are more than 1 non-absent variants, Variants::Multiple is used.
  • if there is exactly 1 non-absent variant, Variants::Single is used.
  • if all variants are absent, the layout of ! is used, so the entire thing ends up looking like a union with 0 fields.

When actually asking for the layout of such an absent variant, it has to be made up "on the spot".

In terms of testing things like Miri (or anything else that needs to work with layout variants information), this leads to the "interesting" situation that we need an enum with at least 3 variants where 1 is "absent" to make sure that Variants::Multiple with absent variants is handled correctly.

This could be improved by generalizing Variants::Multiple to also support "discriminants" of "type" () and !, thus uniformly handling all enums.

Also see the second half of #69763 (comment), and discussion below #69763 (comment).

Cc @eddyb

@RalfJung RalfJung added C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html labels Mar 25, 2020
@csmoe csmoe changed the title Layout for enums does not match MIR (and types) vry well Layout for enums does not match MIR (and types) very well Mar 26, 2020
@jonas-schievink jonas-schievink added the A-layout Area: Memory layout of types label Oct 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-layout Area: Memory layout of types A-MIR Area: Mid-level IR (MIR) - https://blog.rust-lang.org/2016/04/19/MIR.html C-cleanup Category: PRs that clean code up or issues documenting cleanup. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants