From 73beb62a8efbc039068613fd93726a38a581d76d Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 27 Dec 2018 11:14:20 -0500 Subject: [PATCH] adopt datafrog 2.0 --- Cargo.lock | 8 +-- Cargo.toml | 2 +- polonius-engine/Cargo.toml | 2 +- polonius-engine/src/output/datafrog_opt.rs | 64 ++++++++----------- .../src/output/location_insensitive.rs | 18 ++---- polonius-engine/src/output/naive.rs | 30 ++++----- 6 files changed, 53 insertions(+), 71 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 79c10f89c38..2f16fde75b5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -155,7 +155,7 @@ dependencies = [ [[package]] name = "datafrog" -version = "1.0.0" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -415,7 +415,7 @@ version = "0.3.0" dependencies = [ "assert_cli 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", - "datafrog 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "datafrog 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -430,7 +430,7 @@ dependencies = [ name = "polonius-engine" version = "0.6.1" dependencies = [ - "datafrog 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "datafrog 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -826,7 +826,7 @@ dependencies = [ "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum colored 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc0a60679001b62fb628c4da80e574b9645ab4646056d7c9018885efffe45533" -"checksum datafrog 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71a3eacc779bb35090718501c2de27bb679dee18f6c28e6589590e4ed8b9fa08" +"checksum datafrog 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "77ba99c0ba9573918469fac8d6ec440cf6620af901c940e00003edf1b7caa32c" "checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" diff --git a/Cargo.toml b/Cargo.toml index 8a2b136dbd8..d39e7d2c870 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,7 +16,7 @@ diff = "0.1.0" [dependencies] log = "0.4" env_logger = "0.5" -datafrog = "1.0.0" +datafrog = "2.0.0" failure = "0.1.1" rustc-hash = "1.0.0" structopt = "0.2.8" diff --git a/polonius-engine/Cargo.toml b/polonius-engine/Cargo.toml index 0789e22ad7f..996b91cf632 100644 --- a/polonius-engine/Cargo.toml +++ b/polonius-engine/Cargo.toml @@ -9,6 +9,6 @@ readme = "README.md" keywords = ["compiler", "borrowck", "datalog"] [dependencies] -datafrog = "1.0.0" +datafrog = "2.0.0" rustc-hash = "1.0.0" log = "0.4" diff --git a/polonius-engine/src/output/datafrog_opt.rs b/polonius-engine/src/output/datafrog_opt.rs index 0837af2c09b..68e9f8a2024 100644 --- a/polonius-engine/src/output/datafrog_opt.rs +++ b/polonius-engine/src/output/datafrog_opt.rs @@ -46,7 +46,7 @@ pub(super) fn compute( let mut iteration = Iteration::new(); // static inputs - let cfg_edge_rel = Relation::from(all_facts.cfg_edge.iter().map(|&(p, q)| (p, q))); + let cfg_edge_rel = Relation::from_iter(all_facts.cfg_edge.iter().map(|&(p, q)| (p, q))); let killed_rel: Relation<(Loan, Point)> = all_facts.killed.into(); @@ -55,7 +55,7 @@ pub(super) fn compute( // we need `region_live_at` in both variable and relation forms. // (respectively, for join and antijoin). - let region_live_at_rel = Relation::from(all_facts.region_live_at.iter().cloned()); + let region_live_at_rel = Relation::from_iter(all_facts.region_live_at.iter().cloned()); let region_live_at_var = iteration.variable::<((Region, Point), ())>("region_live_at"); // `borrow_region` input but organized for join @@ -144,25 +144,15 @@ pub(super) fn compute( let errors = iteration.variable("errors"); // Make "variable" versions of the relations, needed for joins. - borrow_region_rp.insert(Relation::from( - all_facts.borrow_region.iter().map(|&(r, b, p)| ((r, p), b)), - )); - invalidates.insert(Relation::from( - all_facts.invalidates.iter().map(|&(p, b)| ((b, p), ())), - )); - region_live_at_var.insert(Relation::from( - all_facts.region_live_at.iter().map(|&(r, p)| ((r, p), ())), - )); + borrow_region_rp.extend(all_facts.borrow_region.iter().map(|&(r, b, p)| ((r, p), b))); + invalidates.extend(all_facts.invalidates.iter().map(|&(p, b)| ((b, p), ()))); + region_live_at_var.extend(all_facts.region_live_at.iter().map(|&(r, p)| ((r, p), ()))); // subset(R1, R2, P) :- outlives(R1, R2, P). - subset_r1p.insert(Relation::from( - all_facts.outlives.iter().map(|&(r1, r2, p)| ((r1, p), r2)), - )); + subset_r1p.extend(all_facts.outlives.iter().map(|&(r1, r2, p)| ((r1, p), r2))); // requires(R, B, P) :- borrow_region(R, B, P). - requires_rp.insert(Relation::from( - all_facts.borrow_region.iter().map(|&(r, b, p)| ((r, p), b)), - )); + requires_rp.extend(all_facts.borrow_region.iter().map(|&(r, b, p)| ((r, p), b))); // .. and then start iterating rules! while iteration.changed() { @@ -187,11 +177,11 @@ pub(super) fn compute( // !region_live_at(R2, Q). live_to_dying_regions_r2pq.from_leapjoin( &subset_r1p, - &mut [ - &mut cfg_edge_rel.extend_with(|&((_, p), _)| p), - &mut region_live_at_rel.extend_with(|&((r1, _), _)| r1), - &mut region_live_at_rel.extend_anti(|&((_, _), r2)| r2), - ], + ( + cfg_edge_rel.extend_with(|&((_, p), _)| p), + region_live_at_rel.extend_with(|&((r1, _), _)| r1), + region_live_at_rel.extend_anti(|&((_, _), r2)| r2), + ), |&((r1, p), r2), &q| ((r2, p, q), r1), ); @@ -202,11 +192,11 @@ pub(super) fn compute( // !region_live_at(R, Q). dying_region_requires.from_leapjoin( &requires_rp, - &mut [ - &mut killed_rel.filter_anti(|&((_, p), b)| (b, p)), - &mut cfg_edge_rel.extend_with(|&((_, p), _)| p), - &mut region_live_at_rel.extend_anti(|&((r, _), _)| r), - ], + ( + killed_rel.filter_anti(|&((_, p), b)| (b, p)), + cfg_edge_rel.extend_with(|&((_, p), _)| p), + region_live_at_rel.extend_anti(|&((r, _), _)| r), + ), |&((r, p), b), &q| ((r, p, q), b), ); @@ -268,11 +258,11 @@ pub(super) fn compute( // `R2` are live in Q. subset_r1p.from_leapjoin( &subset_r1p, - &mut [ - &mut cfg_edge_rel.extend_with(|&((_, p), _)| p), - &mut region_live_at_rel.extend_with(|&((r1, _), _)| r1), - &mut region_live_at_rel.extend_with(|&((_, _), r2)| r2), - ], + ( + cfg_edge_rel.extend_with(|&((_, p), _)| p), + region_live_at_rel.extend_with(|&((r1, _), _)| r1), + region_live_at_rel.extend_with(|&((_, _), r2)| r2), + ), |&((r1, _p), r2), &q| ((r1, q), r2), ); @@ -307,11 +297,11 @@ pub(super) fn compute( // region_live_at(R, Q). requires_rp.from_leapjoin( &requires_rp, - &mut [ - &mut killed_rel.filter_anti(|&((_, p), b)| (b, p)), - &mut cfg_edge_rel.extend_with(|&((_, p), _)| p), - &mut region_live_at_rel.extend_with(|&((r, _), _)| r), - ], + ( + killed_rel.filter_anti(|&((_, p), b)| (b, p)), + cfg_edge_rel.extend_with(|&((_, p), _)| p), + region_live_at_rel.extend_with(|&((r, _), _)| r), + ), |&((r, _), b), &q| ((r, q), b), ); diff --git a/polonius-engine/src/output/location_insensitive.rs b/polonius-engine/src/output/location_insensitive.rs index efeb0e2da11..40f0bda9f03 100644 --- a/polonius-engine/src/output/location_insensitive.rs +++ b/polonius-engine/src/output/location_insensitive.rs @@ -46,7 +46,7 @@ pub(super) fn compute( // static inputs let region_live_at: Relation<(Region, Point)> = all_facts.region_live_at.into(); - let invalidates = Relation::from(all_facts.invalidates.iter().map(|&(b, p)| (p, b))); + let invalidates = Relation::from_iter(all_facts.invalidates.iter().map(|&(b, p)| (p, b))); // .. some variables, .. let subset = iteration.variable::<(Region, Region)>("subset"); @@ -57,14 +57,10 @@ pub(super) fn compute( // load initial facts. // subset(R1, R2) :- outlives(R1, R2, _P) - subset.insert(Relation::from( - all_facts.outlives.iter().map(|&(r1, r2, _p)| (r1, r2)), - )); + subset.extend(all_facts.outlives.iter().map(|&(r1, r2, _p)| (r1, r2))); // requires(R, B) :- borrow_region(R, B, _P). - requires.insert(Relation::from( - all_facts.borrow_region.iter().map(|&(r, b, _p)| (r, b)), - )); + requires.extend(all_facts.borrow_region.iter().map(|&(r, b, _p)| (r, b))); // .. and then start iterating rules! while iteration.changed() { @@ -82,10 +78,10 @@ pub(super) fn compute( // potential_errors.from_leapjoin( &requires, - &mut [ - &mut region_live_at.extend_with(|&(r, _b)| r), - &mut invalidates.extend_with(|&(_r, b)| b), - ], + ( + region_live_at.extend_with(|&(r, _b)| r), + invalidates.extend_with(|&(_r, b)| b), + ), |&(_r, b), &p| (b, p), ); } diff --git a/polonius-engine/src/output/naive.rs b/polonius-engine/src/output/naive.rs index f0fee53fc78..ccc09d3bd19 100644 --- a/polonius-engine/src/output/naive.rs +++ b/polonius-engine/src/output/naive.rs @@ -68,7 +68,7 @@ pub(super) fn compute( // we need `region_live_at` in both variable and relation forms. // (respectively, for the regular join and the leapjoin). let region_live_at_var = iteration.variable::<((Region, Point), ())>("region_live_at"); - let region_live_at_rel = Relation::from(all_facts.region_live_at.iter().cloned()); + let region_live_at_rel = Relation::from_iter(all_facts.region_live_at.iter().cloned()); // output let errors = iteration.variable("errors"); @@ -76,12 +76,8 @@ pub(super) fn compute( // load initial facts. subset.insert(all_facts.outlives.into()); requires.insert(all_facts.borrow_region.into()); - invalidates.insert(Relation::from( - all_facts.invalidates.iter().map(|&(p, b)| ((b, p), ())), - )); - region_live_at_var.insert(Relation::from( - all_facts.region_live_at.iter().map(|&(r, p)| ((r, p), ())), - )); + invalidates.extend(all_facts.invalidates.iter().map(|&(p, b)| ((b, p), ()))); + region_live_at_var.extend(all_facts.region_live_at.iter().map(|&(r, p)| ((r, p), ()))); // .. and then start iterating rules! while iteration.changed() { @@ -120,11 +116,11 @@ pub(super) fn compute( // region_live_at(R2, Q). subset.from_leapjoin( &subset, - &mut [ - &mut cfg_edge_rel.extend_with(|&(_r1, _r2, p)| p), - &mut region_live_at_rel.extend_with(|&(r1, _r2, _p)| r1), - &mut region_live_at_rel.extend_with(|&(_r1, r2, _p)| r2), - ], + ( + cfg_edge_rel.extend_with(|&(_r1, _r2, p)| p), + region_live_at_rel.extend_with(|&(r1, _r2, _p)| r1), + region_live_at_rel.extend_with(|&(_r1, r2, _p)| r2), + ), |&(r1, r2, _p), &q| (r1, r2, q), ); @@ -143,11 +139,11 @@ pub(super) fn compute( // region_live_at(R, Q). requires.from_leapjoin( &requires, - &mut [ - &mut killed_rel.filter_anti(|&(_r, b, p)| (b, p)), - &mut cfg_edge_rel.extend_with(|&(_r, _b, p)| p), - &mut region_live_at_rel.extend_with(|&(r, _b, _p)| r), - ], + ( + killed_rel.filter_anti(|&(_r, b, p)| (b, p)), + cfg_edge_rel.extend_with(|&(_r, _b, p)| p), + region_live_at_rel.extend_with(|&(r, _b, _p)| r), + ), |&(r, b, _p), &q| (r, b, q), );