Skip to content

Commit

Permalink
revised mir-dataflow so bitvectors carry a phantom type for their ind…
Browse files Browse the repository at this point in the history
…ex 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`
  • Loading branch information
pnkfelix committed May 23, 2016
1 parent 0796ee7 commit 71af40b
Show file tree
Hide file tree
Showing 6 changed files with 272 additions and 180 deletions.
29 changes: 29 additions & 0 deletions src/librustc_borrowck/bitslice.rs
Expand Up @@ -109,3 +109,32 @@ pub fn bits_to_string(words: &[Word], bits: usize) -> String {
result.push(']');
return result
}

#[inline]
pub fn bitwise<Op:BitwiseOperator>(out_vec: &mut [usize],
in_vec: &[usize],
op: &Op) -> bool {
assert_eq!(out_vec.len(), in_vec.len());
let mut changed = false;
for (out_elt, in_elt) in out_vec.iter_mut().zip(in_vec) {
let old_val = *out_elt;
let new_val = op.join(old_val, *in_elt);
*out_elt = new_val;
changed |= old_val != new_val;
}
changed
}

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

pub struct Union;
impl BitwiseOperator for Union {
fn join(&self, a: usize, b: usize) -> usize { a | b }
}
pub struct Subtract;
impl BitwiseOperator for Subtract {
fn join(&self, a: usize, b: usize) -> usize { a & !b }
}
11 changes: 6 additions & 5 deletions src/librustc_borrowck/borrowck/mir/dataflow/graphviz.rs
Expand Up @@ -54,8 +54,9 @@ struct Graph<'a, 'tcx, MWF:'a> where MWF: MirWithFlowState<'tcx>,

pub fn print_borrowck_graph_to<'a, 'tcx, BD>(
mbcx: &MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>,
path: &Path) -> io::Result<()> where BD: BitDenotation,
BD::Bit: Debug, BD::Ctxt: HasMoveData<'tcx>
path: &Path)
-> io::Result<()>
where BD: BitDenotation, BD::Bit: Debug, BD::Ctxt: HasMoveData<'tcx>,
{
let g = Graph { mbcx: mbcx, phantom: PhantomData };
let mut v = Vec::new();
Expand Down Expand Up @@ -180,7 +181,7 @@ impl<'a, 'tcx, MWF> dot::Labeller<'a> for Graph<'a, 'tcx, MWF>
<td></td></tr>",
bg = BG_FLOWCONTENT,
face = FACE_MONOSPACE,
entrybits=bits_to_string(entry, bits_per_block))
entrybits=bits_to_string(entry.words(), bits_per_block))
},
|w| {
let ctxt = self.mbcx.analysis_ctxt();
Expand All @@ -197,7 +198,7 @@ impl<'a, 'tcx, MWF> dot::Labeller<'a> for Graph<'a, 'tcx, MWF>
<td></td></tr>",
bg = BG_FLOWCONTENT,
face = FACE_MONOSPACE,
genbits=bits_to_string(gen, bits_per_block))?;
genbits=bits_to_string(gen.words(), bits_per_block))?;
}

{
Expand All @@ -209,7 +210,7 @@ impl<'a, 'tcx, MWF> dot::Labeller<'a> for Graph<'a, 'tcx, MWF>
bg = BG_FLOWCONTENT,
align = ALIGN_RIGHT,
face = FACE_MONOSPACE,
killbits=bits_to_string(kill, bits_per_block))?;
killbits=bits_to_string(kill.words(), bits_per_block))?;
}

// (chunked_present_right)
Expand Down

0 comments on commit 71af40b

Please sign in to comment.