Skip to content

Commit 71af40b

Browse files
committed
revised mir-dataflow so bitvectors carry a phantom type for their index domain.
As some drive-by's: * moved bitwise operators into `mod bitslice` * factored out `fn gen` and `fn kill` methods on `BlockSets` type * removed outdated comment about `fn propagate_call_return`
1 parent 0796ee7 commit 71af40b

File tree

6 files changed

+272
-180
lines changed

6 files changed

+272
-180
lines changed

src/librustc_borrowck/bitslice.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,32 @@ pub fn bits_to_string(words: &[Word], bits: usize) -> String {
109109
result.push(']');
110110
return result
111111
}
112+
113+
#[inline]
114+
pub fn bitwise<Op:BitwiseOperator>(out_vec: &mut [usize],
115+
in_vec: &[usize],
116+
op: &Op) -> bool {
117+
assert_eq!(out_vec.len(), in_vec.len());
118+
let mut changed = false;
119+
for (out_elt, in_elt) in out_vec.iter_mut().zip(in_vec) {
120+
let old_val = *out_elt;
121+
let new_val = op.join(old_val, *in_elt);
122+
*out_elt = new_val;
123+
changed |= old_val != new_val;
124+
}
125+
changed
126+
}
127+
128+
pub trait BitwiseOperator {
129+
/// Applies some bit-operation pointwise to each of the bits in the two inputs.
130+
fn join(&self, pred1: usize, pred2: usize) -> usize;
131+
}
132+
133+
pub struct Union;
134+
impl BitwiseOperator for Union {
135+
fn join(&self, a: usize, b: usize) -> usize { a | b }
136+
}
137+
pub struct Subtract;
138+
impl BitwiseOperator for Subtract {
139+
fn join(&self, a: usize, b: usize) -> usize { a & !b }
140+
}

src/librustc_borrowck/borrowck/mir/dataflow/graphviz.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,9 @@ struct Graph<'a, 'tcx, MWF:'a> where MWF: MirWithFlowState<'tcx>,
5454

5555
pub fn print_borrowck_graph_to<'a, 'tcx, BD>(
5656
mbcx: &MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>,
57-
path: &Path) -> io::Result<()> where BD: BitDenotation,
58-
BD::Bit: Debug, BD::Ctxt: HasMoveData<'tcx>
57+
path: &Path)
58+
-> io::Result<()>
59+
where BD: BitDenotation, BD::Bit: Debug, BD::Ctxt: HasMoveData<'tcx>,
5960
{
6061
let g = Graph { mbcx: mbcx, phantom: PhantomData };
6162
let mut v = Vec::new();
@@ -180,7 +181,7 @@ impl<'a, 'tcx, MWF> dot::Labeller<'a> for Graph<'a, 'tcx, MWF>
180181
<td></td></tr>",
181182
bg = BG_FLOWCONTENT,
182183
face = FACE_MONOSPACE,
183-
entrybits=bits_to_string(entry, bits_per_block))
184+
entrybits=bits_to_string(entry.words(), bits_per_block))
184185
},
185186
|w| {
186187
let ctxt = self.mbcx.analysis_ctxt();
@@ -197,7 +198,7 @@ impl<'a, 'tcx, MWF> dot::Labeller<'a> for Graph<'a, 'tcx, MWF>
197198
<td></td></tr>",
198199
bg = BG_FLOWCONTENT,
199200
face = FACE_MONOSPACE,
200-
genbits=bits_to_string(gen, bits_per_block))?;
201+
genbits=bits_to_string(gen.words(), bits_per_block))?;
201202
}
202203

203204
{
@@ -209,7 +210,7 @@ impl<'a, 'tcx, MWF> dot::Labeller<'a> for Graph<'a, 'tcx, MWF>
209210
bg = BG_FLOWCONTENT,
210211
align = ALIGN_RIGHT,
211212
face = FACE_MONOSPACE,
212-
killbits=bits_to_string(kill, bits_per_block))?;
213+
killbits=bits_to_string(kill.words(), bits_per_block))?;
213214
}
214215

215216
// (chunked_present_right)

0 commit comments

Comments
 (0)