Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polonius: update polonius-engine to 0.12.0 #69482

Merged
merged 1 commit into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2494,9 +2494,9 @@ checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"

[[package]]
name = "polonius-engine"
version = "0.11.0"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e478d7c38eb785c6416cbe58df12aa55d7aefa3759b6d3e044b2ed03f423cec"
checksum = "04d8ef65e3f89ecaec9ca7cb0e0911b4617352d4494018bcf934992f03f2024c"
dependencies = [
"datafrog",
"log",
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ scoped-tls = "1.0"
log = { version = "0.4", features = ["release_max_level_info", "std"] }
rustc-rayon = "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_attr = { path = "../librustc_attr" }
rustc_feature = { path = "../librustc_feature" }
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ dot = { path = "../libgraphviz", package = "graphviz" }
itertools = "0.8"
log = "0.4"
log_settings = "0.1.1"
polonius-engine = "0.11.0"
polonius-engine = "0.12.0"
rustc = { path = "../librustc" }
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
rustc_attr = { path = "../librustc_attr" }
Expand Down
20 changes: 10 additions & 10 deletions src/librustc_mir/borrow_check/facts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,16 +71,16 @@ impl AllFactsExt for AllFacts {
killed,
outlives,
invalidates,
var_used,
var_defined,
var_drop_used,
var_uses_region,
var_drops_region,
child,
path_belongs_to_var,
initialized_at,
moved_out_at,
path_accessed_at,
var_used_at,
var_defined_at,
var_dropped_at,
use_of_var_derefs_origin,
drop_of_var_derefs_origin,
child_path,
path_is_var,
path_assigned_at_base,
path_moved_at_base,
path_accessed_at_base,
known_subset,
])
}
Expand Down
30 changes: 21 additions & 9 deletions src/librustc_mir/borrow_check/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,18 @@ fn populate_polonius_move_facts(
body: &Body<'_>,
) {
all_facts
.path_belongs_to_var
.path_is_var
.extend(move_data.rev_lookup.iter_locals_enumerated().map(|(v, &m)| (m, v)));

for (child, move_path) in move_data.move_paths.iter_enumerated() {
all_facts
.child
.extend(move_path.parents(&move_data.move_paths).map(|(parent, _)| (child, parent)));
if let Some(parent) = move_path.parent {
all_facts.child_path.push((child, parent));
}
}

let fn_entry_start = location_table
.start_index(Location { block: BasicBlock::from_u32(0u32), statement_index: 0 });

// initialized_at
for init in move_data.inits.iter() {
match init.location {
Expand All @@ -115,28 +118,37 @@ fn populate_polonius_move_facts(
// the successors, but not in the unwind block.
let first_statement = Location { block: successor, statement_index: 0 };
all_facts
.initialized_at
.path_assigned_at_base
.push((init.path, location_table.start_index(first_statement)));
}
} else {
// In all other cases, the initialization just happens at the
// 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
InitLocation::Argument(local) => {
assert!(body.local_kind(local) == LocalKind::Arg);
let fn_entry = Location { block: BasicBlock::from_u32(0u32), statement_index: 0 };
all_facts.initialized_at.push((init.path, location_table.start_index(fn_entry)));
all_facts.path_assigned_at_base.push((init.path, fn_entry_start));
}
}
}

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
// deinitialisation is assumed to always happen!
all_facts
.moved_out_at
.path_moved_at_base
.extend(move_data.moves.iter().map(|mo| (mo.path, location_table.mid_index(mo.source))));
}

Expand Down
45 changes: 24 additions & 21 deletions src/librustc_mir/borrow_check/type_check/liveness/polonius.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ type VarPointRelation = Vec<(Local, LocationIndex)>;
type PathPointRelation = Vec<(MovePathIndex, LocationIndex)>;

struct UseFactsExtractor<'me> {
var_defined: &'me mut VarPointRelation,
var_used: &'me mut VarPointRelation,
var_defined_at: &'me mut VarPointRelation,
var_used_at: &'me mut VarPointRelation,
location_table: &'me LocationTable,
var_drop_used: &'me mut Vec<(Local, Location)>,
var_dropped_at: &'me mut VarPointRelation,
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
Expand All @@ -28,22 +28,22 @@ impl UseFactsExtractor<'_> {

fn insert_def(&mut self, local: Local, location: Location) {
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) {
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) {
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) {
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> {
Expand Down Expand Up @@ -88,51 +88,54 @@ pub(super) fn populate_access_facts(
body: ReadOnlyBodyAndCache<'_, 'tcx>,
location_table: &LocationTable,
move_data: &MoveData<'_>,
drop_used: &mut Vec<(Local, Location)>,
dropped_at: &mut Vec<(Local, Location)>,
) {
debug!("populate_access_facts()");

if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
let mut extractor = UseFactsExtractor {
var_defined: &mut facts.var_defined,
var_used: &mut facts.var_used,
var_drop_used: drop_used,
path_accessed_at: &mut facts.path_accessed_at,
var_defined_at: &mut facts.var_defined_at,
var_used_at: &mut facts.var_used_at,
var_dropped_at: &mut facts.var_dropped_at,
path_accessed_at_base: &mut facts.path_accessed_at_base,
location_table,
move_data,
};
extractor.visit_body(body);

facts.var_drop_used.extend(
drop_used.iter().map(|&(local, location)| (local, location_table.mid_index(location))),
facts.var_dropped_at.extend(
dropped_at.iter().map(|&(local, location)| (local, location_table.mid_index(location))),
);

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 universal_regions = &typeck.borrowck_context.universal_regions;
typeck.infcx.tcx.for_each_free_region(&local_decl.ty, |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
// (`kind`), emit a Polonius `var_drops_region(local, region)` fact.
pub(super) fn add_var_drops_regions(
// (`kind`), emit a Polonius `use_of_var_derefs_origin(local, origin)` fact.
pub(super) fn add_drop_of_var_derefs_origin(
typeck: &mut TypeChecker<'_, 'tcx>,
local: Local,
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() {
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
let universal_regions = &typeck.borrowck_context.universal_regions;
typeck.infcx.tcx.for_each_free_region(kind, |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));
});
}
}
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/type_check/liveness/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ impl LivenessContext<'_, '_, '_, 'tcx> {
for &kind in &drop_data.dropck_result.kinds {
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);
}
}

Expand Down