diff options
| author | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2023-01-05 10:15:33 +0100 |
|---|---|---|
| committer | Tomasz Miąsko <tomasz.miasko@gmail.com> | 2023-02-23 14:05:03 +0100 |
| commit | 23e3840014e17cd20f6ebe5e268133b3ce5ab1a6 (patch) | |
| tree | b93649562063a9b4f68ccb6186aa1aba4c778542 /compiler/rustc_mir_dataflow/src/framework/engine.rs | |
| parent | 00eec854f167c546cedd0911f4cc302a54ed0be9 (diff) | |
| download | rust-23e3840014e17cd20f6ebe5e268133b3ce5ab1a6.tar.gz rust-23e3840014e17cd20f6ebe5e268133b3ce5ab1a6.zip | |
Remove dead unwinds before drop elaboration
As a part of drop elaboration, we identify dead unwinds, i.e., unwind edges on a drop terminators which are known to be unreachable, because there is no need to drop anything. Previously, the data flow framework was informed about the dead unwinds, and it assumed those edges are absent from MIR. Unfortunately, the data flow framework wasn't consistent in maintaining this assumption. In particular, if a block was reachable only through a dead unwind edge, its state was propagated to other blocks still. This became an issue in the context of change removes DropAndReplace terminator, since it introduces initialization into cleanup blocks. To avoid this issue, remove unreachable unwind edges before the drop elaboration, and elaborate only blocks that remain reachable.
Diffstat (limited to 'compiler/rustc_mir_dataflow/src/framework/engine.rs')
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/framework/engine.rs | 32 |
1 files changed, 2 insertions, 30 deletions
diff --git a/compiler/rustc_mir_dataflow/src/framework/engine.rs b/compiler/rustc_mir_dataflow/src/framework/engine.rs index 6ddbe69e17e..91c3bf0ad21 100644 --- a/compiler/rustc_mir_dataflow/src/framework/engine.rs +++ b/compiler/rustc_mir_dataflow/src/framework/engine.rs @@ -12,7 +12,6 @@ use rustc_ast as ast; use rustc_data_structures::work_queue::WorkQueue; use rustc_graphviz as dot; use rustc_hir::def_id::DefId; -use rustc_index::bit_set::BitSet; use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::mir::{self, traversal, BasicBlock}; use rustc_middle::mir::{create_dump_file, dump_enabled}; @@ -78,7 +77,6 @@ where { tcx: TyCtxt<'tcx>, body: &'a mir::Body<'tcx>, - dead_unwinds: Option<&'a BitSet<BasicBlock>>, entry_sets: IndexVec<BasicBlock, A::Domain>, pass_name: Option<&'static str>, analysis: A, @@ -154,25 +152,7 @@ where bug!("`initialize_start_block` is not yet supported for backward dataflow analyses"); } - Engine { - analysis, - tcx, - body, - dead_unwinds: None, - pass_name: None, - entry_sets, - apply_trans_for_block, - } - } - - /// Signals that we do not want dataflow state to propagate across unwind edges for these - /// `BasicBlock`s. - /// - /// You must take care that `dead_unwinds` does not contain a `BasicBlock` that *can* actually - /// unwind during execution. Otherwise, your dataflow results will not be correct. - pub fn dead_unwinds(mut self, dead_unwinds: &'a BitSet<BasicBlock>) -> Self { - self.dead_unwinds = Some(dead_unwinds); - self + Engine { analysis, tcx, body, pass_name: None, entry_sets, apply_trans_for_block } } /// Adds an identifier to the graphviz output for this particular run of a dataflow analysis. @@ -190,14 +170,7 @@ where A::Domain: DebugWithContext<A>, { let Engine { - analysis, - body, - dead_unwinds, - mut entry_sets, - tcx, - apply_trans_for_block, - pass_name, - .. + analysis, body, mut entry_sets, tcx, apply_trans_for_block, pass_name, .. } = self; let mut dirty_queue: WorkQueue<BasicBlock> = WorkQueue::with_none(body.basic_blocks.len()); @@ -236,7 +209,6 @@ where &analysis, tcx, body, - dead_unwinds, &mut state, (bb, bb_data), |target: BasicBlock, state: &A::Domain| { |
