Skip to content

Commit

Permalink
replace Output type parameters with FactTypes
Browse files Browse the repository at this point in the history
  • Loading branch information
csmoe committed Sep 23, 2019
1 parent 08fe124 commit 0a98cca
Showing 1 changed file with 11 additions and 24 deletions.
35 changes: 11 additions & 24 deletions polonius-engine/src/output/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mod initialization;
mod liveness;
mod location_insensitive;
mod naive;
use facts::{AllFacts, Atom};
use facts::{AllFacts, Atom, FactTypes};

#[derive(Debug, Clone, Copy)]
pub enum Algorithm {
Expand Down Expand Up @@ -62,21 +62,14 @@ impl ::std::str::FromStr for Algorithm {
}

#[derive(Clone, Debug)]
pub struct Output<Region, Loan, Point, Variable, MovePath>
where
Region: Atom,
Region: Atom,
Loan: Atom,
Point: Atom,
Variable: Atom,
MovePath: Atom,
pub struct Output<T: FactTypes>
{
pub errors: FxHashMap<Point, Vec<Loan>>,
pub errors: FxHashMap<T::Point, Vec<T::Loan>>,

pub dump_enabled: bool,

// these are just for debugging
pub borrow_live_at: FxHashMap<Point, Vec<Loan>>,
pub borrow_live_at: FxHashMap<T::Point, Vec<T::Loan>>,
pub restricts: FxHashMap<Point, BTreeMap<Region, BTreeSet<Loan>>>,
pub restricts_anywhere: FxHashMap<Region, BTreeSet<Loan>>,
pub region_live_at: FxHashMap<Point, Vec<Region>>,
Expand Down Expand Up @@ -125,16 +118,10 @@ fn compare_errors<Loan: Atom, Point: Atom>(
differ
}

impl<Region, Loan, Point, Variable, MovePath> Output<Region, Loan, Point, Variable, MovePath>
where
Region: Atom,
Loan: Atom,
Point: Atom,
Variable: Atom,
MovePath: Atom,
impl<T: FactTypes> Output<T>
{
pub fn compute(
all_facts: &AllFacts<Region, Loan, Point, Variable, MovePath>,
all_facts: &AllFacts<T>,
algorithm: Algorithm,
dump_enabled: bool,
) -> Self {
Expand Down Expand Up @@ -180,37 +167,37 @@ where
}
}

pub fn errors_at(&self, location: Point) -> &[Loan] {
pub fn errors_at(&self, location: T::Point) -> &[T::Loan] {
match self.errors.get(&location) {
Some(v) => v,
None => &[],
}
}

pub fn borrows_in_scope_at(&self, location: Point) -> &[Loan] {
pub fn borrows_in_scope_at(&self, location: T::Point) -> &[T::Loan] {
match self.borrow_live_at.get(&location) {
Some(p) => p,
None => &[],
}
}

pub fn restricts_at(&self, location: Point) -> Cow<'_, BTreeMap<Region, BTreeSet<Loan>>> {
pub fn restricts_at(&self, location: T::Point) -> Cow<'_, BTreeMap<T::Region, BTreeSet<T::Loan>>> {
assert!(self.dump_enabled);
match self.restricts.get(&location) {
Some(map) => Cow::Borrowed(map),
None => Cow::Owned(BTreeMap::default()),
}
}

pub fn regions_live_at(&self, location: Point) -> &[Region] {
pub fn regions_live_at(&self, location: T::Point) -> &[T::Region] {
assert!(self.dump_enabled);
match self.region_live_at.get(&location) {
Some(v) => v,
None => &[],
}
}

pub fn subsets_at(&self, location: Point) -> Cow<'_, BTreeMap<Region, BTreeSet<Region>>> {
pub fn subsets_at(&self, location: T::Point) -> Cow<'_, BTreeMap<T::Region, BTreeSet<T::Region>>> {
assert!(self.dump_enabled);
match self.subset.get(&location) {
Some(v) => Cow::Borrowed(v),
Expand Down

0 comments on commit 0a98cca

Please sign in to comment.