diff options
Diffstat (limited to 'compiler/rustc_data_structures/src/graph/dominators/mod.rs')
-rw-r--r-- | compiler/rustc_data_structures/src/graph/dominators/mod.rs | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/compiler/rustc_data_structures/src/graph/dominators/mod.rs b/compiler/rustc_data_structures/src/graph/dominators/mod.rs index 00913a483..471457f61 100644 --- a/compiler/rustc_data_structures/src/graph/dominators/mod.rs +++ b/compiler/rustc_data_structures/src/graph/dominators/mod.rs @@ -22,7 +22,7 @@ struct PreOrderFrame<Iter> { } rustc_index::newtype_index! { - struct PreorderIndex { .. } + struct PreorderIndex {} } pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> { @@ -135,7 +135,10 @@ pub fn dominators<G: ControlFlowGraph>(graph: G) -> Dominators<G::Node> { // This loop computes the semi[w] for w. semi[w] = w; for v in graph.predecessors(pre_order_to_real[w]) { - let v = real_to_pre_order[v].unwrap(); + // Reachable vertices may have unreachable predecessors, so ignore any of them + let Some(v) = real_to_pre_order[v] else { + continue + }; // eval returns a vertex x from which semi[x] is minimum among // vertices semi[v] +> x *> v. @@ -268,21 +271,17 @@ pub struct Dominators<N: Idx> { } impl<Node: Idx> Dominators<Node> { - pub fn dummy() -> Self { - Self { post_order_rank: IndexVec::new(), immediate_dominators: IndexVec::new() } - } - pub fn is_reachable(&self, node: Node) -> bool { self.immediate_dominators[node].is_some() } pub fn immediate_dominator(&self, node: Node) -> Node { - assert!(self.is_reachable(node), "node {:?} is not reachable", node); + assert!(self.is_reachable(node), "node {node:?} is not reachable"); self.immediate_dominators[node].unwrap() } pub fn dominators(&self, node: Node) -> Iter<'_, Node> { - assert!(self.is_reachable(node), "node {:?} is not reachable", node); + assert!(self.is_reachable(node), "node {node:?} is not reachable"); Iter { dominators: self, node: Some(node) } } @@ -296,7 +295,7 @@ impl<Node: Idx> Dominators<Node> { /// of two unrelated nodes will also be consistent, but otherwise the order has no /// meaning.) This method cannot be used to determine if either Node dominates the other. pub fn rank_partial_cmp(&self, lhs: Node, rhs: Node) -> Option<Ordering> { - self.post_order_rank[lhs].partial_cmp(&self.post_order_rank[rhs]) + self.post_order_rank[rhs].partial_cmp(&self.post_order_rank[lhs]) } } |