small polish of loan invalidations fact generation

This commit is contained in:
Rémy Rakic 2023-11-23 14:19:04 +00:00
parent 951901bedc
commit c976bc114a
2 changed files with 12 additions and 22 deletions

View File

@ -24,18 +24,12 @@ pub(super) fn emit_loan_invalidations<'tcx>(
) {
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 mut visitor =
LoanInvalidationsGenerator { all_facts, borrow_set, tcx, location_table, body, dominators };
visitor.visit_body(body);
}
struct InvalidationGenerator<'cx, 'tcx> {
struct LoanInvalidationsGenerator<'cx, 'tcx> {
tcx: TyCtxt<'tcx>,
all_facts: &'cx mut AllFacts,
location_table: &'cx LocationTable,
@ -46,7 +40,7 @@ struct InvalidationGenerator<'cx, 'tcx> {
/// Visits the whole MIR and generates `invalidates()` facts.
/// Most of the code implementing this was stolen from `borrow_check/mod.rs`.
impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
impl<'cx, 'tcx> Visitor<'tcx> for LoanInvalidationsGenerator<'cx, 'tcx> {
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
self.check_activations(location);
@ -208,7 +202,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx> {
}
}
impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
impl<'cx, 'tcx> LoanInvalidationsGenerator<'cx, 'tcx> {
/// Simulates mutation of a place.
fn mutate_place(&mut self, location: Location, place: Place<'tcx>, kind: AccessDepth) {
self.access_place(
@ -342,20 +336,16 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> {
rw: ReadOrWrite,
) {
debug!(
"invalidation::check_access_for_conflict(location={:?}, place={:?}, sd={:?}, \
rw={:?})",
"check_access_for_conflict(location={:?}, place={:?}, sd={:?}, rw={:?})",
location, place, sd, rw,
);
let tcx = self.tcx;
let body = self.body;
let borrow_set = self.borrow_set;
each_borrow_involving_path(
self,
tcx,
body,
self.tcx,
self.body,
location,
(sd, place),
borrow_set,
self.borrow_set,
|_| true,
|this, borrow_index, borrow| {
match (rw, borrow.kind) {

View File

@ -13,7 +13,7 @@ use crate::location::LocationTable;
use crate::type_check::free_region_relations::UniversalRegionRelations;
use crate::universal_regions::UniversalRegions;
mod invalidation;
mod loan_invalidations;
mod loan_kills;
/// Emit facts needed for move/init analysis: moves and assignments.
@ -144,7 +144,7 @@ pub(crate) fn emit_loan_invalidations_facts<'tcx>(
return;
};
invalidation::emit_loan_invalidations(tcx, all_facts, location_table, body, borrow_set);
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.