Skip to content

Commit 3270a1d

Browse files
committed
Revert "replace Idx with NodeIndex. not finished!"
This reverts commit c67c1b6.
1 parent c67c1b6 commit 3270a1d

35 files changed

+196
-189
lines changed

src/librustc/mir/repr.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
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, NodeIndex};
14+
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
15+
use rustc_data_structures::graph_algorithms::NodeIndex;
1516
use hir::def_id::DefId;
1617
use ty::subst::Substs;
1718
use ty::{self, AdtDef, ClosureSubsts, FnOutput, Region, Ty};
@@ -35,17 +36,12 @@ macro_rules! newtype_index {
3536
RustcEncodable, RustcDecodable)]
3637
pub struct $name(u32);
3738

38-
impl NodeIndex for $name {}
39-
40-
impl From<usize> for $name {
41-
fn from(value: usize) -> Self {
39+
impl Idx for $name {
40+
fn new(value: usize) -> Self {
4241
assert!(value < (u32::MAX) as usize);
4342
$name(value as u32)
4443
}
45-
}
46-
47-
impl Into<usize> for $name {
48-
fn into(self) -> usize {
44+
fn index(self) -> usize {
4945
self.0 as usize
5046
}
5147
}
@@ -167,17 +163,23 @@ impl<'tcx> IndexMut<BasicBlock> for Mir<'tcx> {
167163
}
168164
}
169165

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-
//}
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+
}
181183

182184
/// Grouped information about the source code origin of a MIR entity.
183185
/// Intended to be inspected by diagnostics and debuginfo.
@@ -803,7 +805,7 @@ impl<'tcx> Debug for Lvalue<'tcx> {
803805
ProjectionElem::Deref =>
804806
write!(fmt, "(*{:?})", data.base),
805807
ProjectionElem::Field(field, ty) =>
806-
write!(fmt, "({:?}.{:?}: {:?})", data.base, field, ty),
808+
write!(fmt, "({:?}.{:?}: {:?})", data.base, field.index(), ty),
807809
ProjectionElem::Index(ref index) =>
808810
write!(fmt, "{:?}[{:?}]", data.base, index),
809811
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::NodeIndex;
14+
use rustc_data_structures::indexed_vec::Idx;
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.into()) {
63+
if !self.visited.insert(idx.index()) {
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.into());
118+
po.visited.insert(root.index());
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.into()) {
188+
if self.visited.insert(bb.index()) {
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::NodeIndex;
18+
use rustc_data_structures::indexed_vec::Idx;
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::from(index);
256+
let block = BasicBlock::new(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::NodeIndex;
15+
use rustc_data_structures::indexed_vec::Idx;
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::NodeIndex;
13+
use rustc_data_structures::indexed_vec::Idx;
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::NodeIndex;
11+
use rustc_data_structures::indexed_vec::Idx;
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:NodeIndex> {
170+
struct Bits<E:Idx> {
171171
bits: IdxSetBuf<E>,
172172
}
173173

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

178-
impl<E:NodeIndex> Bits<E> {
178+
impl<E:Idx> 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: NodeIndex> {
224+
pub struct AllSets<E: Idx> {
225225
/// Analysis bitwidth for each block.
226226
bits_per_block: usize,
227227

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

246-
pub struct BlockSets<'a, E: NodeIndex> {
246+
pub struct BlockSets<'a, E: Idx> {
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:NodeIndex> BlockSets<'a, E> {
252+
impl<'a, E:Idx> 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:NodeIndex> BlockSets<'a, E> {
260260
}
261261
}
262262

263-
impl<E:NodeIndex> AllSets<E> {
263+
impl<E:Idx> 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: NodeIndex;
299+
type Idx: Idx;
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::NodeIndex;
17+
use rustc_data_structures::indexed_vec::Idx;
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::NodeIndex;
25+
use rustc_data_structures::indexed_vec::Idx;
2626
use syntax::codemap::Span;
2727

2828
use std::fmt;

src/librustc_borrowck/borrowck/mir/gather_moves.rs

Lines changed: 7 additions & 11 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::{NodeIndex, IndexVec};
15+
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1616

1717
use std::cell::{Cell};
1818
use std::collections::hash_map::Entry;
@@ -29,25 +29,21 @@ 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::NodeIndex;
32+
use rustc_data_structures::indexed_vec::Idx;
3333

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

3939
impl $Index {
4040
}
4141

42-
impl NodeIndex for $Index {
43-
}
44-
impl From<usize> for $Index {
45-
fn from(idx: usize) -> Self {
42+
impl Idx for $Index {
43+
fn new(idx: usize) -> Self {
4644
unsafe { $Index(NonZero::new(idx + 1)) }
4745
}
48-
}
49-
impl Into<usize> for $Index {
50-
fn into(self) -> usize {
46+
fn index(self) -> usize {
5147
*self.0 - 1
5248
}
5349
}
@@ -317,7 +313,7 @@ impl<'tcx> MovePathLookup<'tcx> {
317313
i
318314
}
319315

320-
fn lookup_or_generate<I: NodeIndex>(vec: &mut IndexVec<I, Option<MovePathIndex>>,
316+
fn lookup_or_generate<I: Idx>(vec: &mut IndexVec<I, Option<MovePathIndex>>,
321317
idx: I,
322318
next_index: &mut MovePathIndex)
323319
-> 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, NodeIndex};
14+
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
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)