Skip to content

Commit 1e09198

Browse files
committed
replace NodeIndex with Idx in graph_algorithms
1 parent 3270a1d commit 1e09198

File tree

6 files changed

+22
-28
lines changed

6 files changed

+22
-28
lines changed

src/librustc/mir/repr.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use graphviz::IntoCow;
1212
use middle::const_val::ConstVal;
1313
use rustc_const_math::{ConstUsize, ConstInt, ConstMathErr};
1414
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
15-
use rustc_data_structures::graph_algorithms::NodeIndex;
1615
use hir::def_id::DefId;
1716
use ty::subst::Substs;
1817
use ty::{self, AdtDef, ClosureSubsts, FnOutput, Region, Ty};
@@ -175,12 +174,6 @@ impl Into<usize> for BasicBlock {
175174
}
176175
}
177176

178-
impl NodeIndex for BasicBlock {
179-
fn as_usize(self) -> usize {
180-
self.index()
181-
}
182-
}
183-
184177
/// Grouped information about the source code origin of a MIR entity.
185178
/// Intended to be inspected by diagnostics and debuginfo.
186179
/// Most passes can work with it as a whole, within a single function.

src/librustc_data_structures/graph_algorithms/dominators/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use super::Graph;
1818
use super::iterate::reverse_post_order;
1919
use super::node_vec::NodeVec;
20+
use super::super::indexed_vec::Idx;
2021

2122
use std::fmt;
2223

@@ -162,7 +163,7 @@ impl<G: Graph> Dominators<G> {
162163
NodeVec::from_default_with_len(self.immediate_dominators.len());
163164
let mut root = None;
164165
for (index, immed_dom) in self.immediate_dominators.iter().enumerate() {
165-
let node = G::Node::from(index);
166+
let node = G::Node::new(index);
166167
match *immed_dom {
167168
None => { /* node not reachable */ }
168169
Some(immed_dom) => {

src/librustc_data_structures/graph_algorithms/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
10-
use std::fmt::Debug;
11-
use std::hash::Hash;
10+
11+
use super::indexed_vec::Idx;
1212

1313
//pub mod bit_set;
1414
pub mod dominators;
@@ -25,7 +25,7 @@ pub trait Graph
2525
where Self: for<'graph> GraphPredecessors<'graph, Item=<Self as Graph>::Node>,
2626
Self: for<'graph> GraphSuccessors<'graph, Item=<Self as Graph>::Node>
2727
{
28-
type Node: NodeIndex;
28+
type Node: Idx;
2929

3030
fn num_nodes(&self) -> usize;
3131
fn start_node(&self) -> Self::Node;
@@ -45,9 +45,9 @@ pub trait GraphSuccessors<'graph> {
4545
type Iter: Iterator<Item=Self::Item>;
4646
}
4747

48-
pub trait NodeIndex: Copy + Debug + Eq + Ord + Hash + Into<usize> + From<usize> {
49-
fn as_usize(self) -> usize {
50-
self.into()
51-
}
52-
}
48+
//pub trait NodeIndex: Copy + Debug + Eq + Ord + Hash + Into<usize> + From<usize> {
49+
// fn as_usize(self) -> usize {
50+
// self.into()
51+
// }
52+
//}
5353

src/librustc_data_structures/graph_algorithms/node_vec.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use std::ops::{Index, IndexMut};
1414
pub use std::slice::Iter;
1515

1616
use super::Graph;
17+
use super::super::indexed_vec::Idx;
1718

1819
#[derive(Clone, Debug)]
1920
pub struct NodeVec<G: Graph, T> {
@@ -52,7 +53,7 @@ impl<G: Graph, T> NodeVec<G, T> {
5253
where F: FnMut(G::Node) -> T
5354
{
5455
NodeVec {
55-
vec: (0..num_nodes).map(G::Node::from).map(f).collect(),
56+
vec: (0..num_nodes).map(G::Node::new).map(f).collect(),
5657
graph: PhantomData,
5758
}
5859
}
@@ -70,14 +71,14 @@ impl<G: Graph, T> Index<G::Node> for NodeVec<G, T> {
7071
type Output = T;
7172

7273
fn index(&self, index: G::Node) -> &T {
73-
let index: usize = index.into();
74+
let index: usize = index.index();
7475
&self.vec[index]
7576
}
7677
}
7778

7879
impl<G: Graph, T> IndexMut<G::Node> for NodeVec<G, T> {
7980
fn index_mut(&mut self, index: G::Node) -> &mut T {
80-
let index: usize = index.into();
81+
let index: usize = index.index();
8182
&mut self.vec[index]
8283
}
8384
}

src/librustc_data_structures/graph_algorithms/reachable/mod.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
//! Compute reachability using a simple dataflow propagation.
1212
//! Store end-result in a big NxN bit matrix.
1313
14-
use super::{Graph, NodeIndex};
15-
//use super::bit_set::BitSet;
14+
use super::Graph;
1615
use super::super::bitvec::BitVector;
1716
use super::iterate::reverse_post_order;
17+
use super::super::indexed_vec::Idx;
1818

1919
#[cfg(test)]
2020
mod test;
@@ -35,12 +35,12 @@ pub fn reachable_given_rpo<G: Graph>(graph: &G,
3535
for &node in reverse_post_order.iter().rev() {
3636
// every node can reach itself
3737
//changed |= reachability.bits.insert(node, node.as_usize());
38-
changed |= reachability.bits[node.as_usize()].insert(node.as_usize());
38+
changed |= reachability.bits[node.index()].insert(node.index());
3939

4040
// and every pred can reach everything node can reach
4141
for pred in graph.predecessors(node) {
4242
//changed |= reachability.bits.insert_bits_from(node, pred);
43-
changed |= reachability.bits[node.as_usize()].insert(pred.as_usize());
43+
changed |= reachability.bits[node.index()].insert(pred.index());
4444
}
4545
}
4646
}
@@ -58,14 +58,12 @@ impl Reachability {
5858
fn new<G: Graph>(graph: &G) -> Self {
5959
let num_nodes = graph.num_nodes();
6060
Reachability {
61-
//bits: BitSet::new(graph, num_nodes),
6261
bits: vec![BitVector::new(num_nodes)],
6362
}
6463
}
6564

6665
pub fn can_reach<G: Graph>(&self, source: G::Node, target: G::Node) -> bool {
67-
let bit: usize = target.into();
68-
//self.bits.is_set(source, bit)
69-
self.bits[source.as_usize()].contains(bit)
66+
let bit: usize = target.index();
67+
self.bits[source.index()].contains(bit)
7068
}
7169
}

src/librustc_data_structures/indexed_vec.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use std::fmt::Debug;
1112
use std::iter::{self, FromIterator};
1213
use std::slice;
1314
use std::marker::PhantomData;
@@ -20,7 +21,7 @@ use rustc_serialize as serialize;
2021
/// Represents some newtyped `usize` wrapper.
2122
///
2223
/// (purpose: avoid mixing indexes for different bitvector domains.)
23-
pub trait Idx: Copy + 'static {
24+
pub trait Idx: Copy + 'static + Eq + Debug {
2425
fn new(usize) -> Self;
2526
fn index(self) -> usize;
2627
}

0 commit comments

Comments
 (0)