Use niche-filling optimization even when multiple variants have data.#94075
Use niche-filling optimization even when multiple variants have data.#94075bors merged 2 commits intorust-lang:masterfrom
Conversation
|
Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
|
(rust-highfive has picked a reviewer for you, use r? to override) |
|
Several static size checks needed the size lowered. I'm unsure how to handle this since they'll fail with a bootstrapped compiler, so I've just commented them out for now. |
This comment has been minimized.
This comment has been minimized.
cb54662 to
31b8643
Compare
This comment has been minimized.
This comment has been minimized.
oli-obk
left a comment
There was a problem hiding this comment.
This is amazing! Will review in detail later, but starting a perf run now
|
@bors try @rust-timer queue |
|
Awaiting bors try build completion. @rustbot label: +S-waiting-on-perf |
|
⌛ Trying commit 31b86437df15d7b335697d3f971721104335d04e with merge dbc0f1b7dd1014d9c7e56714953a0daf1b4f4c35... |
31b8643 to
ffc62f6
Compare
|
r? @eddyb -- reviewing this is out of my league ;) Before merging something like this, we need to make sure that debuginfo generation handles this correctly (especially the cpp-like encoding). cc @wesleywiser |
This comment has been minimized.
This comment has been minimized.
|
Wow that's cool. :D It would probably be good to also have a ui test ensuring specific cases are handled (like some of the examples from the issue). I imagine there would be an existing ui test that can be extended, but I am not sure. |
ffc62f6 to
690139c
Compare
|
I added a simple test case.
|
690139c to
73d9948
Compare
|
Nevermind; |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
This test case seems to have crept in from another PR...?
|
This is incredible work! I've wanted to see this level of niche optimization for a long time. I think this makes niche optimization work more like people often expect it'll work. |
|
@nnethercote What do you find unsatisfactory about the output now? |
|
The main problem is that there are things marked as The smaller problem is that it's not shown how the tag is stored for Something like this would be much clearer: |
|
On the subject of the performance regression, it seems like the impact to From the detailed info, it seems like a big portion of that is blamed on time in LLVM_lto_optimize. Maybe there's nothing that can be done to address that, but it seemed worth noting. (Is it conceivable that the change here might actually be causing LLVM_lto_optimize to be doing new useful work when compiling |
Not in a way that is obvious to me. |
|
I don't understand the linked performance results. The command says the |
|
The cachegrind commands are if you want to investigate what changed. They are not the actual commands that ran. What you see in the table is the result of |
|
It's probably worth opening an issue for the perf investigation; discussions in merged PRs tend to get lost.
|
|
Hmm, should the following enum be eligible for niche optimization now (courtesy u/gitpy on Reddit)? enum Data {
A(f64),
B(Buf),
}
struct Buf(*const u8, i16);
fn main() {
println!("{}", std::mem::size_of::<Buf>()); // 16
println!("{}", std::mem::size_of::<Data>()); // 24 even on nightly
} |
|
Padding is not used as a niche -- it could contain anything, including the value that you would want to indicate the other variant. |
|
@cuviper Ah, right. Amusingly you can now offer the compiler a place that works as a niche, though =) enum Data {
A(f64),
B(Buf),
}
struct Buf(*const u8, i16, bool);
// ++++++
println!("{}", std::mem::size_of::<Buf>()); // 16
println!("{}", std::mem::size_of::<Data>()); // 16 on nightly! |
|
Yep! And if you want even more niche, you can use a univariant enum, with a repr to keep it from being a ZST: #[repr(u8)] // or bigger!
enum Pad { Empty } |
Fixes #46213