-Zdump-mir is incomplete for dead functions
Given the following program
fn main() {
let _closure = |x: i32| x+x;
}
I would expect rustc filename.rs -Zdump-mir=all to dump all stages of the MIR of all functions. What happens instead is that for the closure, only the 000-* and 001-* passes are emitted; the 002-* are missing. That's probably because they are not actually emitted into the binary, so they never get generated. I think that's a bug; one should expect -Zdump-mir to generate the MIR of all phases of all code.
(I noticed this because I was adding a mir-opt test and it told me it couldn't find the file.)
Wouldn’t consider this a bug at all. Seems like a fairly obvious outcome of the compiler skipping doing unnecessary work. Not sure if it actually skips any work yet (it probably does), but the query-ification is certainly moving toward being able to do less.
Rewriting the test seems like a way better idea to me.
Simonas Kazlauskas at 2017-08-04 19:12:39
In that case the documentation of
-Z dump-mirshould be changed to "dump mir state of some functions at various points in translation if they happen to be translated". Also, the flag becomes much less useful to explore and play around with MIR transformations.I see
-Zdump-miras an explicit request to the compiler to indeed translate all functions and produce the MIR and show it to me. Not doing so is not skipping unnecessary work, it rather is not doing work it was asked to do.Ralf Jung at 2017-08-05 01:53:49
Note: it helps to call
rustc --emit mir -Zdump-mir=all; that makes it dump more stuff.Ralf Jung at 2019-04-19 18:53:58