/// Set `self = self & other` and return true if `self` changed.
/// (i.e., if any bits were removed).
pub fn intersect(&mut self, other: &BitSet<T>) -> bool {
- bitwise(self.words_mut(), other.words(), &Intersect)
+ bitwise(self.words_mut(), other.words(), |a, b| { a & b })
}
/// Get a slice of the underlying words.
impl<T: Idx> UnionIntoBitSet<T> for BitSet<T> {
fn union_into(&self, other: &mut BitSet<T>) -> bool {
- bitwise(other.words_mut(), self.words(), &Union)
+ bitwise(other.words_mut(), self.words(), |a, b| { a | b })
}
}
impl<T: Idx> SubtractFromBitSet<T> for BitSet<T> {
fn subtract_from(&self, other: &mut BitSet<T>) -> bool {
- bitwise(other.words_mut(), self.words(), &Subtract)
+ bitwise(other.words_mut(), self.words(), |a, b| { a & !b })
}
}
}
}
-pub trait BitwiseOperator {
- /// Applies some bit-operation pointwise to each of the bits in the two inputs.
- fn join(&self, pred1: Word, pred2: Word) -> Word;
+pub trait BitSetOperator {
+ /// Combine one bitset into another.
+ fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool;
}
#[inline]
-pub fn bitwise<Op: BitwiseOperator>(out_vec: &mut [Word], in_vec: &[Word], op: &Op) -> bool
+fn bitwise<Op>(out_vec: &mut [Word], in_vec: &[Word], op: Op) -> bool
+ where Op: Fn(Word, Word) -> Word
{
assert_eq!(out_vec.len(), in_vec.len());
let mut changed = false;
for (out_elem, in_elem) in out_vec.iter_mut().zip(in_vec.iter()) {
let old_val = *out_elem;
- let new_val = op.join(old_val, *in_elem);
+ let new_val = op(old_val, *in_elem);
*out_elem = new_val;
changed |= old_val != new_val;
}
changed
}
-pub struct Intersect;
-impl BitwiseOperator for Intersect {
- #[inline]
- fn join(&self, a: Word, b: Word) -> Word { a & b }
-}
-
-pub struct Union;
-impl BitwiseOperator for Union {
- #[inline]
- fn join(&self, a: Word, b: Word) -> Word { a | b }
-}
-
-pub struct Subtract;
-impl BitwiseOperator for Subtract {
- #[inline]
- fn join(&self, a: Word, b: Word) -> Word { a & !b }
-}
-
const SPARSE_MAX: usize = 8;
/// A fixed-size bitset type with a sparse representation and a maximum of
}
}
-impl<'a, 'tcx> BitwiseOperator for HaveBeenBorrowedLocals<'a, 'tcx> {
+impl<'a, 'tcx> BitSetOperator for HaveBeenBorrowedLocals<'a, 'tcx> {
#[inline]
- fn join(&self, pred1: Word, pred2: Word) -> Word {
- pred1 | pred2 // "maybe" means we union effects of both preds
+ fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool {
+ inout_set.union(in_set) // "maybe" means we union effects of both preds
}
}
use rustc::ty::{RegionKind, RegionVid};
use rustc::ty::RegionKind::ReScope;
-use rustc_data_structures::bit_set::{BitSet, BitwiseOperator, Word};
+use rustc_data_structures::bit_set::{BitSet, BitSetOperator};
use rustc_data_structures::fx::FxHashMap;
-use rustc_data_structures::indexed_vec::IndexVec;
+use rustc_data_structures::indexed_vec::{Idx, IndexVec};
use rustc_data_structures::sync::Lrc;
use dataflow::{BitDenotation, BlockSets, InitialFlow};
}
}
-impl<'a, 'gcx, 'tcx> BitwiseOperator for Borrows<'a, 'gcx, 'tcx> {
+impl<'a, 'gcx, 'tcx> BitSetOperator for Borrows<'a, 'gcx, 'tcx> {
#[inline]
- fn join(&self, pred1: Word, pred2: Word) -> Word {
- pred1 | pred2 // union effects of preds when computing reservations
+ fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool {
+ inout_set.union(in_set) // "maybe" means we union effects of both preds
}
}
use rustc::ty::TyCtxt;
use rustc::mir::{self, Mir, Location};
-use rustc_data_structures::bit_set::{BitSet, BitwiseOperator, Word};
+use rustc_data_structures::bit_set::{BitSet, BitSetOperator};
use rustc_data_structures::indexed_vec::Idx;
use super::MoveDataParamEnv;
}
}
-impl<'a, 'gcx, 'tcx> BitwiseOperator for MaybeInitializedPlaces<'a, 'gcx, 'tcx> {
+impl<'a, 'gcx, 'tcx> BitSetOperator for MaybeInitializedPlaces<'a, 'gcx, 'tcx> {
#[inline]
- fn join(&self, pred1: Word, pred2: Word) -> Word {
- pred1 | pred2 // "maybe" means we union effects of both preds
+ fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool {
+ inout_set.union(in_set) // "maybe" means we union effects of both preds
}
}
-impl<'a, 'gcx, 'tcx> BitwiseOperator for MaybeUninitializedPlaces<'a, 'gcx, 'tcx> {
+impl<'a, 'gcx, 'tcx> BitSetOperator for MaybeUninitializedPlaces<'a, 'gcx, 'tcx> {
#[inline]
- fn join(&self, pred1: Word, pred2: Word) -> Word {
- pred1 | pred2 // "maybe" means we union effects of both preds
+ fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool {
+ inout_set.union(in_set) // "maybe" means we union effects of both preds
}
}
-impl<'a, 'gcx, 'tcx> BitwiseOperator for DefinitelyInitializedPlaces<'a, 'gcx, 'tcx> {
+impl<'a, 'gcx, 'tcx> BitSetOperator for DefinitelyInitializedPlaces<'a, 'gcx, 'tcx> {
#[inline]
- fn join(&self, pred1: Word, pred2: Word) -> Word {
- pred1 & pred2 // "definitely" means we intersect effects of both preds
+ fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool {
+ inout_set.intersect(in_set) // "definitely" means we intersect effects of both preds
}
}
-impl<'a, 'gcx, 'tcx> BitwiseOperator for EverInitializedPlaces<'a, 'gcx, 'tcx> {
+impl<'a, 'gcx, 'tcx> BitSetOperator for EverInitializedPlaces<'a, 'gcx, 'tcx> {
#[inline]
- fn join(&self, pred1: Word, pred2: Word) -> Word {
- pred1 | pred2 // inits from both preds are in scope
+ fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool {
+ inout_set.union(in_set) // inits from both preds are in scope
}
}
}
}
-impl<'a, 'tcx> BitwiseOperator for MaybeStorageLive<'a, 'tcx> {
+impl<'a, 'tcx> BitSetOperator for MaybeStorageLive<'a, 'tcx> {
#[inline]
- fn join(&self, pred1: Word, pred2: Word) -> Word {
- pred1 | pred2 // "maybe" means we union effects of both preds
+ fn join<T: Idx>(&self, inout_set: &mut BitSet<T>, in_set: &BitSet<T>) -> bool {
+ inout_set.union(in_set) // "maybe" means we union effects of both preds
}
}
use syntax::ast::{self, MetaItem};
-use rustc_data_structures::bit_set::{bitwise, BitwiseOperator, BitSet, HybridBitSet};
+use rustc_data_structures::bit_set::{BitSet, BitSetOperator, HybridBitSet};
use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::work_queue::WorkQueue;
fn bottom_value() -> bool;
}
-pub trait BitDenotation: BitwiseOperator {
+pub trait BitDenotation: BitSetOperator {
/// Specifies what index type is used to access the bitvector.
type Idx: Idx;
in_out: &BitSet<D::Idx>,
bb: mir::BasicBlock,
dirty_queue: &mut WorkQueue<mir::BasicBlock>) {
- let entry_set = self.flow_state.sets.for_block(bb.index()).on_entry;
- let set_changed = bitwise(entry_set.words_mut(),
- in_out.words(),
- &self.flow_state.operator);
+ let entry_set = &mut self.flow_state.sets.for_block(bb.index()).on_entry;
+ let set_changed = self.flow_state.operator.join(entry_set, &in_out);
if set_changed {
dirty_queue.insert(bb);
}