Skip to content

Commit

Permalink
Auto merge of #68241 - ecstatic-morse:unified-dataflow-impls, r=<try>
Browse files Browse the repository at this point in the history
[WIP] Migrate dataflow impls to new framework

This uses #65672 to implement the most commonly used dataflow analyses so that the performance of the new framework can be tuned. For now, it's just for perf runs.

r? @ghost
  • Loading branch information
bors committed Jan 20, 2020
2 parents 29b854f + b1081c0 commit 6e516c1
Show file tree
Hide file tree
Showing 23 changed files with 2,537 additions and 1,077 deletions.
25 changes: 25 additions & 0 deletions src/librustc/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,31 @@ impl<'tcx> Body<'tcx> {
}
}

/// Returns a partially initialized MIR body containing only a list of basic blocks.
///
/// The returned MIR contains no `LocalDecl`s (even for the return place) or source scopes. It
/// is only useful for testing but cannot be `#[cfg(test)]` because it is used in a different
/// crate.
pub fn new_cfg_only(basic_blocks: IndexVec<BasicBlock, BasicBlockData<'tcx>>) -> Self {
Body {
phase: MirPhase::Build,
basic_blocks,
source_scopes: IndexVec::new(),
yield_ty: None,
generator_drop: None,
generator_layout: None,
local_decls: IndexVec::new(),
user_type_annotations: IndexVec::new(),
arg_count: 0,
spread_arg: None,
span: DUMMY_SP,
control_flow_destroyed: Vec::new(),
generator_kind: None,
var_debug_info: Vec::new(),
ignore_interior_mut_in_const_validation: false,
}
}

#[inline]
pub fn basic_blocks(&self) -> &IndexVec<BasicBlock, BasicBlockData<'tcx>> {
&self.basic_blocks
Expand Down
69 changes: 18 additions & 51 deletions src/librustc_mir/borrow_check/flows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,37 +3,36 @@
//! FIXME: this might be better as a "generic" fixed-point combinator,
//! but is not as ugly as it is right now.
use rustc::mir::{BasicBlock, Location};
use rustc_index::bit_set::BitIter;
#![allow(unused)]

use crate::borrow_check::location::LocationIndex;

use crate::borrow_check::nll::PoloniusOutput;

use crate::dataflow::generic::ResultsCursor;
use crate::dataflow::indexes::BorrowIndex;
use crate::dataflow::move_paths::HasMoveData;
use crate::dataflow::Borrows;
use crate::dataflow::EverInitializedPlaces;
use crate::dataflow::MaybeUninitializedPlaces;
use crate::dataflow::{FlowAtLocation, FlowsAtLocation};
use either::Either;
use std::fmt;
use std::rc::Rc;

crate struct Flows<'b, 'tcx> {
borrows: FlowAtLocation<'tcx, Borrows<'b, 'tcx>>,
pub uninits: FlowAtLocation<'tcx, MaybeUninitializedPlaces<'b, 'tcx>>,
pub ever_inits: FlowAtLocation<'tcx, EverInitializedPlaces<'b, 'tcx>>,
pub borrows: ResultsCursor<'b, 'tcx, Borrows<'b, 'tcx>>,
pub uninits: ResultsCursor<'b, 'tcx, MaybeUninitializedPlaces<'b, 'tcx>>,
pub ever_inits: ResultsCursor<'b, 'tcx, EverInitializedPlaces<'b, 'tcx>>,

/// Polonius Output
pub polonius_output: Option<Rc<PoloniusOutput>>,
}

impl<'b, 'tcx> Flows<'b, 'tcx> {
crate fn new(
borrows: FlowAtLocation<'tcx, Borrows<'b, 'tcx>>,
uninits: FlowAtLocation<'tcx, MaybeUninitializedPlaces<'b, 'tcx>>,
ever_inits: FlowAtLocation<'tcx, EverInitializedPlaces<'b, 'tcx>>,
borrows: ResultsCursor<'b, 'tcx, Borrows<'b, 'tcx>>,
uninits: ResultsCursor<'b, 'tcx, MaybeUninitializedPlaces<'b, 'tcx>>,
ever_inits: ResultsCursor<'b, 'tcx, EverInitializedPlaces<'b, 'tcx>>,
polonius_output: Option<Rc<PoloniusOutput>>,
) -> Self {
Flows { borrows, uninits, ever_inits, polonius_output }
Expand All @@ -46,43 +45,9 @@ impl<'b, 'tcx> Flows<'b, 'tcx> {
if let Some(ref polonius) = self.polonius_output {
Either::Left(polonius.errors_at(location).iter().cloned())
} else {
Either::Right(self.borrows.iter_incoming())
Either::Right(self.borrows.get().iter())
}
}

crate fn with_outgoing_borrows(&self, op: impl FnOnce(BitIter<'_, BorrowIndex>)) {
self.borrows.with_iter_outgoing(op)
}
}

macro_rules! each_flow {
($this:ident, $meth:ident($arg:ident)) => {
FlowAtLocation::$meth(&mut $this.borrows, $arg);
FlowAtLocation::$meth(&mut $this.uninits, $arg);
FlowAtLocation::$meth(&mut $this.ever_inits, $arg);
};
}

impl<'b, 'tcx> FlowsAtLocation for Flows<'b, 'tcx> {
fn reset_to_entry_of(&mut self, bb: BasicBlock) {
each_flow!(self, reset_to_entry_of(bb));
}

fn reset_to_exit_of(&mut self, bb: BasicBlock) {
each_flow!(self, reset_to_exit_of(bb));
}

fn reconstruct_statement_effect(&mut self, location: Location) {
each_flow!(self, reconstruct_statement_effect(location));
}

fn reconstruct_terminator_effect(&mut self, location: Location) {
each_flow!(self, reconstruct_terminator_effect(location));
}

fn apply_local_effect(&mut self, location: Location) {
each_flow!(self, apply_local_effect(location));
}
}

impl<'b, 'tcx> fmt::Display for Flows<'b, 'tcx> {
Expand All @@ -91,48 +56,50 @@ impl<'b, 'tcx> fmt::Display for Flows<'b, 'tcx> {

s.push_str("borrows in effect: [");
let mut saw_one = false;
self.borrows.each_state_bit(|borrow| {
self.borrows.get().iter().for_each(|borrow| {
if saw_one {
s.push_str(", ");
};
saw_one = true;
let borrow_data = &self.borrows.operator().borrows()[borrow];
let borrow_data = &self.borrows.analysis().borrows()[borrow];
s.push_str(&borrow_data.to_string());
});
s.push_str("] ");

/*
s.push_str("borrows generated: [");
let mut saw_one = false;
self.borrows.each_gen_bit(|borrow| {
if saw_one {
s.push_str(", ");
};
saw_one = true;
let borrow_data = &self.borrows.operator().borrows()[borrow];
let borrow_data = &self.borrows.analysis().borrows()[borrow];
s.push_str(&borrow_data.to_string());
});
s.push_str("] ");
*/

s.push_str("uninits: [");
let mut saw_one = false;
self.uninits.each_state_bit(|mpi_uninit| {
self.uninits.get().iter().for_each(|mpi_uninit| {
if saw_one {
s.push_str(", ");
};
saw_one = true;
let move_path = &self.uninits.operator().move_data().move_paths[mpi_uninit];
let move_path = &self.uninits.analysis().move_data().move_paths[mpi_uninit];
s.push_str(&move_path.to_string());
});
s.push_str("] ");

s.push_str("ever_init: [");
let mut saw_one = false;
self.ever_inits.each_state_bit(|mpi_ever_init| {
self.ever_inits.get().iter().for_each(|mpi_ever_init| {
if saw_one {
s.push_str(", ");
};
saw_one = true;
let ever_init = &self.ever_inits.operator().move_data().inits[mpi_ever_init];
let ever_init = &self.ever_inits.analysis().move_data().inits[mpi_ever_init];
s.push_str(&format!("{:?}", ever_init));
});
s.push_str("]");
Expand Down
Loading

0 comments on commit 6e516c1

Please sign in to comment.