about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRémy Rakic <remy.rakic+github@gmail.com>2023-11-23 16:14:25 +0000
committerRémy Rakic <remy.rakic+github@gmail.com>2023-11-26 13:03:32 +0000
commitf969af2195f38b711faad7b2b2cabffd162b5ec6 (patch)
tree7367d1b70fdd210bcc0cf03f70f948aa5d3d0f9d
parent96042bc247cdef3469effad1ab307d4c354366d2 (diff)
downloadrust-f969af2195f38b711faad7b2b2cabffd162b5ec6.tar.gz
rust-f969af2195f38b711faad7b2b2cabffd162b5ec6.zip
move remaining legacy polonius fact generation out of NLL module
-rw-r--r--compiler/rustc_borrowck/src/nll.rs28
-rw-r--r--compiler/rustc_borrowck/src/polonius/loan_invalidations.rs1
-rw-r--r--compiler/rustc_borrowck/src/polonius/loan_kills.rs1
-rw-r--r--compiler/rustc_borrowck/src/polonius/mod.rs56
4 files changed, 46 insertions, 40 deletions
diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs
index 10a8dbe2927..510f1bcd46c 100644
--- a/compiler/rustc_borrowck/src/nll.rs
+++ b/compiler/rustc_borrowck/src/nll.rs
@@ -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 {
diff --git a/compiler/rustc_borrowck/src/polonius/loan_invalidations.rs b/compiler/rustc_borrowck/src/polonius/loan_invalidations.rs
index 23bf8457816..232bd741825 100644
--- a/compiler/rustc_borrowck/src/polonius/loan_invalidations.rs
+++ b/compiler/rustc_borrowck/src/polonius/loan_invalidations.rs
@@ -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 };
diff --git a/compiler/rustc_borrowck/src/polonius/loan_kills.rs b/compiler/rustc_borrowck/src/polonius/loan_kills.rs
index cc836115c31..5df94383702 100644
--- a/compiler/rustc_borrowck/src/polonius/loan_kills.rs
+++ b/compiler/rustc_borrowck/src/polonius/loan_kills.rs
@@ -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);
diff --git a/compiler/rustc_borrowck/src/polonius/mod.rs b/compiler/rustc_borrowck/src/polonius/mod.rs
index 9454118d9c4..40126d50d57 100644
--- a/compiler/rustc_borrowck/src/polonius/mod.rs
+++ b/compiler/rustc_borrowck/src/polonius/mod.rs
@@ -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,
@@ -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);
 }