Skip to content

Commit 6f40cdb

Browse files
Albin Stjernalqd
Albin Stjerna
authored andcommitted
- polonius: adapt to the new fact format
- update polonius-engine dependency to 0.12.0 - rustfmt the files failing tidy
1 parent 49c68bd commit 6f40cdb

File tree

7 files changed

+60
-45
lines changed

7 files changed

+60
-45
lines changed

Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -2494,9 +2494,9 @@ checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
24942494

24952495
[[package]]
24962496
name = "polonius-engine"
2497-
version = "0.11.0"
2497+
version = "0.12.0"
24982498
source = "registry+https://github.com/rust-lang/crates.io-index"
2499-
checksum = "1e478d7c38eb785c6416cbe58df12aa55d7aefa3759b6d3e044b2ed03f423cec"
2499+
checksum = "04d8ef65e3f89ecaec9ca7cb0e0911b4617352d4494018bcf934992f03f2024c"
25002500
dependencies = [
25012501
"datafrog",
25022502
"log",

src/librustc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ scoped-tls = "1.0"
1717
log = { version = "0.4", features = ["release_max_level_info", "std"] }
1818
rustc-rayon = "0.3.0"
1919
rustc-rayon-core = "0.3.0"
20-
polonius-engine = "0.11.0"
20+
polonius-engine = "0.12.0"
2121
rustc_apfloat = { path = "../librustc_apfloat" }
2222
rustc_attr = { path = "../librustc_attr" }
2323
rustc_feature = { path = "../librustc_feature" }

src/librustc_mir/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ dot = { path = "../libgraphviz", package = "graphviz" }
1515
itertools = "0.8"
1616
log = "0.4"
1717
log_settings = "0.1.1"
18-
polonius-engine = "0.11.0"
18+
polonius-engine = "0.12.0"
1919
rustc = { path = "../librustc" }
2020
rustc_ast_pretty = { path = "../librustc_ast_pretty" }
2121
rustc_attr = { path = "../librustc_attr" }

src/librustc_mir/borrow_check/facts.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -71,16 +71,16 @@ impl AllFactsExt for AllFacts {
7171
killed,
7272
outlives,
7373
invalidates,
74-
var_used,
75-
var_defined,
76-
var_drop_used,
77-
var_uses_region,
78-
var_drops_region,
79-
child,
80-
path_belongs_to_var,
81-
initialized_at,
82-
moved_out_at,
83-
path_accessed_at,
74+
var_used_at,
75+
var_defined_at,
76+
var_dropped_at,
77+
use_of_var_derefs_origin,
78+
drop_of_var_derefs_origin,
79+
child_path,
80+
path_is_var,
81+
path_assigned_at_base,
82+
path_moved_at_base,
83+
path_accessed_at_base,
8484
known_subset,
8585
])
8686
}

src/librustc_mir/borrow_check/nll.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,18 @@ fn populate_polonius_move_facts(
8686
body: &Body<'_>,
8787
) {
8888
all_facts
89-
.path_belongs_to_var
89+
.path_is_var
9090
.extend(move_data.rev_lookup.iter_locals_enumerated().map(|(v, &m)| (m, v)));
9191

9292
for (child, move_path) in move_data.move_paths.iter_enumerated() {
93-
all_facts
94-
.child
95-
.extend(move_path.parents(&move_data.move_paths).map(|(parent, _)| (child, parent)));
93+
if let Some(parent) = move_path.parent {
94+
all_facts.child_path.push((child, parent));
95+
}
9696
}
9797

98+
let fn_entry_start = location_table
99+
.start_index(Location { block: BasicBlock::from_u32(0u32), statement_index: 0 });
100+
98101
// initialized_at
99102
for init in move_data.inits.iter() {
100103
match init.location {
@@ -115,28 +118,37 @@ fn populate_polonius_move_facts(
115118
// the successors, but not in the unwind block.
116119
let first_statement = Location { block: successor, statement_index: 0 };
117120
all_facts
118-
.initialized_at
121+
.path_assigned_at_base
119122
.push((init.path, location_table.start_index(first_statement)));
120123
}
121124
} else {
122125
// In all other cases, the initialization just happens at the
123126
// midpoint, like any other effect.
124-
all_facts.initialized_at.push((init.path, location_table.mid_index(location)));
127+
all_facts
128+
.path_assigned_at_base
129+
.push((init.path, location_table.mid_index(location)));
125130
}
126131
}
127132
// Arguments are initialized on function entry
128133
InitLocation::Argument(local) => {
129134
assert!(body.local_kind(local) == LocalKind::Arg);
130-
let fn_entry = Location { block: BasicBlock::from_u32(0u32), statement_index: 0 };
131-
all_facts.initialized_at.push((init.path, location_table.start_index(fn_entry)));
135+
all_facts.path_assigned_at_base.push((init.path, fn_entry_start));
132136
}
133137
}
134138
}
135139

140+
for (local, &path) in move_data.rev_lookup.iter_locals_enumerated() {
141+
if body.local_kind(local) != LocalKind::Arg {
142+
// Non-arguments start out deinitialised; we simulate this with an
143+
// initial move:
144+
all_facts.path_moved_at_base.push((path, fn_entry_start));
145+
}
146+
}
147+
136148
// moved_out_at
137149
// deinitialisation is assumed to always happen!
138150
all_facts
139-
.moved_out_at
151+
.path_moved_at_base
140152
.extend(move_data.moves.iter().map(|mo| (mo.path, location_table.mid_index(mo.source))));
141153
}
142154

src/librustc_mir/borrow_check/type_check/liveness/polonius.rs

+24-21
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ type VarPointRelation = Vec<(Local, LocationIndex)>;
1212
type PathPointRelation = Vec<(MovePathIndex, LocationIndex)>;
1313

1414
struct UseFactsExtractor<'me> {
15-
var_defined: &'me mut VarPointRelation,
16-
var_used: &'me mut VarPointRelation,
15+
var_defined_at: &'me mut VarPointRelation,
16+
var_used_at: &'me mut VarPointRelation,
1717
location_table: &'me LocationTable,
18-
var_drop_used: &'me mut Vec<(Local, Location)>,
18+
var_dropped_at: &'me mut VarPointRelation,
1919
move_data: &'me MoveData<'me>,
20-
path_accessed_at: &'me mut PathPointRelation,
20+
path_accessed_at_base: &'me mut PathPointRelation,
2121
}
2222

2323
// A Visitor to walk through the MIR and extract point-wise facts
@@ -28,22 +28,22 @@ impl UseFactsExtractor<'_> {
2828

2929
fn insert_def(&mut self, local: Local, location: Location) {
3030
debug!("UseFactsExtractor::insert_def()");
31-
self.var_defined.push((local, self.location_to_index(location)));
31+
self.var_defined_at.push((local, self.location_to_index(location)));
3232
}
3333

3434
fn insert_use(&mut self, local: Local, location: Location) {
3535
debug!("UseFactsExtractor::insert_use()");
36-
self.var_used.push((local, self.location_to_index(location)));
36+
self.var_used_at.push((local, self.location_to_index(location)));
3737
}
3838

3939
fn insert_drop_use(&mut self, local: Local, location: Location) {
4040
debug!("UseFactsExtractor::insert_drop_use()");
41-
self.var_drop_used.push((local, location));
41+
self.var_dropped_at.push((local, self.location_to_index(location)));
4242
}
4343

4444
fn insert_path_access(&mut self, path: MovePathIndex, location: Location) {
4545
debug!("UseFactsExtractor::insert_path_access({:?}, {:?})", path, location);
46-
self.path_accessed_at.push((path, self.location_to_index(location)));
46+
self.path_accessed_at_base.push((path, self.location_table.start_index(location)));
4747
}
4848

4949
fn place_to_mpi(&self, place: &Place<'_>) -> Option<MovePathIndex> {
@@ -88,51 +88,54 @@ pub(super) fn populate_access_facts(
8888
body: ReadOnlyBodyAndCache<'_, 'tcx>,
8989
location_table: &LocationTable,
9090
move_data: &MoveData<'_>,
91-
drop_used: &mut Vec<(Local, Location)>,
91+
dropped_at: &mut Vec<(Local, Location)>,
9292
) {
9393
debug!("populate_access_facts()");
9494

9595
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
9696
let mut extractor = UseFactsExtractor {
97-
var_defined: &mut facts.var_defined,
98-
var_used: &mut facts.var_used,
99-
var_drop_used: drop_used,
100-
path_accessed_at: &mut facts.path_accessed_at,
97+
var_defined_at: &mut facts.var_defined_at,
98+
var_used_at: &mut facts.var_used_at,
99+
var_dropped_at: &mut facts.var_dropped_at,
100+
path_accessed_at_base: &mut facts.path_accessed_at_base,
101101
location_table,
102102
move_data,
103103
};
104104
extractor.visit_body(body);
105105

106-
facts.var_drop_used.extend(
107-
drop_used.iter().map(|&(local, location)| (local, location_table.mid_index(location))),
106+
facts.var_dropped_at.extend(
107+
dropped_at.iter().map(|&(local, location)| (local, location_table.mid_index(location))),
108108
);
109109

110110
for (local, local_decl) in body.local_decls.iter_enumerated() {
111-
debug!("add var_uses_regions facts - local={:?}, type={:?}", local, local_decl.ty);
111+
debug!(
112+
"add use_of_var_derefs_origin facts - local={:?}, type={:?}",
113+
local, local_decl.ty
114+
);
112115
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
113116
let universal_regions = &typeck.borrowck_context.universal_regions;
114117
typeck.infcx.tcx.for_each_free_region(&local_decl.ty, |region| {
115118
let region_vid = universal_regions.to_region_vid(region);
116-
facts.var_uses_region.push((local, region_vid));
119+
facts.use_of_var_derefs_origin.push((local, region_vid));
117120
});
118121
}
119122
}
120123
}
121124

122125
// For every potentially drop()-touched region `region` in `local`'s type
123-
// (`kind`), emit a Polonius `var_drops_region(local, region)` fact.
124-
pub(super) fn add_var_drops_regions(
126+
// (`kind`), emit a Polonius `use_of_var_derefs_origin(local, origin)` fact.
127+
pub(super) fn add_drop_of_var_derefs_origin(
125128
typeck: &mut TypeChecker<'_, 'tcx>,
126129
local: Local,
127130
kind: &GenericArg<'tcx>,
128131
) {
129-
debug!("add_var_drops_region(local={:?}, kind={:?}", local, kind);
132+
debug!("add_drop_of_var_derefs_origin(local={:?}, kind={:?}", local, kind);
130133
if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
131134
let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
132135
let universal_regions = &typeck.borrowck_context.universal_regions;
133136
typeck.infcx.tcx.for_each_free_region(kind, |drop_live_region| {
134137
let region_vid = universal_regions.to_region_vid(drop_live_region);
135-
facts.var_drops_region.push((local, region_vid));
138+
facts.drop_of_var_derefs_origin.push((local, region_vid));
136139
});
137140
}
138141
}

src/librustc_mir/borrow_check/type_check/liveness/trace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ impl LivenessContext<'_, '_, '_, 'tcx> {
484484
for &kind in &drop_data.dropck_result.kinds {
485485
Self::make_all_regions_live(self.elements, &mut self.typeck, kind, live_at);
486486

487-
polonius::add_var_drops_regions(&mut self.typeck, dropped_local, &kind);
487+
polonius::add_drop_of_var_derefs_origin(&mut self.typeck, dropped_local, &kind);
488488
}
489489
}
490490

0 commit comments

Comments
 (0)