- polonius: adapt to the new fact format

- update polonius-engine dependency to 0.12.0

- rustfmt the files failing tidy
This commit is contained in:
Albin Stjerna 2019-11-20 20:34:24 +01:00 committed by Remy Rakic
parent 49c68bd53f
commit 6f40cdb380
7 changed files with 60 additions and 45 deletions

View File

@ -2494,9 +2494,9 @@ checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
[[package]] [[package]]
name = "polonius-engine" name = "polonius-engine"
version = "0.11.0" version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e478d7c38eb785c6416cbe58df12aa55d7aefa3759b6d3e044b2ed03f423cec" checksum = "04d8ef65e3f89ecaec9ca7cb0e0911b4617352d4494018bcf934992f03f2024c"
dependencies = [ dependencies = [
"datafrog", "datafrog",
"log", "log",

View File

@ -17,7 +17,7 @@ scoped-tls = "1.0"
log = { version = "0.4", features = ["release_max_level_info", "std"] } log = { version = "0.4", features = ["release_max_level_info", "std"] }
rustc-rayon = "0.3.0" rustc-rayon = "0.3.0"
rustc-rayon-core = "0.3.0" rustc-rayon-core = "0.3.0"
polonius-engine = "0.11.0" polonius-engine = "0.12.0"
rustc_apfloat = { path = "../librustc_apfloat" } rustc_apfloat = { path = "../librustc_apfloat" }
rustc_attr = { path = "../librustc_attr" } rustc_attr = { path = "../librustc_attr" }
rustc_feature = { path = "../librustc_feature" } rustc_feature = { path = "../librustc_feature" }

View File

@ -15,7 +15,7 @@ dot = { path = "../libgraphviz", package = "graphviz" }
itertools = "0.8" itertools = "0.8"
log = "0.4" log = "0.4"
log_settings = "0.1.1" log_settings = "0.1.1"
polonius-engine = "0.11.0" polonius-engine = "0.12.0"
rustc = { path = "../librustc" } rustc = { path = "../librustc" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" } rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_attr = { path = "../librustc_attr" } rustc_attr = { path = "../librustc_attr" }

View File

@ -71,16 +71,16 @@ impl AllFactsExt for AllFacts {
killed, killed,
outlives, outlives,
invalidates, invalidates,
var_used, var_used_at,
var_defined, var_defined_at,
var_drop_used, var_dropped_at,
var_uses_region, use_of_var_derefs_origin,
var_drops_region, drop_of_var_derefs_origin,
child, child_path,
path_belongs_to_var, path_is_var,
initialized_at, path_assigned_at_base,
moved_out_at, path_moved_at_base,
path_accessed_at, path_accessed_at_base,
known_subset, known_subset,
]) ])
} }

View File

@ -86,15 +86,18 @@ fn populate_polonius_move_facts(
body: &Body<'_>, body: &Body<'_>,
) { ) {
all_facts all_facts
.path_belongs_to_var .path_is_var
.extend(move_data.rev_lookup.iter_locals_enumerated().map(|(v, &m)| (m, v))); .extend(move_data.rev_lookup.iter_locals_enumerated().map(|(v, &m)| (m, v)));
for (child, move_path) in move_data.move_paths.iter_enumerated() { for (child, move_path) in move_data.move_paths.iter_enumerated() {
all_facts if let Some(parent) = move_path.parent {
.child all_facts.child_path.push((child, parent));
.extend(move_path.parents(&move_data.move_paths).map(|(parent, _)| (child, parent))); }
} }
let fn_entry_start = location_table
.start_index(Location { block: BasicBlock::from_u32(0u32), statement_index: 0 });
// initialized_at // initialized_at
for init in move_data.inits.iter() { for init in move_data.inits.iter() {
match init.location { match init.location {
@ -115,28 +118,37 @@ fn populate_polonius_move_facts(
// the successors, but not in the unwind block. // the successors, but not in the unwind block.
let first_statement = Location { block: successor, statement_index: 0 }; let first_statement = Location { block: successor, statement_index: 0 };
all_facts all_facts
.initialized_at .path_assigned_at_base
.push((init.path, location_table.start_index(first_statement))); .push((init.path, location_table.start_index(first_statement)));
} }
} else { } else {
// In all other cases, the initialization just happens at the // In all other cases, the initialization just happens at the
// midpoint, like any other effect. // midpoint, like any other effect.
all_facts.initialized_at.push((init.path, location_table.mid_index(location))); all_facts
.path_assigned_at_base
.push((init.path, location_table.mid_index(location)));
} }
} }
// Arguments are initialized on function entry // Arguments are initialized on function entry
InitLocation::Argument(local) => { InitLocation::Argument(local) => {
assert!(body.local_kind(local) == LocalKind::Arg); assert!(body.local_kind(local) == LocalKind::Arg);
let fn_entry = Location { block: BasicBlock::from_u32(0u32), statement_index: 0 }; all_facts.path_assigned_at_base.push((init.path, fn_entry_start));
all_facts.initialized_at.push((init.path, location_table.start_index(fn_entry)));
} }
} }
} }
for (local, &path) in move_data.rev_lookup.iter_locals_enumerated() {
if body.local_kind(local) != LocalKind::Arg {
// Non-arguments start out deinitialised; we simulate this with an
// initial move:
all_facts.path_moved_at_base.push((path, fn_entry_start));
}
}
// moved_out_at // moved_out_at
// deinitialisation is assumed to always happen! // deinitialisation is assumed to always happen!
all_facts all_facts
.moved_out_at .path_moved_at_base
.extend(move_data.moves.iter().map(|mo| (mo.path, location_table.mid_index(mo.source)))); .extend(move_data.moves.iter().map(|mo| (mo.path, location_table.mid_index(mo.source))));
} }

View File

@ -12,12 +12,12 @@ type VarPointRelation = Vec<(Local, LocationIndex)>;
type PathPointRelation = Vec<(MovePathIndex, LocationIndex)>; type PathPointRelation = Vec<(MovePathIndex, LocationIndex)>;
struct UseFactsExtractor<'me> { struct UseFactsExtractor<'me> {
var_defined: &'me mut VarPointRelation, var_defined_at: &'me mut VarPointRelation,
var_used: &'me mut VarPointRelation, var_used_at: &'me mut VarPointRelation,
location_table: &'me LocationTable, location_table: &'me LocationTable,
var_drop_used: &'me mut Vec<(Local, Location)>, var_dropped_at: &'me mut VarPointRelation,
move_data: &'me MoveData<'me>, move_data: &'me MoveData<'me>,
path_accessed_at: &'me mut PathPointRelation, path_accessed_at_base: &'me mut PathPointRelation,
} }
// A Visitor to walk through the MIR and extract point-wise facts // A Visitor to walk through the MIR and extract point-wise facts
@ -28,22 +28,22 @@ impl UseFactsExtractor<'_> {
fn insert_def(&mut self, local: Local, location: Location) { fn insert_def(&mut self, local: Local, location: Location) {
debug!("UseFactsExtractor::insert_def()"); debug!("UseFactsExtractor::insert_def()");
self.var_defined.push((local, self.location_to_index(location))); self.var_defined_at.push((local, self.location_to_index(location)));
} }
fn insert_use(&mut self, local: Local, location: Location) { fn insert_use(&mut self, local: Local, location: Location) {
debug!("UseFactsExtractor::insert_use()"); debug!("UseFactsExtractor::insert_use()");
self.var_used.push((local, self.location_to_index(location))); self.var_used_at.push((local, self.location_to_index(location)));
} }
fn insert_drop_use(&mut self, local: Local, location: Location) { fn insert_drop_use(&mut self, local: Local, location: Location) {
debug!("UseFactsExtractor::insert_drop_use()"); debug!("UseFactsExtractor::insert_drop_use()");
self.var_drop_used.push((local, location)); self.var_dropped_at.push((local, self.location_to_index(location)));
} }
fn insert_path_access(&mut self, path: MovePathIndex, location: Location) { fn insert_path_access(&mut self, path: MovePathIndex, location: Location) {
debug!("UseFactsExtractor::insert_path_access({:?}, {:?})", path, location); debug!("UseFactsExtractor::insert_path_access({:?}, {:?})", path, location);
self.path_accessed_at.push((path, self.location_to_index(location))); self.path_accessed_at_base.push((path, self.location_table.start_index(location)));
} }
fn place_to_mpi(&self, place: &Place<'_>) -> Option<MovePathIndex> { fn place_to_mpi(&self, place: &Place<'_>) -> Option<MovePathIndex> {
@ -88,51 +88,54 @@ pub(super) fn populate_access_facts(
body: ReadOnlyBodyAndCache<'_, 'tcx>, body: ReadOnlyBodyAndCache<'_, 'tcx>,
location_table: &LocationTable, location_table: &LocationTable,
move_data: &MoveData<'_>, move_data: &MoveData<'_>,
drop_used: &mut Vec<(Local, Location)>, dropped_at: &mut Vec<(Local, Location)>,
) { ) {
debug!("populate_access_facts()"); debug!("populate_access_facts()");
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() { if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
let mut extractor = UseFactsExtractor { let mut extractor = UseFactsExtractor {
var_defined: &mut facts.var_defined, var_defined_at: &mut facts.var_defined_at,
var_used: &mut facts.var_used, var_used_at: &mut facts.var_used_at,
var_drop_used: drop_used, var_dropped_at: &mut facts.var_dropped_at,
path_accessed_at: &mut facts.path_accessed_at, path_accessed_at_base: &mut facts.path_accessed_at_base,
location_table, location_table,
move_data, move_data,
}; };
extractor.visit_body(body); extractor.visit_body(body);
facts.var_drop_used.extend( facts.var_dropped_at.extend(
drop_used.iter().map(|&(local, location)| (local, location_table.mid_index(location))), dropped_at.iter().map(|&(local, location)| (local, location_table.mid_index(location))),
); );
for (local, local_decl) in body.local_decls.iter_enumerated() { for (local, local_decl) in body.local_decls.iter_enumerated() {
debug!("add var_uses_regions facts - local={:?}, type={:?}", local, local_decl.ty); debug!(
"add use_of_var_derefs_origin facts - local={:?}, type={:?}",
local, local_decl.ty
);
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation"); let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
let universal_regions = &typeck.borrowck_context.universal_regions; let universal_regions = &typeck.borrowck_context.universal_regions;
typeck.infcx.tcx.for_each_free_region(&local_decl.ty, |region| { typeck.infcx.tcx.for_each_free_region(&local_decl.ty, |region| {
let region_vid = universal_regions.to_region_vid(region); let region_vid = universal_regions.to_region_vid(region);
facts.var_uses_region.push((local, region_vid)); facts.use_of_var_derefs_origin.push((local, region_vid));
}); });
} }
} }
} }
// For every potentially drop()-touched region `region` in `local`'s type // For every potentially drop()-touched region `region` in `local`'s type
// (`kind`), emit a Polonius `var_drops_region(local, region)` fact. // (`kind`), emit a Polonius `use_of_var_derefs_origin(local, origin)` fact.
pub(super) fn add_var_drops_regions( pub(super) fn add_drop_of_var_derefs_origin(
typeck: &mut TypeChecker<'_, 'tcx>, typeck: &mut TypeChecker<'_, 'tcx>,
local: Local, local: Local,
kind: &GenericArg<'tcx>, kind: &GenericArg<'tcx>,
) { ) {
debug!("add_var_drops_region(local={:?}, kind={:?}", local, kind); debug!("add_drop_of_var_derefs_origin(local={:?}, kind={:?}", local, kind);
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() { if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation"); let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
let universal_regions = &typeck.borrowck_context.universal_regions; let universal_regions = &typeck.borrowck_context.universal_regions;
typeck.infcx.tcx.for_each_free_region(kind, |drop_live_region| { typeck.infcx.tcx.for_each_free_region(kind, |drop_live_region| {
let region_vid = universal_regions.to_region_vid(drop_live_region); let region_vid = universal_regions.to_region_vid(drop_live_region);
facts.var_drops_region.push((local, region_vid)); facts.drop_of_var_derefs_origin.push((local, region_vid));
}); });
} }
} }

View File

@ -484,7 +484,7 @@ impl LivenessContext<'_, '_, '_, 'tcx> {
for &kind in &drop_data.dropck_result.kinds { for &kind in &drop_data.dropck_result.kinds {
Self::make_all_regions_live(self.elements, &mut self.typeck, kind, live_at); Self::make_all_regions_live(self.elements, &mut self.typeck, kind, live_at);
polonius::add_var_drops_regions(&mut self.typeck, dropped_local, &kind); polonius::add_drop_of_var_derefs_origin(&mut self.typeck, dropped_local, &kind);
} }
} }