Skip to content

Commit 1d2aa4d

Browse files
authored
Rollup merge of #143769 - tmiasko:rm-backward-switch-int, r=lqd
Remove support for SwitchInt edge effects in backward dataflow Those effects are untested and unused. Remove them along with the implementation of `BasicBlocks::switch_sources`.
2 parents 8c5f3e4 + 5b6d661 commit 1d2aa4d

File tree

2 files changed

+7
-48
lines changed

2 files changed

+7
-48
lines changed

compiler/rustc_middle/src/mir/basic_blocks.rs

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::sync::OnceLock;
22

3-
use rustc_data_structures::fx::FxHashMap;
43
use rustc_data_structures::graph;
54
use rustc_data_structures::graph::dominators::{Dominators, dominators};
65
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
@@ -10,7 +9,7 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
109
use smallvec::SmallVec;
1110

1211
use crate::mir::traversal::Postorder;
13-
use crate::mir::{BasicBlock, BasicBlockData, START_BLOCK, Terminator, TerminatorKind};
12+
use crate::mir::{BasicBlock, BasicBlockData, START_BLOCK};
1413

1514
#[derive(Clone, TyEncodable, TyDecodable, Debug, HashStable, TypeFoldable, TypeVisitable)]
1615
pub struct BasicBlocks<'tcx> {
@@ -21,15 +20,6 @@ pub struct BasicBlocks<'tcx> {
2120
// Typically 95%+ of basic blocks have 4 or fewer predecessors.
2221
type Predecessors = IndexVec<BasicBlock, SmallVec<[BasicBlock; 4]>>;
2322

24-
/// Each `(target, switch)` entry in the map contains a list of switch values
25-
/// that lead to a `target` block from a `switch` block.
26-
///
27-
/// Note: this type is currently never instantiated, because it's only used for
28-
/// `BasicBlocks::switch_sources`, which is only called by backwards analyses
29-
/// that do `SwitchInt` handling, and we don't have any of those, not even in
30-
/// tests. See #95120 and #94576.
31-
type SwitchSources = FxHashMap<(BasicBlock, BasicBlock), SmallVec<[SwitchTargetValue; 1]>>;
32-
3323
#[derive(Debug, Clone, Copy)]
3424
pub enum SwitchTargetValue {
3525
// A normal switch value.
@@ -41,7 +31,6 @@ pub enum SwitchTargetValue {
4131
#[derive(Clone, Default, Debug)]
4232
struct Cache {
4333
predecessors: OnceLock<Predecessors>,
44-
switch_sources: OnceLock<SwitchSources>,
4534
reverse_postorder: OnceLock<Vec<BasicBlock>>,
4635
dominators: OnceLock<Dominators<BasicBlock>>,
4736
}
@@ -86,33 +75,6 @@ impl<'tcx> BasicBlocks<'tcx> {
8675
})
8776
}
8877

89-
/// Returns info about switch values that lead from one block to another
90-
/// block. See `SwitchSources`.
91-
#[inline]
92-
pub fn switch_sources(&self) -> &SwitchSources {
93-
self.cache.switch_sources.get_or_init(|| {
94-
let mut switch_sources: SwitchSources = FxHashMap::default();
95-
for (bb, data) in self.basic_blocks.iter_enumerated() {
96-
if let Some(Terminator {
97-
kind: TerminatorKind::SwitchInt { targets, .. }, ..
98-
}) = &data.terminator
99-
{
100-
for (value, target) in targets.iter() {
101-
switch_sources
102-
.entry((target, bb))
103-
.or_default()
104-
.push(SwitchTargetValue::Normal(value));
105-
}
106-
switch_sources
107-
.entry((targets.otherwise(), bb))
108-
.or_default()
109-
.push(SwitchTargetValue::Otherwise);
110-
}
111-
}
112-
switch_sources
113-
})
114-
}
115-
11678
/// Returns mutable reference to basic blocks. Invalidates CFG cache.
11779
#[inline]
11880
pub fn as_mut(&mut self) -> &mut IndexVec<BasicBlock, BasicBlockData<'tcx>> {

compiler/rustc_mir_dataflow/src/framework/direction.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::ops::RangeInclusive;
22

3+
use rustc_middle::bug;
34
use rustc_middle::mir::{
45
self, BasicBlock, CallReturnPlaces, Location, SwitchTargetValue, TerminatorEdges,
56
};
@@ -112,15 +113,11 @@ impl Direction for Backward {
112113
propagate(pred, &tmp);
113114
}
114115

115-
mir::TerminatorKind::SwitchInt { ref targets, ref discr } => {
116-
if let Some(mut data) = analysis.get_switch_int_data(block, discr) {
117-
let mut tmp = analysis.bottom_value(body);
118-
for &value in &body.basic_blocks.switch_sources()[&(block, pred)] {
119-
tmp.clone_from(exit_state);
120-
analysis
121-
.apply_switch_int_edge_effect(&mut data, &mut tmp, value, targets);
122-
propagate(pred, &tmp);
123-
}
116+
mir::TerminatorKind::SwitchInt { ref discr, .. } => {
117+
if let Some(_data) = analysis.get_switch_int_data(pred, discr) {
118+
bug!(
119+
"SwitchInt edge effects are unsupported in backward dataflow analyses"
120+
);
124121
} else {
125122
propagate(pred, exit_state)
126123
}

0 commit comments

Comments
 (0)