Skip to content

Commit

Permalink
small polish of loan invalidations fact generation
Browse files Browse the repository at this point in the history
  • Loading branch information
lqd committed Nov 26, 2023
1 parent 951901b commit c976bc1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_borrowck/src/polonius/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c976bc1

Please sign in to comment.