Skip to content

Commit

Permalink
extract polonius loan invalidations fact generation
Browse files Browse the repository at this point in the history
and move the polonius module to the borrowck root
  • Loading branch information
lqd committed Nov 26, 2023
1 parent 459a616 commit 16a5da7
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 25 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ mod dataflow;
mod def_use;
mod diagnostics;
mod facts;
mod invalidation;
mod location;
mod member_constraints;
mod nll;
mod path_utils;
mod place_ext;
mod places_conflict;
mod polonius;
mod prefixes;
mod region_infer;
mod renumber;
Expand Down
12 changes: 8 additions & 4 deletions compiler/rustc_borrowck/src/nll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,14 @@ use std::path::PathBuf;
use std::rc::Rc;
use std::str::FromStr;

mod polonius;

use crate::{
borrow_set::BorrowSet,
constraint_generation,
consumers::ConsumerOptions,
diagnostics::RegionErrors,
facts::{AllFacts, AllFactsExt, RustcFacts},
invalidation,
location::LocationTable,
polonius,
region_infer::{values::RegionValueElements, RegionInferenceContext},
renumber,
type_check::{self, MirTypeckRegionConstraints, MirTypeckResults},
Expand Down Expand Up @@ -176,7 +174,13 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
);

// Generate various additional constraints.
invalidation::generate_invalidates(infcx.tcx, &mut all_facts, location_table, body, borrow_set);
polonius::emit_loan_invalidations_facts(
infcx.tcx,
&mut all_facts,
location_table,
body,
borrow_set,
);

let def_id = body.source.def_id();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,25 @@ use crate::{
ReadOrWrite, Reservation, Shallow, Write, WriteKind,
};

pub(super) fn generate_invalidates<'tcx>(
/// Emit `loan_invalidated_at` facts.
pub(super) fn emit_loan_invalidations<'tcx>(
tcx: TyCtxt<'tcx>,
all_facts: &mut Option<AllFacts>,
all_facts: &mut AllFacts,
location_table: &LocationTable,
body: &Body<'tcx>,
borrow_set: &BorrowSet<'tcx>,
) {
if all_facts.is_none() {
// Nothing to do if we don't have any facts
return;
}

if let Some(all_facts) = all_facts {
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
let dominators = body.basic_blocks.dominators();
let mut ig = InvalidationGenerator {
all_facts,
borrow_set,
tcx,
location_table,
body: body,
dominators,
};
ig.visit_body(body);
}
let _prof_timer = tcx.prof.generic_activity("polonius_fact_generation");
let dominators = body.basic_blocks.dominators();
let mut ig = InvalidationGenerator {
all_facts,
borrow_set,
tcx,
location_table,
body: body,
dominators,
};
ig.visit_body(body);
}

struct InvalidationGenerator<'cx, 'tcx> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//! parity.

use rustc_middle::mir::{Body, LocalKind, Location, START_BLOCK};
use rustc_middle::ty::TyCtxt;
use rustc_mir_dataflow::move_paths::{InitKind, InitLocation, MoveData};

use crate::borrow_set::BorrowSet;
Expand All @@ -12,6 +13,8 @@ use crate::location::LocationTable;
use crate::type_check::free_region_relations::UniversalRegionRelations;
use crate::universal_regions::UniversalRegions;

mod invalidation;

/// Emit facts needed for move/init analysis: moves and assignments.
pub(crate) fn emit_move_facts(
all_facts: &mut AllFacts,
Expand Down Expand Up @@ -126,3 +129,19 @@ pub(crate) fn emit_universal_region_facts(
}
}
}

/// Emit facts about loan invalidations
pub(crate) fn emit_loan_invalidations_facts<'tcx>(
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;
};

invalidation::emit_loan_invalidations(tcx, all_facts, location_table, body, borrow_set);
}

0 comments on commit 16a5da7

Please sign in to comment.