Skip to content

Commit c67c1b6

Browse files
committed
replace Idx with NodeIndex. not finished!
1 parent 8ed531b commit c67c1b6

35 files changed

+189
-196
lines changed

src/librustc/mir/repr.rs

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
use graphviz::IntoCow;
1212
use middle::const_val::ConstVal;
1313
use rustc_const_math::{ConstUsize, ConstInt, ConstMathErr};
14-
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
15-
use rustc_data_structures::graph_algorithms::NodeIndex;
14+
use rustc_data_structures::indexed_vec::{IndexVec, NodeIndex};
1615
use hir::def_id::DefId;
1716
use ty::subst::Substs;
1817
use ty::{self, AdtDef, ClosureSubsts, FnOutput, Region, Ty};
@@ -36,12 +35,17 @@ macro_rules! newtype_index {
3635
RustcEncodable, RustcDecodable)]
3736
pub struct $name(u32);
3837

39-
impl Idx for $name {
40-
fn new(value: usize) -> Self {
38+
impl NodeIndex for $name {}
39+
40+
impl From<usize> for $name {
41+
fn from(value: usize) -> Self {
4142
assert!(value < (u32::MAX) as usize);
4243
$name(value as u32)
4344
}
44-
fn index(self) -> usize {
45+
}
46+
47+
impl Into<usize> for $name {
48+
fn into(self) -> usize {
4549
self.0 as usize
4650
}
4751
}
@@ -163,23 +167,17 @@ impl<'tcx> IndexMut<BasicBlock> for Mir<'tcx> {
163167
}
164168
}
165169

166-
impl From<usize> for BasicBlock {
167-
fn from(n: usize) -> BasicBlock {
168-
assert!(n < (u32::MAX as usize));
169-
BasicBlock(n as u32)
170-
}
171-
}
172-
impl Into<usize> for BasicBlock {
173-
fn into(self: BasicBlock) -> usize {
174-
self.index()
175-
}
176-
}
177-
178-
impl NodeIndex for BasicBlock {
179-
fn as_usize(self) -> usize {
180-
self.index()
181-
}
182-
}
170+
//impl From<usize> for BasicBlock {
171+
// fn from(n: usize) -> BasicBlock {
172+
// assert!(n < (u32::MAX as usize));
173+
// BasicBlock(n as u32)
174+
// }
175+
//}
176+
//impl Into<usize> for BasicBlock {
177+
// fn into(self: BasicBlock) -> usize {
178+
// self.index()
179+
// }
180+
//}
183181

184182
/// Grouped information about the source code origin of a MIR entity.
185183
/// Intended to be inspected by diagnostics and debuginfo.
@@ -805,7 +803,7 @@ impl<'tcx> Debug for Lvalue<'tcx> {
805803
ProjectionElem::Deref =>
806804
write!(fmt, "(*{:?})", data.base),
807805
ProjectionElem::Field(field, ty) =>
808-
write!(fmt, "({:?}.{:?}: {:?})", data.base, field.index(), ty),
806+
write!(fmt, "({:?}.{:?}: {:?})", data.base, field, ty),
809807
ProjectionElem::Index(ref index) =>
810808
write!(fmt, "{:?}[{:?}]", data.base, index),
811809
ProjectionElem::ConstantIndex { offset, min_length, from_end: false } =>

src/librustc/mir/traversal.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use std::vec;
1212

1313
use rustc_data_structures::bitvec::BitVector;
14-
use rustc_data_structures::indexed_vec::Idx;
14+
use rustc_data_structures::indexed_vec::NodeIndex;
1515

1616
use super::repr::*;
1717

@@ -60,7 +60,7 @@ impl<'a, 'tcx> Iterator for Preorder<'a, 'tcx> {
6060

6161
fn next(&mut self) -> Option<(BasicBlock, &'a BasicBlockData<'tcx>)> {
6262
while let Some(idx) = self.worklist.pop() {
63-
if !self.visited.insert(idx.index()) {
63+
if !self.visited.insert(idx.into()) {
6464
continue;
6565
}
6666

@@ -115,7 +115,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
115115
let data = &po.mir[root];
116116

117117
if let Some(ref term) = data.terminator {
118-
po.visited.insert(root.index());
118+
po.visited.insert(root.into());
119119

120120
let succs = term.successors().into_owned().into_iter();
121121

@@ -185,7 +185,7 @@ impl<'a, 'tcx> Postorder<'a, 'tcx> {
185185
break;
186186
};
187187

188-
if self.visited.insert(bb.index()) {
188+
if self.visited.insert(bb.into()) {
189189
if let Some(ref term) = self.mir[bb].terminator {
190190
let succs = term.successors().into_owned().into_iter();
191191
self.visit_stack.push((bb, succs));

src/librustc/mir/visit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use ty::{ClosureSubsts, FnOutput, Region, Ty};
1515
use mir::repr::*;
1616
use rustc_const_math::ConstUsize;
1717
use rustc_data_structures::tuple_slice::TupleSlice;
18-
use rustc_data_structures::indexed_vec::Idx;
18+
use rustc_data_structures::indexed_vec::NodeIndex;
1919
use syntax::codemap::Span;
2020

2121
// # The MIR Visitor
@@ -253,7 +253,7 @@ macro_rules! make_mir_visitor {
253253
fn super_mir(&mut self,
254254
mir: & $($mutability)* Mir<'tcx>) {
255255
for index in 0..mir.basic_blocks().len() {
256-
let block = BasicBlock::new(index);
256+
let block = BasicBlock::from(index);
257257
self.visit_basic_block_data(block, &$($mutability)* mir[block]);
258258
}
259259

src/librustc_borrowck/borrowck/mir/dataflow/graphviz.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
1313
use syntax::ast::NodeId;
1414
use rustc::mir::repr::{BasicBlock, Mir};
15-
use rustc_data_structures::indexed_vec::Idx;
15+
use rustc_data_structures::indexed_vec::NodeIndex;
1616

1717
use dot;
1818
use dot::IntoCow;

src/librustc_borrowck/borrowck/mir/dataflow/impls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use rustc::ty::TyCtxt;
1212
use rustc::mir::repr::{self, Mir};
13-
use rustc_data_structures::indexed_vec::Idx;
13+
use rustc_data_structures::indexed_vec::NodeIndex;
1414

1515
use super::super::gather_moves::{Location};
1616
use super::super::gather_moves::{MoveOutIndex, MovePathIndex};

src/librustc_borrowck/borrowck/mir/dataflow/mod.rs

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

11-
use rustc_data_structures::indexed_vec::Idx;
11+
use rustc_data_structures::indexed_vec::NodeIndex;
1212

1313
use rustc::ty::TyCtxt;
1414
use rustc::mir::repr::{self, Mir};
@@ -167,15 +167,15 @@ impl<'a, 'tcx: 'a, BD> MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>
167167

168168
/// Maps each block to a set of bits
169169
#[derive(Debug)]
170-
struct Bits<E:Idx> {
170+
struct Bits<E:NodeIndex> {
171171
bits: IdxSetBuf<E>,
172172
}
173173

174-
impl<E:Idx> Clone for Bits<E> {
174+
impl<E:NodeIndex> Clone for Bits<E> {
175175
fn clone(&self) -> Self { Bits { bits: self.bits.clone() } }
176176
}
177177

178-
impl<E:Idx> Bits<E> {
178+
impl<E:NodeIndex> Bits<E> {
179179
fn new(bits: IdxSetBuf<E>) -> Self {
180180
Bits { bits: bits }
181181
}
@@ -221,7 +221,7 @@ pub struct DataflowState<O: BitDenotation>
221221
}
222222

223223
#[derive(Debug)]
224-
pub struct AllSets<E: Idx> {
224+
pub struct AllSets<E: NodeIndex> {
225225
/// Analysis bitwidth for each block.
226226
bits_per_block: usize,
227227

@@ -243,13 +243,13 @@ pub struct AllSets<E: Idx> {
243243
on_entry_sets: Bits<E>,
244244
}
245245

246-
pub struct BlockSets<'a, E: Idx> {
246+
pub struct BlockSets<'a, E: NodeIndex> {
247247
on_entry: &'a mut IdxSet<E>,
248248
gen_set: &'a mut IdxSet<E>,
249249
kill_set: &'a mut IdxSet<E>,
250250
}
251251

252-
impl<'a, E:Idx> BlockSets<'a, E> {
252+
impl<'a, E:NodeIndex> BlockSets<'a, E> {
253253
fn gen(&mut self, e: &E) {
254254
self.gen_set.add(e);
255255
self.kill_set.remove(e);
@@ -260,7 +260,7 @@ impl<'a, E:Idx> BlockSets<'a, E> {
260260
}
261261
}
262262

263-
impl<E:Idx> AllSets<E> {
263+
impl<E:NodeIndex> AllSets<E> {
264264
pub fn bits_per_block(&self) -> usize { self.bits_per_block }
265265
pub fn for_block(&mut self, block_idx: usize) -> BlockSets<E> {
266266
let offset = self.words_per_block * block_idx;
@@ -296,7 +296,7 @@ pub trait DataflowOperator: BitwiseOperator {
296296

297297
pub trait BitDenotation {
298298
/// Specifies what index type is used to access the bitvector.
299-
type Idx: Idx;
299+
type Idx: NodeIndex;
300300

301301
/// Specifies what, if any, separate context needs to be supplied for methods below.
302302
type Ctxt;

src/librustc_borrowck/borrowck/mir/dataflow/sanity_check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use syntax::codemap::Span;
1414

1515
use rustc::ty::{self, TyCtxt};
1616
use rustc::mir::repr::{self, Mir};
17-
use rustc_data_structures::indexed_vec::Idx;
17+
use rustc_data_structures::indexed_vec::NodeIndex;
1818

1919
use super::super::gather_moves::{MovePathIndex};
2020
use super::super::MoveDataParamEnv;

src/librustc_borrowck/borrowck/mir/elaborate_drops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc::mir::transform::{Pass, MirPass, MirSource};
2222
use rustc::middle::const_val::ConstVal;
2323
use rustc::middle::lang_items;
2424
use rustc::util::nodemap::FnvHashMap;
25-
use rustc_data_structures::indexed_vec::Idx;
25+
use rustc_data_structures::indexed_vec::NodeIndex;
2626
use syntax::codemap::Span;
2727

2828
use std::fmt;

src/librustc_borrowck/borrowck/mir/gather_moves.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
use rustc::ty::{FnOutput, TyCtxt};
1313
use rustc::mir::repr::*;
1414
use rustc::util::nodemap::FnvHashMap;
15-
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
15+
use rustc_data_structures::indexed_vec::{NodeIndex, IndexVec};
1616

1717
use std::cell::{Cell};
1818
use std::collections::hash_map::Entry;
@@ -29,21 +29,25 @@ use super::abs_domain::{AbstractElem, Lift};
2929
// (which is likely to yield a subtle off-by-one error).
3030
mod indexes {
3131
use core::nonzero::NonZero;
32-
use rustc_data_structures::indexed_vec::Idx;
32+
use rustc_data_structures::indexed_vec::NodeIndex;
3333

3434
macro_rules! new_index {
3535
($Index:ident) => {
36-
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
36+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash, Ord, PartialOrd)]
3737
pub struct $Index(NonZero<usize>);
3838

3939
impl $Index {
4040
}
4141

42-
impl Idx for $Index {
43-
fn new(idx: usize) -> Self {
42+
impl NodeIndex for $Index {
43+
}
44+
impl From<usize> for $Index {
45+
fn from(idx: usize) -> Self {
4446
unsafe { $Index(NonZero::new(idx + 1)) }
4547
}
46-
fn index(self) -> usize {
48+
}
49+
impl Into<usize> for $Index {
50+
fn into(self) -> usize {
4751
*self.0 - 1
4852
}
4953
}
@@ -313,7 +317,7 @@ impl<'tcx> MovePathLookup<'tcx> {
313317
i
314318
}
315319

316-
fn lookup_or_generate<I: Idx>(vec: &mut IndexVec<I, Option<MovePathIndex>>,
320+
fn lookup_or_generate<I: NodeIndex>(vec: &mut IndexVec<I, Option<MovePathIndex>>,
317321
idx: I,
318322
next_index: &mut MovePathIndex)
319323
-> Lookup<MovePathIndex> {

src/librustc_borrowck/borrowck/mir/patch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
use super::gather_moves::Location;
1212
use rustc::ty::Ty;
1313
use rustc::mir::repr::*;
14-
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
14+
use rustc_data_structures::indexed_vec::{IndexVec, NodeIndex};
1515

1616
/// This struct represents a patch to MIR, which can add
1717
/// new statements and basic blocks and patch over block

0 commit comments

Comments
 (0)