Skip to content

Commit f969af2

Browse files
committed
move remaining legacy polonius fact generation out of NLL module
1 parent 96042bc commit f969af2

File tree

4 files changed

+46
-40
lines changed

4 files changed

+46
-40
lines changed

compiler/rustc_borrowck/src/nll.rs

+6-22
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,6 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
122122
polonius_input,
123123
);
124124

125-
if let Some(all_facts) = &mut all_facts {
126-
let _prof_timer = infcx.tcx.prof.generic_activity("polonius_fact_generation");
127-
polonius::emit_move_facts(all_facts, move_data, location_table, body);
128-
polonius::emit_universal_region_facts(
129-
all_facts,
130-
borrow_set,
131-
&universal_regions,
132-
&universal_region_relations,
133-
);
134-
}
135-
136125
// Create the region inference context, taking ownership of the
137126
// region inference data that was contained in `infcx`, and the
138127
// base constraints generated by the type-check.
@@ -148,12 +137,16 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
148137
} = constraints;
149138
let placeholder_indices = Rc::new(placeholder_indices);
150139

151-
polonius::emit_cfg_and_loan_kills_facts(
152-
infcx.tcx,
140+
// If requested, emit legacy polonius facts.
141+
polonius::emit_facts(
153142
&mut all_facts,
143+
infcx.tcx,
154144
location_table,
155145
body,
156146
borrow_set,
147+
move_data,
148+
&universal_regions,
149+
&universal_region_relations,
157150
);
158151

159152
let mut regioncx = RegionInferenceContext::new(
@@ -171,15 +164,6 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
171164
live_loans,
172165
);
173166

174-
// Generate various additional constraints.
175-
polonius::emit_loan_invalidations_facts(
176-
infcx.tcx,
177-
&mut all_facts,
178-
location_table,
179-
body,
180-
borrow_set,
181-
);
182-
183167
// If requested: dump NLL facts, and run legacy polonius analysis.
184168
let polonius_output = all_facts.as_ref().and_then(|all_facts| {
185169
if infcx.tcx.sess.opts.unstable_opts.nll_facts {

compiler/rustc_borrowck/src/polonius/loan_invalidations.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ pub(super) fn emit_loan_invalidations<'tcx>(
2222
body: &Body<'tcx>,
2323
borrow_set: &BorrowSet<'tcx>,
2424
) {
25-
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
2625
let dominators = body.basic_blocks.dominators();
2726
let mut visitor =
2827
LoanInvalidationsGenerator { all_facts, borrow_set, tcx, location_table, body, dominators };

compiler/rustc_borrowck/src/polonius/loan_kills.rs

-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ pub(super) fn emit_loan_kills<'tcx>(
1717
body: &Body<'tcx>,
1818
borrow_set: &BorrowSet<'tcx>,
1919
) {
20-
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
2120
let mut visitor = LoanKillsGenerator { borrow_set, tcx, location_table, all_facts, body };
2221
for (bb, data) in body.basic_blocks.iter_enumerated() {
2322
visitor.visit_basic_block_data(bb, data);

compiler/rustc_borrowck/src/polonius/mod.rs

+40-16
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,42 @@ use crate::universal_regions::UniversalRegions;
1616
mod loan_invalidations;
1717
mod loan_kills;
1818

19+
/// When requested, emit most of the facts needed by polonius:
20+
/// - moves and assignments
21+
/// - universal regions and their relations
22+
/// - CFG points and edges
23+
/// - loan kills
24+
/// - loan invalidations
25+
///
26+
/// The rest of the facts are emitted during typeck and liveness.
27+
pub(crate) fn emit_facts<'tcx>(
28+
all_facts: &mut Option<AllFacts>,
29+
tcx: TyCtxt<'tcx>,
30+
location_table: &LocationTable,
31+
body: &Body<'tcx>,
32+
borrow_set: &BorrowSet<'tcx>,
33+
move_data: &MoveData<'_>,
34+
universal_regions: &UniversalRegions<'_>,
35+
universal_region_relations: &UniversalRegionRelations<'_>,
36+
) {
37+
let Some(all_facts) = all_facts else {
38+
// We don't do anything if there are no facts to fill.
39+
return;
40+
};
41+
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
42+
emit_move_facts(all_facts, move_data, location_table, body);
43+
emit_universal_region_facts(
44+
all_facts,
45+
borrow_set,
46+
&universal_regions,
47+
&universal_region_relations,
48+
);
49+
emit_cfg_and_loan_kills_facts(all_facts, tcx, location_table, body, borrow_set);
50+
emit_loan_invalidations_facts(all_facts, tcx, location_table, body, borrow_set);
51+
}
52+
1953
/// Emit facts needed for move/init analysis: moves and assignments.
20-
pub(crate) fn emit_move_facts(
54+
fn emit_move_facts(
2155
all_facts: &mut AllFacts,
2256
move_data: &MoveData<'_>,
2357
location_table: &LocationTable,
@@ -91,7 +125,7 @@ pub(crate) fn emit_move_facts(
91125
}
92126

93127
/// Emit universal regions facts, and their relations.
94-
pub(crate) fn emit_universal_region_facts(
128+
fn emit_universal_region_facts(
95129
all_facts: &mut AllFacts,
96130
borrow_set: &BorrowSet<'_>,
97131
universal_regions: &UniversalRegions<'_>,
@@ -132,33 +166,23 @@ pub(crate) fn emit_universal_region_facts(
132166
}
133167

134168
/// Emit facts about loan invalidations.
135-
pub(crate) fn emit_loan_invalidations_facts<'tcx>(
169+
fn emit_loan_invalidations_facts<'tcx>(
170+
all_facts: &mut AllFacts,
136171
tcx: TyCtxt<'tcx>,
137-
all_facts: &mut Option<AllFacts>,
138172
location_table: &LocationTable,
139173
body: &Body<'tcx>,
140174
borrow_set: &BorrowSet<'tcx>,
141175
) {
142-
let Some(all_facts) = all_facts else {
143-
// Nothing to do if we don't have any facts to fill
144-
return;
145-
};
146-
147176
loan_invalidations::emit_loan_invalidations(tcx, all_facts, location_table, body, borrow_set);
148177
}
149178

150179
/// Emit facts about CFG points and edges, as well as locations where loans are killed.
151-
pub(crate) fn emit_cfg_and_loan_kills_facts<'tcx>(
180+
fn emit_cfg_and_loan_kills_facts<'tcx>(
181+
all_facts: &mut AllFacts,
152182
tcx: TyCtxt<'tcx>,
153-
all_facts: &mut Option<AllFacts>,
154183
location_table: &LocationTable,
155184
body: &Body<'tcx>,
156185
borrow_set: &BorrowSet<'tcx>,
157186
) {
158-
let Some(all_facts) = all_facts else {
159-
// Nothing to do if we don't have any facts to fill
160-
return;
161-
};
162-
163187
loan_kills::emit_loan_kills(tcx, all_facts, location_table, body, borrow_set);
164188
}

0 commit comments

Comments
 (0)