Skip to content

Commit 698e870

Browse files
Stop adding unreachable basic blocks to dataflow work queue
Also adds some debug assertions to prevent API consumers from visiting those basic blocks by accident.
1 parent efe634f commit 698e870

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

src/librustc_mir/dataflow/framework/cursor.rs

+9
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ where
3434
///
3535
/// When this flag is set, we need to reset to an entry set before doing a seek.
3636
state_needs_reset: bool,
37+
38+
#[cfg(debug_assertions)]
39+
reachable_blocks: BitSet<BasicBlock>,
3740
}
3841

3942
impl<'mir, 'tcx, A, R> ResultsCursor<'mir, 'tcx, A, R>
@@ -55,6 +58,9 @@ where
5558
state_needs_reset: true,
5659
state: BitSet::new_empty(bits_per_block),
5760
pos: CursorPosition::block_entry(mir::START_BLOCK),
61+
62+
#[cfg(debug_assertions)]
63+
reachable_blocks: mir::traversal::reachable_as_bitset(body),
5864
}
5965
}
6066

@@ -85,6 +91,9 @@ where
8591
///
8692
/// For backward dataflow analyses, this is the dataflow state after the terminator.
8793
pub(super) fn seek_to_block_entry(&mut self, block: BasicBlock) {
94+
#[cfg(debug_assertions)]
95+
assert!(self.reachable_blocks.contains(block));
96+
8897
self.state.overwrite(&self.results.borrow().entry_set_for_block(block));
8998
self.pos = CursorPosition::block_entry(block);
9099
self.state_needs_reset = false;

src/librustc_mir/dataflow/framework/engine.rs

-9
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,6 @@ where
213213
}
214214
}
215215

216-
// Add blocks that are not reachable from START_BLOCK to the work queue. These blocks will
217-
// be processed after the ones added above.
218-
//
219-
// FIXME(ecstaticmorse): Is this actually necessary? In principle, we shouldn't need to
220-
// know the dataflow state in unreachable basic blocks.
221-
for bb in body.basic_blocks().indices() {
222-
dirty_queue.insert(bb);
223-
}
224-
225216
let mut state = BitSet::new_empty(bits_per_block);
226217
while let Some(bb) = dirty_queue.pop() {
227218
let bb_data = &body[bb];

src/librustc_mir/dataflow/framework/visitor.rs

+6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ pub fn visit_results<F, V>(
1616
{
1717
let mut state = results.new_flow_state(body);
1818

19+
#[cfg(debug_assertions)]
20+
let reachable_blocks = mir::traversal::reachable_as_bitset(body);
21+
1922
for block in blocks {
23+
#[cfg(debug_assertions)]
24+
assert!(reachable_blocks.contains(block));
25+
2026
let block_data = &body[block];
2127
V::Direction::visit_results_in_block(&mut state, block, block_data, results, vis);
2228
}

0 commit comments

Comments
 (0)