Skip to content

Commit

Permalink
Merge pull request #80 from brownsys/upstream-update
Browse files Browse the repository at this point in the history
Allow pruning borrowcheck fact base when calculating aliases
  • Loading branch information
willcrichton authored Aug 31, 2023
2 parents 2a2d981 + 8a0ce41 commit 7cf3b2f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions crates/flowistry/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
)]

extern crate either;
extern crate polonius_engine;
extern crate rustc_borrowck;
extern crate rustc_data_structures;
extern crate rustc_driver;
Expand Down
30 changes: 28 additions & 2 deletions crates/flowistry/src/mir/aliases.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ use crate::{
mir::utils::AsyncHack,
};

type BorrowckLocationIndex =
<rustc_borrowck::consumers::RustcFacts as crate::polonius_engine::FactTypes>::Point;

#[derive(Default)]
struct GatherBorrows<'tcx> {
borrows: Vec<(RegionVid, BorrowKind, Place<'tcx>)>,
Expand Down Expand Up @@ -71,7 +74,21 @@ impl<'a, 'tcx> Aliases<'a, 'tcx> {
def_id: DefId,
body_with_facts: &'a BodyWithBorrowckFacts<'tcx>,
) -> Self {
let loans = Self::compute_loans(tcx, def_id, body_with_facts);
let loans = Self::compute_loans(tcx, def_id, body_with_facts, |_, _, _| true);
Aliases {
tcx,
body: &body_with_facts.body,
loans,
}
}

pub fn build_with_fact_selection(
tcx: TyCtxt<'tcx>,
def_id: DefId,
body_with_facts: &'a BodyWithBorrowckFacts<'tcx>,
selector: impl Fn(RegionVid, RegionVid, BorrowckLocationIndex) -> bool,
) -> Self {
let loans = Self::compute_loans(tcx, def_id, body_with_facts, selector);
Aliases {
tcx,
body: &body_with_facts.body,
Expand All @@ -83,11 +100,20 @@ impl<'a, 'tcx> Aliases<'a, 'tcx> {
tcx: TyCtxt<'tcx>,
def_id: DefId,
body_with_facts: &'a BodyWithBorrowckFacts<'tcx>,
constraint_selector: impl Fn(RegionVid, RegionVid, BorrowckLocationIndex) -> bool,
) -> LoanMap<'tcx> {
let start = Instant::now();
let body = &body_with_facts.body;
let static_region = RegionVid::from_usize(0);
let subset_base = &body_with_facts.input_facts.as_ref().unwrap().subset_base;
let ref subset_base = body_with_facts
.input_facts
.as_ref()
.unwrap()
.subset_base
.iter()
.cloned()
.filter(|(r1, r2, i)| constraint_selector(*r1, *r2, *i))
.collect::<Vec<_>>();

let all_pointers = body
.local_decls()
Expand Down

0 comments on commit 7cf3b2f

Please sign in to comment.