GuillaumeGomez / rustc-tools

Some internal rustc tools made accessible
https://guillaumegomez.github.io/rustc-tools/
MIT License
41 stars 5 forks source link

missing optimized MIR #34

Open nsarlin-zama opened 4 weeks ago

nsarlin-zama commented 4 weeks ago

I don't know exactly what is the exact trigger for this, but I sometimes encounter a "missing optimized MIR" error when using tools built using this crate. This can be reproduced for example by running the example tool on itself, after having commented out the OddFunctionLineCount pass:

fn main() {
    let cargo_args = std::env::args().skip(2).collect::<Vec<_>>();
    rustc_tools::cargo_integration(&cargo_args, |args| {
        with_lints(args, vec![], |store: &mut LintStore| {
            store.register_early_pass(|| Box::new(warn_generics::WarnGenerics));
            //store.register_late_pass(|_| Box::new(odd_function_line_count::OddFunctionLineCount));
            store.register_late_pass(|_| Box::new(unwrap_call::UnwrapCall));
        })
        .expect("with_lints failed");
    })
    .expect("cargo_integration failed");
}
error: missing optimized MIR for an item in the crate `rustc_tools`
   |
note: missing optimized MIR for this item (was the crate `rustc_tools` compiled with `--emit=metadata`?)
  --> ~/.cargo/registry/src/index.crates.io-6f17d22bba15001f/rustc-tools-0.78.1/src/cargo.rs:27:1
   |
27 | / pub fn cargo_integration<T, F: Fn(&[String]) -> T>(
28 | |     cargo_args: &[String],
29 | |     f: F,
30 | | ) -> Result<T, String> {
   | |______________________^

error: aborting due to 1 previous error; 1 warning emitted

Adding --emit=metadata to the compiler flags seems to fix it but I don't know if this is the best solution. One side-effect is that it generates a libmain.rmeta file.

fn main() {
    let cargo_args = std::env::args().skip(2).collect::<Vec<_>>();
    rustc_tools::cargo_integration(&cargo_args, |args| {
        let mut args = args.to_vec();
        args.push("--emit=metadata".to_string());
        with_lints(&args, vec![], |store: &mut LintStore| {
            store.register_early_pass(|| Box::new(warn_generics::WarnGenerics));
            //store.register_late_pass(|_| Box::new(odd_function_line_count::OddFunctionLineCount));
            store.register_late_pass(|_| Box::new(unwrap_call::UnwrapCall));
        })
        .expect("with_lints failed");
    })
    .expect("cargo_integration failed");
}
nsarlin-zama commented 4 weeks ago

Maybe this is related to https://github.com/rust-lang/rust/issues/126012

GuillaumeGomez commented 3 weeks ago

So it will be fixed once the compiler version is updated I suppose. Not great though. :-/

nsarlin-zama commented 6 days ago

I think that 1.80 should fix this ? I can do the upgrade to the latest compiler if it can help you and if you haven't started working on it. The toolchain that should be used is nightly-2024-07-25, right ?

GuillaumeGomez commented 6 days ago

I think so yes. If you're motivated to do it, it's very welcome. :)

nsarlin-zama commented 6 days ago

Sadly upgrading the compiler version does not seem to fix it, it might not be related to the linked issue...

GuillaumeGomez commented 6 days ago

Hum, interesting. Gonna try to take a look when I have some time.