Skip to content

Commit 5811950

Browse files
committed
Review feedback.
Removed `BitDenotation: DataflowOperator` relationship. Alpha-renamed `fn initial_value` to `fn bottom_value`.
1 parent a7e3204 commit 5811950

File tree

2 files changed

+21
-23
lines changed

2 files changed

+21
-23
lines changed

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

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub trait Dataflow {
3535
}
3636

3737
impl<'a, 'tcx: 'a, BD> Dataflow for MirBorrowckCtxtPreDataflow<'a, 'tcx, BD>
38-
where BD: BitDenotation, BD::Bit: Debug, BD::Ctxt: HasMoveData<'tcx>
38+
where BD: BitDenotation + DataflowOperator, BD::Bit: Debug, BD::Ctxt: HasMoveData<'tcx>
3939
{
4040
fn dataflow(&mut self) {
4141
self.flow_state.build_sets();
@@ -53,7 +53,7 @@ struct PropagationContext<'b, 'a: 'b, 'tcx: 'a, O>
5353
}
5454

5555
impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD>
56-
where BD: BitDenotation, BD::Ctxt: HasMoveData<'tcx>
56+
where BD: BitDenotation + DataflowOperator, BD::Ctxt: HasMoveData<'tcx>
5757
{
5858
fn propagate(&mut self) {
5959
let mut temp = vec![0; self.flow_state.sets.words_per_block];
@@ -100,10 +100,10 @@ impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD>
100100
}
101101

102102
impl<'b, 'a: 'b, 'tcx: 'a, BD> PropagationContext<'b, 'a, 'tcx, BD>
103-
where BD: BitDenotation, BD::Ctxt: HasMoveData<'tcx>
103+
where BD: BitDenotation + DataflowOperator, BD::Ctxt: HasMoveData<'tcx>
104104
{
105105
fn reset(&mut self, bits: &mut [usize]) {
106-
let e = if BD::initial_value() {usize::MAX} else {0};
106+
let e = if BD::bottom_value() {usize::MAX} else {0};
107107
for b in bits {
108108
*b = e;
109109
}
@@ -317,17 +317,17 @@ impl<O: BitDenotation> DataflowState<O> {
317317
}
318318

319319
pub trait BitwiseOperator {
320-
/// Joins two predecessor bits together, typically either `|` or `&`
320+
/// Applies some bit-operation pointwise to each of the bits in the two inputs.
321321
fn join(&self, pred1: usize, pred2: usize) -> usize;
322322
}
323323

324324
/// Parameterization for the precise form of data flow that is used.
325-
pub trait DataflowOperator : BitwiseOperator {
325+
pub trait DataflowOperator: BitwiseOperator {
326326
/// Specifies the initial value for each bit in the `on_entry` set
327-
fn initial_value() -> bool;
327+
fn bottom_value() -> bool;
328328
}
329329

330-
pub trait BitDenotation: DataflowOperator {
330+
pub trait BitDenotation {
331331
/// Specifies what is represented by each bit in the dataflow bitvector.
332332
type Bit;
333333

@@ -425,7 +425,7 @@ pub trait BitDenotation: DataflowOperator {
425425
}
426426

427427
impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D>
428-
where D: BitDenotation, D::Ctxt: HasMoveData<'tcx>
428+
where D: BitDenotation + DataflowOperator, D::Ctxt: HasMoveData<'tcx>
429429
{
430430
pub fn new(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
431431
mir: &'a Mir<'tcx>,
@@ -437,7 +437,7 @@ impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D>
437437
let num_blocks = mir.basic_blocks.len();
438438
let num_words = num_blocks * words_per_block;
439439

440-
let entry = if D::initial_value() { usize::MAX } else {0};
440+
let entry = if D::bottom_value() { usize::MAX } else {0};
441441

442442
let zeroes = Bits::new(0, num_words);
443443
let on_entry = Bits::new(entry, num_words);
@@ -460,7 +460,7 @@ impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D>
460460
}
461461

462462
impl<'a, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D>
463-
where D: BitDenotation, D::Ctxt: HasMoveData<'tcx>
463+
where D: BitDenotation + DataflowOperator, D::Ctxt: HasMoveData<'tcx>
464464
{
465465
/// Propagates the bits of `in_out` into all the successors of `bb`,
466466
/// using bitwise operator denoted by `self.operator`.
@@ -851,7 +851,6 @@ impl<'a, 'tcx> BitDenotation for MaybeInitializedLvals<'a, 'tcx> {
851851
fn interpret<'c>(&self, ctxt: &'c Self::Ctxt, idx: usize) -> &'c Self::Bit {
852852
&ctxt.2.move_paths[MovePathIndex::new(idx)]
853853
}
854-
855854
fn start_block_effect(&self, ctxt: &Self::Ctxt, sets: &mut BlockSets)
856855
{
857856
super::drop_flag_effects_for_function_entry(
@@ -1072,12 +1071,10 @@ impl<'a, 'tcx> BitwiseOperator for DefinitelyInitializedLvals<'a, 'tcx> {
10721071
}
10731072
}
10741073

1075-
// FIXME: `DataflowOperator::initial_value` should be named
1076-
// `bottom_value`. The way that dataflow fixed point iteration works,
1077-
// you want to start at bottom and work your way to a fixed point.
1078-
// This needs to include the detail that the control-flow merges will
1079-
// apply the `join` operator above to current state (which starts at
1080-
// that bottom value).
1074+
// The way that dataflow fixed point iteration works, you want to
1075+
// start at bottom and work your way to a fixed point. Control-flow
1076+
// merges will apply the `join` operator to each block entry's current
1077+
// state (which starts at that bottom value).
10811078
//
10821079
// This means, for propagation across the graph, that you either want
10831080
// to start at all-zeroes and then use Union as your merge when
@@ -1086,28 +1083,28 @@ impl<'a, 'tcx> BitwiseOperator for DefinitelyInitializedLvals<'a, 'tcx> {
10861083

10871084
impl<'a, 'tcx> DataflowOperator for MovingOutStatements<'a, 'tcx> {
10881085
#[inline]
1089-
fn initial_value() -> bool {
1086+
fn bottom_value() -> bool {
10901087
false // bottom = no loans in scope by default
10911088
}
10921089
}
10931090

10941091
impl<'a, 'tcx> DataflowOperator for MaybeInitializedLvals<'a, 'tcx> {
10951092
#[inline]
1096-
fn initial_value() -> bool {
1093+
fn bottom_value() -> bool {
10971094
false // bottom = uninitialized
10981095
}
10991096
}
11001097

11011098
impl<'a, 'tcx> DataflowOperator for MaybeUninitializedLvals<'a, 'tcx> {
11021099
#[inline]
1103-
fn initial_value() -> bool {
1100+
fn bottom_value() -> bool {
11041101
false // bottom = initialized (start_block_effect counters this at outset)
11051102
}
11061103
}
11071104

11081105
impl<'a, 'tcx> DataflowOperator for DefinitelyInitializedLvals<'a, 'tcx> {
11091106
#[inline]
1110-
fn initial_value() -> bool {
1107+
fn bottom_value() -> bool {
11111108
true // bottom = initialized
11121109
}
11131110
}

src/librustc_borrowck/borrowck/mir/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ mod gather_moves;
2929
// mod graphviz;
3030

3131
use self::dataflow::{BitDenotation};
32+
use self::dataflow::{DataflowOperator};
3233
use self::dataflow::{Dataflow, DataflowAnalysis, DataflowResults};
3334
use self::dataflow::{HasMoveData};
3435
use self::dataflow::{MaybeInitializedLvals, MaybeUninitializedLvals};
@@ -119,7 +120,7 @@ fn do_dataflow<'a, 'tcx, BD>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
119120
attributes: &[ast::Attribute],
120121
ctxt: BD::Ctxt,
121122
bd: BD) -> (BD::Ctxt, DataflowResults<BD>)
122-
where BD: BitDenotation, BD::Bit: Debug, BD::Ctxt: HasMoveData<'tcx>
123+
where BD: BitDenotation + DataflowOperator, BD::Bit: Debug, BD::Ctxt: HasMoveData<'tcx>
123124
{
124125
use syntax::attr::AttrMetaMethods;
125126

0 commit comments

Comments
 (0)