Skip to content

Commit 07214bd

Browse files
committed
Refactoring: pull bitvector initialization out from other parts of dataflow.
This is meant to ease development of multi-stage dataflow analyses where the output from one analysis is used to initialize the state for the next; in such a context, you cannot start with `bottom_value` for all the bits.
1 parent 71e619f commit 07214bd

File tree

4 files changed

+18
-21
lines changed

4 files changed

+18
-21
lines changed

src/librustc_mir/dataflow/impls/borrows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_data_structures::bitslice::{BitwiseOperator};
1919
use rustc_data_structures::indexed_set::{IdxSet};
2020
use rustc_data_structures::indexed_vec::{IndexVec};
2121

22-
use dataflow::{BitDenotation, BlockSets, DataflowOperator};
22+
use dataflow::{BitDenotation, BlockSets, InitialFlow};
2323
pub use dataflow::indexes::BorrowIndex;
2424
use borrow_check::nll::region_infer::RegionInferenceContext;
2525
use borrow_check::nll::ToRegionVid;
@@ -287,7 +287,7 @@ impl<'a, 'gcx, 'tcx> BitwiseOperator for Borrows<'a, 'gcx, 'tcx> {
287287
}
288288
}
289289

290-
impl<'a, 'gcx, 'tcx> DataflowOperator for Borrows<'a, 'gcx, 'tcx> {
290+
impl<'a, 'gcx, 'tcx> InitialFlow for Borrows<'a, 'gcx, 'tcx> {
291291
#[inline]
292292
fn bottom_value() -> bool {
293293
false // bottom = no Rvalue::Refs are active by default

src/librustc_mir/dataflow/impls/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use util::elaborate_drops::DropFlagState;
2424

2525
use super::move_paths::{HasMoveData, MoveData, MoveOutIndex, MovePathIndex, InitIndex};
2626
use super::move_paths::{LookupResult, InitKind};
27-
use super::{BitDenotation, BlockSets, DataflowOperator};
27+
use super::{BitDenotation, BlockSets, InitialFlow};
2828

2929
use super::drop_flag_effects_for_function_entry;
3030
use super::drop_flag_effects_for_location;
@@ -728,35 +728,35 @@ impl<'a, 'gcx, 'tcx> BitwiseOperator for EverInitializedLvals<'a, 'gcx, 'tcx> {
728728
// propagating, or you start at all-ones and then use Intersect as
729729
// your merge when propagating.
730730

731-
impl<'a, 'gcx, 'tcx> DataflowOperator for MaybeInitializedLvals<'a, 'gcx, 'tcx> {
731+
impl<'a, 'gcx, 'tcx> InitialFlow for MaybeInitializedLvals<'a, 'gcx, 'tcx> {
732732
#[inline]
733733
fn bottom_value() -> bool {
734734
false // bottom = uninitialized
735735
}
736736
}
737737

738-
impl<'a, 'gcx, 'tcx> DataflowOperator for MaybeUninitializedLvals<'a, 'gcx, 'tcx> {
738+
impl<'a, 'gcx, 'tcx> InitialFlow for MaybeUninitializedLvals<'a, 'gcx, 'tcx> {
739739
#[inline]
740740
fn bottom_value() -> bool {
741741
false // bottom = initialized (start_block_effect counters this at outset)
742742
}
743743
}
744744

745-
impl<'a, 'gcx, 'tcx> DataflowOperator for DefinitelyInitializedLvals<'a, 'gcx, 'tcx> {
745+
impl<'a, 'gcx, 'tcx> InitialFlow for DefinitelyInitializedLvals<'a, 'gcx, 'tcx> {
746746
#[inline]
747747
fn bottom_value() -> bool {
748748
true // bottom = initialized (start_block_effect counters this at outset)
749749
}
750750
}
751751

752-
impl<'a, 'gcx, 'tcx> DataflowOperator for MovingOutStatements<'a, 'gcx, 'tcx> {
752+
impl<'a, 'gcx, 'tcx> InitialFlow for MovingOutStatements<'a, 'gcx, 'tcx> {
753753
#[inline]
754754
fn bottom_value() -> bool {
755755
false // bottom = no loans in scope by default
756756
}
757757
}
758758

759-
impl<'a, 'gcx, 'tcx> DataflowOperator for EverInitializedLvals<'a, 'gcx, 'tcx> {
759+
impl<'a, 'gcx, 'tcx> InitialFlow for EverInitializedLvals<'a, 'gcx, 'tcx> {
760760
#[inline]
761761
fn bottom_value() -> bool {
762762
false // bottom = no initialized variables by default

src/librustc_mir/dataflow/impls/storage_liveness.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl<'a, 'tcx> BitwiseOperator for MaybeStorageLive<'a, 'tcx> {
7474
}
7575
}
7676

77-
impl<'a, 'tcx> DataflowOperator for MaybeStorageLive<'a, 'tcx> {
77+
impl<'a, 'tcx> InitialFlow for MaybeStorageLive<'a, 'tcx> {
7878
#[inline]
7979
fn bottom_value() -> bool {
8080
false // bottom = dead

src/librustc_mir/dataflow/mod.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub(crate) fn do_dataflow<'a, 'gcx, 'tcx, BD, P>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
124124
bd: BD,
125125
p: P)
126126
-> DataflowResults<BD>
127-
where BD: BitDenotation,
127+
where BD: BitDenotation + InitialFlow,
128128
P: Fn(&BD, BD::Idx) -> DebugFormatted
129129
{
130130
let name_found = |sess: &Session, attrs: &[ast::Attribute], name| -> Option<String> {
@@ -173,7 +173,6 @@ impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation
173173
};
174174
while propcx.changed {
175175
propcx.changed = false;
176-
propcx.reset(&mut temp);
177176
propcx.walk_cfg(&mut temp);
178177
}
179178
}
@@ -209,13 +208,6 @@ impl<'a, 'tcx: 'a, BD> DataflowAnalysis<'a, 'tcx, BD> where BD: BitDenotation
209208

210209
impl<'b, 'a: 'b, 'tcx: 'a, BD> PropagationContext<'b, 'a, 'tcx, BD> where BD: BitDenotation
211210
{
212-
fn reset(&mut self, bits: &mut IdxSet<BD::Idx>) {
213-
let e = if BD::bottom_value() {!0} else {0};
214-
for b in bits.words_mut() {
215-
*b = e;
216-
}
217-
}
218-
219211
fn walk_cfg(&mut self, in_out: &mut IdxSet<BD::Idx>) {
220212
let mir = self.builder.mir;
221213
for (bb_idx, bb_data) in mir.basic_blocks().iter().enumerate() {
@@ -553,12 +545,17 @@ impl<E:Idx> AllSets<E> {
553545
}
554546

555547
/// Parameterization for the precise form of data flow that is used.
556-
pub trait DataflowOperator: BitwiseOperator {
548+
/// `InitialFlow` handles initializing the bitvectors before any
549+
/// code is inspected by the analysis. Analyses that need more nuanced
550+
/// initialization (e.g. they need to consult the results of some other
551+
/// dataflow analysis to set up the initial bitvectors) should not
552+
/// implement this.
553+
pub trait InitialFlow {
557554
/// Specifies the initial value for each bit in the `on_entry` set
558555
fn bottom_value() -> bool;
559556
}
560557

561-
pub trait BitDenotation: DataflowOperator {
558+
pub trait BitDenotation: BitwiseOperator {
562559
/// Specifies what index type is used to access the bitvector.
563560
type Idx: Idx;
564561

@@ -644,7 +641,7 @@ impl<'a, 'gcx, 'tcx: 'a, D> DataflowAnalysis<'a, 'tcx, D> where D: BitDenotation
644641
pub fn new(_tcx: TyCtxt<'a, 'gcx, 'tcx>,
645642
mir: &'a Mir<'tcx>,
646643
dead_unwinds: &'a IdxSet<mir::BasicBlock>,
647-
denotation: D) -> Self {
644+
denotation: D) -> Self where D: InitialFlow {
648645
let bits_per_block = denotation.bits_per_block();
649646
let usize_bits = mem::size_of::<usize>() * 8;
650647
let words_per_block = (bits_per_block + usize_bits - 1) / usize_bits;

0 commit comments

Comments
 (0)