I would like to do some analyzing work on top of the MIR of std/alloc library. My goal is to watch the MIR that is relevant to memory allocation, including box, allocator, libc::malloc or HeapAlloc, etc.
We can use several ways to dump the MIR of a normal crate:
setting RUSTFLAGS="--emit mir" in the environment variables.
The rust project itself is built by x.py and rustbuild. After some exploring, I could not find a way to dump the MIR of a crate located inside the project. But I guess using the stage0/beta compiler to dump the MIR is sufficient.
The way I get the MIR dump is by setting RUSTFLAGS="--emit mir" in the environment variables.
But when I set it to RUSTFLAGS="-Z dump-mir-graphviz=yes" and run py .\x.py build .\library\alloc\ in the shell, the stage0 rustc reports error:
Caused by:
process didn't exit successfully: `rust\build\<target>\stage0\bin\rustc.exe - ... -Z dump-mir-graphviz=yes ... ` (exit code: 1)
--- stderr
error: the option `Z` is only accepted on the nightly compiler
How could I use the nightly version or is there a way to dump the mir not by setting the RUSTFLAGS globally?
Setting RUSTFLAGS will cause rustbuild itself to be compiled with those flags too I think. Rustbuild is built using the bootstrap compiler without the escape hatch used to allow nightly features. You can use RUSTFLAGS_BOOTSTRAP or RUSTFLAGS_NOT_BOOTSTRAP depending on if you want to have it apply when compiling using the bootstrap compiler (--stage 0) or not (--stage 1 or --stage 2).
You can also use cargo -Zbuild-std build --target <target> on nightly to make cargo build the standard library instead of using the precompiled one. This will make RUSTFLAGS="--emit mir" apply to the standard library too I believe.