Make BitSlice's Word properly generic.

Currently `Word` is `usize`, and there are various places in the code
that assume this.

This patch mostly just changes `usize` occurrences to `Word`. Most of
the changes were found as compile errors when I changed `Word` to a type
other than `usize`, but there was one non-obvious case in
librustc_mir/dataflow/mod.rs that caused bounds check failures before I
fixed it.
This commit is contained in:
Nicholas Nethercote 2018-07-13 10:53:57 +10:00
parent 05742ffb43
commit f0c67951d0
6 changed files with 22 additions and 22 deletions

View File

@ -79,7 +79,7 @@ fn bit_lookup(bit: usize) -> BitLookup {
} }
fn bit_str(bit: Word) -> String { fn bit_str(bit: usize) -> String {
let byte = bit >> 3; let byte = bit >> 3;
let lobits = 1 << (bit & 0b111); let lobits = 1 << (bit & 0b111);
format!("[{}:{}-{:02x}]", bit, byte, lobits) format!("[{}:{}-{:02x}]", bit, byte, lobits)
@ -116,8 +116,8 @@ pub fn bits_to_string(words: &[Word], bits: usize) -> String {
} }
#[inline] #[inline]
pub fn bitwise<Op:BitwiseOperator>(out_vec: &mut [usize], pub fn bitwise<Op:BitwiseOperator>(out_vec: &mut [Word],
in_vec: &[usize], in_vec: &[Word],
op: &Op) -> bool { op: &Op) -> bool {
assert_eq!(out_vec.len(), in_vec.len()); assert_eq!(out_vec.len(), in_vec.len());
let mut changed = false; let mut changed = false;
@ -132,21 +132,21 @@ pub fn bitwise<Op:BitwiseOperator>(out_vec: &mut [usize],
pub trait BitwiseOperator { pub trait BitwiseOperator {
/// Applies some bit-operation pointwise to each of the bits in the two inputs. /// Applies some bit-operation pointwise to each of the bits in the two inputs.
fn join(&self, pred1: usize, pred2: usize) -> usize; fn join(&self, pred1: Word, pred2: Word) -> Word;
} }
pub struct Intersect; pub struct Intersect;
impl BitwiseOperator for Intersect { impl BitwiseOperator for Intersect {
#[inline] #[inline]
fn join(&self, a: usize, b: usize) -> usize { a & b } fn join(&self, a: Word, b: Word) -> Word { a & b }
} }
pub struct Union; pub struct Union;
impl BitwiseOperator for Union { impl BitwiseOperator for Union {
#[inline] #[inline]
fn join(&self, a: usize, b: usize) -> usize { a | b } fn join(&self, a: Word, b: Word) -> Word { a | b }
} }
pub struct Subtract; pub struct Subtract;
impl BitwiseOperator for Subtract { impl BitwiseOperator for Subtract {
#[inline] #[inline]
fn join(&self, a: usize, b: usize) -> usize { a & !b } fn join(&self, a: Word, b: Word) -> Word { a & !b }
} }

View File

@ -74,7 +74,7 @@ impl<'a, 'tcx> BitDenotation for HaveBeenBorrowedLocals<'a, 'tcx> {
impl<'a, 'tcx> BitwiseOperator for HaveBeenBorrowedLocals<'a, 'tcx> { impl<'a, 'tcx> BitwiseOperator for HaveBeenBorrowedLocals<'a, 'tcx> {
#[inline] #[inline]
fn join(&self, pred1: usize, pred2: usize) -> usize { fn join(&self, pred1: Word, pred2: Word) -> Word {
pred1 | pred2 // "maybe" means we union effects of both preds pred1 | pred2 // "maybe" means we union effects of both preds
} }
} }

View File

@ -20,7 +20,7 @@ use rustc::ty::TyCtxt;
use rustc::ty::{RegionKind, RegionVid}; use rustc::ty::{RegionKind, RegionVid};
use rustc::ty::RegionKind::ReScope; use rustc::ty::RegionKind::ReScope;
use rustc_data_structures::bitslice::BitwiseOperator; use rustc_data_structures::bitslice::{BitwiseOperator, Word};
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::indexed_set::IdxSet; use rustc_data_structures::indexed_set::IdxSet;
use rustc_data_structures::indexed_vec::IndexVec; use rustc_data_structures::indexed_vec::IndexVec;
@ -370,7 +370,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
impl<'a, 'gcx, 'tcx> BitwiseOperator for Borrows<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> BitwiseOperator for Borrows<'a, 'gcx, 'tcx> {
#[inline] #[inline]
fn join(&self, pred1: usize, pred2: usize) -> usize { fn join(&self, pred1: Word, pred2: Word) -> Word {
pred1 | pred2 // union effects of preds when computing reservations pred1 | pred2 // union effects of preds when computing reservations
} }
} }

View File

@ -14,7 +14,7 @@
use rustc::ty::TyCtxt; use rustc::ty::TyCtxt;
use rustc::mir::{self, Mir, Location}; use rustc::mir::{self, Mir, Location};
use rustc_data_structures::bitslice::{BitwiseOperator}; use rustc_data_structures::bitslice::{BitwiseOperator, Word};
use rustc_data_structures::indexed_set::{IdxSet}; use rustc_data_structures::indexed_set::{IdxSet};
use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::indexed_vec::Idx;
@ -663,35 +663,35 @@ impl<'a, 'gcx, 'tcx> BitDenotation for EverInitializedPlaces<'a, 'gcx, 'tcx> {
impl<'a, 'gcx, 'tcx> BitwiseOperator for MaybeInitializedPlaces<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> BitwiseOperator for MaybeInitializedPlaces<'a, 'gcx, 'tcx> {
#[inline] #[inline]
fn join(&self, pred1: usize, pred2: usize) -> usize { fn join(&self, pred1: Word, pred2: Word) -> Word {
pred1 | pred2 // "maybe" means we union effects of both preds pred1 | pred2 // "maybe" means we union effects of both preds
} }
} }
impl<'a, 'gcx, 'tcx> BitwiseOperator for MaybeUninitializedPlaces<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> BitwiseOperator for MaybeUninitializedPlaces<'a, 'gcx, 'tcx> {
#[inline] #[inline]
fn join(&self, pred1: usize, pred2: usize) -> usize { fn join(&self, pred1: Word, pred2: Word) -> Word {
pred1 | pred2 // "maybe" means we union effects of both preds pred1 | pred2 // "maybe" means we union effects of both preds
} }
} }
impl<'a, 'gcx, 'tcx> BitwiseOperator for DefinitelyInitializedPlaces<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> BitwiseOperator for DefinitelyInitializedPlaces<'a, 'gcx, 'tcx> {
#[inline] #[inline]
fn join(&self, pred1: usize, pred2: usize) -> usize { fn join(&self, pred1: Word, pred2: Word) -> Word {
pred1 & pred2 // "definitely" means we intersect effects of both preds pred1 & pred2 // "definitely" means we intersect effects of both preds
} }
} }
impl<'a, 'gcx, 'tcx> BitwiseOperator for MovingOutStatements<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> BitwiseOperator for MovingOutStatements<'a, 'gcx, 'tcx> {
#[inline] #[inline]
fn join(&self, pred1: usize, pred2: usize) -> usize { fn join(&self, pred1: Word, pred2: Word) -> Word {
pred1 | pred2 // moves from both preds are in scope pred1 | pred2 // moves from both preds are in scope
} }
} }
impl<'a, 'gcx, 'tcx> BitwiseOperator for EverInitializedPlaces<'a, 'gcx, 'tcx> { impl<'a, 'gcx, 'tcx> BitwiseOperator for EverInitializedPlaces<'a, 'gcx, 'tcx> {
#[inline] #[inline]
fn join(&self, pred1: usize, pred2: usize) -> usize { fn join(&self, pred1: Word, pred2: Word) -> Word {
pred1 | pred2 // inits from both preds are in scope pred1 | pred2 // inits from both preds are in scope
} }
} }

View File

@ -69,7 +69,7 @@ impl<'a, 'tcx> BitDenotation for MaybeStorageLive<'a, 'tcx> {
impl<'a, 'tcx> BitwiseOperator for MaybeStorageLive<'a, 'tcx> { impl<'a, 'tcx> BitwiseOperator for MaybeStorageLive<'a, 'tcx> {
#[inline] #[inline]
fn join(&self, pred1: usize, pred2: usize) -> usize { fn join(&self, pred1: Word, pred2: Word) -> Word {
pred1 | pred2 // "maybe" means we union effects of both preds pred1 | pred2 // "maybe" means we union effects of both preds
} }
} }

View File

@ -12,7 +12,7 @@ use syntax::ast::{self, MetaItem};
use rustc_data_structures::indexed_set::{IdxSet, IdxSetBuf}; use rustc_data_structures::indexed_set::{IdxSet, IdxSetBuf};
use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::bitslice::{bitwise, BitwiseOperator}; use rustc_data_structures::bitslice::{bitwise, BitwiseOperator, Word};
use rustc_data_structures::work_queue::WorkQueue; use rustc_data_structures::work_queue::WorkQueue;
use rustc::ty::{self, TyCtxt}; use rustc::ty::{self, TyCtxt};
@ -467,7 +467,7 @@ pub struct AllSets<E: Idx> {
bits_per_block: usize, bits_per_block: usize,
/// Number of words associated with each block entry /// Number of words associated with each block entry
/// equal to bits_per_block / usize::BITS, rounded up. /// equal to bits_per_block / (mem::size_of::<Word> * 8), rounded up.
words_per_block: usize, words_per_block: usize,
/// For each block, bits generated by executing the statements in /// For each block, bits generated by executing the statements in
@ -734,9 +734,9 @@ impl<'a, 'tcx, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation
dead_unwinds: &'a IdxSet<mir::BasicBlock>, dead_unwinds: &'a IdxSet<mir::BasicBlock>,
denotation: D) -> Self where D: InitialFlow { denotation: D) -> Self where D: InitialFlow {
let bits_per_block = denotation.bits_per_block(); let bits_per_block = denotation.bits_per_block();
let usize_bits = mem::size_of::<usize>() * 8; let bits_per_word = mem::size_of::<Word>() * 8;
let words_per_block = (bits_per_block + usize_bits - 1) / usize_bits; let words_per_block = (bits_per_block + bits_per_word - 1) / bits_per_word;
let bits_per_block_rounded_up = words_per_block * usize_bits; // a multiple of word size let bits_per_block_rounded_up = words_per_block * bits_per_word; // a multiple of word size
let num_blocks = mir.basic_blocks().len(); let num_blocks = mir.basic_blocks().len();
let num_overall = num_blocks * bits_per_block_rounded_up; let num_overall = num_blocks * bits_per_block_rounded_up;