diff --git a/polonius-engine/src/facts.rs b/polonius-engine/src/facts.rs index 4e449f9034b..eb90b3f2846 100644 --- a/polonius-engine/src/facts.rs +++ b/polonius-engine/src/facts.rs @@ -3,68 +3,70 @@ use std::hash::Hash; /// The "facts" which are the basis of the NLL borrow analysis. #[derive(Clone, Debug)] -pub struct AllFacts { - /// `borrow_region(R, B, P)` -- the region R may refer to data - /// from borrow B starting at the point P (this is usually the +pub struct AllFacts { + /// `borrow_region(O, L, P)` -- the origin `O` may refer to data + /// from loan `L` starting at the point `P` (this is usually the /// point *after* a borrow rvalue) - pub borrow_region: Vec<(R, L, P)>, + pub borrow_region: Vec<(Origin, Loan, Point)>, - /// `universal_region(R)` -- this is a "free region" within fn body - pub universal_region: Vec, + /// `universal_region(O)` -- this is a "free region" within fn body + pub universal_region: Vec, - /// `cfg_edge(P,Q)` for each edge P -> Q in the control flow - pub cfg_edge: Vec<(P, P)>, + /// `cfg_edge(P, Q)` for each edge `P -> Q` in the control flow + pub cfg_edge: Vec<(Point, Point)>, - /// `killed(B,P)` when some prefix of the path borrowed at B is assigned at point P - pub killed: Vec<(L, P)>, + /// `killed(L, P)` when some prefix of the path borrowed at `L` is assigned at point `P` + pub killed: Vec<(Loan, Point)>, - /// `outlives(R1, R2, P)` when we require `R1@P: R2@P` - pub outlives: Vec<(R, R, P)>, + /// `outlives(O1, P2, P)` when we require `O1@P: O2@P` + pub outlives: Vec<(Origin, Origin, Point)>, - /// `invalidates(P, L)` when the loan L is invalidated at point P - pub invalidates: Vec<(P, L)>, + /// `invalidates(P, L)` when the loan `L` is invalidated at point `P` + pub invalidates: Vec<(Point, Loan)>, - /// `var_used(V, P) when the variable V is used for anything but a drop at point P` - pub var_used: Vec<(V, P)>, + /// `var_used(V, P)` when the variable `V` is used for anything but a drop at point `P` + pub var_used: Vec<(Variable, Point)>, - /// `var_defined(V, P) when the variable V is overwritten by the point P` - pub var_defined: Vec<(V, P)>, + /// `var_defined(V, P)` when the variable `V` is overwritten by the point `P` + pub var_defined: Vec<(Variable, Point)>, - /// `var_used(V, P) when the variable V is used in a drop at point P` - pub var_drop_used: Vec<(V, P)>, + /// `var_used(V, P)` when the variable `V` is used in a drop at point `P` + pub var_drop_used: Vec<(Variable, Point)>, - /// `var_uses_region(V, R) when the type of V includes the region R` - pub var_uses_region: Vec<(V, R)>, + /// `var_uses_region(V, O)` when the type of `V` includes the origin `O` + pub var_uses_region: Vec<(Variable, Origin)>, - /// `var_drops_region(V, R) when the type of V includes the region R and uses - /// it when dropping` - pub var_drops_region: Vec<(V, R)>, + /// `var_drops_region(V, O)` when the type of `V` includes the origin `O` and uses + /// it when dropping + pub var_drops_region: Vec<(Variable, Origin)>, - /// `child(M1, M2) when the move path `M1` is the direct or transitive child + /// `child(M1, M2)` when the move path `M1` is the direct or transitive child /// of `M2`, e.g. `child(x.y, x)`, `child(x.y.z, x.y)`, `child(x.y.z, x)` /// would all be true if there was a path like `x.y.z`. - pub child: Vec<(M, M)>, + pub child: Vec<(MovePath, MovePath)>, - /// `path_belongs_to_var(M, V) the root path `M` starting in variable `V`. - pub path_belongs_to_var: Vec<(M, V)>, + /// `path_belongs_to_var(M, V)` the root path `M` starting in variable `V`. + pub path_belongs_to_var: Vec<(MovePath, Variable)>, - /// `initialized_at(M, P) when the move path `M` was initialized at point + /// `initialized_at(M, P)` when the move path `M` was initialized at point /// `P`. This fact is only emitted for a prefix `M`, and not for the /// implicit initialization of all of `M`'s children. E.g. a statement like /// `x.y = 3` at point `P` would give the fact `initialized_at(x.y, P)` (but /// neither `initialized_at(x.y.z, P)` nor `initialized_at(x, P)`). - pub initialized_at: Vec<(M, P)>, + pub initialized_at: Vec<(MovePath, Point)>, - /// `moved_out_at(M, P) when the move path `M` was moved at point `P`. The + /// `moved_out_at(M, P)` when the move path `M` was moved at point `P`. The /// same logic is applied as for `initialized_at` above. - pub moved_out_at: Vec<(M, P)>, + pub moved_out_at: Vec<(MovePath, Point)>, - /// `path_accessed_at(M, P) when the move path `M` was accessed at point + /// `path_accessed_at(M, P)` when the move path `M` was accessed at point /// `P`. The same logic as for `initialized_at` and `moved_out_at` applies. - pub path_accessed_at: Vec<(M, P)>, + pub path_accessed_at: Vec<(MovePath, Point)>, } -impl Default for AllFacts { +impl Default + for AllFacts +{ fn default() -> Self { AllFacts { borrow_region: Vec::default(), diff --git a/polonius-engine/src/output/datafrog_opt.rs b/polonius-engine/src/output/datafrog_opt.rs index 044bc43f6a4..378597dc969 100644 --- a/polonius-engine/src/output/datafrog_opt.rs +++ b/polonius-engine/src/output/datafrog_opt.rs @@ -18,10 +18,10 @@ use crate::output::Output; use datafrog::{Iteration, Relation, RelationLeaper}; use facts::{AllFacts, Atom}; -pub(super) fn compute( +pub(super) fn compute( dump_enabled: bool, - all_facts: AllFacts, -) -> Output { + all_facts: AllFacts, +) -> Output { let mut result = Output::new(dump_enabled); let var_maybe_initialized_on_exit = initialization::init_var_maybe_initialized_on_exit( @@ -62,22 +62,22 @@ pub(super) fn compute = region_live_at.into(); - let region_live_at_var = iteration.variable::<((Region, Point), ())>("region_live_at"); + let region_live_at_rel: Relation<(Origin, Point)> = region_live_at.into(); + let region_live_at_var = iteration.variable::<((Origin, Point), ())>("region_live_at"); // `borrow_region` input but organized for join - let borrow_region_rp = iteration.variable::<((Region, Point), Loan)>("borrow_region_rp"); + let borrow_region_rp = iteration.variable::<((Origin, Point), Loan)>("borrow_region_rp"); // .decl subset(R1, R2, P) // // Indicates that `R1: R2` at the point `P`. - let subset_r1p = iteration.variable::<((Region, Point), Region)>("subset_r1p"); + let subset_r1p = iteration.variable::<((Origin, Point), Origin)>("subset_r1p"); // .decl requires(R, B, P) // - // At the point, things with region R may depend on data from + // At the point, things with origin R may depend on data from // borrow B - let requires_rp = iteration.variable::<((Region, Point), Loan)>("requires_rp"); + let requires_rp = iteration.variable::<((Origin, Point), Loan)>("requires_rp"); // .decl borrow_live_at(B, P) -- true if the restrictions of the borrow B // need to be enforced at the point P @@ -95,14 +95,14 @@ pub(super) fn compute("live_to_dying_regions_r2pq"); + iteration.variable::<((Origin, Point, Point), Origin)>("live_to_dying_regions_r2pq"); // .decl dying_region_requires((R, P, Q), B) // - // The region `R` requires the borrow `B`, but the - // region `R` goes dead along the edge `P -> Q` + // The origin `R` requires the borrow `B`, but the + // origin `R` goes dead along the edge `P -> Q` let dying_region_requires = - iteration.variable::<((Region, Point, Point), Loan)>("dying_region_requires"); + iteration.variable::<((Origin, Point, Point), Loan)>("dying_region_requires"); // .decl dying_can_reach_origins(R, P, Q) // @@ -110,40 +110,40 @@ pub(super) fn compute("dying_can_reach_origins"); + iteration.variable::<((Origin, Point), Point)>("dying_can_reach_origins"); // .decl dying_can_reach(R1, R2, P, Q) // - // Indicates that the region `R1`, which is dead - // in `Q`, can reach the region `R2` in P. + // Indicates that the origin `R1`, which is dead + // in `Q`, can reach the origin `R2` in P. // // This is effectively the transitive subset // relation, but we try to limit it to regions // that are dying on the edge P -> Q. let dying_can_reach_r2q = - iteration.variable::<((Region, Point), (Region, Point))>("dying_can_reach"); + iteration.variable::<((Origin, Point), (Origin, Point))>("dying_can_reach"); let dying_can_reach_1 = iteration.variable_indistinct("dying_can_reach_1"); // .decl dying_can_reach_live(R1, R2, P, Q) // // Indicates that, along the edge `P -> Q`, the dead (in Q) - // region R1 can reach the live (in Q) region R2 via a subset + // origin R1 can reach the live (in Q) origin R2 via a subset // relation. This is a subset of the full `dying_can_reach` // relation where we filter down to those cases where R2 is // live in Q. let dying_can_reach_live = - iteration.variable::<((Region, Point, Point), Region)>("dying_can_reach_live"); + iteration.variable::<((Origin, Point, Point), Origin)>("dying_can_reach_live"); // .decl dead_borrow_region_can_reach_root((R, P), B) // // Indicates a "borrow region" R at P which is not live on // entry to P. let dead_borrow_region_can_reach_root = - iteration.variable::<((Region, Point), Loan)>("dead_borrow_region_can_reach_root"); + iteration.variable::<((Origin, Point), Loan)>("dead_borrow_region_can_reach_root"); // .decl dead_borrow_region_can_reach_dead((R2, P), B) let dead_borrow_region_can_reach_dead = - iteration.variable::<((Region, Point), Loan)>("dead_borrow_region_can_reach_dead"); + iteration.variable::<((Origin, Point), Loan)>("dead_borrow_region_can_reach_dead"); let dead_borrow_region_can_reach_dead_1 = iteration.variable_indistinct("dead_borrow_region_can_reach_dead_1"); @@ -234,7 +234,7 @@ pub(super) fn compute Q` where `R1` is dead in Q; in - // that case, for each region `R2` live in `Q` + // that case, for each origin `R2` live in `Q` // where `R1 <= R2` in P, we add `R2 requires B` // to `Q`. requires_rp.from_join( @@ -366,12 +366,12 @@ pub(super) fn compute( +pub(super) fn compute( dump_enabled: bool, - all_facts: AllFacts, -) -> Output { + all_facts: AllFacts, +) -> Output { let lins_output = location_insensitive::compute(dump_enabled, &all_facts); if lins_output.errors.is_empty() { lins_output diff --git a/polonius-engine/src/output/initialization.rs b/polonius-engine/src/output/initialization.rs index d8a6cb11835..463ce804b8a 100644 --- a/polonius-engine/src/output/initialization.rs +++ b/polonius-engine/src/output/initialization.rs @@ -5,17 +5,17 @@ use facts::Atom; use datafrog::{Iteration, Relation, RelationLeaper}; -pub(super) fn init_var_maybe_initialized_on_exit( +pub(super) fn init_var_maybe_initialized_on_exit( child: Vec<(MovePath, MovePath)>, path_belongs_to_var: Vec<(MovePath, Variable)>, initialized_at: Vec<(MovePath, Point)>, moved_out_at: Vec<(MovePath, Point)>, path_accessed_at: Vec<(MovePath, Point)>, cfg_edge: &[(Point, Point)], - output: &mut Output, + output: &mut Output, ) -> Vec<(Variable, Point)> where - Region: Atom, + Origin: Atom, Loan: Atom, Point: Atom, Variable: Atom, diff --git a/polonius-engine/src/output/liveness.rs b/polonius-engine/src/output/liveness.rs index da152e6202b..098665062d2 100644 --- a/polonius-engine/src/output/liveness.rs +++ b/polonius-engine/src/output/liveness.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -//! An implementation of the region liveness calculation logic +//! An implementation of the origin liveness calculation logic use std::collections::BTreeSet; use std::time::Instant; @@ -18,18 +18,18 @@ use facts::Atom; use datafrog::{Iteration, Relation, RelationLeaper}; -pub(super) fn compute_live_regions( +pub(super) fn compute_live_regions( var_used: Vec<(Variable, Point)>, var_drop_used: Vec<(Variable, Point)>, var_defined: Vec<(Variable, Point)>, - var_uses_region: Vec<(Variable, Region)>, - var_drops_region: Vec<(Variable, Region)>, + var_uses_region: Vec<(Variable, Origin)>, + var_drops_region: Vec<(Variable, Origin)>, cfg_edge: &[(Point, Point)], var_maybe_initialized_on_exit: Vec<(Variable, Point)>, - output: &mut Output, -) -> Vec<(Region, Point)> + output: &mut Output, +) -> Vec<(Origin, Point)> where - Region: Atom, + Origin: Atom, Loan: Atom, Point: Atom, Variable: Atom, @@ -44,8 +44,8 @@ where let cfg_edge_rel: Relation<(Point, Point)> = cfg_edge.iter().map(|(p, q)| (*p, *q)).collect(); let cfg_edge_reverse_rel: Relation<(Point, Point)> = cfg_edge.iter().map(|(p, q)| (*q, *p)).collect(); - let var_uses_region_rel: Relation<(Variable, Region)> = var_uses_region.into(); - let var_drops_region_rel: Relation<(Variable, Region)> = var_drops_region.into(); + let var_uses_region_rel: Relation<(Variable, Origin)> = var_uses_region.into(); + let var_drops_region_rel: Relation<(Variable, Origin)> = var_drops_region.into(); let var_maybe_initialized_on_exit_rel: Relation<(Variable, Point)> = var_maybe_initialized_on_exit.into(); let var_drop_used_rel: Relation<((Variable, Point), ())> = var_drop_used @@ -61,7 +61,7 @@ where let var_drop_live_var = iteration.variable::<(Variable, Point)>("var_drop_live_at"); // This is what we are actually calculating: - let region_live_at_var = iteration.variable::<((Region, Point), ())>("region_live_at"); + let region_live_at_var = iteration.variable::<((Origin, Point), ())>("region_live_at"); // This propagates the relation `var_live(V, P) :- var_used(V, P)`: var_live_var.insert(var_used.into()); @@ -163,10 +163,10 @@ where .collect() } -pub(super) fn make_universal_region_live( - region_live_at: &mut Vec<(Region, Point)>, +pub(super) fn make_universal_region_live( + region_live_at: &mut Vec<(Origin, Point)>, cfg_edge: &[(Point, Point)], - universal_region: Vec, + universal_region: Vec, ) { debug!("make_universal_regions_live()"); @@ -185,7 +185,7 @@ pub(super) fn make_universal_region_live( } pub(super) fn init_region_live_at< - Region: Atom, + Origin: Atom, Loan: Atom, Point: Atom, Variable: Atom, @@ -194,13 +194,13 @@ pub(super) fn init_region_live_at< var_used: Vec<(Variable, Point)>, var_drop_used: Vec<(Variable, Point)>, var_defined: Vec<(Variable, Point)>, - var_uses_region: Vec<(Variable, Region)>, - var_drops_region: Vec<(Variable, Region)>, + var_uses_region: Vec<(Variable, Origin)>, + var_drops_region: Vec<(Variable, Origin)>, var_maybe_initialized_on_exit: Vec<(Variable, Point)>, cfg_edge: &[(Point, Point)], - universal_region: Vec, - output: &mut Output, -) -> Vec<(Region, Point)> { + universal_region: Vec, + output: &mut Output, +) -> Vec<(Origin, Point)> { debug!("init_region_live_at()"); let mut region_live_at = compute_live_regions( var_used, diff --git a/polonius-engine/src/output/location_insensitive.rs b/polonius-engine/src/output/location_insensitive.rs index 519806224df..4805aa47742 100644 --- a/polonius-engine/src/output/location_insensitive.rs +++ b/polonius-engine/src/output/location_insensitive.rs @@ -18,10 +18,10 @@ use crate::output::Output; use datafrog::{Iteration, Relation, RelationLeaper}; use facts::{AllFacts, Atom}; -pub(super) fn compute( +pub(super) fn compute( dump_enabled: bool, - all_facts: &AllFacts, -) -> Output { + all_facts: &AllFacts, +) -> Output { let mut result = Output::new(dump_enabled); let var_maybe_initialized_on_exit = initialization::init_var_maybe_initialized_on_exit( all_facts.child.clone(), @@ -51,12 +51,12 @@ pub(super) fn compute = region_live_at.into(); + let region_live_at: Relation<(Origin, Point)> = region_live_at.into(); let invalidates = Relation::from_iter(all_facts.invalidates.iter().map(|&(b, p)| (p, b))); // .. some variables, .. - let subset = iteration.variable::<(Region, Region)>("subset"); - let requires = iteration.variable::<(Region, Loan)>("requires"); + let subset = iteration.variable::<(Origin, Origin)>("subset"); + let requires = iteration.variable::<(Origin, Loan)>("requires"); let potential_errors = iteration.variable::<(Loan, Point)>("potential_errors"); @@ -103,20 +103,20 @@ pub(super) fn compute +pub struct Output where - Region: Atom, - Region: Atom, + Origin: Atom, Loan: Atom, Point: Atom, Variable: Atom, @@ -77,12 +76,12 @@ where // these are just for debugging pub borrow_live_at: FxHashMap>, - pub restricts: FxHashMap>>, - pub restricts_anywhere: FxHashMap>, - pub region_live_at: FxHashMap>, + pub restricts: FxHashMap>>, + pub restricts_anywhere: FxHashMap>, + pub region_live_at: FxHashMap>, pub invalidates: FxHashMap>, - pub subset: FxHashMap>>, - pub subset_anywhere: FxHashMap>, + pub subset: FxHashMap>>, + pub subset_anywhere: FxHashMap>, pub var_live_at: FxHashMap>, pub var_drop_live_at: FxHashMap>, pub path_maybe_initialized_at: FxHashMap>, @@ -125,16 +124,16 @@ fn compare_errors( differ } -impl Output +impl Output where - Region: Atom, + Origin: Atom, Loan: Atom, Point: Atom, Variable: Atom, MovePath: Atom, { pub fn compute( - all_facts: &AllFacts, + all_facts: &AllFacts, algorithm: Algorithm, dump_enabled: bool, ) -> Self { @@ -194,7 +193,7 @@ where } } - pub fn restricts_at(&self, location: Point) -> Cow<'_, BTreeMap>> { + pub fn restricts_at(&self, location: Point) -> Cow<'_, BTreeMap>> { assert!(self.dump_enabled); match self.restricts.get(&location) { Some(map) => Cow::Borrowed(map), @@ -202,7 +201,7 @@ where } } - pub fn regions_live_at(&self, location: Point) -> &[Region] { + pub fn regions_live_at(&self, location: Point) -> &[Origin] { assert!(self.dump_enabled); match self.region_live_at.get(&location) { Some(v) => v, @@ -210,7 +209,7 @@ where } } - pub fn subsets_at(&self, location: Point) -> Cow<'_, BTreeMap>> { + pub fn subsets_at(&self, location: Point) -> Cow<'_, BTreeMap>> { assert!(self.dump_enabled); match self.subset.get(&location) { Some(v) => Cow::Borrowed(v), diff --git a/polonius-engine/src/output/naive.rs b/polonius-engine/src/output/naive.rs index 028fdfd4d3a..acacd7fab37 100644 --- a/polonius-engine/src/output/naive.rs +++ b/polonius-engine/src/output/naive.rs @@ -20,10 +20,10 @@ use facts::{AllFacts, Atom}; use datafrog::{Iteration, Relation, RelationLeaper}; -pub(super) fn compute( +pub(super) fn compute( dump_enabled: bool, - all_facts: AllFacts, -) -> Output { + all_facts: AllFacts, +) -> Output { let mut result = Output::new(dump_enabled); let var_maybe_initialized_on_exit = initialization::init_var_maybe_initialized_on_exit( @@ -57,11 +57,11 @@ pub(super) fn compute = all_facts.cfg_edge.into(); let killed_rel: Relation<(Loan, Point)> = all_facts.killed.into(); - let region_live_at_rel: Relation<(Region, Point)> = region_live_at.into(); + let region_live_at_rel: Relation<(Origin, Point)> = region_live_at.into(); // .. some variables, .. - let subset = iteration.variable::<(Region, Region, Point)>("subset"); - let requires = iteration.variable::<(Region, Loan, Point)>("requires"); + let subset = iteration.variable::<(Origin, Origin, Point)>("subset"); + let requires = iteration.variable::<(Origin, Loan, Point)>("requires"); let borrow_live_at = iteration.variable::<((Loan, Point), ())>("borrow_live_at"); // `invalidates` facts, stored ready for joins @@ -76,13 +76,11 @@ pub(super) fn compute("region_live_at"); + let region_live_at_var = iteration.variable::<((Origin, Point), ())>("region_live_at"); // output let errors = iteration.variable("errors"); - //let compute_region_live_at = all_facts.region_live_at.is_empty(); - // load initial facts. subset.insert(all_facts.outlives.into()); requires.insert(all_facts.borrow_region.into()); @@ -185,22 +183,22 @@ pub(super) fn compute }, + Use { origins: Vec }, Fact(Fact), } #[derive(Clone, Debug, PartialEq)] pub enum Fact { Outlives { a: String, b: String }, - BorrowRegionAt { region: String, loan: String }, + BorrowRegionAt { origin: String, loan: String }, Invalidates { loan: String }, Kill { loan: String }, - RegionLiveAt { region: String }, + RegionLiveAt { origin: String }, DefineVariable { variable: String }, UseVariable { variable: String }, } diff --git a/polonius-parser/src/parser.lalrpop b/polonius-parser/src/parser.lalrpop index ae023ce807d..62392378cbe 100644 --- a/polonius-parser/src/parser.lalrpop +++ b/polonius-parser/src/parser.lalrpop @@ -12,12 +12,12 @@ Comment: () = { VarRegionMappings = Comma; VarRegionMapping: (String, String) = { - "(" "," ")" => (<>), + "(" "," ")" => (<>), }; VarUsesRegion = "var_uses_region" "{" "}"; VarDropsRegion = "var_drops_region" "{" "}"; -UniversalRegions = "universal_regions" "{" > "}"; +UniversalRegions = "universal_regions" "{" > "}"; BlockDefn : Block = { "block" "{" Comment* "}" => Block { <> }, }; @@ -39,17 +39,17 @@ Effect = { }; Fact : Fact = { - "outlives" "(" ":" ")" => Fact::Outlives { <> }, - "borrow_region_at" "(" "," ")" => Fact::BorrowRegionAt { <> }, + "outlives" "(" ":" ")" => Fact::Outlives { <> }, + "borrow_region_at" "(" "," ")" => Fact::BorrowRegionAt { <> }, "invalidates" "(" ")" => Fact::Invalidates { <> }, "kill" "(" ")" => Fact::Kill { <> }, "var_used" "(" ")" => Fact::UseVariable { <> }, "var_defined" "(" ")" => Fact::DefineVariable { <> }, - "region_live_at" "(" ")" => Fact::RegionLiveAt { <> }, + "region_live_at" "(" ")" => Fact::RegionLiveAt { <> }, "var_drop_used" "(" ")" => Fact::UseVariable { <> }, }; -Use : Effect = "use" "(" > ")" => Effect::Use { <> }; +Use : Effect = "use" "(" > ")" => Effect::Use { <> }; Comma: Vec = { ",")*> => match e { @@ -62,7 +62,7 @@ Comma: Vec = { } }; -Region: String = { +Origin: String = { r"'\w+" => <>.to_string() }; diff --git a/polonius-parser/src/tests.rs b/polonius-parser/src/tests.rs index 83d8e8c3828..859c03bc24a 100644 --- a/polonius-parser/src/tests.rs +++ b/polonius-parser/src/tests.rs @@ -77,7 +77,7 @@ fn effects() { assert_eq!( effects[0], Effect::Use { - regions: vec!["'a".to_string()] + origins: vec!["'a".to_string()] } ); assert_eq!( @@ -90,7 +90,7 @@ fn effects() { assert_eq!( effects[2], Effect::Fact(Fact::BorrowRegionAt { - region: "'b".to_string(), + origin: "'b".to_string(), loan: "L1".to_string() }) ); @@ -137,14 +137,14 @@ fn effects_start() { loan: "L0".to_string() }), Effect::Fact(Fact::RegionLiveAt { - region: "'a".to_string() + origin: "'a".to_string() }) ] ); assert_eq!( statements.effects, [Effect::Use { - regions: vec!["'a".to_string()] + origins: vec!["'a".to_string()] }] ); @@ -172,7 +172,7 @@ fn effects_start() { assert_eq!( statements.effects, [Effect::Use { - regions: vec!["'c".to_string()] + origins: vec!["'c".to_string()] }] ); } diff --git a/src/dump.rs b/src/dump.rs index 8aa0ef02a3d..2c9d0a56e68 100644 --- a/src/dump.rs +++ b/src/dump.rs @@ -13,7 +13,7 @@ use std::hash::Hash; use std::io::{self, Write}; use std::path::PathBuf; -pub(crate) type Output = PoloniusEngineOutput; +pub(crate) type Output = PoloniusEngineOutput; pub(crate) fn dump_output( output: &Output, @@ -287,9 +287,9 @@ pub(crate) trait Atom: Copy + From + Into { fn table(intern: &InternerTables) -> &Interner; } -impl Atom for Region { +impl Atom for Origin { fn table(intern: &InternerTables) -> &Interner { - &intern.regions + &intern.origins } } @@ -486,7 +486,7 @@ fn build_outputs_by_point_for_visualization( ), facts_by_point( output.region_live_at.iter(), - |(pt, region)| (*pt, region.clone()), + |(pt, origin)| (*pt, origin.clone()), "region_live_at".to_string(), 1, intern, diff --git a/src/facts.rs b/src/facts.rs index 44af95e57ec..a04d9c2cf99 100644 --- a/src/facts.rs +++ b/src/facts.rs @@ -1,6 +1,6 @@ use polonius_engine; -pub(crate) type AllFacts = polonius_engine::AllFacts; +pub(crate) type AllFacts = polonius_engine::AllFacts; macro_rules! index_type { ($t:ident) => { @@ -31,7 +31,7 @@ macro_rules! index_type { }; } -index_type!(Region); +index_type!(Origin); index_type!(Loan); index_type!(Point); index_type!(Variable); diff --git a/src/intern.rs b/src/intern.rs index 7ab4dc479c3..1fb0caa333d 100644 --- a/src/intern.rs +++ b/src/intern.rs @@ -41,7 +41,7 @@ where } pub(crate) struct InternerTables { - pub(crate) regions: Interner, + pub(crate) origins: Interner, pub(crate) loans: Interner, pub(crate) points: Interner, pub(crate) variables: Interner, @@ -51,7 +51,7 @@ pub(crate) struct InternerTables { impl InternerTables { pub(crate) fn new() -> Self { Self { - regions: Interner::new(), + origins: Interner::new(), loans: Interner::new(), points: Interner::new(), variables: Interner::new(), @@ -74,7 +74,7 @@ macro_rules! intern_impl { }; } -intern_impl!(Region, regions); +intern_impl!(Origin, origins); intern_impl!(Loan, loans); intern_impl!(Point, points); intern_impl!(Variable, variables); diff --git a/src/program.rs b/src/program.rs index c31dc516d55..311ee927e6a 100644 --- a/src/program.rs +++ b/src/program.rs @@ -7,23 +7,23 @@ use polonius_parser::{ parse_input, }; -use crate::facts::{AllFacts, Loan, MovePath, Point, Region, Variable}; +use crate::facts::{AllFacts, Loan, MovePath, Origin, Point, Variable}; use crate::intern::InternerTables; /// A structure to hold and deduplicate facts #[derive(Default)] struct Facts { - borrow_region: BTreeSet<(Region, Loan, Point)>, - universal_region: BTreeSet, + borrow_region: BTreeSet<(Origin, Loan, Point)>, + universal_region: BTreeSet, cfg_edge: BTreeSet<(Point, Point)>, killed: BTreeSet<(Loan, Point)>, - outlives: BTreeSet<(Region, Region, Point)>, + outlives: BTreeSet<(Origin, Origin, Point)>, invalidates: BTreeSet<(Point, Loan)>, var_defined: BTreeSet<(Variable, Point)>, var_used: BTreeSet<(Variable, Point)>, var_drop_used: BTreeSet<(Variable, Point)>, - var_uses_region: BTreeSet<(Variable, Region)>, - var_drops_region: BTreeSet<(Variable, Region)>, + var_uses_region: BTreeSet<(Variable, Origin)>, + var_drops_region: BTreeSet<(Variable, Origin)>, child: BTreeSet<(MovePath, MovePath)>, path_belongs_to_var: BTreeSet<(MovePath, Variable)>, initialized_at: BTreeSet<(MovePath, Point)>, @@ -63,29 +63,29 @@ pub(crate) fn parse_from_program( let mut facts: Facts = Default::default(); - // facts: universal_region(Region) + // facts: universal_region(Origin) facts.universal_region.extend( input .universal_regions .iter() - .map(|region| tables.regions.intern(region)), + .map(|origin| tables.origins.intern(origin)), ); facts .var_drops_region - .extend(input.var_drops_region.iter().map(|(variable, region)| { + .extend(input.var_drops_region.iter().map(|(variable, origin)| { ( tables.variables.intern(variable), - tables.regions.intern(region), + tables.origins.intern(origin), ) })); facts .var_uses_region - .extend(input.var_uses_region.iter().map(|(variable, region)| { + .extend(input.var_uses_region.iter().map(|(variable, origin)| { ( tables.variables.intern(variable), - tables.regions.intern(region), + tables.origins.intern(origin), ) })); @@ -169,23 +169,23 @@ pub(crate) fn parse_from_program( fn emit_fact(facts: &mut Facts, fact: &Fact, point: Point, tables: &mut InternerTables) { match fact { - // facts: borrow_region(Region, Loan, Point) + // facts: borrow_region(Origin, Loan, Point) Fact::BorrowRegionAt { - ref region, + ref origin, ref loan, } => { - // borrow_region: a `borrow_region_at` occurs on the Mid point - let region = tables.regions.intern(region); + // borrow_region: a `borrow_region` occurs on the Mid point + let origin = tables.origins.intern(origin); let loan = tables.loans.intern(loan); - facts.borrow_region.insert((region, loan, point)); + facts.borrow_region.insert((origin, loan, point)); } - // facts: outlives(Region, Region, Point) + // facts: outlives(Origin, Origin, Point) Fact::Outlives { ref a, ref b } => { // outlives: a `outlives` occurs on Mid points - let region_a = tables.regions.intern(a); - let region_b = tables.regions.intern(b); + let region_a = tables.origins.intern(a); + let region_b = tables.origins.intern(b); facts.outlives.insert((region_a, region_b, point)); } @@ -262,7 +262,7 @@ mod tests { let universal_regions: Vec<_> = facts .universal_region .iter() - .map(|r| tables.regions.untern(*r).to_string()) + .map(|r| tables.origins.untern(*r).to_string()) .collect(); assert_eq!(universal_regions, ["'a", "'b", "'c"]); @@ -288,8 +288,8 @@ mod tests { assert_eq!(facts.outlives.len(), 1); { - let region_a = tables.regions.untern(facts.outlives[0].0); - let region_b = tables.regions.untern(facts.outlives[0].1); + let region_a = tables.origins.untern(facts.outlives[0].0); + let region_b = tables.origins.untern(facts.outlives[0].1); let point = tables.points.untern(facts.outlives[0].2); assert_eq!(region_a, "'a"); @@ -299,11 +299,11 @@ mod tests { assert_eq!(facts.borrow_region.len(), 1); { - let region = tables.regions.untern(facts.borrow_region[0].0); + let origin = tables.origins.untern(facts.borrow_region[0].0); let loan = tables.loans.untern(facts.borrow_region[0].1); let point = tables.points.untern(facts.borrow_region[0].2); - assert_eq!(region, "'b"); + assert_eq!(origin, "'b"); assert_eq!(loan, "L1"); assert_eq!(point, "\"Mid(B1[0])\""); } diff --git a/src/test.rs b/src/test.rs index 63f23a42ced..7a7364d5084 100644 --- a/src/test.rs +++ b/src/test.rs @@ -162,7 +162,7 @@ fn no_subset_symmetries_exist() -> Result<(), Error> { // are extracted from rustc's test suite, and fail because of differences between the Naive // and DatafrogOpt variants, on the computation of the transitive closure. // They are part of the same pattern that the optimized variant misses, and only differ in -// the length of the `outlives` chain reaching a live region at a specific point. +// the length of the `outlives` chain reaching a live origin at a specific point. #[test] fn send_is_not_static_std_sync() { @@ -223,7 +223,7 @@ fn issue_31567() { #[test] fn borrowed_local_error() { - // This test is related to the previous 3: there is still a borrow_region outliving a live region, + // This test is related to the previous 3: there is still a borrow_region outliving a live origin, // through a chain of `outlives` at a single point, but this time there are also 2 points // and an edge.