1
Fork 0

Fix MIR pretty printer for non-local DefIds

This commit is contained in:
Ömer Sinan Ağacan 2021-02-10 17:32:45 +03:00
parent 7e0241c637
commit fe82365630

View file

@ -289,19 +289,19 @@ pub fn write_mir_pretty<'tcx>(
} }
Ok(()) Ok(())
}; };
match tcx.hir().body_const_context(def_id.expect_local()) {
None => render_body(w, tcx.optimized_mir(def_id))?, // For `const fn` we want to render both the optimized MIR and the MIR for ctfe.
// For `const fn` we want to render the optimized MIR. If you want the mir used in if tcx.is_const_fn_raw(def_id) {
// ctfe, you can dump the MIR after the `Deaggregator` optimization pass. render_body(w, tcx.optimized_mir(def_id))?;
Some(rustc_hir::ConstContext::ConstFn) => { writeln!(w)?;
render_body(w, tcx.optimized_mir(def_id))?; writeln!(w, "// MIR FOR CTFE")?;
writeln!(w)?; // Do not use `render_body`, as that would render the promoteds again, but these
writeln!(w, "// MIR FOR CTFE")?; // are shared between mir_for_ctfe and optimized_mir
// Do not use `render_body`, as that would render the promoteds again, but these write_mir_fn(tcx, tcx.mir_for_ctfe(def_id), &mut |_, _| Ok(()), w)?;
// are shared between mir_for_ctfe and optimized_mir } else {
write_mir_fn(tcx, tcx.mir_for_ctfe(def_id), &mut |_, _| Ok(()), w)?; let instance_mir =
} tcx.instance_mir(ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)));
Some(_) => render_body(w, tcx.mir_for_ctfe(def_id))?, render_body(w, instance_mir)?;
} }
} }
Ok(()) Ok(())