about summary refs log tree commit diff
path: root/src/librustc_data_structures/control_flow_graph
diff options
context:
space:
mode:
authorVadim Petrochenkov <vadim.petrochenkov@gmail.com>2017-08-19 03:09:55 +0300
committerVadim Petrochenkov <vadim.petrochenkov@gmail.com>2017-08-19 13:27:16 +0300
commitde4dbe5789d1a4f11c50aa891f9c9cad13860370 (patch)
tree2278fa59ab2ac96c137bc70ad98d8466bae3bb20 /src/librustc_data_structures/control_flow_graph
parent7f397bdb062fe13a4707219a2f32486c5294f642 (diff)
rustc: Remove some dead code
Diffstat (limited to 'src/librustc_data_structures/control_flow_graph')
-rw-r--r--src/librustc_data_structures/control_flow_graph/dominators/mod.rs79
-rw-r--r--src/librustc_data_structures/control_flow_graph/iterate/mod.rs16
-rw-r--r--src/librustc_data_structures/control_flow_graph/iterate/test.rs20
-rw-r--r--src/librustc_data_structures/control_flow_graph/mod.rs3
-rw-r--r--src/librustc_data_structures/control_flow_graph/reachable/mod.rs62
-rw-r--r--src/librustc_data_structures/control_flow_graph/reachable/test.rs50
-rw-r--r--src/librustc_data_structures/control_flow_graph/transpose.rs64
7 files changed, 2 insertions, 292 deletions
diff --git a/src/librustc_data_structures/control_flow_graph/dominators/mod.rs b/src/librustc_data_structures/control_flow_graph/dominators/mod.rs
index 65dd336fdbd..90670517f59 100644
--- a/src/librustc_data_structures/control_flow_graph/dominators/mod.rs
+++ b/src/librustc_data_structures/control_flow_graph/dominators/mod.rs
@@ -134,56 +134,10 @@ impl<Node: Idx> Dominators<Node> {
         self.dominators(node).any(|n| n == dom)
     }
 
-    pub fn mutual_dominator_node(&self, node1: Node, node2: Node) -> Node {
-        assert!(self.is_reachable(node1),
-                "node {:?} is not reachable",
-                node1);
-        assert!(self.is_reachable(node2),
-                "node {:?} is not reachable",
-                node2);
-        intersect::<Node>(&self.post_order_rank,
-                          &self.immediate_dominators,
-                          node1,
-                          node2)
-    }
-
-    pub fn mutual_dominator<I>(&self, iter: I) -> Option<Node>
-        where I: IntoIterator<Item = Node>
-    {
-        let mut iter = iter.into_iter();
-        iter.next()
-            .map(|dom| iter.fold(dom, |dom, node| self.mutual_dominator_node(dom, node)))
-    }
-
-    pub fn all_immediate_dominators(&self) -> &IndexVec<Node, Option<Node>> {
+    #[cfg(test)]
+    fn all_immediate_dominators(&self) -> &IndexVec<Node, Option<Node>> {
         &self.immediate_dominators
     }
-
-    pub fn dominator_tree(&self) -> DominatorTree<Node> {
-        let elem: Vec<Node> = Vec::new();
-        let mut children: IndexVec<Node, Vec<Node>> =
-            IndexVec::from_elem_n(elem, self.immediate_dominators.len());
-        let mut root = None;
-        for (index, immed_dom) in self.immediate_dominators.iter().enumerate() {
-            let node = Node::new(index);
-            match *immed_dom {
-                None => {
-                    // node not reachable
-                }
-                Some(immed_dom) => {
-                    if node == immed_dom {
-                        root = Some(node);
-                    } else {
-                        children[immed_dom].push(node);
-                    }
-                }
-            }
-        }
-        DominatorTree {
-            root: root.unwrap(),
-            children,
-        }
-    }
 }
 
 pub struct Iter<'dom, Node: Idx + 'dom> {
@@ -215,38 +169,9 @@ pub struct DominatorTree<N: Idx> {
 }
 
 impl<Node: Idx> DominatorTree<Node> {
-    pub fn root(&self) -> Node {
-        self.root
-    }
-
     pub fn children(&self, node: Node) -> &[Node] {
         &self.children[node]
     }
-
-    pub fn iter_children_of(&self, node: Node) -> IterChildrenOf<Node> {
-        IterChildrenOf {
-            tree: self,
-            stack: vec![node],
-        }
-    }
-}
-
-pub struct IterChildrenOf<'iter, Node: Idx + 'iter> {
-    tree: &'iter DominatorTree<Node>,
-    stack: Vec<Node>,
-}
-
-impl<'iter, Node: Idx> Iterator for IterChildrenOf<'iter, Node> {
-    type Item = Node;
-
-    fn next(&mut self) -> Option<Node> {
-        if let Some(node) = self.stack.pop() {
-            self.stack.extend(self.tree.children(node));
-            Some(node)
-        } else {
-            None
-        }
-    }
 }
 
 impl<Node: Idx> fmt::Debug for DominatorTree<Node> {
diff --git a/src/librustc_data_structures/control_flow_graph/iterate/mod.rs b/src/librustc_data_structures/control_flow_graph/iterate/mod.rs
index 11b557cbcad..2d70b406342 100644
--- a/src/librustc_data_structures/control_flow_graph/iterate/mod.rs
+++ b/src/librustc_data_structures/control_flow_graph/iterate/mod.rs
@@ -47,22 +47,6 @@ fn post_order_walk<G: ControlFlowGraph>(graph: &G,
     result.push(node);
 }
 
-pub fn pre_order_walk<G: ControlFlowGraph>(graph: &G,
-                                           node: G::Node,
-                                           result: &mut Vec<G::Node>,
-                                           visited: &mut IndexVec<G::Node, bool>) {
-    if visited[node] {
-        return;
-    }
-    visited[node] = true;
-
-    result.push(node);
-
-    for successor in graph.successors(node) {
-        pre_order_walk(graph, successor, result, visited);
-    }
-}
-
 pub fn reverse_post_order<G: ControlFlowGraph>(graph: &G, start_node: G::Node) -> Vec<G::Node> {
     let mut vec = post_order_from(graph, start_node);
     vec.reverse();
diff --git a/src/librustc_data_structures/control_flow_graph/iterate/test.rs b/src/librustc_data_structures/control_flow_graph/iterate/test.rs
index dca45602f17..100881ddfdd 100644
--- a/src/librustc_data_structures/control_flow_graph/iterate/test.rs
+++ b/src/librustc_data_structures/control_flow_graph/iterate/test.rs
@@ -9,7 +9,6 @@
 // except according to those terms.
 
 use super::super::test::TestGraph;
-use super::super::transpose::TransposedGraph;
 
 use super::*;
 
@@ -20,22 +19,3 @@ fn diamond_post_order() {
     let result = post_order_from(&graph, 0);
     assert_eq!(result, vec![3, 1, 2, 0]);
 }
-
-
-#[test]
-fn rev_post_order_inner_loop() {
-    // 0 -> 1 ->     2     -> 3 -> 5
-    //      ^     ^    v      |
-    //      |     6 <- 4      |
-    //      +-----------------+
-    let graph = TestGraph::new(0,
-                               &[(0, 1), (1, 2), (2, 3), (3, 5), (3, 1), (2, 4), (4, 6), (6, 2)]);
-
-    let rev_graph = TransposedGraph::new(&graph);
-
-    let result = post_order_from_to(&rev_graph, 6, Some(2));
-    assert_eq!(result, vec![4, 6]);
-
-    let result = post_order_from_to(&rev_graph, 3, Some(1));
-    assert_eq!(result, vec![4, 6, 2, 3]);
-}
diff --git a/src/librustc_data_structures/control_flow_graph/mod.rs b/src/librustc_data_structures/control_flow_graph/mod.rs
index eb6839df627..7bf776675c6 100644
--- a/src/librustc_data_structures/control_flow_graph/mod.rs
+++ b/src/librustc_data_structures/control_flow_graph/mod.rs
@@ -9,13 +9,10 @@
 // except according to those terms.
 
 use super::indexed_vec::Idx;
-pub use std::slice::Iter;
 
 pub mod dominators;
 pub mod iterate;
-pub mod reachable;
 mod reference;
-pub mod transpose;
 
 #[cfg(test)]
 mod test;
diff --git a/src/librustc_data_structures/control_flow_graph/reachable/mod.rs b/src/librustc_data_structures/control_flow_graph/reachable/mod.rs
deleted file mode 100644
index 24210ebb95d..00000000000
--- a/src/librustc_data_structures/control_flow_graph/reachable/mod.rs
+++ /dev/null
@@ -1,62 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-//! Compute reachability using a simple dataflow propagation.
-//! Store end-result in a big NxN bit matrix.
-
-use super::ControlFlowGraph;
-use super::super::bitvec::BitVector;
-use super::iterate::reverse_post_order;
-use super::super::indexed_vec::{IndexVec, Idx};
-
-#[cfg(test)]
-mod test;
-
-pub fn reachable<G: ControlFlowGraph>(graph: &G) -> Reachability<G::Node> {
-    let reverse_post_order = reverse_post_order(graph, graph.start_node());
-    reachable_given_rpo(graph, &reverse_post_order)
-}
-
-pub fn reachable_given_rpo<G: ControlFlowGraph>(graph: &G,
-                                                reverse_post_order: &[G::Node])
-                                                -> Reachability<G::Node> {
-    let mut reachability = Reachability::new(graph);
-    let mut changed = true;
-    while changed {
-        changed = false;
-        for &node in reverse_post_order.iter().rev() {
-            // every node can reach itself
-            changed |= reachability.bits[node].insert(node.index());
-
-            // and every pred can reach everything node can reach
-            for pred in graph.predecessors(node) {
-                let nodes_bits = reachability.bits[node].clone();
-                changed |= reachability.bits[pred].insert_all(&nodes_bits);
-            }
-        }
-    }
-    reachability
-}
-
-pub struct Reachability<Node: Idx> {
-    bits: IndexVec<Node, BitVector>,
-}
-
-impl<Node: Idx> Reachability<Node> {
-    fn new<G: ControlFlowGraph>(graph: &G) -> Self {
-        let num_nodes = graph.num_nodes();
-        Reachability { bits: IndexVec::from_elem_n(BitVector::new(num_nodes), num_nodes) }
-    }
-
-    pub fn can_reach(&self, source: Node, target: Node) -> bool {
-        let bit: usize = target.index();
-        self.bits[source].contains(bit)
-    }
-}
diff --git a/src/librustc_data_structures/control_flow_graph/reachable/test.rs b/src/librustc_data_structures/control_flow_graph/reachable/test.rs
deleted file mode 100644
index ef45deeaafc..00000000000
--- a/src/librustc_data_structures/control_flow_graph/reachable/test.rs
+++ /dev/null
@@ -1,50 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use super::super::test::TestGraph;
-
-use super::*;
-
-#[test]
-fn test1() {
-    // 0 -> 1 -> 2 -> 3
-    //      ^    v
-    //      6 <- 4 -> 5
-    let graph = TestGraph::new(0, &[(0, 1), (1, 2), (2, 3), (2, 4), (4, 5), (4, 6), (6, 1)]);
-    let reachable = reachable(&graph);
-    assert!((0..6).all(|i| reachable.can_reach(0, i)));
-    assert!((1..6).all(|i| reachable.can_reach(1, i)));
-    assert!((1..6).all(|i| reachable.can_reach(2, i)));
-    assert!((1..6).all(|i| reachable.can_reach(4, i)));
-    assert!((1..6).all(|i| reachable.can_reach(6, i)));
-    assert!(reachable.can_reach(3, 3));
-    assert!(!reachable.can_reach(3, 5));
-    assert!(!reachable.can_reach(5, 3));
-}
-
-/// use bigger indices to cross between words in the bit set
-#[test]
-fn test2() {
-    // 30 -> 31 -> 32 -> 33
-    //       ^      v
-    //       36 <- 34 -> 35
-    let graph = TestGraph::new(30,
-                               &[(30, 31), (31, 32), (32, 33), (32, 34), (34, 35), (34, 36),
-                                 (36, 31)]);
-    let reachable = reachable(&graph);
-    assert!((30..36).all(|i| reachable.can_reach(30, i)));
-    assert!((31..36).all(|i| reachable.can_reach(31, i)));
-    assert!((31..36).all(|i| reachable.can_reach(32, i)));
-    assert!((31..36).all(|i| reachable.can_reach(34, i)));
-    assert!((31..36).all(|i| reachable.can_reach(36, i)));
-    assert!(reachable.can_reach(33, 33));
-    assert!(!reachable.can_reach(33, 35));
-    assert!(!reachable.can_reach(35, 33));
-}
diff --git a/src/librustc_data_structures/control_flow_graph/transpose.rs b/src/librustc_data_structures/control_flow_graph/transpose.rs
deleted file mode 100644
index 163d65c089c..00000000000
--- a/src/librustc_data_structures/control_flow_graph/transpose.rs
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
-// file at the top-level directory of this distribution and at
-// http://rust-lang.org/COPYRIGHT.
-//
-// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
-// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
-// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
-// option. This file may not be copied, modified, or distributed
-// except according to those terms.
-
-use super::*;
-
-pub struct TransposedGraph<G: ControlFlowGraph> {
-    base_graph: G,
-    start_node: G::Node,
-}
-
-impl<G: ControlFlowGraph> TransposedGraph<G> {
-    pub fn new(base_graph: G) -> Self {
-        let start_node = base_graph.start_node();
-        Self::with_start(base_graph, start_node)
-    }
-
-    pub fn with_start(base_graph: G, start_node: G::Node) -> Self {
-        TransposedGraph {
-            base_graph,
-            start_node,
-        }
-    }
-}
-
-impl<G: ControlFlowGraph> ControlFlowGraph for TransposedGraph<G> {
-    type Node = G::Node;
-
-    fn num_nodes(&self) -> usize {
-        self.base_graph.num_nodes()
-    }
-
-    fn start_node(&self) -> Self::Node {
-        self.start_node
-    }
-
-    fn predecessors<'graph>(&'graph self,
-                            node: Self::Node)
-                            -> <Self as GraphPredecessors<'graph>>::Iter {
-        self.base_graph.successors(node)
-    }
-
-    fn successors<'graph>(&'graph self,
-                          node: Self::Node)
-                          -> <Self as GraphSuccessors<'graph>>::Iter {
-        self.base_graph.predecessors(node)
-    }
-}
-
-impl<'graph, G: ControlFlowGraph> GraphPredecessors<'graph> for TransposedGraph<G> {
-    type Item = G::Node;
-    type Iter = <G as GraphSuccessors<'graph>>::Iter;
-}
-
-impl<'graph, G: ControlFlowGraph> GraphSuccessors<'graph> for TransposedGraph<G> {
-    type Item = G::Node;
-    type Iter = <G as GraphPredecessors<'graph>>::Iter;
-}