-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fix repr(align) enum handling #96814
Conversation
Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
r? @jackh726 (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with comment fix (just the typo would be enough, but I got side-tracked using the change suggestion UI and added some more details)
Ah I missed this, right, so this PR not ready for merging. rust/compiler/rustc_codegen_ssa/src/mir/rvalue.rs Lines 301 to 340 in d32ce37
So the discriminant reading should happen before that, with rust/compiler/rustc_codegen_ssa/src/mir/rvalue.rs Lines 475 to 488 in d32ce37
This suggests another avenue for these casts: |
cc @nagisa wrt the above comment, and because of the codegen logic that #75529 touched - if we go the route of not having direct However, it strikes me that today (And/or if/when we get the ability to read discriminants from |
I tried that, but couldn't complete the type golf since I didn't have a place to work with.
Yeah that would be nice, make both Miri's and codegen's job much easier. :D |
The I'm perfectly content with the idea of us losing
|
Good, so looks like we have broad agreement here. Then we seem to have 2 options:
Doing it in the MIR seems more elegant, so if we can get some MIR people to help here that would be great. :) |
This comment has been minimized.
This comment has been minimized.
I'll create a PR |
done: #96862
We lost some of them. I tried to get them back by telling LLVM more things about the result of the discriminant (the input automatically gets that via |
☔ The latest upstream changes (presumably #96891) made this pull request unmergeable. Please resolve the merge conflicts. |
r? @eddyb |
Change enum->int casts to not go through MIR casts. follow-up to rust-lang#96814 this simplifies all backends and even gives LLVM more information about the return value of `Rvalue::Discriminant`, enabling optimizations in more cases.
Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
@@ -11,5 +11,13 @@ enum Aligned { | |||
fn main() { | |||
let aligned = Aligned::Zero; | |||
let fo = aligned as u8; | |||
println!("foo {}",fo); | |||
println!("foo {}", fo); | |||
println!("{}", tou8(Aligned::Zero)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should this be an assertion instead of a print? Otherwise we're only testing that this code runs, not that it does the right thing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added assertions but kept the prints, just in case they were relevant to trigger the ICE.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me with an explanation for the prints or changed to an assert
This comment has been minimized.
This comment has been minimized.
@bors r=oli-obk |
📌 Commit d5721ce has been approved by |
…laumeGomez Rollup of 6 pull requests Successful merges: - rust-lang#95503 (bootstrap: Allow building individual crates) - rust-lang#96814 (Fix repr(align) enum handling) - rust-lang#98256 (Fix whitespace handling after where clause) - rust-lang#98880 (Proper macOS libLLVM symlink when cross compiling) - rust-lang#98944 (Edit `rustc_mir_dataflow::framework::lattice::FlatSet` docs) - rust-lang#98951 (Update books) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
assert Scalar sanity With rust-lang#96814 having landed, finally our `Scalar` layouts have the invariants they deserve. :)
Change enum->int casts to not go through MIR casts. follow-up to rust-lang/rust#96814 this simplifies all backends and even gives LLVM more information about the return value of `Rvalue::Discriminant`, enabling optimizations in more cases.
enum
, for better or worse, supportsrepr(align)
. That has already caused a bug in #92464, which was "fixed" in #92932, but it turns out that that fix is wrong and caused #96185.So this reverts #92932 (which fixes #96185), and attempts another strategy for fixing #92464: special-case enums when doing a cast, re-using the code to load the discriminant rather than assuming that the enum has scalar layout. This works fine for the interpreter.
However, #92464 contained another testcase that was previously not in the test suite -- and after adding it, it ICEs again. This is not surprising; codegen needs the same patch that I did in the interpreter. Probably this has to happen around here. Unfortunately I don't know how to do that -- the interpreter can load a discriminant from an operand, but codegen can only do that from a place. @oli-obk @eddyb @bjorn3 any idea?