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

adopt datafrog 2.0 #95

Merged
merged 1 commit into from
Dec 27, 2018
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion polonius-engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
64 changes: 27 additions & 37 deletions polonius-engine/src/output/datafrog_opt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(
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();

Expand All @@ -55,7 +55,7 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(

// 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
Expand Down Expand Up @@ -144,25 +144,15 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(
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() {
Expand All @@ -187,11 +177,11 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(
// !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),
);

Expand All @@ -202,11 +192,11 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(
// !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),
);

Expand Down Expand Up @@ -268,11 +258,11 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(
// `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),
);

Expand Down Expand Up @@ -307,11 +297,11 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(
// 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),
);

Expand Down
18 changes: 7 additions & 11 deletions polonius-engine/src/output/location_insensitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(

// 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");
Expand All @@ -57,14 +57,10 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(
// 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() {
Expand All @@ -82,10 +78,10 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(
//
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),
);
}
Expand Down
30 changes: 13 additions & 17 deletions polonius-engine/src/output/naive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,16 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(
// 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");

// 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() {
Expand Down Expand Up @@ -120,11 +116,11 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(
// 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),
);

Expand All @@ -143,11 +139,11 @@ pub(super) fn compute<Region: Atom, Loan: Atom, Point: Atom>(
// 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),
);

Expand Down