diff options
| author | Jacob Pratt <jacob@jhpratt.dev> | 2025-08-21 17:57:50 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-21 17:57:50 -0400 |
| commit | cd0972f6f5277f7910837bff4b639d665756e3d2 (patch) | |
| tree | 98afc0ad61bfd1b4d1ea604daafff484d719b358 /compiler/rustc_mir_build | |
| parent | 057fee915cabc3b5a9045d01fe66a6527886afcb (diff) | |
| parent | 695473ae676756935192644c026945dc3d2da318 (diff) | |
| download | rust-cd0972f6f5277f7910837bff4b639d665756e3d2.tar.gz rust-cd0972f6f5277f7910837bff4b639d665756e3d2.zip | |
Rollup merge of #144780 - bjorn3:mir_build_debug, r=matthewjasper
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.
Diffstat (limited to 'compiler/rustc_mir_build')
| -rw-r--r-- | compiler/rustc_mir_build/src/builder/coverageinfo.rs | 15 | ||||
| -rw-r--r-- | compiler/rustc_mir_build/src/builder/mod.rs | 22 |
2 files changed, 37 insertions, 0 deletions
diff --git a/compiler/rustc_mir_build/src/builder/coverageinfo.rs b/compiler/rustc_mir_build/src/builder/coverageinfo.rs index 14199c20921..091b9dad5bc 100644 --- a/compiler/rustc_mir_build/src/builder/coverageinfo.rs +++ b/compiler/rustc_mir_build/src/builder/coverageinfo.rs @@ -157,6 +157,21 @@ impl CoverageInfoBuilder { // if there's nothing interesting in it. Box::new(CoverageInfoHi { num_block_markers, branch_spans }) } + + pub(crate) fn as_done(&self) -> Box<CoverageInfoHi> { + let &Self { nots: _, markers: BlockMarkerGen { num_block_markers }, ref branch_info } = + self; + + let branch_spans = branch_info + .as_ref() + .map(|branch_info| branch_info.branch_spans.as_slice()) + .unwrap_or_default() + .to_owned(); + + // For simplicity, always return an info struct (without Option), even + // if there's nothing interesting in it. + Box::new(CoverageInfoHi { num_block_markers, branch_spans }) + } } impl<'tcx> Builder<'_, 'tcx> { diff --git a/compiler/rustc_mir_build/src/builder/mod.rs b/compiler/rustc_mir_build/src/builder/mod.rs index 9570760f943..6a8f0b21ee0 100644 --- a/compiler/rustc_mir_build/src/builder/mod.rs +++ b/compiler/rustc_mir_build/src/builder/mod.rs @@ -790,6 +790,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { builder } + #[allow(dead_code)] + fn dump_for_debugging(&self) { + let mut body = Body::new( + MirSource::item(self.def_id.to_def_id()), + self.cfg.basic_blocks.clone(), + self.source_scopes.clone(), + self.local_decls.clone(), + self.canonical_user_type_annotations.clone(), + self.arg_count.clone(), + self.var_debug_info.clone(), + self.fn_span.clone(), + self.coroutine.clone(), + None, + ); + body.coverage_info_hi = self.coverage_info.as_ref().map(|b| b.as_done()); + + use rustc_middle::mir::pretty; + let options = pretty::PrettyPrintMirOptions::from_cli(self.tcx); + pretty::write_mir_fn(self.tcx, &body, &mut |_, _| Ok(()), &mut std::io::stdout(), options) + .unwrap(); + } + fn finish(self) -> Body<'tcx> { let mut body = Body::new( MirSource::item(self.def_id.to_def_id()), |
