move remaining legacy polonius fact generation out of NLL module

This commit is contained in:
Rémy Rakic 2023-11-23 16:14:25 +00:00
parent 96042bc247
commit f969af2195
4 changed files with 46 additions and 40 deletions

View File

@ -122,17 +122,6 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
polonius_input,
);
if let Some(all_facts) = &mut all_facts {
let _prof_timer = infcx.tcx.prof.generic_activity("polonius_fact_generation");
polonius::emit_move_facts(all_facts, move_data, location_table, body);
polonius::emit_universal_region_facts(
all_facts,
borrow_set,
&universal_regions,
&universal_region_relations,
);
}
// Create the region inference context, taking ownership of the
// region inference data that was contained in `infcx`, and the
// base constraints generated by the type-check.
@ -148,12 +137,16 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
} = constraints;
let placeholder_indices = Rc::new(placeholder_indices);
polonius::emit_cfg_and_loan_kills_facts(
infcx.tcx,
// If requested, emit legacy polonius facts.
polonius::emit_facts(
&mut all_facts,
infcx.tcx,
location_table,
body,
borrow_set,
move_data,
&universal_regions,
&universal_region_relations,
);
let mut regioncx = RegionInferenceContext::new(
@ -171,15 +164,6 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
live_loans,
);
// Generate various additional constraints.
polonius::emit_loan_invalidations_facts(
infcx.tcx,
&mut all_facts,
location_table,
body,
borrow_set,
);
// If requested: dump NLL facts, and run legacy polonius analysis.
let polonius_output = all_facts.as_ref().and_then(|all_facts| {
if infcx.tcx.sess.opts.unstable_opts.nll_facts {

View File

@ -22,7 +22,6 @@ pub(super) fn emit_loan_invalidations<'tcx>(
body: &Body<'tcx>,
borrow_set: &BorrowSet<'tcx>,
) {
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
let dominators = body.basic_blocks.dominators();
let mut visitor =
LoanInvalidationsGenerator { all_facts, borrow_set, tcx, location_table, body, dominators };

View File

@ -17,7 +17,6 @@ pub(super) fn emit_loan_kills<'tcx>(
body: &Body<'tcx>,
borrow_set: &BorrowSet<'tcx>,
) {
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
let mut visitor = LoanKillsGenerator { borrow_set, tcx, location_table, all_facts, body };
for (bb, data) in body.basic_blocks.iter_enumerated() {
visitor.visit_basic_block_data(bb, data);

View File

@ -16,8 +16,42 @@
mod loan_invalidations;
mod loan_kills;
/// When requested, emit most of the facts needed by polonius:
/// - moves and assignments
/// - universal regions and their relations
/// - CFG points and edges
/// - loan kills
/// - loan invalidations
///
/// The rest of the facts are emitted during typeck and liveness.
pub(crate) fn emit_facts<'tcx>(
all_facts: &mut Option<AllFacts>,
tcx: TyCtxt<'tcx>,
location_table: &LocationTable,
body: &Body<'tcx>,
borrow_set: &BorrowSet<'tcx>,
move_data: &MoveData<'_>,
universal_regions: &UniversalRegions<'_>,
universal_region_relations: &UniversalRegionRelations<'_>,
) {
let Some(all_facts) = all_facts else {
// We don't do anything if there are no facts to fill.
return;
};
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
emit_move_facts(all_facts, move_data, location_table, body);
emit_universal_region_facts(
all_facts,
borrow_set,
&universal_regions,
&universal_region_relations,
);
emit_cfg_and_loan_kills_facts(all_facts, tcx, location_table, body, borrow_set);
emit_loan_invalidations_facts(all_facts, tcx, location_table, body, borrow_set);
}
/// Emit facts needed for move/init analysis: moves and assignments.
pub(crate) fn emit_move_facts(
fn emit_move_facts(
all_facts: &mut AllFacts,
move_data: &MoveData<'_>,
location_table: &LocationTable,
@ -91,7 +125,7 @@ pub(crate) fn emit_move_facts(
}
/// Emit universal regions facts, and their relations.
pub(crate) fn emit_universal_region_facts(
fn emit_universal_region_facts(
all_facts: &mut AllFacts,
borrow_set: &BorrowSet<'_>,
universal_regions: &UniversalRegions<'_>,
@ -132,33 +166,23 @@ pub(crate) fn emit_universal_region_facts(
}
/// Emit facts about loan invalidations.
pub(crate) fn emit_loan_invalidations_facts<'tcx>(
fn emit_loan_invalidations_facts<'tcx>(
all_facts: &mut AllFacts,
tcx: TyCtxt<'tcx>,
all_facts: &mut Option<AllFacts>,
location_table: &LocationTable,
body: &Body<'tcx>,
borrow_set: &BorrowSet<'tcx>,
) {
let Some(all_facts) = all_facts else {
// Nothing to do if we don't have any facts to fill
return;
};
loan_invalidations::emit_loan_invalidations(tcx, all_facts, location_table, body, borrow_set);
}
/// Emit facts about CFG points and edges, as well as locations where loans are killed.
pub(crate) fn emit_cfg_and_loan_kills_facts<'tcx>(
fn emit_cfg_and_loan_kills_facts<'tcx>(
all_facts: &mut AllFacts,
tcx: TyCtxt<'tcx>,
all_facts: &mut Option<AllFacts>,
location_table: &LocationTable,
body: &Body<'tcx>,
borrow_set: &BorrowSet<'tcx>,
) {
let Some(all_facts) = all_facts else {
// Nothing to do if we don't have any facts to fill
return;
};
loan_kills::emit_loan_kills(tcx, all_facts, location_table, body, borrow_set);
}