diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-08-29 06:34:43 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-29 06:34:43 +0200 |
| commit | d182081de1ae2fe580c038abd526d85cedafa712 (patch) | |
| tree | 0393e811cb218b1ee3d8a2a408a25d05d3ac29c9 /compiler/rustc_mir_dataflow/src/framework | |
| parent | a96b44c9e2f952282cff1b833f39d10b8cda5f66 (diff) | |
| parent | b48870b451dd9d3f3f827aa54d9becdfdd811ba3 (diff) | |
| download | rust-d182081de1ae2fe580c038abd526d85cedafa712.tar.gz rust-d182081de1ae2fe580c038abd526d85cedafa712.zip | |
Rollup merge of #99027 - tmiasko:basic-blocks, r=oli-obk
Replace `Body::basic_blocks()` with field access Since the refactoring in #98930, it is possible to borrow the basic blocks independently from other parts of MIR by accessing the `basic_blocks` field directly. Replace unnecessary `Body::basic_blocks()` method with a direct field access, which has an additional benefit of borrowing the basic blocks only.
Diffstat (limited to 'compiler/rustc_mir_dataflow/src/framework')
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/framework/engine.rs | 9 | ||||
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/framework/graphviz.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_mir_dataflow/src/framework/tests.rs | 10 |
3 files changed, 10 insertions, 13 deletions
diff --git a/compiler/rustc_mir_dataflow/src/framework/engine.rs b/compiler/rustc_mir_dataflow/src/framework/engine.rs index 112204c7599..bc75645e7c9 100644 --- a/compiler/rustc_mir_dataflow/src/framework/engine.rs +++ b/compiler/rustc_mir_dataflow/src/framework/engine.rs @@ -111,9 +111,9 @@ where // Otherwise, compute and store the cumulative transfer function for each block. let identity = GenKillSet::identity(analysis.bottom_value(body).domain_size()); - let mut trans_for_block = IndexVec::from_elem(identity, body.basic_blocks()); + let mut trans_for_block = IndexVec::from_elem(identity, &body.basic_blocks); - for (block, block_data) in body.basic_blocks().iter_enumerated() { + for (block, block_data) in body.basic_blocks.iter_enumerated() { let trans = &mut trans_for_block[block]; A::Direction::gen_kill_effects_in_block(&analysis, trans, block, block_data); } @@ -147,7 +147,7 @@ where apply_trans_for_block: Option<Box<dyn Fn(BasicBlock, &mut A::Domain)>>, ) -> Self { let bottom_value = analysis.bottom_value(body); - let mut entry_sets = IndexVec::from_elem(bottom_value.clone(), body.basic_blocks()); + let mut entry_sets = IndexVec::from_elem(bottom_value.clone(), &body.basic_blocks); analysis.initialize_start_block(body, &mut entry_sets[mir::START_BLOCK]); if A::Direction::IS_BACKWARD && entry_sets[mir::START_BLOCK] != bottom_value { @@ -200,8 +200,7 @@ where .. } = self; - let mut dirty_queue: WorkQueue<BasicBlock> = - WorkQueue::with_none(body.basic_blocks().len()); + let mut dirty_queue: WorkQueue<BasicBlock> = WorkQueue::with_none(body.basic_blocks.len()); if A::Direction::IS_FORWARD { for (bb, _) in traversal::reverse_postorder(body) { diff --git a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs index c94198c56a8..579fe68a149 100644 --- a/compiler/rustc_mir_dataflow/src/framework/graphviz.rs +++ b/compiler/rustc_mir_dataflow/src/framework/graphviz.rs @@ -108,12 +108,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().collect::<Vec<_>>().into() } fn edges(&self) -> dot::Edges<'_, Self::Edge> { self.body - .basic_blocks() + .basic_blocks .indices() .flat_map(|bb| dataflow_successors(self.body, bb)) .collect::<Vec<_>>() diff --git a/compiler/rustc_mir_dataflow/src/framework/tests.rs b/compiler/rustc_mir_dataflow/src/framework/tests.rs index d9461fd3abd..17102454a88 100644 --- a/compiler/rustc_mir_dataflow/src/framework/tests.rs +++ b/compiler/rustc_mir_dataflow/src/framework/tests.rs @@ -100,9 +100,9 @@ impl<D: Direction> MockAnalysis<'_, D> { fn mock_entry_sets(&self) -> IndexVec<BasicBlock, BitSet<usize>> { let empty = self.bottom_value(self.body); - let mut ret = IndexVec::from_elem(empty, &self.body.basic_blocks()); + let mut ret = IndexVec::from_elem(empty, &self.body.basic_blocks); - for (bb, _) in self.body.basic_blocks().iter_enumerated() { + for (bb, _) in self.body.basic_blocks.iter_enumerated() { ret[bb] = self.mock_entry_set(bb); } @@ -169,7 +169,7 @@ impl<'tcx, D: Direction> AnalysisDomain<'tcx> for MockAnalysis<'tcx, D> { const NAME: &'static str = "mock"; fn bottom_value(&self, body: &mir::Body<'tcx>) -> Self::Domain { - BitSet::new_empty(Self::BASIC_BLOCK_OFFSET + body.basic_blocks().len()) + BitSet::new_empty(Self::BASIC_BLOCK_OFFSET + body.basic_blocks.len()) } fn initialize_start_block(&self, _: &mir::Body<'tcx>, _: &mut Self::Domain) { @@ -271,9 +271,7 @@ fn test_cursor<D: Direction>(analysis: MockAnalysis<'_, D>) { cursor.allow_unreachable(); let every_target = || { - body.basic_blocks() - .iter_enumerated() - .flat_map(|(bb, _)| SeekTarget::iter_in_block(body, bb)) + body.basic_blocks.iter_enumerated().flat_map(|(bb, _)| SeekTarget::iter_in_block(body, bb)) }; let mut seek_to_target = |targ| { |
