Skip to content

Commit b5f102c

Browse files
committed
Rollup merge of rust-lang#48840 - varkor:idxset-cleanup, r=pnkfelix
Remove some unnecessary IdxSet methods This replaces `IdxSet:: reset_to_empty` with `IdxSet:: clear`, and `IdxSet::elems`/`IdxSet::each_bit` with `IdxSet::iter`. Based on some [comments on #rustc](https://botbot.me/mozilla/rustc/2018-01-23/?msg=96063396). r? @pnkfelix
2 parents c65ee94 + f69a099 commit b5f102c

File tree

4 files changed

+18
-87
lines changed

4 files changed

+18
-87
lines changed

src/librustc_data_structures/indexed_set.rs

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -224,70 +224,6 @@ impl<T: Idx> IdxSet<T> {
224224
_pd: PhantomData,
225225
}
226226
}
227-
228-
/// Calls `f` on each index value held in this set, up to the
229-
/// bound `max_bits` on the size of universe of indexes.
230-
pub fn each_bit<F>(&self, max_bits: usize, f: F) where F: FnMut(T) {
231-
each_bit(self, max_bits, f)
232-
}
233-
234-
/// Removes all elements from this set.
235-
pub fn reset_to_empty(&mut self) {
236-
for word in self.words_mut() { *word = 0; }
237-
}
238-
239-
pub fn elems(&self, universe_size: usize) -> Elems<T> {
240-
Elems { i: 0, set: self, universe_size: universe_size }
241-
}
242-
}
243-
244-
pub struct Elems<'a, T: Idx> { i: usize, set: &'a IdxSet<T>, universe_size: usize }
245-
246-
impl<'a, T: Idx> Iterator for Elems<'a, T> {
247-
type Item = T;
248-
fn next(&mut self) -> Option<T> {
249-
if self.i >= self.universe_size { return None; }
250-
let mut i = self.i;
251-
loop {
252-
if i >= self.universe_size {
253-
self.i = i; // (mark iteration as complete.)
254-
return None;
255-
}
256-
if self.set.contains(&T::new(i)) {
257-
self.i = i + 1; // (next element to start at.)
258-
return Some(T::new(i));
259-
}
260-
i = i + 1;
261-
}
262-
}
263-
}
264-
265-
fn each_bit<T: Idx, F>(words: &IdxSet<T>, max_bits: usize, mut f: F) where F: FnMut(T) {
266-
let usize_bits: usize = mem::size_of::<usize>() * 8;
267-
268-
for (word_index, &word) in words.words().iter().enumerate() {
269-
if word != 0 {
270-
let base_index = word_index * usize_bits;
271-
for offset in 0..usize_bits {
272-
let bit = 1 << offset;
273-
if (word & bit) != 0 {
274-
// NB: we round up the total number of bits
275-
// that we store in any given bit set so that
276-
// it is an even multiple of usize::BITS. This
277-
// means that there may be some stray bits at
278-
// the end that do not correspond to any
279-
// actual value; that's why we first check
280-
// that we are in range of bits_per_block.
281-
let bit_index = base_index + offset as usize;
282-
if bit_index >= max_bits {
283-
return;
284-
} else {
285-
f(Idx::new(bit_index));
286-
}
287-
}
288-
}
289-
}
290-
}
291227
}
292228

293229
pub struct Iter<'a, T: Idx> {

src/librustc_mir/borrow_check/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
530530
// Look for any active borrows to locals
531531
let domain = flow_state.borrows.operator();
532532
let data = domain.borrows();
533-
flow_state.borrows.with_elems_outgoing(|borrows| {
533+
flow_state.borrows.with_iter_outgoing(|borrows| {
534534
for i in borrows {
535535
let borrow = &data[i.borrow_index()];
536536
self.check_for_local_borrow(borrow, span);
@@ -546,7 +546,7 @@ impl<'cx, 'gcx, 'tcx> DataflowResultsConsumer<'cx, 'tcx> for MirBorrowckCtxt<'cx
546546
// so this "extra check" serves as a kind of backup.
547547
let domain = flow_state.borrows.operator();
548548
let data = domain.borrows();
549-
flow_state.borrows.with_elems_outgoing(|borrows| {
549+
flow_state.borrows.with_iter_outgoing(|borrows| {
550550
for i in borrows {
551551
let borrow = &data[i.borrow_index()];
552552
let context = ContextKind::StorageDead.new(loc);
@@ -1292,7 +1292,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
12921292
place
12931293
);
12941294

1295-
for i in flow_state.ever_inits.elems_incoming() {
1295+
for i in flow_state.ever_inits.iter_incoming() {
12961296
let init = self.move_data.inits[i];
12971297
let init_place = &self.move_data.move_paths[init.path].place;
12981298
if self.places_conflict(&init_place, place, Deep) {
@@ -2129,8 +2129,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
21292129

21302130
// check for loan restricting path P being used. Accounts for
21312131
// borrows of P, P.a.b, etc.
2132-
let mut elems_incoming = flow_state.borrows.elems_incoming();
2133-
while let Some(i) = elems_incoming.next() {
2132+
let mut iter_incoming = flow_state.borrows.iter_incoming();
2133+
while let Some(i) = iter_incoming.next() {
21342134
let borrowed = &data[i.borrow_index()];
21352135

21362136
if self.places_conflict(&borrowed.borrowed_place, place, access) {

src/librustc_mir/dataflow/at_location.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! locations.
1313
1414
use rustc::mir::{BasicBlock, Location};
15-
use rustc_data_structures::indexed_set::{self, IdxSetBuf};
15+
use rustc_data_structures::indexed_set::{IdxSetBuf, Iter};
1616
use rustc_data_structures::indexed_vec::Idx;
1717

1818
use dataflow::{BitDenotation, BlockSets, DataflowResults};
@@ -81,8 +81,7 @@ where
8181
where
8282
F: FnMut(BD::Idx),
8383
{
84-
self.curr_state
85-
.each_bit(self.base_results.operator().bits_per_block(), f)
84+
self.curr_state.iter().for_each(f)
8685
}
8786

8887
/// Iterate over each `gen` bit in the current effect (invoke
@@ -92,8 +91,7 @@ where
9291
where
9392
F: FnMut(BD::Idx),
9493
{
95-
self.stmt_gen
96-
.each_bit(self.base_results.operator().bits_per_block(), f)
94+
self.stmt_gen.iter().for_each(f)
9795
}
9896

9997
pub fn new(results: DataflowResults<BD>) -> Self {
@@ -119,23 +117,21 @@ where
119117
}
120118

121119
/// Returns an iterator over the elements present in the current state.
122-
pub fn elems_incoming(&self) -> iter::Peekable<indexed_set::Elems<BD::Idx>> {
123-
let univ = self.base_results.sets().bits_per_block();
124-
self.curr_state.elems(univ).peekable()
120+
pub fn iter_incoming(&self) -> iter::Peekable<Iter<BD::Idx>> {
121+
self.curr_state.iter().peekable()
125122
}
126123

127124
/// Creates a clone of the current state and applies the local
128125
/// effects to the clone (leaving the state of self intact).
129126
/// Invokes `f` with an iterator over the resulting state.
130-
pub fn with_elems_outgoing<F>(&self, f: F)
127+
pub fn with_iter_outgoing<F>(&self, f: F)
131128
where
132-
F: FnOnce(indexed_set::Elems<BD::Idx>),
129+
F: FnOnce(Iter<BD::Idx>),
133130
{
134131
let mut curr_state = self.curr_state.clone();
135132
curr_state.union(&self.stmt_gen);
136133
curr_state.subtract(&self.stmt_kill);
137-
let univ = self.base_results.sets().bits_per_block();
138-
f(curr_state.elems(univ));
134+
f(curr_state.iter());
139135
}
140136
}
141137

@@ -147,8 +143,8 @@ impl<BD> FlowsAtLocation for FlowAtLocation<BD>
147143
}
148144

149145
fn reconstruct_statement_effect(&mut self, loc: Location) {
150-
self.stmt_gen.reset_to_empty();
151-
self.stmt_kill.reset_to_empty();
146+
self.stmt_gen.clear();
147+
self.stmt_kill.clear();
152148
{
153149
let mut sets = BlockSets {
154150
on_entry: &mut self.curr_state,
@@ -172,8 +168,8 @@ impl<BD> FlowsAtLocation for FlowAtLocation<BD>
172168
}
173169

174170
fn reconstruct_terminator_effect(&mut self, loc: Location) {
175-
self.stmt_gen.reset_to_empty();
176-
self.stmt_kill.reset_to_empty();
171+
self.stmt_gen.clear();
172+
self.stmt_kill.clear();
177173
{
178174
let mut sets = BlockSets {
179175
on_entry: &mut self.curr_state,

src/librustc_mir/dataflow/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,8 +444,7 @@ pub struct DataflowState<O: BitDenotation>
444444
impl<O: BitDenotation> DataflowState<O> {
445445
pub fn each_bit<F>(&self, words: &IdxSet<O::Idx>, f: F) where F: FnMut(O::Idx)
446446
{
447-
let bits_per_block = self.operator.bits_per_block();
448-
words.each_bit(bits_per_block, f)
447+
words.iter().for_each(f)
449448
}
450449

451450
pub(crate) fn interpret_set<'c, P>(&self,

0 commit comments

Comments
 (0)