Skip to content

Commit 2978c66

Browse files
committed
Add a method to dump MIR in the middle of MIR building
This makes it easier to debug issues with MIR building by inserting dump_for_debugging calls around the suspected code responsible for the bad MIR.
1 parent 6c02dd4 commit 2978c66

File tree

1 file changed

+22
-0
lines changed
  • compiler/rustc_mir_build/src/builder

1 file changed

+22
-0
lines changed

compiler/rustc_mir_build/src/builder/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
789789
builder
790790
}
791791

792+
#[allow(dead_code)]
793+
fn dump_for_debugging(&self) {
794+
let body = Body::new(
795+
MirSource::item(self.def_id.to_def_id()),
796+
self.cfg.basic_blocks.clone(),
797+
self.source_scopes.clone(),
798+
self.local_decls.clone(),
799+
self.canonical_user_type_annotations.clone(),
800+
self.arg_count.clone(),
801+
self.var_debug_info.clone(),
802+
self.fn_span.clone(),
803+
self.coroutine.clone(),
804+
None,
805+
);
806+
//body.coverage_info_hi = self.coverage_info.clone().map(|b| b.into_done());
807+
808+
use rustc_middle::mir::pretty;
809+
let options = pretty::PrettyPrintMirOptions::from_cli(self.tcx);
810+
pretty::write_mir_fn(self.tcx, &body, &mut |_, _| Ok(()), &mut std::io::stdout(), options)
811+
.unwrap();
812+
}
813+
792814
fn finish(self) -> Body<'tcx> {
793815
let mut body = Body::new(
794816
MirSource::item(self.def_id.to_def_id()),

0 commit comments

Comments
 (0)