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

optimize enum of #[repr(int)] enums with non-overlapping discriminants to just use inner discriminant #126010

Closed
programmerjake opened this issue Jun 5, 2024 · 3 comments
Labels
A-codegen Area: Code generation A-layout Area: Memory layout of types C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@programmerjake
Copy link
Member

currently this layout optimization is not done:

// could be size 2 since A and B's discriminants are in the same spot with non-overlapping contiguous values, but currently isn't
enum Top {
    A(A),
    B(B),
}

#[repr(u8)]
enum A {
    A0(u8) = 0,
    A1(u8) = 1,
}

#[repr(u8)]
enum B {
    B2(u8) = 2,
    B3(u8) = 3,
}

previously mentioned: #46213 (comment)

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 5, 2024
@programmerjake
Copy link
Member Author

@rustbot label +A-codegen +A-layout +C-enhancement +T-compiler

@rustbot rustbot added A-codegen Area: Code generation A-layout Area: Memory layout of types C-enhancement Category: An issue proposing an enhancement or a PR with one. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 5, 2024
@the8472
Copy link
Member

the8472 commented Jun 5, 2024

Dup of #119055

@workingjubilee
Copy link
Member

closing as duplicate.

@workingjubilee workingjubilee closed this as not planned Won't fix, can't repro, duplicate, stale Jun 5, 2024
@saethlin saethlin removed the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Jun 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-layout Area: Memory layout of types C-enhancement Category: An issue proposing an enhancement or a PR with one. 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

5 participants