Skip to content

Commit f2b0b67

Browse files
committed
Fix bitslice printing.
In multiple ways: - Two calls to `bits_to_string()` passed in byte lengths rather than bit lengths, which meant only 1/8th of the `BitSlice` was printed. - `bit_str`'s purpose is entirely mysterious. I removed it and changed its callers to print the indices in the obvious way. - `bits_to_string`'s inner loop was totally wrong, such that it printed entirely bogus results. - `bits_to_string` now also adds a '|' between words, which makes the output easier to read, e.g.: `[ff-ff-ff-ff-ff-ff-ff-ff|ff-ff-ff-ff-ff-ff-ff-07]`.
1 parent f0c6795 commit f2b0b67

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

src/librustc_data_structures/bitslice.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ impl BitSlice for [Word] {
2828
fn clear_bit(&mut self, idx: usize) -> bool {
2929
let words = self;
3030
debug!("clear_bit: words={} idx={}",
31-
bits_to_string(words, words.len() * mem::size_of::<Word>()), bit_str(idx));
31+
bits_to_string(words, words.len() * mem::size_of::<Word>() * 8), idx);
3232
let BitLookup { word, bit_in_word, bit_mask } = bit_lookup(idx);
33-
debug!("word={} bit_in_word={} bit_mask={}", word, bit_in_word, bit_mask);
33+
debug!("word={} bit_in_word={} bit_mask=0x{:x}", word, bit_in_word, bit_mask);
3434
let oldv = words[word];
3535
let newv = oldv & !bit_mask;
3636
words[word] = newv;
@@ -42,7 +42,7 @@ impl BitSlice for [Word] {
4242
fn set_bit(&mut self, idx: usize) -> bool {
4343
let words = self;
4444
debug!("set_bit: words={} idx={}",
45-
bits_to_string(words, words.len() * mem::size_of::<Word>()), bit_str(idx));
45+
bits_to_string(words, words.len() * mem::size_of::<Word>() * 8), idx);
4646
let BitLookup { word, bit_in_word, bit_mask } = bit_lookup(idx);
4747
debug!("word={} bit_in_word={} bit_mask={}", word, bit_in_word, bit_mask);
4848
let oldv = words[word];
@@ -78,13 +78,6 @@ fn bit_lookup(bit: usize) -> BitLookup {
7878
BitLookup { word: word, bit_in_word: bit_in_word, bit_mask: bit_mask }
7979
}
8080

81-
82-
fn bit_str(bit: usize) -> String {
83-
let byte = bit >> 3;
84-
let lobits = 1 << (bit & 0b111);
85-
format!("[{}:{}-{:02x}]", bit, byte, lobits)
86-
}
87-
8881
pub fn bits_to_string(words: &[Word], bits: usize) -> String {
8982
let mut result = String::new();
9083
let mut sep = '[';
@@ -95,7 +88,7 @@ pub fn bits_to_string(words: &[Word], bits: usize) -> String {
9588
let mut i = 0;
9689
for &word in words.iter() {
9790
let mut v = word;
98-
loop { // for each byte in `v`:
91+
for _ in 0..mem::size_of::<Word>() { // for each byte in `v`:
9992
let remain = bits - i;
10093
// If less than a byte remains, then mask just that many bits.
10194
let mask = if remain <= 8 { (1 << remain) - 1 } else { 0xFF };
@@ -110,6 +103,7 @@ pub fn bits_to_string(words: &[Word], bits: usize) -> String {
110103
i += 8;
111104
sep = '-';
112105
}
106+
sep = '|';
113107
}
114108
result.push(']');
115109
return result

0 commit comments

Comments
 (0)