1
Fork 0

Removed type Bit and fn interpret items from trait BitDenotation.

Also got rid of the `trait HasMoveData`, since I am now just imposing
the constraint that `BitDenotation<Ctxt=MoveData<'tcx>>` where
necessary instead.
This commit is contained in:
Felix S. Klock II 2016-05-24 16:46:19 +02:00
parent 0cf5f1023e
commit fdf80bc60c
5 changed files with 21 additions and 62 deletions

View file

@ -109,7 +109,7 @@ pub fn print_borrowck_graph_to<'a, 'tcx, BD, P>(
path: &Path,
render_idx: P)
-> io::Result<()>
where BD: BitDenotation<Ctxt=MoveData<'tcx>>, BD::Bit: Debug,
where BD: BitDenotation<Ctxt=MoveData<'tcx>>,
P: for <'b> Fn(&'b BD::Ctxt, BD::Idx) -> &'b Debug
{
let g = Graph { mbcx: mbcx, phantom: PhantomData, render_idx: render_idx };
@ -131,7 +131,7 @@ fn outgoing(mir: &Mir, bb: BasicBlock) -> Vec<Edge> {
}
impl<'a, 'tcx, MWF, P> dot::Labeller<'a> for Graph<'a, 'tcx, MWF, P>
where MWF: MirWithFlowState<'tcx>, <MWF::BD as BitDenotation>::Bit: Debug,
where MWF: MirWithFlowState<'tcx>,
P: for <'b> Fn(&'b <MWF::BD as BitDenotation>::Ctxt, <MWF::BD as BitDenotation>::Idx) -> &'b Debug,
{
type Node = Node;

View file

@ -12,7 +12,7 @@ use rustc::ty::TyCtxt;
use rustc::mir::repr::{self, Mir};
use super::super::gather_moves::{Location};
use super::super::gather_moves::{MoveData, MoveOut, MoveOutIndex, MovePath, MovePathIndex};
use super::super::gather_moves::{MoveData, MoveOutIndex, MovePathIndex};
use super::super::DropFlagState;
use super::super::drop_flag_effects_for_function_entry;
use super::super::drop_flag_effects_for_location;
@ -226,15 +226,12 @@ impl<'a, 'tcx> DefinitelyInitializedLvals<'a, 'tcx> {
impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
type Idx = MovePathIndex;
type Bit = MovePath<'tcx>;
type Ctxt = MoveData<'tcx>;
fn name() -> &'static str { "maybe_init" }
fn bits_per_block(&self, ctxt: &Self::Ctxt) -> usize {
ctxt.move_paths.len()
}
fn interpret<'c>(&self, ctxt: &'c Self::Ctxt, idx: usize) -> &'c Self::Bit {
&ctxt.move_paths[MovePathIndex::new(idx)]
}
fn start_block_effect(&self, ctxt: &Self::Ctxt, sets: &mut BlockSets<MovePathIndex>)
{
drop_flag_effects_for_function_entry(
@ -288,15 +285,11 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
type Idx = MovePathIndex;
type Bit = MovePath<'tcx>;
type Ctxt = MoveData<'tcx>;
fn name() -> &'static str { "maybe_uninit" }
fn bits_per_block(&self, ctxt: &Self::Ctxt) -> usize {
ctxt.move_paths.len()
}
fn interpret<'c>(&self, ctxt: &'c Self::Ctxt, idx: usize) -> &'c Self::Bit {
&ctxt.move_paths[MovePathIndex::new(idx)]
}
// sets on_entry bits for Arg lvalues
fn start_block_effect(&self, ctxt: &Self::Ctxt, sets: &mut BlockSets<MovePathIndex>) {
@ -354,15 +347,11 @@ impl<'a, 'tcx> BitDenotation for MaybeUninitializedLvals<'a, 'tcx> {
impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
type Idx = MovePathIndex;
type Bit = MovePath<'tcx>;
type Ctxt = MoveData<'tcx>;
fn name() -> &'static str { "definite_init" }
fn bits_per_block(&self, ctxt: &Self::Ctxt) -> usize {
ctxt.move_paths.len()
}
fn interpret<'c>(&self, ctxt: &'c Self::Ctxt, idx: usize) -> &'c Self::Bit {
&ctxt.move_paths[MovePathIndex::new(idx)]
}
// sets on_entry bits for Arg lvalues
fn start_block_effect(&self, ctxt: &Self::Ctxt, sets: &mut BlockSets<MovePathIndex>) {
@ -419,15 +408,12 @@ impl<'a, 'tcx> BitDenotation for DefinitelyInitializedLvals<'a, 'tcx> {
impl<'a, 'tcx> BitDenotation for MovingOutStatements<'a, 'tcx> {
type Idx = MoveOutIndex;
type Bit = MoveOut;
type Ctxt = MoveData<'tcx>;
fn name() -> &'static str { "moving_out" }
fn bits_per_block(&self, ctxt: &Self::Ctxt) -> usize {
ctxt.moves.len()
}
fn interpret<'c>(&self, ctxt: &'c Self::Ctxt, idx: usize) -> &'c Self::Bit {
&ctxt.moves[idx]
}
fn start_block_effect(&self,_move_data: &Self::Ctxt, _sets: &mut BlockSets<MoveOutIndex>) {
// no move-statements have been executed prior to function
// execution, so this method has no effect on `_sets`.

View file

@ -36,8 +36,7 @@ pub trait Dataflow<BD: BitDenotation> {
}
impl<'a, 'tcx: 'a, BD> Dataflow<BD> for MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>
where BD: BitDenotation<Ctxt=MoveData<'tcx>> + DataflowOperator,
BD::Bit: Debug,
where BD: BitDenotation<Ctxt=MoveData<'tcx>> + DataflowOperator
{
fn dataflow<P>(&mut self, p: P) where P: Fn(&BD::Ctxt, BD::Idx) -> &Debug {
self.flow_state.build_sets();
@ -48,14 +47,14 @@ impl<'a, 'tcx: 'a, BD> Dataflow<BD> for MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>
}
struct PropagationContext<'b, 'a: 'b, 'tcx: 'a, O>
where O: 'b + BitDenotation, O::Ctxt: 'a+HasMoveData<'tcx>
where O: 'b + BitDenotation, O::Ctxt: 'a
{
builder: &'b mut DataflowAnalysis<'a, 'tcx, O>,
changed: bool,
}
impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD>
where BD: BitDenotation + DataflowOperator, BD::Ctxt: HasMoveData<'tcx>
where BD: BitDenotation + DataflowOperator
{
fn propagate(&mut self) {
let mut temp = OwnIdxSet::new_empty(self.flow_state.sets.bits_per_block);
@ -102,7 +101,7 @@ impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD>
}
impl<'b, 'a: 'b, 'tcx: 'a, BD> PropagationContext<'b, 'a, 'tcx, BD>
where BD: BitDenotation + DataflowOperator, BD::Ctxt: HasMoveData<'tcx>
where BD: BitDenotation + DataflowOperator
{
fn reset(&mut self, bits: &mut IdxSet<BD::Idx>) {
let e = if BD::bottom_value() {!0} else {0};
@ -141,7 +140,7 @@ fn dataflow_path(context: &str, prepost: &str, path: &str) -> PathBuf {
}
impl<'a, 'tcx: 'a, BD> MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>
where BD: BitDenotation<Ctxt=MoveData<'tcx>>, BD::Bit: Debug
where BD: BitDenotation<Ctxt=MoveData<'tcx>>
{
fn pre_dataflow_instrumentation<P>(&self, p: P) -> io::Result<()>
where P: Fn(&BD::Ctxt, BD::Idx) -> &Debug
@ -182,19 +181,8 @@ impl<E:Idx> Bits<E> {
}
}
pub trait HasMoveData<'tcx> {
fn move_data(&self) -> &MoveData<'tcx>;
}
impl<'tcx> HasMoveData<'tcx> for MoveData<'tcx> {
fn move_data(&self) -> &MoveData<'tcx> { self }
}
impl<'tcx, A, B> HasMoveData<'tcx> for (A, B, MoveData<'tcx>) {
fn move_data(&self) -> &MoveData<'tcx> { &self.2 }
}
pub struct DataflowAnalysis<'a, 'tcx: 'a, O>
where O: BitDenotation, O::Ctxt: 'a+HasMoveData<'tcx>
where O: BitDenotation, O::Ctxt: 'a
{
flow_state: DataflowState<O>,
mir: &'a Mir<'tcx>,
@ -202,7 +190,7 @@ pub struct DataflowAnalysis<'a, 'tcx: 'a, O>
}
impl<'a, 'tcx: 'a, O> DataflowAnalysis<'a, 'tcx, O>
where O: BitDenotation, O::Ctxt: HasMoveData<'tcx>
where O: BitDenotation
{
pub fn results(self) -> DataflowResults<O> {
DataflowResults(self.flow_state)
@ -301,9 +289,6 @@ pub trait DataflowOperator: BitwiseOperator {
}
pub trait BitDenotation {
/// Specifies what is represented by each bit in the dataflow bitvector.
type Bit;
/// Specifies what index type is used to access the bitvector.
type Idx: Idx;
@ -322,10 +307,6 @@ pub trait BitDenotation {
/// Size of each bitvector allocated for each block in the analysis.
fn bits_per_block(&self, &Self::Ctxt) -> usize;
/// Provides the meaning of each entry in the dataflow bitvector.
/// (Mostly intended for use for better debug instrumentation.)
fn interpret<'a>(&self, &'a Self::Ctxt, idx: usize) -> &'a Self::Bit;
/// Mutates the block-sets (the flow sets for the given
/// basic block) according to the effects that have been
/// established *prior* to entering the start block.
@ -396,8 +377,7 @@ pub trait BitDenotation {
}
impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D>
where D: BitDenotation + DataflowOperator,
D::Ctxt: HasMoveData<'tcx>
where D: BitDenotation + DataflowOperator
{
pub fn new(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
mir: &'a Mir<'tcx>,
@ -439,8 +419,7 @@ impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D>
}
impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D>
where D: BitDenotation + DataflowOperator,
D::Ctxt: HasMoveData<'tcx>,
where D: BitDenotation + DataflowOperator
{
/// Propagates the bits of `in_out` into all the successors of `bb`,
/// using bitwise operator denoted by `self.operator`.

View file

@ -15,10 +15,9 @@ use syntax::codemap::Span;
use rustc::ty::{self, TyCtxt};
use rustc::mir::repr::{self, Mir};
use super::super::gather_moves::{MovePath, MovePathIndex};
use super::super::gather_moves::{MoveData, MovePathIndex};
use super::BitDenotation;
use super::DataflowResults;
use super::HasMoveData;
/// This function scans `mir` for all calls to the intrinsic
/// `rustc_peek` that have the expression form `rustc_peek(&expr)`.
@ -42,7 +41,7 @@ pub fn sanity_check_via_rustc_peek<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
_attributes: &[ast::Attribute],
flow_ctxt: &O::Ctxt,
results: &DataflowResults<O>)
where O: BitDenotation<Bit=MovePath<'tcx>, Idx=MovePathIndex>, O::Ctxt: HasMoveData<'tcx>
where O: BitDenotation<Ctxt=MoveData<'tcx>, Idx=MovePathIndex>
{
debug!("sanity_check_via_rustc_peek id: {:?}", id);
// FIXME: this is not DRY. Figure out way to abstract this and
@ -57,10 +56,10 @@ pub fn sanity_check_via_rustc_peek<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
mir: &Mir<'tcx>,
flow_ctxt: &O::Ctxt,
move_data: &O::Ctxt,
results: &DataflowResults<O>,
bb: repr::BasicBlock) where
O: BitDenotation<Bit=MovePath<'tcx>, Idx=MovePathIndex>, O::Ctxt: HasMoveData<'tcx>
O: BitDenotation<Ctxt=MoveData<'tcx>, Idx=MovePathIndex>
{
let bb_data = mir.basic_block_data(bb);
let &repr::BasicBlockData { ref statements,
@ -88,8 +87,6 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
let mut gen = results.0.sets.gen_set_for(bb.index()).to_owned();
let mut kill = results.0.sets.kill_set_for(bb.index()).to_owned();
let move_data = flow_ctxt.move_data();
// Emulate effect of all statements in the block up to (but not
// including) the borrow within `peek_arg_lval`. Do *not* include
// call to `peek_arg_lval` itself (since we are peeking the state
@ -138,7 +135,7 @@ fn each_block<'a, 'tcx, O>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// reset GEN and KILL sets before emulating their effect.
for e in sets.gen_set.words_mut() { *e = 0; }
for e in sets.kill_set.words_mut() { *e = 0; }
results.0.operator.statement_effect(flow_ctxt, &mut sets, bb, j);
results.0.operator.statement_effect(move_data, &mut sets, bb, j);
sets.on_entry.union(sets.gen_set);
sets.on_entry.subtract(sets.kill_set);
}

View file

@ -31,14 +31,11 @@ mod gather_moves;
use self::dataflow::{BitDenotation};
use self::dataflow::{DataflowOperator};
use self::dataflow::{Dataflow, DataflowAnalysis, DataflowResults};
use self::dataflow::{HasMoveData};
use self::dataflow::{MaybeInitializedLvals, MaybeUninitializedLvals};
use self::dataflow::{DefinitelyInitializedLvals};
use self::gather_moves::{MoveData, MovePathIndex, Location};
use self::gather_moves::{MovePathContent};
use std::fmt::Debug;
fn has_rustc_mir_with(attrs: &[ast::Attribute], name: &str) -> Option<P<MetaItem>> {
for attr in attrs {
if attr.check_name("rustc_mir") {
@ -118,7 +115,7 @@ fn do_dataflow<'a, 'tcx, BD>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
attributes: &[ast::Attribute],
ctxt: &BD::Ctxt,
bd: BD) -> DataflowResults<BD>
where BD: BitDenotation<Idx=MovePathIndex, Ctxt=MoveData<'tcx>> + DataflowOperator, BD::Bit: Debug
where BD: BitDenotation<Idx=MovePathIndex, Ctxt=MoveData<'tcx>> + DataflowOperator
{
use syntax::attr::AttrMetaMethods;
@ -154,7 +151,7 @@ fn do_dataflow<'a, 'tcx, BD>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
pub struct MirBorrowckCtxtPreDataflow<'a, 'tcx: 'a, BD>
where BD: BitDenotation, BD::Ctxt: 'a+HasMoveData<'tcx>
where BD: BitDenotation, BD::Ctxt: 'a
{
node_id: ast::NodeId,
flow_state: DataflowAnalysis<'a, 'tcx, BD>,