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

Segfault on more than 256 enumerations #83

Closed
vertexclique opened this issue Dec 28, 2022 · 6 comments · Fixed by #90
Closed

Segfault on more than 256 enumerations #83

vertexclique opened this issue Dec 28, 2022 · 6 comments · Fixed by #90

Comments

@vertexclique
Copy link

Happens on both nightly and on stable:
cargo 1.66.0 (d65d197ad 2022-11-15)

............../nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-ce965b63303a743e.so(+0x3259ca3)[0x7f876605bca3]
/lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f8762a6a520]
............../XXXX/target/debug/deps/libnum_enum_derive-9556be49b01582cc.so(+0x260044)[0x7f8751ff7044]
@GilShoshan94
Copy link
Contributor

Are you using #[repr(u8)] on your enum ?

If so, it's normal that it fails since u8 give you 256 discriminant.
Try #[repr(u16)] instead.

About the segfault instead of a compilation error, I have no idea.

@illicitonion
Copy link
Owner

@vertexclique Thanks for the bug report - please could you include a sample code snippet that reproduces the problem? I've tried to reproduce a few different ways, and haven't been able to...

@vertexclique
Copy link
Author

vertexclique commented Dec 31, 2022

Smaller repr on the larger variants is always compiler error. It's not segfault. I unfortunately can't share the repro code. Only thing is there variants are 0 variadics so literally something like this:

enum Data {
A,
B,
C,
... 900 more
}

I wrote 256 because it staggers during compilation. I suspect something else might be going on that I don't know.

@vertexclique vertexclique changed the title Segfeault on more than 256 enumerations Segfault on more than 256 enumerations Dec 31, 2022
@illicitonion
Copy link
Owner

Can you share exactly what attributes you have on the enum? What's its repr? What trait(s) are you deriving?

@vertexclique
Copy link
Author

#[derive(Debug, Clone, Copy, PartialOrd, Display, PartialEq, Eq, TryFromPrimitive)]
#[repr(u16)]
pub enum Data {
  A,
  B,
  C,
  ... 900 more
}

@illicitonion
Copy link
Owner

As far as I can tell, this is actually blowing up the stack of rustc (at least that's the only way I could repro this), and #89 should fix it by simplifying the generated code.

illicitonion added a commit that referenced this issue Jan 10, 2023
This is very slow, but should not crash the compiler (as it did before #89)

Closes #83
illicitonion added a commit that referenced this issue Jan 10, 2023
This is very slow to compile, but should not crash the compiler (as it did before #89)

Closes #83
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants