diff options
Diffstat (limited to 'compiler/rustc_mir_dataflow/src/framework')
4 files changed, 30 insertions, 22 deletions
diff --git a/compiler/rustc_mir_dataflow/src/framework/direction.rs b/compiler/rustc_mir_dataflow/src/framework/direction.rs index 2ae3ae02f..c8fe1af66 100644 --- a/compiler/rustc_mir_dataflow/src/framework/direction.rs +++ b/compiler/rustc_mir_dataflow/src/framework/direction.rs @@ -1,4 +1,4 @@ -use rustc_middle::mir::{self, BasicBlock, Location, SwitchTargets}; +use rustc_middle::mir::{self, BasicBlock, Location, SwitchTargets, UnwindAction}; use rustc_middle::ty::TyCtxt; use std::ops::RangeInclusive; @@ -474,15 +474,14 @@ impl Direction for Forward { { use mir::TerminatorKind::*; match bb_data.terminator().kind { - Return | Resume | Abort | GeneratorDrop | Unreachable => {} + Return | Resume | Terminate | GeneratorDrop | Unreachable => {} Goto { target } => propagate(target, exit_state), - Assert { target, cleanup: unwind, expected: _, msg: _, cond: _ } + Assert { target, unwind, expected: _, msg: _, cond: _ } | Drop { target, unwind, place: _ } - | DropAndReplace { target, unwind, value: _, place: _ } | FalseUnwind { real_target: target, unwind } => { - if let Some(unwind) = unwind { + if let UnwindAction::Cleanup(unwind) = unwind { propagate(unwind, exit_state); } @@ -504,7 +503,7 @@ impl Direction for Forward { } Call { - cleanup, + unwind, destination, target, func: _, @@ -512,7 +511,7 @@ impl Direction for Forward { from_hir_call: _, fn_span: _, } => { - if let Some(unwind) = cleanup { + if let UnwindAction::Cleanup(unwind) = unwind { propagate(unwind, exit_state); } @@ -534,9 +533,9 @@ impl Direction for Forward { options: _, line_spans: _, destination, - cleanup, + unwind, } => { - if let Some(unwind) = cleanup { + if let UnwindAction::Cleanup(unwind) = unwind { propagate(unwind, exit_state); } diff --git a/compiler/rustc_mir_dataflow/src/framework/engine.rs b/compiler/rustc_mir_dataflow/src/framework/engine.rs index 91c3bf0ad..2abdee064 100644 --- a/compiler/rustc_mir_dataflow/src/framework/engine.rs +++ b/compiler/rustc_mir_dataflow/src/framework/engine.rs @@ -15,6 +15,7 @@ use rustc_hir::def_id::DefId; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::mir::{self, traversal, BasicBlock}; use rustc_middle::mir::{create_dump_file, dump_enabled}; +use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::TyCtxt; use rustc_span::symbol::{sym, Symbol}; @@ -285,7 +286,7 @@ where if tcx.sess.opts.unstable_opts.graphviz_dark_mode { render_opts.push(dot::RenderOption::DarkTheme); } - dot::render_opts(&graphviz, &mut buf, &render_opts)?; + with_no_trimmed_paths!(dot::render_opts(&graphviz, &mut buf, &render_opts)?); file.write_all(&buf)?; diff --git a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs index 96c42894b..707729f8f 100644 --- a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs +++ b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs @@ -6,6 +6,7 @@ use std::{io, ops, str}; use regex::Regex; use rustc_graphviz as dot; +use rustc_index::bit_set::BitSet; use rustc_middle::mir::graphviz_safe_def_name; use rustc_middle::mir::{self, BasicBlock, Body, Location}; @@ -34,6 +35,7 @@ where body: &'a Body<'tcx>, results: &'a Results<'tcx, A>, style: OutputStyle, + reachable: BitSet<BasicBlock>, } impl<'a, 'tcx, A> Formatter<'a, 'tcx, A> @@ -41,7 +43,8 @@ where A: Analysis<'tcx>, { pub fn new(body: &'a Body<'tcx>, results: &'a Results<'tcx, A>, style: OutputStyle) -> Self { - Formatter { body, results, style } + let reachable = mir::traversal::reachable_as_bitset(body); + Formatter { body, results, style, reachable } } } @@ -108,7 +111,12 @@ where type Edge = CfgEdge; fn nodes(&self) -> dot::Nodes<'_, Self::Node> { - self.body.basic_blocks.indices().collect::<Vec<_>>().into() + self.body + .basic_blocks + .indices() + .filter(|&idx| self.reachable.contains(idx)) + .collect::<Vec<_>>() + .into() } fn edges(&self) -> dot::Edges<'_, Self::Edge> { @@ -386,8 +394,8 @@ where ) -> io::Result<()> { let diffs = StateDiffCollector::run(body, block, self.results.results(), self.style); - let mut befores = diffs.before.map(|v| v.into_iter()); - let mut afters = diffs.after.into_iter(); + let mut diffs_before = diffs.before.map(|v| v.into_iter()); + let mut diffs_after = diffs.after.into_iter(); let next_in_dataflow_order = |it: &mut std::vec::IntoIter<_>| { if A::Direction::IS_FORWARD { it.next().unwrap() } else { it.next_back().unwrap() } @@ -397,8 +405,8 @@ where let statement_str = format!("{statement:?}"); let index_str = format!("{i}"); - let after = next_in_dataflow_order(&mut afters); - let before = befores.as_mut().map(next_in_dataflow_order); + let after = next_in_dataflow_order(&mut diffs_after); + let before = diffs_before.as_mut().map(next_in_dataflow_order); self.write_row(w, &index_str, &statement_str, |_this, w, fmt| { if let Some(before) = before { @@ -409,11 +417,11 @@ where })?; } - let after = next_in_dataflow_order(&mut afters); - let before = befores.as_mut().map(next_in_dataflow_order); + let after = next_in_dataflow_order(&mut diffs_after); + let before = diffs_before.as_mut().map(next_in_dataflow_order); - assert!(afters.is_empty()); - assert!(befores.as_ref().map_or(true, ExactSizeIterator::is_empty)); + assert!(diffs_after.is_empty()); + assert!(diffs_before.as_ref().map_or(true, ExactSizeIterator::is_empty)); let terminator = body[block].terminator(); let mut terminator_str = String::new(); diff --git a/compiler/rustc_mir_dataflow/src/framework/tests.rs b/compiler/rustc_mir_dataflow/src/framework/tests.rs index 17102454a..60679b17d 100644 --- a/compiler/rustc_mir_dataflow/src/framework/tests.rs +++ b/compiler/rustc_mir_dataflow/src/framework/tests.rs @@ -39,7 +39,7 @@ fn mock_body<'tcx>() -> mir::Body<'tcx> { args: vec![], destination: dummy_place.clone(), target: Some(mir::START_BLOCK), - cleanup: None, + unwind: mir::UnwindAction::Continue, from_hir_call: false, fn_span: DUMMY_SP, }, @@ -53,7 +53,7 @@ fn mock_body<'tcx>() -> mir::Body<'tcx> { args: vec![], destination: dummy_place.clone(), target: Some(mir::START_BLOCK), - cleanup: None, + unwind: mir::UnwindAction::Continue, from_hir_call: false, fn_span: DUMMY_SP, }, |