Skip to content

Commit f0c6795

Browse files
committed
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.
1 parent 05742ff commit f0c6795

File tree

6 files changed

+22
-22
lines changed

6 files changed

+22
-22
lines changed

src/librustc_data_structures/bitslice.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn bit_lookup(bit: usize) -> BitLookup {
7979
}
8080

8181

82-
fn bit_str(bit: Word) -> String {
82+
fn bit_str(bit: usize) -> String {
8383
let byte = bit >> 3;
8484
let lobits = 1 << (bit & 0b111);
8585
format!("[{}:{}-{:02x}]", bit, byte, lobits)
@@ -116,8 +116,8 @@ pub fn bits_to_string(words: &[Word], bits: usize) -> String {
116116
}
117117

118118
#[inline]
119-
pub fn bitwise<Op:BitwiseOperator>(out_vec: &mut [usize],
120-
in_vec: &[usize],
119+
pub fn bitwise<Op:BitwiseOperator>(out_vec: &mut [Word],
120+
in_vec: &[Word],
121121
op: &Op) -> bool {
122122
assert_eq!(out_vec.len(), in_vec.len());
123123
let mut changed = false;
@@ -132,21 +132,21 @@ pub fn bitwise<Op:BitwiseOperator>(out_vec: &mut [usize],
132132

133133
pub trait BitwiseOperator {
134134
/// Applies some bit-operation pointwise to each of the bits in the two inputs.
135-
fn join(&self, pred1: usize, pred2: usize) -> usize;
135+
fn join(&self, pred1: Word, pred2: Word) -> Word;
136136
}
137137

138138
pub struct Intersect;
139139
impl BitwiseOperator for Intersect {
140140
#[inline]
141-
fn join(&self, a: usize, b: usize) -> usize { a & b }
141+
fn join(&self, a: Word, b: Word) -> Word { a & b }
142142
}
143143
pub struct Union;
144144
impl BitwiseOperator for Union {
145145
#[inline]
146-
fn join(&self, a: usize, b: usize) -> usize { a | b }
146+
fn join(&self, a: Word, b: Word) -> Word { a | b }
147147
}
148148
pub struct Subtract;
149149
impl BitwiseOperator for Subtract {
150150
#[inline]
151-
fn join(&self, a: usize, b: usize) -> usize { a & !b }
151+
fn join(&self, a: Word, b: Word) -> Word { a & !b }
152152
}

src/librustc_mir/dataflow/impls/borrowed_locals.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'a, 'tcx> BitDenotation for HaveBeenBorrowedLocals<'a, 'tcx> {
7474

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

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc::ty::TyCtxt;
2020
use rustc::ty::{RegionKind, RegionVid};
2121
use rustc::ty::RegionKind::ReScope;
2222

23-
use rustc_data_structures::bitslice::BitwiseOperator;
23+
use rustc_data_structures::bitslice::{BitwiseOperator, Word};
2424
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
2525
use rustc_data_structures::indexed_set::IdxSet;
2626
use rustc_data_structures::indexed_vec::IndexVec;
@@ -370,7 +370,7 @@ impl<'a, 'gcx, 'tcx> BitDenotation for Borrows<'a, 'gcx, 'tcx> {
370370

371371
impl<'a, 'gcx, 'tcx> BitwiseOperator for Borrows<'a, 'gcx, 'tcx> {
372372
#[inline]
373-
fn join(&self, pred1: usize, pred2: usize) -> usize {
373+
fn join(&self, pred1: Word, pred2: Word) -> Word {
374374
pred1 | pred2 // union effects of preds when computing reservations
375375
}
376376
}

src/librustc_mir/dataflow/impls/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
1515
use rustc::ty::TyCtxt;
1616
use rustc::mir::{self, Mir, Location};
17-
use rustc_data_structures::bitslice::{BitwiseOperator};
17+
use rustc_data_structures::bitslice::{BitwiseOperator, Word};
1818
use rustc_data_structures::indexed_set::{IdxSet};
1919
use rustc_data_structures::indexed_vec::Idx;
2020

@@ -663,35 +663,35 @@ impl<'a, 'gcx, 'tcx> BitDenotation for EverInitializedPlaces<'a, 'gcx, 'tcx> {
663663

664664
impl<'a, 'gcx, 'tcx> BitwiseOperator for MaybeInitializedPlaces<'a, 'gcx, 'tcx> {
665665
#[inline]
666-
fn join(&self, pred1: usize, pred2: usize) -> usize {
666+
fn join(&self, pred1: Word, pred2: Word) -> Word {
667667
pred1 | pred2 // "maybe" means we union effects of both preds
668668
}
669669
}
670670

671671
impl<'a, 'gcx, 'tcx> BitwiseOperator for MaybeUninitializedPlaces<'a, 'gcx, 'tcx> {
672672
#[inline]
673-
fn join(&self, pred1: usize, pred2: usize) -> usize {
673+
fn join(&self, pred1: Word, pred2: Word) -> Word {
674674
pred1 | pred2 // "maybe" means we union effects of both preds
675675
}
676676
}
677677

678678
impl<'a, 'gcx, 'tcx> BitwiseOperator for DefinitelyInitializedPlaces<'a, 'gcx, 'tcx> {
679679
#[inline]
680-
fn join(&self, pred1: usize, pred2: usize) -> usize {
680+
fn join(&self, pred1: Word, pred2: Word) -> Word {
681681
pred1 & pred2 // "definitely" means we intersect effects of both preds
682682
}
683683
}
684684

685685
impl<'a, 'gcx, 'tcx> BitwiseOperator for MovingOutStatements<'a, 'gcx, 'tcx> {
686686
#[inline]
687-
fn join(&self, pred1: usize, pred2: usize) -> usize {
687+
fn join(&self, pred1: Word, pred2: Word) -> Word {
688688
pred1 | pred2 // moves from both preds are in scope
689689
}
690690
}
691691

692692
impl<'a, 'gcx, 'tcx> BitwiseOperator for EverInitializedPlaces<'a, 'gcx, 'tcx> {
693693
#[inline]
694-
fn join(&self, pred1: usize, pred2: usize) -> usize {
694+
fn join(&self, pred1: Word, pred2: Word) -> Word {
695695
pred1 | pred2 // inits from both preds are in scope
696696
}
697697
}

src/librustc_mir/dataflow/impls/storage_liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'a, 'tcx> BitDenotation for MaybeStorageLive<'a, 'tcx> {
6969

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

src/librustc_mir/dataflow/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use syntax::ast::{self, MetaItem};
1212

1313
use rustc_data_structures::indexed_set::{IdxSet, IdxSetBuf};
1414
use rustc_data_structures::indexed_vec::Idx;
15-
use rustc_data_structures::bitslice::{bitwise, BitwiseOperator};
15+
use rustc_data_structures::bitslice::{bitwise, BitwiseOperator, Word};
1616
use rustc_data_structures::work_queue::WorkQueue;
1717

1818
use rustc::ty::{self, TyCtxt};
@@ -467,7 +467,7 @@ pub struct AllSets<E: Idx> {
467467
bits_per_block: usize,
468468

469469
/// Number of words associated with each block entry
470-
/// equal to bits_per_block / usize::BITS, rounded up.
470+
/// equal to bits_per_block / (mem::size_of::<Word> * 8), rounded up.
471471
words_per_block: usize,
472472

473473
/// 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
734734
dead_unwinds: &'a IdxSet<mir::BasicBlock>,
735735
denotation: D) -> Self where D: InitialFlow {
736736
let bits_per_block = denotation.bits_per_block();
737-
let usize_bits = mem::size_of::<usize>() * 8;
738-
let words_per_block = (bits_per_block + usize_bits - 1) / usize_bits;
739-
let bits_per_block_rounded_up = words_per_block * usize_bits; // a multiple of word size
737+
let bits_per_word = mem::size_of::<Word>() * 8;
738+
let words_per_block = (bits_per_block + bits_per_word - 1) / bits_per_word;
739+
let bits_per_block_rounded_up = words_per_block * bits_per_word; // a multiple of word size
740740
let num_blocks = mir.basic_blocks().len();
741741
let num_overall = num_blocks * bits_per_block_rounded_up;
742742

0 commit comments

Comments
 (0)