Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow pruning borrowcheck fact base when calculating aliases #80

Merged
merged 3 commits into from
Aug 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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