Skip to content

Commit 7ab0d1a

Browse files
committed
Port to using the newer graph, which offers iterators instead of the
older `each` method, but is otherwise identical.
1 parent 52c3462 commit 7ab0d1a

File tree

10 files changed

+320
-244
lines changed

10 files changed

+320
-244
lines changed

src/librustc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ pub mod middle {
104104
pub mod entry;
105105
pub mod expr_use_visitor;
106106
pub mod fast_reject;
107-
pub mod graph;
108107
pub mod intrinsicck;
109108
pub mod infer;
110109
pub mod lang_items;

src/librustc/middle/cfg/construct.rs

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

11+
use rustc_data_structures::graph;
1112
use middle::cfg::*;
1213
use middle::def;
13-
use middle::graph;
1414
use middle::pat_util;
1515
use middle::region::CodeExtent;
1616
use middle::ty;

src/librustc/middle/cfg/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! Module that constructs a control-flow graph representing an item.
1212
//! Uses `Graph` as the underlying representation.
1313
14-
use middle::graph;
14+
use rustc_data_structures::graph;
1515
use middle::ty;
1616
use syntax::ast;
1717

@@ -24,7 +24,7 @@ pub struct CFG {
2424
pub exit: CFGIndex,
2525
}
2626

27-
#[derive(Copy, Clone, PartialEq)]
27+
#[derive(Copy, Clone, Debug, PartialEq)]
2828
pub enum CFGNodeData {
2929
AST(ast::NodeId),
3030
Entry,
@@ -43,6 +43,7 @@ impl CFGNodeData {
4343
}
4444
}
4545

46+
#[derive(Debug)]
4647
pub struct CFGEdgeData {
4748
pub exiting_scopes: Vec<ast::NodeId>
4849
}

src/librustc/middle/dataflow.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,10 +576,9 @@ impl<'a, 'b, 'tcx, O:DataFlowOperator> PropagationContext<'a, 'b, 'tcx, O> {
576576
pred_bits: &[usize],
577577
cfg: &cfg::CFG,
578578
cfgidx: CFGIndex) {
579-
cfg.graph.each_outgoing_edge(cfgidx, |_e_idx, edge| {
579+
for (_, edge) in cfg.graph.outgoing_edges(cfgidx) {
580580
self.propagate_bits_into_entry_set_for(pred_bits, edge);
581-
true
582-
});
581+
}
583582
}
584583

585584
fn propagate_bits_into_entry_set_for(&mut self,

src/librustc/middle/infer/region_inference/mod.rs

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ use self::Classification::*;
2020

2121
use super::{RegionVariableOrigin, SubregionOrigin, TypeTrace, MiscVariable};
2222

23+
use rustc_data_structures::graph::{self, Direction, NodeIndex};
2324
use middle::region;
2425
use middle::ty::{self, Ty};
2526
use middle::ty::{BoundRegion, FreeRegion, Region, RegionVid};
2627
use middle::ty::{ReEmpty, ReStatic, ReInfer, ReFree, ReEarlyBound};
2728
use middle::ty::{ReLateBound, ReScope, ReVar, ReSkolemized, BrFresh};
2829
use middle::ty_relate::RelateResult;
29-
use middle::graph;
30-
use middle::graph::{Direction, NodeIndex};
3130
use util::common::indenter;
3231
use util::nodemap::{FnvHashMap, FnvHashSet};
3332
use util::ppaux::{Repr, UserString};
@@ -1325,10 +1324,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
13251324
let num_vars = self.num_vars();
13261325

13271326
let constraints = self.constraints.borrow();
1328-
let num_edges = constraints.len();
13291327

1330-
let mut graph = graph::Graph::with_capacity(num_vars as usize + 1,
1331-
num_edges);
1328+
let mut graph = graph::Graph::new();
13321329

13331330
for _ in 0..num_vars {
13341331
graph.add_node(());
@@ -1370,10 +1367,10 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
13701367
// not contained by an upper-bound.
13711368
let (mut lower_bounds, lower_dup) =
13721369
self.collect_concrete_regions(graph, var_data, node_idx,
1373-
graph::Incoming, dup_vec);
1370+
graph::INCOMING, dup_vec);
13741371
let (mut upper_bounds, upper_dup) =
13751372
self.collect_concrete_regions(graph, var_data, node_idx,
1376-
graph::Outgoing, dup_vec);
1373+
graph::OUTGOING, dup_vec);
13771374

13781375
if lower_dup || upper_dup {
13791376
return;
@@ -1433,7 +1430,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
14331430
// that have no intersection.
14341431
let (upper_bounds, dup_found) =
14351432
self.collect_concrete_regions(graph, var_data, node_idx,
1436-
graph::Outgoing, dup_vec);
1433+
graph::OUTGOING, dup_vec);
14371434

14381435
if dup_found {
14391436
return;
@@ -1508,8 +1505,8 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
15081505
// figure out the direction from which this node takes its
15091506
// values, and search for concrete regions etc in that direction
15101507
let dir = match classification {
1511-
Expanding => graph::Incoming,
1512-
Contracting => graph::Outgoing,
1508+
Expanding => graph::INCOMING,
1509+
Contracting => graph::OUTGOING,
15131510
};
15141511

15151512
process_edges(self, &mut state, graph, node_idx, dir);
@@ -1519,14 +1516,14 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
15191516
return (result, dup_found);
15201517

15211518
fn process_edges<'a, 'tcx>(this: &RegionVarBindings<'a, 'tcx>,
1522-
state: &mut WalkState<'tcx>,
1523-
graph: &RegionGraph,
1524-
source_vid: RegionVid,
1525-
dir: Direction) {
1519+
state: &mut WalkState<'tcx>,
1520+
graph: &RegionGraph,
1521+
source_vid: RegionVid,
1522+
dir: Direction) {
15261523
debug!("process_edges(source_vid={:?}, dir={:?})", source_vid, dir);
15271524

15281525
let source_node_index = NodeIndex(source_vid.index as usize);
1529-
graph.each_adjacent_edge(source_node_index, dir, |_, edge| {
1526+
for (_, edge) in graph.adjacent_edges(source_node_index, dir) {
15301527
match edge.data {
15311528
ConstrainVarSubVar(from_vid, to_vid) => {
15321529
let opp_vid =
@@ -1544,8 +1541,7 @@ impl<'a, 'tcx> RegionVarBindings<'a, 'tcx> {
15441541
});
15451542
}
15461543
}
1547-
true
1548-
});
1544+
}
15491545
}
15501546
}
15511547

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
use std::iter;
2+
3+
/// A very simple BitVector type.
4+
pub struct BitVector {
5+
data: Vec<u64>
6+
}
7+
8+
impl BitVector {
9+
pub fn new(num_bits: usize) -> BitVector {
10+
let num_words = (num_bits + 63) / 64;
11+
BitVector { data: iter::repeat(0).take(num_words).collect() }
12+
}
13+
14+
fn word_mask(&self, bit: usize) -> (usize, u64) {
15+
let word = bit / 64;
16+
let mask = 1 << (bit % 64);
17+
(word, mask)
18+
}
19+
20+
pub fn contains(&self, bit: usize) -> bool {
21+
let (word, mask) = self.word_mask(bit);
22+
(self.data[word] & mask) != 0
23+
}
24+
25+
pub fn insert(&mut self, bit: usize) -> bool {
26+
let (word, mask) = self.word_mask(bit);
27+
let data = &mut self.data[word];
28+
let value = *data;
29+
*data = value | mask;
30+
(value | mask) != value
31+
}
32+
}

0 commit comments

Comments
 (0)