Skip to content

Commit

Permalink
move remaining legacy polonius fact generation out of NLL module
Browse files Browse the repository at this point in the history
  • Loading branch information
lqd committed Nov 26, 2023
1 parent 96042bc commit f969af2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 40 deletions.
28 changes: 6 additions & 22 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand All @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_borrowck/src/polonius/loan_invalidations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_borrowck/src/polonius/loan_kills.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
56 changes: 40 additions & 16 deletions compiler/rustc_borrowck/src/polonius/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,42 @@ use crate::universal_regions::UniversalRegions;
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,
Expand Down Expand Up @@ -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<'_>,
Expand Down Expand Up @@ -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);
}

0 comments on commit f969af2

Please sign in to comment.