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
Consider not transmuting mem::Discriminant at all. #5
Comments
Just confirmed that this example: pub enum Foo {
A,
B(i32),
C(String),
D([u8; 200])
}
pub fn discr(foo: &Foo) -> isize {
match foo {
Foo::A => 0,
Foo::B(_) => 1,
Foo::C(_) => 2,
Foo::D(_) => 3,
}
} compiles to: %0 = getelementptr inbounds %Foo, %Foo* %foo, i64 0, i32 0, i64 0
%1 = load i8, i8* %0, align 8, !range !2
%_2 = zext i8 %1 to i64
ret i64 %_2 Even if I change the Maybe when the |
I thought This crate has discarded the use of |
Re ba02f3a :) |
Thanks for the rapid fix, @magiclen ! |
Thanks! I'm closing this issue, since this seems resolved now. |
The current version of this crate relies on transmuting
mem::Discriminant<T>
values:enum-ordinalize/src/lib.rs
Lines 423 to 445 in 80b7469
But it's clear from the code that this pathway was kept despite it having broken at least once. Why was it kept, for performance?
IIRC (from conversations with @nox, I believe), LLVM can optimize identity
switch
es, you just have to get the values right (we added the ability to specify explicit discriminants inenum
s with data, to allow "lining up" twoenum
s for that optimization).Please consider not using
unsafe
code to get around standard library stability, or at least putting it behind a nightly-only feature (which could be made to only compile on nightly by use of#![cfg_attr(feature = "nightly", feature(...))]
).cc @Hoverbear (who stumbled over an older version of this crate being broken, we assume)
The text was updated successfully, but these errors were encountered: