Skip to content

Commit 4a940b3

Browse files
committed
move flow_in_progress into dataflow and document it
1 parent ebd086b commit 4a940b3

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

src/librustc_mir/borrow_check/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ use rustc::mir::{Field, Statement, StatementKind, Terminator, TerminatorKind};
2222
use rustc::mir::ClosureRegionRequirements;
2323

2424
use rustc_data_structures::fx::FxHashSet;
25-
use rustc_data_structures::indexed_set::{IdxSetBuf};
25+
use rustc_data_structures::indexed_set::IdxSetBuf;
2626
use rustc_data_structures::indexed_vec::Idx;
2727

2828
use syntax::ast;
2929
use syntax_pos::Span;
3030

3131
use dataflow::{do_dataflow, DebugFormatted};
32+
use dataflow::FlowAtLocation;
3233
use dataflow::MoveDataParamEnv;
3334
use dataflow::{DataflowAnalysis, DataflowResultsConsumer};
34-
use dataflow::{FlowAtLocation, FlowsAtLocation};
3535
use dataflow::{MaybeInitializedLvals, MaybeUninitializedLvals};
3636
use dataflow::{EverInitializedLvals, MovingOutStatements};
3737
use dataflow::{Borrows, BorrowData, ReserveOrActivateIndex};

src/librustc_mir/borrow_check/nll/constraint_generation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use rustc::ty::fold::TypeFoldable;
2222
use rustc::util::common::ErrorReported;
2323
use rustc_data_structures::fx::FxHashSet;
2424
use syntax::codemap::DUMMY_SP;
25-
use borrow_check::{FlowAtLocation, FlowsAtLocation};
25+
use dataflow::{FlowAtLocation, FlowsAtLocation};
2626
use dataflow::MaybeInitializedLvals;
2727
use dataflow::move_paths::{HasMoveData, MoveData};
2828

src/librustc_mir/borrow_check/nll/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use std::collections::BTreeSet;
1717
use std::io;
1818
use transform::MirSource;
1919
use util::liveness::{LivenessResults, LocalSet};
20-
use borrow_check::FlowAtLocation;
20+
use dataflow::FlowAtLocation;
2121
use dataflow::MaybeInitializedLvals;
2222
use dataflow::move_paths::MoveData;
2323

src/librustc_mir/dataflow/at_location.rs

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,43 @@ use std::iter;
2525
/// There's probably a way to auto-impl this, but I think
2626
/// it is cleaner to have manual visitor impls.
2727
pub trait FlowsAtLocation {
28-
// reset the state bitvector to represent the entry to block `bb`.
28+
/// Reset the state bitvector to represent the entry to block `bb`.
2929
fn reset_to_entry_of(&mut self, bb: BasicBlock);
3030

31-
// build gen + kill sets for statement at `loc`.
31+
/// Build gen + kill sets for statement at `loc`.
32+
///
33+
/// Note that invoking this method alone does not change the
34+
/// `curr_state` -- you must invoke `apply_local_effect`
35+
/// afterwards.
3236
fn reconstruct_statement_effect(&mut self, loc: Location);
3337

34-
// build gen + kill sets for terminator for `loc`.
38+
/// Build gen + kill sets for terminator for `loc`.
39+
///
40+
/// Note that invoking this method alone does not change the
41+
/// `curr_state` -- you must invoke `apply_local_effect`
42+
/// afterwards.
3543
fn reconstruct_terminator_effect(&mut self, loc: Location);
3644

37-
// apply current gen + kill sets to `flow_state`.
38-
//
39-
// (`bb` and `stmt_idx` parameters can be ignored if desired by
40-
// client. For the terminator, the `stmt_idx` will be the number
41-
// of statements in the block.)
45+
/// Apply current gen + kill sets to `flow_state`.
46+
///
47+
/// (`loc` parameters can be ignored if desired by
48+
/// client. For the terminator, the `stmt_idx` will be the number
49+
/// of statements in the block.)
4250
fn apply_local_effect(&mut self, loc: Location);
4351
}
4452

4553
/// Represents the state of dataflow at a particular
4654
/// CFG location, both before and after it is
4755
/// executed.
56+
///
57+
/// Data flow results are typically computed only as basic block
58+
/// boundaries. A `FlowInProgress` allows you to reconstruct the
59+
/// effects at any point in the control-flow graph by starting with
60+
/// the state at the start of the basic block (`reset_to_entry_of`)
61+
/// and then replaying the effects of statements and terminators
62+
/// (e.g. via `reconstruct_statement_effect` and
63+
/// `reconstruct_terminator_effect`; don't forget to call
64+
/// `apply_local_effect`).
4865
pub struct FlowAtLocation<BD>
4966
where
5067
BD: BitDenotation,
@@ -59,6 +76,7 @@ impl<BD> FlowAtLocation<BD>
5976
where
6077
BD: BitDenotation,
6178
{
79+
/// Iterate over each bit set in the current state.
6280
pub fn each_state_bit<F>(&self, f: F)
6381
where
6482
F: FnMut(BD::Idx),
@@ -67,6 +85,9 @@ where
6785
.each_bit(self.base_results.operator().bits_per_block(), f)
6886
}
6987

88+
/// Iterate over each `gen` bit in the current effect (invoke
89+
/// `reconstruct_statement_effect` or
90+
/// `reconstruct_terminator_effect` first).
7091
pub fn each_gen_bit<F>(&self, f: F)
7192
where
7293
F: FnMut(BD::Idx),
@@ -88,6 +109,7 @@ where
88109
}
89110
}
90111

112+
/// Access the underlying operator.
91113
pub fn operator(&self) -> &BD {
92114
self.base_results.operator()
93115
}
@@ -96,11 +118,15 @@ where
96118
self.curr_state.contains(x)
97119
}
98120

121+
/// Returns an iterator over the elements present in the current state.
99122
pub fn elems_incoming(&self) -> iter::Peekable<indexed_set::Elems<BD::Idx>> {
100123
let univ = self.base_results.sets().bits_per_block();
101124
self.curr_state.elems(univ).peekable()
102125
}
103126

127+
/// Creates a clone of the current state and applies the local
128+
/// effects to the clone (leaving the state of self intact).
129+
/// Invokes `f` with an iterator over the resulting state.
104130
pub fn with_elems_outgoing<F>(&self, f: F)
105131
where
106132
F: FnOnce(indexed_set::Elems<BD::Idx>),

0 commit comments

Comments
 (0)