Skip to content

Commit 8562497

Browse files
committed
improve consistency within fact gen
- fix names - fix ordering of arguments
1 parent 7ad1f5b commit 8562497

File tree

4 files changed

+44
-46
lines changed

4 files changed

+44
-46
lines changed

compiler/rustc_borrowck/src/polonius/legacy/accesses.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ use crate::universal_regions::UniversalRegions;
1111

1212
/// Emit polonius facts for variable defs, uses, drops, and path accesses.
1313
pub(crate) fn emit_access_facts<'tcx>(
14-
facts: &mut AllFacts,
1514
tcx: TyCtxt<'tcx>,
15+
facts: &mut AllFacts,
1616
body: &Body<'tcx>,
17+
location_table: &LocationTable,
1718
move_data: &MoveData<'tcx>,
1819
universal_regions: &UniversalRegions<'tcx>,
19-
location_table: &LocationTable,
2020
) {
2121
let mut extractor = AccessFactsExtractor { facts, move_data, location_table };
2222
extractor.visit_body(body);

compiler/rustc_borrowck/src/polonius/legacy/loan_invalidations.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ use crate::{
2121
/// Emit `loan_invalidated_at` facts.
2222
pub(super) fn emit_loan_invalidations<'tcx>(
2323
tcx: TyCtxt<'tcx>,
24-
all_facts: &mut AllFacts,
25-
location_table: &LocationTable,
24+
facts: &mut AllFacts,
2625
body: &Body<'tcx>,
26+
location_table: &LocationTable,
2727
borrow_set: &BorrowSet<'tcx>,
2828
) {
2929
let dominators = body.basic_blocks.dominators();
3030
let mut visitor =
31-
LoanInvalidationsGenerator { all_facts, borrow_set, tcx, location_table, body, dominators };
31+
LoanInvalidationsGenerator { facts, borrow_set, tcx, location_table, body, dominators };
3232
visitor.visit_body(body);
3333
}
3434

3535
struct LoanInvalidationsGenerator<'a, 'tcx> {
3636
tcx: TyCtxt<'tcx>,
37-
all_facts: &'a mut AllFacts,
38-
location_table: &'a LocationTable,
37+
facts: &'a mut AllFacts,
3938
body: &'a Body<'tcx>,
39+
location_table: &'a LocationTable,
4040
dominators: &'a Dominators<BasicBlock>,
4141
borrow_set: &'a BorrowSet<'tcx>,
4242
}
@@ -151,7 +151,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'a, 'tcx> {
151151
let resume = self.location_table.start_index(resume.start_location());
152152
for (i, data) in borrow_set.iter_enumerated() {
153153
if borrow_of_local_data(data.borrowed_place) {
154-
self.all_facts.loan_invalidated_at.push((resume, i));
154+
self.facts.loan_invalidated_at.push((resume, i));
155155
}
156156
}
157157

@@ -165,7 +165,7 @@ impl<'a, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'a, 'tcx> {
165165
let start = self.location_table.start_index(location);
166166
for (i, data) in borrow_set.iter_enumerated() {
167167
if borrow_of_local_data(data.borrowed_place) {
168-
self.all_facts.loan_invalidated_at.push((start, i));
168+
self.facts.loan_invalidated_at.push((start, i));
169169
}
170170
}
171171
}
@@ -409,7 +409,7 @@ impl<'a, 'tcx> LoanInvalidationsGenerator<'a, 'tcx> {
409409
/// Generates a new `loan_invalidated_at(L, B)` fact.
410410
fn emit_loan_invalidated_at(&mut self, b: BorrowIndex, l: Location) {
411411
let lidx = self.location_table.start_index(l);
412-
self.all_facts.loan_invalidated_at.push((lidx, b));
412+
self.facts.loan_invalidated_at.push((lidx, b));
413413
}
414414

415415
fn check_activations(&mut self, location: Location) {

compiler/rustc_borrowck/src/polonius/legacy/loan_kills.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,20 @@ use crate::places_conflict;
1414
/// Emit `loan_killed_at` and `cfg_edge` facts at the same time.
1515
pub(super) fn emit_loan_kills<'tcx>(
1616
tcx: TyCtxt<'tcx>,
17-
all_facts: &mut AllFacts,
18-
location_table: &LocationTable,
17+
facts: &mut AllFacts,
1918
body: &Body<'tcx>,
19+
location_table: &LocationTable,
2020
borrow_set: &BorrowSet<'tcx>,
2121
) {
22-
let mut visitor = LoanKillsGenerator { borrow_set, tcx, location_table, all_facts, body };
22+
let mut visitor = LoanKillsGenerator { borrow_set, tcx, location_table, facts, body };
2323
for (bb, data) in body.basic_blocks.iter_enumerated() {
2424
visitor.visit_basic_block_data(bb, data);
2525
}
2626
}
2727

2828
struct LoanKillsGenerator<'a, 'tcx> {
2929
tcx: TyCtxt<'tcx>,
30-
all_facts: &'a mut AllFacts,
30+
facts: &'a mut AllFacts,
3131
location_table: &'a LocationTable,
3232
borrow_set: &'a BorrowSet<'tcx>,
3333
body: &'a Body<'tcx>,
@@ -36,12 +36,12 @@ struct LoanKillsGenerator<'a, 'tcx> {
3636
impl<'a, 'tcx> Visitor<'tcx> for LoanKillsGenerator<'a, 'tcx> {
3737
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
3838
// Also record CFG facts here.
39-
self.all_facts.cfg_edge.push((
39+
self.facts.cfg_edge.push((
4040
self.location_table.start_index(location),
4141
self.location_table.mid_index(location),
4242
));
4343

44-
self.all_facts.cfg_edge.push((
44+
self.facts.cfg_edge.push((
4545
self.location_table.mid_index(location),
4646
self.location_table.start_index(location.successor_within_block()),
4747
));
@@ -63,15 +63,15 @@ impl<'a, 'tcx> Visitor<'tcx> for LoanKillsGenerator<'a, 'tcx> {
6363

6464
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
6565
// Also record CFG facts here.
66-
self.all_facts.cfg_edge.push((
66+
self.facts.cfg_edge.push((
6767
self.location_table.start_index(location),
6868
self.location_table.mid_index(location),
6969
));
7070

7171
let successor_blocks = terminator.successors();
72-
self.all_facts.cfg_edge.reserve(successor_blocks.size_hint().0);
72+
self.facts.cfg_edge.reserve(successor_blocks.size_hint().0);
7373
for successor_block in successor_blocks {
74-
self.all_facts.cfg_edge.push((
74+
self.facts.cfg_edge.push((
7575
self.location_table.mid_index(location),
7676
self.location_table.start_index(successor_block.start_location()),
7777
));
@@ -128,7 +128,7 @@ impl<'tcx> LoanKillsGenerator<'_, 'tcx> {
128128

129129
if places_conflict {
130130
let location_index = self.location_table.mid_index(location);
131-
self.all_facts.loan_killed_at.push((borrow_index, location_index));
131+
self.facts.loan_killed_at.push((borrow_index, location_index));
132132
}
133133
}
134134
}
@@ -140,9 +140,9 @@ impl<'tcx> LoanKillsGenerator<'_, 'tcx> {
140140
fn record_killed_borrows_for_local(&mut self, local: Local, location: Location) {
141141
if let Some(borrow_indices) = self.borrow_set.local_map.get(&local) {
142142
let location_index = self.location_table.mid_index(location);
143-
self.all_facts.loan_killed_at.reserve(borrow_indices.len());
143+
self.facts.loan_killed_at.reserve(borrow_indices.len());
144144
for &borrow_index in borrow_indices {
145-
self.all_facts.loan_killed_at.push((borrow_index, location_index));
145+
self.facts.loan_killed_at.push((borrow_index, location_index));
146146
}
147147
}
148148
}

compiler/rustc_borrowck/src/polonius/legacy/mod.rs

+22-24
Original file line numberDiff line numberDiff line change
@@ -43,40 +43,38 @@ pub(crate) fn emit_facts<'tcx>(
4343
universal_region_relations: &UniversalRegionRelations<'tcx>,
4444
constraints: &MirTypeckRegionConstraints<'tcx>,
4545
) {
46-
let Some(all_facts) = all_facts else {
46+
let Some(facts) = all_facts else {
4747
// We don't do anything if there are no facts to fill.
4848
return;
4949
};
5050
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
51-
emit_move_facts(all_facts, move_data, location_table, body);
52-
emit_universal_region_facts(all_facts, borrow_set, universal_region_relations);
53-
loan_kills::emit_loan_kills(tcx, all_facts, location_table, body, borrow_set);
54-
loan_invalidations::emit_loan_invalidations(tcx, all_facts, location_table, body, borrow_set);
51+
emit_move_facts(facts, body, location_table, move_data);
52+
emit_universal_region_facts(facts, borrow_set, universal_region_relations);
53+
loan_kills::emit_loan_kills(tcx, facts, body, location_table, borrow_set);
54+
loan_invalidations::emit_loan_invalidations(tcx, facts, body, location_table, borrow_set);
5555
accesses::emit_access_facts(
56-
all_facts,
5756
tcx,
57+
facts,
5858
body,
59+
location_table,
5960
move_data,
6061
&universal_region_relations.universal_regions,
61-
location_table,
6262
);
63-
emit_outlives_facts(all_facts, location_table, constraints);
63+
emit_outlives_facts(facts, location_table, constraints);
6464
}
6565

6666
/// Emit facts needed for move/init analysis: moves and assignments.
6767
fn emit_move_facts(
68-
all_facts: &mut AllFacts,
69-
move_data: &MoveData<'_>,
70-
location_table: &LocationTable,
68+
facts: &mut AllFacts,
7169
body: &Body<'_>,
70+
location_table: &LocationTable,
71+
move_data: &MoveData<'_>,
7272
) {
73-
all_facts
74-
.path_is_var
75-
.extend(move_data.rev_lookup.iter_locals_enumerated().map(|(l, r)| (r, l)));
73+
facts.path_is_var.extend(move_data.rev_lookup.iter_locals_enumerated().map(|(l, r)| (r, l)));
7674

7775
for (child, move_path) in move_data.move_paths.iter_enumerated() {
7876
if let Some(parent) = move_path.parent {
79-
all_facts.child_path.push((child, parent));
77+
facts.child_path.push((child, parent));
8078
}
8179
}
8280

@@ -102,22 +100,22 @@ fn emit_move_facts(
102100
// The initialization happened in (or rather, when arriving at)
103101
// the successors, but not in the unwind block.
104102
let first_statement = Location { block: successor, statement_index: 0 };
105-
all_facts
103+
facts
106104
.path_assigned_at_base
107105
.push((init.path, location_table.start_index(first_statement)));
108106
}
109107
} else {
110108
// In all other cases, the initialization just happens at the
111109
// midpoint, like any other effect.
112-
all_facts
110+
facts
113111
.path_assigned_at_base
114112
.push((init.path, location_table.mid_index(location)));
115113
}
116114
}
117115
// Arguments are initialized on function entry
118116
InitLocation::Argument(local) => {
119117
assert!(body.local_kind(local) == LocalKind::Arg);
120-
all_facts.path_assigned_at_base.push((init.path, fn_entry_start));
118+
facts.path_assigned_at_base.push((init.path, fn_entry_start));
121119
}
122120
}
123121
}
@@ -126,20 +124,20 @@ fn emit_move_facts(
126124
if body.local_kind(local) != LocalKind::Arg {
127125
// Non-arguments start out deinitialised; we simulate this with an
128126
// initial move:
129-
all_facts.path_moved_at_base.push((path, fn_entry_start));
127+
facts.path_moved_at_base.push((path, fn_entry_start));
130128
}
131129
}
132130

133131
// moved_out_at
134132
// deinitialisation is assumed to always happen!
135-
all_facts
133+
facts
136134
.path_moved_at_base
137135
.extend(move_data.moves.iter().map(|mo| (mo.path, location_table.mid_index(mo.source))));
138136
}
139137

140138
/// Emit universal regions facts, and their relations.
141139
fn emit_universal_region_facts(
142-
all_facts: &mut AllFacts,
140+
facts: &mut AllFacts,
143141
borrow_set: &BorrowSet<'_>,
144142
universal_region_relations: &UniversalRegionRelations<'_>,
145143
) {
@@ -150,7 +148,7 @@ fn emit_universal_region_facts(
150148
// added to the existing number of loans, as if they succeeded them in the set.
151149
//
152150
let universal_regions = &universal_region_relations.universal_regions;
153-
all_facts
151+
facts
154152
.universal_region
155153
.extend(universal_regions.universal_regions_iter().map(PoloniusRegionVid::from));
156154
let borrow_count = borrow_set.len();
@@ -163,7 +161,7 @@ fn emit_universal_region_facts(
163161
for universal_region in universal_regions.universal_regions_iter() {
164162
let universal_region_idx = universal_region.index();
165163
let placeholder_loan_idx = borrow_count + universal_region_idx;
166-
all_facts.placeholder.push((universal_region.into(), placeholder_loan_idx.into()));
164+
facts.placeholder.push((universal_region.into(), placeholder_loan_idx.into()));
167165
}
168166

169167
// 2: the universal region relations `outlives` constraints are emitted as
@@ -175,7 +173,7 @@ fn emit_universal_region_facts(
175173
fr1={:?}, fr2={:?}",
176174
fr1, fr2
177175
);
178-
all_facts.known_placeholder_subset.push((fr1.into(), fr2.into()));
176+
facts.known_placeholder_subset.push((fr1.into(), fr2.into()));
179177
}
180178
}
181179
}

0 commit comments

Comments
 (0)