From aa1267f630e01d19dcd9247ffb3a795aba0df461 Mon Sep 17 00:00:00 2001 From: Tomasz Miąsko Date: Sat, 21 Jan 2023 00:00:00 +0000 Subject: Preprocess dominator tree to answer queries in O(1) --- .../src/graph/dominators/mod.rs | 107 ++++++++++++++++++--- .../src/graph/dominators/tests.rs | 20 ++-- 2 files changed, 105 insertions(+), 22 deletions(-) (limited to 'compiler/rustc_data_structures') diff --git a/compiler/rustc_data_structures/src/graph/dominators/mod.rs b/compiler/rustc_data_structures/src/graph/dominators/mod.rs index a7de709ba72..5d6a1de1d21 100644 --- a/compiler/rustc_data_structures/src/graph/dominators/mod.rs +++ b/compiler/rustc_data_structures/src/graph/dominators/mod.rs @@ -26,7 +26,7 @@ rustc_index::newtype_index! { struct PreorderIndex {} } -pub fn dominators(graph: G) -> Dominators { +pub fn dominator_tree(graph: G) -> DominatorTree { // compute the post order index (rank) for each node let mut post_order_rank = IndexVec::from_elem_n(0, graph.num_nodes()); @@ -244,7 +244,7 @@ pub fn dominators(graph: G) -> Dominators { let start_node = graph.start_node(); immediate_dominators[start_node] = None; - Dominators { start_node, post_order_rank, immediate_dominators } + DominatorTree { start_node, post_order_rank, immediate_dominators } } /// Evaluate the link-eval virtual forest, providing the currently minimum semi @@ -309,16 +309,18 @@ fn compress( /// Tracks the list of dominators for each node. #[derive(Clone, Debug)] -pub struct Dominators { +pub struct DominatorTree { start_node: N, post_order_rank: IndexVec, // Even though we track only the immediate dominator of each node, it's // possible to get its full list of dominators by looking up the dominator // of each dominator. (See the `impl Iterator for Iter` definition). + // + // Note: immediate_dominators[root] is Some(root)! immediate_dominators: IndexVec>, } -impl Dominators { +impl DominatorTree { /// Returns true if node is reachable from the start node. pub fn is_reachable(&self, node: Node) -> bool { node == self.start_node || self.immediate_dominators[node].is_some() @@ -333,12 +335,7 @@ impl Dominators { /// See the `impl Iterator for Iter` definition to understand how this works. pub fn dominators(&self, node: Node) -> Iter<'_, Node> { assert!(self.is_reachable(node), "node {node:?} is not reachable"); - Iter { dominators: self, node: Some(node) } - } - - pub fn dominates(&self, dom: Node, node: Node) -> bool { - // FIXME -- could be optimized by using post-order-rank - self.dominators(node).any(|n| n == dom) + Iter { dom_tree: self, node: Some(node) } } /// Provide deterministic ordering of nodes such that, if any two nodes have a dominator @@ -351,7 +348,7 @@ impl Dominators { } pub struct Iter<'dom, Node: Idx> { - dominators: &'dom Dominators, + dom_tree: &'dom DominatorTree, node: Option, } @@ -360,10 +357,96 @@ impl<'dom, Node: Idx> Iterator for Iter<'dom, Node> { fn next(&mut self) -> Option { if let Some(node) = self.node { - self.node = self.dominators.immediate_dominator(node); + self.node = self.dom_tree.immediate_dominator(node); Some(node) } else { None } } } + +#[derive(Clone, Debug)] +pub struct Dominators { + time: IndexVec, +} + +/// Describes the number of vertices discovered at the time when processing of a particular vertex +/// started and when it finished. Both values are zero for unreachable vertices. +#[derive(Copy, Clone, Default, Debug)] +struct Time { + start: u32, + finish: u32, +} + +impl Dominators { + pub fn dummy() -> Self { + Self { time: Default::default() } + } + + /// Returns true if `a` dominates `b`. + /// + /// # Panics + /// + /// Panics if `b` is unreachable. + pub fn dominates(&self, a: Node, b: Node) -> bool { + let a = self.time[a]; + let b = self.time[b]; + assert!(b.start != 0, "node {b:?} is not reachable"); + a.start <= b.start && b.finish <= a.finish + } +} + +pub fn dominators(tree: &DominatorTree) -> Dominators { + let DominatorTree { start_node, ref immediate_dominators, post_order_rank: _ } = *tree; + + // Transpose the dominator tree edges, so that child nodes of vertex v are stored in + // node[edges[v].start..edges[y].end]. + let mut edges: IndexVec> = + IndexVec::from_elem(0..0, immediate_dominators); + for &idom in immediate_dominators.iter() { + if let Some(idom) = idom { + edges[idom].end += 1; + } + } + let mut m = 0; + for e in edges.iter_mut() { + m += e.end; + e.start = m; + e.end = m; + } + let mut node = IndexVec::from_elem_n(Idx::new(0), m.try_into().unwrap()); + for (i, &idom) in immediate_dominators.iter_enumerated() { + if let Some(idom) = idom { + edges[idom].start -= 1; + node[edges[idom].start] = i; + } + } + + // Perform a depth-first search of the dominator tree. Record the number of vertices discovered + // when vertex v is discovered first as time[v].start, and when its processing is finished as + // time[v].finish. + let mut time: IndexVec = IndexVec::from_elem(Time::default(), immediate_dominators); + let mut stack = Vec::new(); + + let mut discovered = 1; + stack.push(start_node); + time[start_node].start = discovered; + + while let Some(&i) = stack.last() { + let e = &mut edges[i]; + if e.start == e.end { + // Finish processing vertex i. + time[i].finish = discovered; + stack.pop(); + } else { + let j = node[e.start]; + e.start += 1; + // Start processing vertex j. + discovered += 1; + time[j].start = discovered; + stack.push(j); + } + } + + Dominators { time } +} diff --git a/compiler/rustc_data_structures/src/graph/dominators/tests.rs b/compiler/rustc_data_structures/src/graph/dominators/tests.rs index 8b124516623..61a21724dda 100644 --- a/compiler/rustc_data_structures/src/graph/dominators/tests.rs +++ b/compiler/rustc_data_structures/src/graph/dominators/tests.rs @@ -6,8 +6,8 @@ use super::super::tests::TestGraph; fn diamond() { let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3)]); - let dominators = dominators(&graph); - let immediate_dominators = &dominators.immediate_dominators; + let tree = dominator_tree(&graph); + let immediate_dominators = &tree.immediate_dominators; assert_eq!(immediate_dominators[0], None); assert_eq!(immediate_dominators[1], Some(0)); assert_eq!(immediate_dominators[2], Some(0)); @@ -22,8 +22,8 @@ fn paper() { &[(6, 5), (6, 4), (5, 1), (4, 2), (4, 3), (1, 2), (2, 3), (3, 2), (2, 1)], ); - let dominators = dominators(&graph); - let immediate_dominators = &dominators.immediate_dominators; + let dom_tree = dominator_tree(&graph); + let immediate_dominators = &dom_tree.immediate_dominators; assert_eq!(immediate_dominators[0], None); // <-- note that 0 is not in graph assert_eq!(immediate_dominators[1], Some(6)); assert_eq!(immediate_dominators[2], Some(6)); @@ -41,15 +41,15 @@ fn paper_slt() { &[(1, 2), (1, 3), (2, 3), (2, 7), (3, 4), (3, 6), (4, 5), (5, 4), (6, 7), (7, 8), (8, 5)], ); - dominators(&graph); + dominator_tree(&graph); } #[test] fn immediate_dominator() { let graph = TestGraph::new(1, &[(1, 2), (2, 3)]); - let dominators = dominators(&graph); - assert_eq!(dominators.immediate_dominator(0), None); - assert_eq!(dominators.immediate_dominator(1), None); - assert_eq!(dominators.immediate_dominator(2), Some(1)); - assert_eq!(dominators.immediate_dominator(3), Some(2)); + let tree = dominator_tree(&graph); + assert_eq!(tree.immediate_dominator(0), None); + assert_eq!(tree.immediate_dominator(1), None); + assert_eq!(tree.immediate_dominator(2), Some(1)); + assert_eq!(tree.immediate_dominator(3), Some(2)); } -- cgit 1.4.1-3-g733a5 From ae318e34449c0b8d92f4067d68fda604bac5da82 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 17 May 2023 10:26:04 +0000 Subject: Remove outdated comment. --- compiler/rustc_data_structures/src/graph/dominators/mod.rs | 2 -- 1 file changed, 2 deletions(-) (limited to 'compiler/rustc_data_structures') diff --git a/compiler/rustc_data_structures/src/graph/dominators/mod.rs b/compiler/rustc_data_structures/src/graph/dominators/mod.rs index 5d6a1de1d21..5c5c803cc06 100644 --- a/compiler/rustc_data_structures/src/graph/dominators/mod.rs +++ b/compiler/rustc_data_structures/src/graph/dominators/mod.rs @@ -315,8 +315,6 @@ pub struct DominatorTree { // Even though we track only the immediate dominator of each node, it's // possible to get its full list of dominators by looking up the dominator // of each dominator. (See the `impl Iterator for Iter` definition). - // - // Note: immediate_dominators[root] is Some(root)! immediate_dominators: IndexVec>, } -- cgit 1.4.1-3-g733a5 From 4bbdb64016a0a7e1713d7c35b40ed931a47e4d8c Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 17 May 2023 10:29:12 +0000 Subject: Typo. --- compiler/rustc_data_structures/src/graph/dominators/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler/rustc_data_structures') diff --git a/compiler/rustc_data_structures/src/graph/dominators/mod.rs b/compiler/rustc_data_structures/src/graph/dominators/mod.rs index 5c5c803cc06..2112b7bcbe3 100644 --- a/compiler/rustc_data_structures/src/graph/dominators/mod.rs +++ b/compiler/rustc_data_structures/src/graph/dominators/mod.rs @@ -398,7 +398,7 @@ pub fn dominators(tree: &DominatorTree) -> Dominators { let DominatorTree { start_node, ref immediate_dominators, post_order_rank: _ } = *tree; // Transpose the dominator tree edges, so that child nodes of vertex v are stored in - // node[edges[v].start..edges[y].end]. + // node[edges[v].start..edges[v].end]. let mut edges: IndexVec> = IndexVec::from_elem(0..0, immediate_dominators); for &idom in immediate_dominators.iter() { -- cgit 1.4.1-3-g733a5 From fa8598cb5066b3463d53682170cc695af2c1b380 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 17 May 2023 10:37:29 +0000 Subject: Merge DominatorTree and Dominators. --- .../rustc_const_eval/src/transform/validate.rs | 2 +- .../src/graph/dominators/mod.rs | 58 ++++++++++------------ .../src/graph/dominators/tests.rs | 8 +-- compiler/rustc_middle/src/mir/basic_blocks.rs | 8 +-- compiler/rustc_mir_transform/src/coverage/graph.rs | 19 ++----- compiler/rustc_mir_transform/src/ctfe_limit.rs | 6 +-- 6 files changed, 40 insertions(+), 61 deletions(-) (limited to 'compiler/rustc_data_structures') diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 2d8cbea8bac..fae3589e6f1 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -155,7 +155,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { if self.unwind_edge_count <= 1 { return; } - let dom_tree = self.body.basic_blocks.dominator_tree(); + let dom_tree = self.body.basic_blocks.dominators(); let mut post_contract_node = FxHashMap::default(); // Reusing the allocation across invocations of the closure let mut dom_path = vec![]; diff --git a/compiler/rustc_data_structures/src/graph/dominators/mod.rs b/compiler/rustc_data_structures/src/graph/dominators/mod.rs index 2112b7bcbe3..4868f49d8d5 100644 --- a/compiler/rustc_data_structures/src/graph/dominators/mod.rs +++ b/compiler/rustc_data_structures/src/graph/dominators/mod.rs @@ -26,7 +26,7 @@ rustc_index::newtype_index! { struct PreorderIndex {} } -pub fn dominator_tree(graph: G) -> DominatorTree { +pub fn dominators(graph: &G) -> Dominators { // compute the post order index (rank) for each node let mut post_order_rank = IndexVec::from_elem_n(0, graph.num_nodes()); @@ -244,7 +244,10 @@ pub fn dominator_tree(graph: G) -> DominatorTree { let start_node = graph.start_node(); immediate_dominators[start_node] = None; - DominatorTree { start_node, post_order_rank, immediate_dominators } + + let time = compute_access_time(start_node, &immediate_dominators); + + Dominators { start_node, post_order_rank, immediate_dominators, time } } /// Evaluate the link-eval virtual forest, providing the currently minimum semi @@ -309,16 +312,17 @@ fn compress( /// Tracks the list of dominators for each node. #[derive(Clone, Debug)] -pub struct DominatorTree { +pub struct Dominators { start_node: N, post_order_rank: IndexVec, // Even though we track only the immediate dominator of each node, it's // possible to get its full list of dominators by looking up the dominator // of each dominator. (See the `impl Iterator for Iter` definition). immediate_dominators: IndexVec>, + time: IndexVec, } -impl DominatorTree { +impl Dominators { /// Returns true if node is reachable from the start node. pub fn is_reachable(&self, node: Node) -> bool { node == self.start_node || self.immediate_dominators[node].is_some() @@ -343,10 +347,22 @@ impl DominatorTree { pub fn rank_partial_cmp(&self, lhs: Node, rhs: Node) -> Option { self.post_order_rank[rhs].partial_cmp(&self.post_order_rank[lhs]) } + + /// Returns true if `a` dominates `b`. + /// + /// # Panics + /// + /// Panics if `b` is unreachable. + pub fn dominates(&self, a: Node, b: Node) -> bool { + let a = self.time[a]; + let b = self.time[b]; + assert!(b.start != 0, "node {b:?} is not reachable"); + a.start <= b.start && b.finish <= a.finish + } } pub struct Iter<'dom, Node: Idx> { - dom_tree: &'dom DominatorTree, + dom_tree: &'dom Dominators, node: Option, } @@ -363,11 +379,6 @@ impl<'dom, Node: Idx> Iterator for Iter<'dom, Node> { } } -#[derive(Clone, Debug)] -pub struct Dominators { - time: IndexVec, -} - /// Describes the number of vertices discovered at the time when processing of a particular vertex /// started and when it finished. Both values are zero for unreachable vertices. #[derive(Copy, Clone, Default, Debug)] @@ -376,27 +387,10 @@ struct Time { finish: u32, } -impl Dominators { - pub fn dummy() -> Self { - Self { time: Default::default() } - } - - /// Returns true if `a` dominates `b`. - /// - /// # Panics - /// - /// Panics if `b` is unreachable. - pub fn dominates(&self, a: Node, b: Node) -> bool { - let a = self.time[a]; - let b = self.time[b]; - assert!(b.start != 0, "node {b:?} is not reachable"); - a.start <= b.start && b.finish <= a.finish - } -} - -pub fn dominators(tree: &DominatorTree) -> Dominators { - let DominatorTree { start_node, ref immediate_dominators, post_order_rank: _ } = *tree; - +fn compute_access_time( + start_node: N, + immediate_dominators: &IndexSlice>, +) -> IndexVec { // Transpose the dominator tree edges, so that child nodes of vertex v are stored in // node[edges[v].start..edges[v].end]. let mut edges: IndexVec> = @@ -446,5 +440,5 @@ pub fn dominators(tree: &DominatorTree) -> Dominators { } } - Dominators { time } + time } diff --git a/compiler/rustc_data_structures/src/graph/dominators/tests.rs b/compiler/rustc_data_structures/src/graph/dominators/tests.rs index 61a21724dda..31531fe3e2a 100644 --- a/compiler/rustc_data_structures/src/graph/dominators/tests.rs +++ b/compiler/rustc_data_structures/src/graph/dominators/tests.rs @@ -6,7 +6,7 @@ use super::super::tests::TestGraph; fn diamond() { let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3)]); - let tree = dominator_tree(&graph); + let tree = dominators(&graph); let immediate_dominators = &tree.immediate_dominators; assert_eq!(immediate_dominators[0], None); assert_eq!(immediate_dominators[1], Some(0)); @@ -22,7 +22,7 @@ fn paper() { &[(6, 5), (6, 4), (5, 1), (4, 2), (4, 3), (1, 2), (2, 3), (3, 2), (2, 1)], ); - let dom_tree = dominator_tree(&graph); + let dom_tree = dominators(&graph); let immediate_dominators = &dom_tree.immediate_dominators; assert_eq!(immediate_dominators[0], None); // <-- note that 0 is not in graph assert_eq!(immediate_dominators[1], Some(6)); @@ -41,13 +41,13 @@ fn paper_slt() { &[(1, 2), (1, 3), (2, 3), (2, 7), (3, 4), (3, 6), (4, 5), (5, 4), (6, 7), (7, 8), (8, 5)], ); - dominator_tree(&graph); + dominators(&graph); } #[test] fn immediate_dominator() { let graph = TestGraph::new(1, &[(1, 2), (2, 3)]); - let tree = dominator_tree(&graph); + let tree = dominators(&graph); assert_eq!(tree.immediate_dominator(0), None); assert_eq!(tree.immediate_dominator(1), None); assert_eq!(tree.immediate_dominator(2), Some(1)); diff --git a/compiler/rustc_middle/src/mir/basic_blocks.rs b/compiler/rustc_middle/src/mir/basic_blocks.rs index 27a43c0a0e9..9d70dbfa072 100644 --- a/compiler/rustc_middle/src/mir/basic_blocks.rs +++ b/compiler/rustc_middle/src/mir/basic_blocks.rs @@ -3,7 +3,6 @@ use crate::mir::{BasicBlock, BasicBlockData, Successors, Terminator, TerminatorK use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::graph; -use rustc_data_structures::graph::dominators::{dominator_tree, DominatorTree}; use rustc_data_structures::graph::dominators::{dominators, Dominators}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_data_structures::sync::OnceCell; @@ -28,7 +27,6 @@ struct Cache { switch_sources: OnceCell, is_cyclic: OnceCell, postorder: OnceCell>, - dominator_tree: OnceCell>, dominators: OnceCell>, } @@ -44,12 +42,8 @@ impl<'tcx> BasicBlocks<'tcx> { *self.cache.is_cyclic.get_or_init(|| graph::is_cyclic(self)) } - pub fn dominator_tree(&self) -> &DominatorTree { - self.cache.dominator_tree.get_or_init(|| dominator_tree(&self)) - } - pub fn dominators(&self) -> &Dominators { - self.cache.dominators.get_or_init(|| dominators(self.dominator_tree())) + self.cache.dominators.get_or_init(|| dominators(self)) } /// Returns predecessors for each basic block. diff --git a/compiler/rustc_mir_transform/src/coverage/graph.rs b/compiler/rustc_mir_transform/src/coverage/graph.rs index 0126310e9ff..ea1223fbca6 100644 --- a/compiler/rustc_mir_transform/src/coverage/graph.rs +++ b/compiler/rustc_mir_transform/src/coverage/graph.rs @@ -2,7 +2,7 @@ use super::Error; use itertools::Itertools; use rustc_data_structures::fx::FxHashMap; -use rustc_data_structures::graph::dominators::{self, DominatorTree, Dominators}; +use rustc_data_structures::graph::dominators::{self, Dominators}; use rustc_data_structures::graph::{self, GraphSuccessors, WithNumNodes, WithStartNode}; use rustc_index::bit_set::BitSet; use rustc_index::{IndexSlice, IndexVec}; @@ -25,7 +25,6 @@ pub(super) struct CoverageGraph { bb_to_bcb: IndexVec>, pub successors: IndexVec>, pub predecessors: IndexVec>, - dominator_tree: Option>, dominators: Option>, } @@ -68,17 +67,9 @@ impl CoverageGraph { } } - let mut basic_coverage_blocks = Self { - bcbs, - bb_to_bcb, - successors, - predecessors, - dominator_tree: None, - dominators: None, - }; - let dominator_tree = dominators::dominator_tree(&basic_coverage_blocks); - let dominators = dominators::dominators(&dominator_tree); - basic_coverage_blocks.dominator_tree = Some(dominator_tree); + let mut basic_coverage_blocks = + Self { bcbs, bb_to_bcb, successors, predecessors, dominators: None }; + let dominators = dominators::dominators(&basic_coverage_blocks); basic_coverage_blocks.dominators = Some(dominators); basic_coverage_blocks } @@ -227,7 +218,7 @@ impl CoverageGraph { a: BasicCoverageBlock, b: BasicCoverageBlock, ) -> Option { - self.dominator_tree.as_ref().unwrap().rank_partial_cmp(a, b) + self.dominators.as_ref().unwrap().rank_partial_cmp(a, b) } } diff --git a/compiler/rustc_mir_transform/src/ctfe_limit.rs b/compiler/rustc_mir_transform/src/ctfe_limit.rs index a5b3873533c..1b3ac78fbc6 100644 --- a/compiler/rustc_mir_transform/src/ctfe_limit.rs +++ b/compiler/rustc_mir_transform/src/ctfe_limit.rs @@ -2,7 +2,7 @@ //! (thus indicating there is a loop in the CFG), or whose terminator is a function call. use crate::MirPass; -use rustc_data_structures::graph::dominators::DominatorTree; +use rustc_data_structures::graph::dominators::Dominators; use rustc_middle::mir::{ BasicBlock, BasicBlockData, Body, Statement, StatementKind, TerminatorKind, }; @@ -13,7 +13,7 @@ pub struct CtfeLimit; impl<'tcx> MirPass<'tcx> for CtfeLimit { #[instrument(skip(self, _tcx, body))] fn run_pass(&self, _tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let doms = body.basic_blocks.dominator_tree(); + let doms = body.basic_blocks.dominators(); let indices: Vec = body .basic_blocks .iter_enumerated() @@ -39,7 +39,7 @@ impl<'tcx> MirPass<'tcx> for CtfeLimit { } fn has_back_edge( - doms: &DominatorTree, + doms: &Dominators, node: BasicBlock, node_data: &BasicBlockData<'_>, ) -> bool { -- cgit 1.4.1-3-g733a5 From 7c8f29f02c279acfa7b0c353e2187ad268e25de8 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Thu, 18 May 2023 14:36:13 +0000 Subject: Revert spurious changes. --- compiler/rustc_const_eval/src/transform/validate.rs | 4 ++-- .../src/graph/dominators/tests.rs | 18 +++++++++--------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'compiler/rustc_data_structures') diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index fae3589e6f1..3c350e25ba6 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -155,7 +155,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { if self.unwind_edge_count <= 1 { return; } - let dom_tree = self.body.basic_blocks.dominators(); + let doms = self.body.basic_blocks.dominators(); let mut post_contract_node = FxHashMap::default(); // Reusing the allocation across invocations of the closure let mut dom_path = vec![]; @@ -164,7 +164,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { if let Some(root) = post_contract_node.get(&bb) { break *root; } - let parent = dom_tree.immediate_dominator(bb).unwrap(); + let parent = doms.immediate_dominator(bb).unwrap(); dom_path.push(bb); if !self.body.basic_blocks[parent].is_cleanup { break bb; diff --git a/compiler/rustc_data_structures/src/graph/dominators/tests.rs b/compiler/rustc_data_structures/src/graph/dominators/tests.rs index 31531fe3e2a..8b124516623 100644 --- a/compiler/rustc_data_structures/src/graph/dominators/tests.rs +++ b/compiler/rustc_data_structures/src/graph/dominators/tests.rs @@ -6,8 +6,8 @@ use super::super::tests::TestGraph; fn diamond() { let graph = TestGraph::new(0, &[(0, 1), (0, 2), (1, 3), (2, 3)]); - let tree = dominators(&graph); - let immediate_dominators = &tree.immediate_dominators; + let dominators = dominators(&graph); + let immediate_dominators = &dominators.immediate_dominators; assert_eq!(immediate_dominators[0], None); assert_eq!(immediate_dominators[1], Some(0)); assert_eq!(immediate_dominators[2], Some(0)); @@ -22,8 +22,8 @@ fn paper() { &[(6, 5), (6, 4), (5, 1), (4, 2), (4, 3), (1, 2), (2, 3), (3, 2), (2, 1)], ); - let dom_tree = dominators(&graph); - let immediate_dominators = &dom_tree.immediate_dominators; + let dominators = dominators(&graph); + let immediate_dominators = &dominators.immediate_dominators; assert_eq!(immediate_dominators[0], None); // <-- note that 0 is not in graph assert_eq!(immediate_dominators[1], Some(6)); assert_eq!(immediate_dominators[2], Some(6)); @@ -47,9 +47,9 @@ fn paper_slt() { #[test] fn immediate_dominator() { let graph = TestGraph::new(1, &[(1, 2), (2, 3)]); - let tree = dominators(&graph); - assert_eq!(tree.immediate_dominator(0), None); - assert_eq!(tree.immediate_dominator(1), None); - assert_eq!(tree.immediate_dominator(2), Some(1)); - assert_eq!(tree.immediate_dominator(3), Some(2)); + let dominators = dominators(&graph); + assert_eq!(dominators.immediate_dominator(0), None); + assert_eq!(dominators.immediate_dominator(1), None); + assert_eq!(dominators.immediate_dominator(2), Some(1)); + assert_eq!(dominators.immediate_dominator(3), Some(2)); } -- cgit 1.4.1-3-g733a5