Skip to content

Commit

Permalink
Run rustfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
spastorino committed May 29, 2018
1 parent 9de4e34 commit a8b36c9
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 71 deletions.
21 changes: 11 additions & 10 deletions src/librustc_mir/borrow_check/flows.rs
Expand Up @@ -21,12 +21,12 @@ use borrow_check::location::LocationIndex;

use polonius_engine::Output;

use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
use dataflow::move_paths::indexes::BorrowIndex;
use dataflow::move_paths::HasMoveData;
use dataflow::Borrows;
use dataflow::{EverInitializedPlaces, MovingOutStatements};
use dataflow::{Borrows};
use dataflow::{FlowAtLocation, FlowsAtLocation};
use dataflow::move_paths::HasMoveData;
use dataflow::move_paths::indexes::BorrowIndex;
use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
use either::Either;
use std::fmt;
use std::rc::Rc;
Expand Down Expand Up @@ -62,7 +62,10 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> {
}
}

crate fn borrows_in_scope(&self, location: LocationIndex) -> impl Iterator<Item = BorrowIndex> + '_ {
crate fn borrows_in_scope(
&self,
location: LocationIndex,
) -> impl Iterator<Item = BorrowIndex> + '_ {
if let Some(ref polonius) = self.polonius_output {
Either::Left(polonius.errors_at(location).iter().cloned())
} else {
Expand All @@ -82,7 +85,7 @@ macro_rules! each_flow {
FlowAtLocation::$meth(&mut $this.uninits, $arg);
FlowAtLocation::$meth(&mut $this.move_outs, $arg);
FlowAtLocation::$meth(&mut $this.ever_inits, $arg);
}
};
}

impl<'b, 'gcx, 'tcx> FlowsAtLocation for Flows<'b, 'gcx, 'tcx> {
Expand Down Expand Up @@ -150,8 +153,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
s.push_str(", ");
};
saw_one = true;
let move_path =
&self.uninits.operator().move_data().move_paths[mpi_uninit];
let move_path = &self.uninits.operator().move_data().move_paths[mpi_uninit];
s.push_str(&format!("{}", move_path));
});
s.push_str("] ");
Expand All @@ -175,8 +177,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
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.operator().move_data().inits[mpi_ever_init];
s.push_str(&format!("{:?}", ever_init));
});
s.push_str("]");
Expand Down
137 changes: 76 additions & 61 deletions src/librustc_mir/borrow_check/nll/mod.rs
Expand Up @@ -11,10 +11,10 @@
use borrow_check::borrow_set::BorrowSet;
use borrow_check::location::{LocationIndex, LocationTable};
use borrow_check::nll::facts::AllFactsExt;
use dataflow::indexes::BorrowIndex;
use dataflow::move_paths::MoveData;
use dataflow::FlowAtLocation;
use dataflow::MaybeInitializedPlaces;
use dataflow::indexes::BorrowIndex;
use rustc::hir::def_id::DefId;
use rustc::infer::InferCtxt;
use rustc::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, Mir};
Expand All @@ -23,25 +23,25 @@ use rustc::util::nodemap::FxHashMap;
use std::collections::BTreeSet;
use std::fmt::Debug;
use std::io;
use std::rc::Rc;
use std::path::PathBuf;
use std::rc::Rc;
use transform::MirSource;
use util::liveness::{LivenessResults, LocalSet};

use self::mir_util::PassWhere;
use polonius_engine::{Algorithm, Output};
use util as mir_util;
use util::pretty::{self, ALIGN};
use polonius_engine::{Algorithm, Output};

mod constraint_generation;
pub mod explain_borrow;
mod facts;
mod invalidation;
crate mod region_infer;
mod renumber;
mod subtype_constraint_generation;
crate mod type_check;
mod universal_regions;
mod invalidation;

use self::facts::AllFacts;
use self::region_infer::RegionInferenceContext;
Expand Down Expand Up @@ -119,8 +119,7 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
// Create the region inference context, taking ownership of the region inference
// data that was contained in `infcx`.
let var_origins = infcx.take_region_var_origins();
let mut regioncx =
RegionInferenceContext::new(var_origins, universal_regions, mir);
let mut regioncx = RegionInferenceContext::new(var_origins, universal_regions, mir);

// Generate various constraints.
subtype_constraint_generation::generate(
Expand All @@ -144,22 +143,27 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
location_table,
&mir,
def_id,
borrow_set
borrow_set,
);

// Dump facts if requested.
let polonius_output = all_facts.and_then(|all_facts| {
if infcx.tcx.sess.opts.debugging_opts.nll_facts {
let def_path = infcx.tcx.hir.def_path(def_id);
let dir_path = PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate());
all_facts.write_to_dir(dir_path, location_table).unwrap();
}

if infcx.tcx.sess.opts.debugging_opts.polonius {
Some(Rc::new(Output::compute(&all_facts, Algorithm::DatafrogOpt, false)))
} else {
None
}
if infcx.tcx.sess.opts.debugging_opts.nll_facts {
let def_path = infcx.tcx.hir.def_path(def_id);
let dir_path =
PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate());
all_facts.write_to_dir(dir_path, location_table).unwrap();
}

if infcx.tcx.sess.opts.debugging_opts.polonius {
Some(Rc::new(Output::compute(
&all_facts,
Algorithm::DatafrogOpt,
false,
)))
} else {
None
}
});

// Solve the region constraints.
Expand Down Expand Up @@ -195,7 +199,8 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
return;
}

let regular_liveness_per_location: FxHashMap<_, _> = mir.basic_blocks()
let regular_liveness_per_location: FxHashMap<_, _> = mir
.basic_blocks()
.indices()
.flat_map(|bb| {
let mut results = vec![];
Expand All @@ -208,7 +213,8 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
})
.collect();

let drop_liveness_per_location: FxHashMap<_, _> = mir.basic_blocks()
let drop_liveness_per_location: FxHashMap<_, _> = mir
.basic_blocks()
.indices()
.flat_map(|bb| {
let mut results = vec![];
Expand All @@ -221,47 +227,55 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
})
.collect();

mir_util::dump_mir(infcx.tcx, None, "nll", &0, source, mir, |pass_where, out| {
match pass_where {
// Before the CFG, dump out the values for each region variable.
PassWhere::BeforeCFG => {
regioncx.dump_mir(out)?;

if let Some(closure_region_requirements) = closure_region_requirements {
writeln!(out, "|")?;
writeln!(out, "| Free Region Constraints")?;
for_each_region_constraint(closure_region_requirements, &mut |msg| {
writeln!(out, "| {}", msg)
})?;
mir_util::dump_mir(
infcx.tcx,
None,
"nll",
&0,
source,
mir,
|pass_where, out| {
match pass_where {
// Before the CFG, dump out the values for each region variable.
PassWhere::BeforeCFG => {
regioncx.dump_mir(out)?;

if let Some(closure_region_requirements) = closure_region_requirements {
writeln!(out, "|")?;
writeln!(out, "| Free Region Constraints")?;
for_each_region_constraint(closure_region_requirements, &mut |msg| {
writeln!(out, "| {}", msg)
})?;
}
}
}

// Before each basic block, dump out the values
// that are live on entry to the basic block.
PassWhere::BeforeBlock(bb) => {
let s = live_variable_set(&liveness.regular.ins[bb], &liveness.drop.ins[bb]);
writeln!(out, " | Live variables on entry to {:?}: {}", bb, s)?;
}
// Before each basic block, dump out the values
// that are live on entry to the basic block.
PassWhere::BeforeBlock(bb) => {
let s = live_variable_set(&liveness.regular.ins[bb], &liveness.drop.ins[bb]);
writeln!(out, " | Live variables on entry to {:?}: {}", bb, s)?;
}

PassWhere::BeforeLocation(location) => {
let s = live_variable_set(
&regular_liveness_per_location[&location],
&drop_liveness_per_location[&location],
);
writeln!(
out,
"{:ALIGN$} | Live variables on entry to {:?}: {}",
"",
location,
s,
ALIGN = ALIGN
)?;
}
PassWhere::BeforeLocation(location) => {
let s = live_variable_set(
&regular_liveness_per_location[&location],
&drop_liveness_per_location[&location],
);
writeln!(
out,
"{:ALIGN$} | Live variables on entry to {:?}: {}",
"",
location,
s,
ALIGN = ALIGN
)?;
}

PassWhere::AfterLocation(_) | PassWhere::AfterCFG => {}
}
Ok(())
});
PassWhere::AfterLocation(_) | PassWhere::AfterCFG => {}
}
Ok(())
},
);

// Also dump the inference graph constraints as a graphviz file.
let _: io::Result<()> = do catch {
Expand Down Expand Up @@ -292,7 +306,8 @@ fn dump_annotation<'a, 'gcx, 'tcx>(
// better.

if let Some(closure_region_requirements) = closure_region_requirements {
let mut err = tcx.sess
let mut err = tcx
.sess
.diagnostic()
.span_note_diag(mir.span, "External requirements");

Expand All @@ -312,7 +327,8 @@ fn dump_annotation<'a, 'gcx, 'tcx>(

err.emit();
} else {
let mut err = tcx.sess
let mut err = tcx
.sess
.diagnostic()
.span_note_diag(mir.span, "No external requirements");
regioncx.annotate(&mut err);
Expand All @@ -331,8 +347,7 @@ fn for_each_region_constraint(
};
with_msg(&format!(
"where {:?}: {:?}",
subject,
req.outlived_free_region,
subject, req.outlived_free_region,
))?;
}
Ok(())
Expand Down

0 comments on commit a8b36c9

Please sign in to comment.