Skip to content

Commit 8429d11

Browse files
committed
Use AllFacts from polonius-engine
1 parent 0746522 commit 8429d11

File tree

10 files changed

+82
-26
lines changed

10 files changed

+82
-26
lines changed

src/Cargo.lock

+8
Original file line numberDiff line numberDiff line change
@@ -1424,6 +1424,11 @@ name = "pkg-config"
14241424
version = "0.3.9"
14251425
source = "registry+https://github.com/rust-lang/crates.io-index"
14261426

1427+
[[package]]
1428+
name = "polonius-engine"
1429+
version = "0.1.1"
1430+
source = "registry+https://github.com/rust-lang/crates.io-index"
1431+
14271432
[[package]]
14281433
name = "precomputed-hash"
14291434
version = "0.1.1"
@@ -1745,6 +1750,7 @@ dependencies = [
17451750
"jobserver 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
17461751
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
17471752
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
1753+
"polonius-engine 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
17481754
"proc_macro 0.0.0",
17491755
"rustc_apfloat 0.0.0",
17501756
"rustc_data_structures 0.0.0",
@@ -2111,6 +2117,7 @@ dependencies = [
21112117
"graphviz 0.0.0",
21122118
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
21132119
"log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
2120+
"polonius-engine 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
21142121
"rustc 0.0.0",
21152122
"rustc_apfloat 0.0.0",
21162123
"rustc_data_structures 0.0.0",
@@ -3107,6 +3114,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
31073114
"checksum phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6b07ffcc532ccc85e3afc45865469bf5d9e4ef5bfcf9622e3cfe80c2d275ec03"
31083115
"checksum phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "07e24b0ca9643bdecd0632f2b3da6b1b89bbb0030e0b992afc1113b23a7bc2f2"
31093116
"checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903"
3117+
"checksum polonius-engine 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6201ffe79e3da53bd065fbec2a9b391e5a0dc21038b39bb300612ddc658eb7ee"
31103118
"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
31113119
"checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6"
31123120
"checksum proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "49b6a521dc81b643e9a51e0d1cf05df46d5a2f3c0280ea72bcb68276ba64a118"

src/librustc/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ graphviz = { path = "../libgraphviz" }
1616
jobserver = "0.1"
1717
lazy_static = "1.0.0"
1818
log = { version = "0.4", features = ["release_max_level_info", "std"] }
19+
polonius-engine = "0.1.1"
1920
proc_macro = { path = "../libproc_macro" }
2021
rustc_apfloat = { path = "../librustc_apfloat" }
2122
rustc_target = { path = "../librustc_target" }

src/librustc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ extern crate graphviz;
8080
#[macro_use] extern crate lazy_static;
8181
#[cfg(windows)]
8282
extern crate libc;
83+
extern crate polonius_engine;
8384
extern crate rustc_target;
8485
#[macro_use] extern crate rustc_data_structures;
8586
extern crate serialize;

src/librustc/ty/sty.rs

+19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use hir::def_id::DefId;
1414

1515
use middle::const_val::ConstVal;
1616
use middle::region;
17+
use polonius_engine::Atom;
1718
use rustc_data_structures::indexed_vec::Idx;
1819
use ty::subst::{Substs, Subst, Kind, UnpackedKind};
1920
use ty::{self, AdtDef, TypeFlags, Ty, TyCtxt, TypeFoldable};
@@ -1169,6 +1170,24 @@ newtype_index!(RegionVid
11691170
DEBUG_FORMAT = custom,
11701171
});
11711172

1173+
impl Atom for RegionVid {
1174+
fn index(self) -> usize {
1175+
Idx::index(self)
1176+
}
1177+
}
1178+
1179+
impl From<usize> for RegionVid {
1180+
fn from(i: usize) -> RegionVid {
1181+
RegionVid::new(i)
1182+
}
1183+
}
1184+
1185+
impl From<RegionVid> for usize {
1186+
fn from(vid: RegionVid) -> usize {
1187+
Idx::index(vid)
1188+
}
1189+
}
1190+
11721191
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
11731192
pub enum InferTy {
11741193
TyVar(TyVid),

src/librustc_mir/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ bitflags = "1.0"
1414
graphviz = { path = "../libgraphviz" }
1515
log = "0.4"
1616
log_settings = "0.1.1"
17+
polonius-engine = "0.1.1"
1718
rustc = { path = "../librustc" }
1819
rustc_target = { path = "../librustc_target" }
1920
rustc_data_structures = { path = "../librustc_data_structures" }

src/librustc_mir/borrow_check/nll/facts.rs

+48-25
Original file line numberDiff line numberDiff line change
@@ -10,41 +10,28 @@
1010

1111
use borrow_check::location::{LocationIndex, LocationTable};
1212
use dataflow::indexes::BorrowIndex;
13+
use polonius_engine::AllFacts as PoloniusAllFacts;
14+
use polonius_engine::Atom;
1315
use rustc::ty::RegionVid;
16+
use rustc_data_structures::indexed_vec::Idx;
1417
use std::error::Error;
1518
use std::fmt::Debug;
1619
use std::fs::{self, File};
1720
use std::io::Write;
1821
use std::path::Path;
1922

20-
/// The "facts" which are the basis of the NLL borrow analysis.
21-
#[derive(Default)]
22-
crate struct AllFacts {
23-
// `borrow_region(R, B, P)` -- the region R may refer to data from borrow B
24-
// starting at the point P (this is usually the point *after* a borrow rvalue)
25-
crate borrow_region: Vec<(RegionVid, BorrowIndex, LocationIndex)>,
23+
crate type AllFacts = PoloniusAllFacts<RegionVid, BorrowIndex, LocationIndex>;
2624

27-
// universal_region(R) -- this is a "free region" within fn body
28-
crate universal_region: Vec<RegionVid>,
29-
30-
// `cfg_edge(P,Q)` for each edge P -> Q in the control flow
31-
crate cfg_edge: Vec<(LocationIndex, LocationIndex)>,
32-
33-
// `killed(B,P)` when some prefix of the path borrowed at B is assigned at point P
34-
crate killed: Vec<(BorrowIndex, LocationIndex)>,
35-
36-
// `outlives(R1, R2, P)` when we require `R1@P: R2@P`
37-
crate outlives: Vec<(RegionVid, RegionVid, LocationIndex)>,
38-
39-
// `region_live_at(R, P)` when the region R appears in a live variable at P
40-
crate region_live_at: Vec<(RegionVid, LocationIndex)>,
41-
42-
// `invalidates(P, B)` when the borrow B is invalidated at point P
43-
crate invalidates: Vec<(LocationIndex, BorrowIndex)>,
25+
crate trait AllFactsExt {
26+
fn write_to_dir(
27+
&self,
28+
dir: impl AsRef<Path>,
29+
location_table: &LocationTable,
30+
) -> Result<(), Box<dyn Error>>;
4431
}
4532

46-
impl AllFacts {
47-
crate fn write_to_dir(
33+
impl AllFactsExt for AllFacts {
34+
fn write_to_dir(
4835
&self,
4936
dir: impl AsRef<Path>,
5037
location_table: &LocationTable,
@@ -79,6 +66,42 @@ impl AllFacts {
7966
}
8067
}
8168

69+
impl Atom for BorrowIndex {
70+
fn index(self) -> usize {
71+
Idx::index(self)
72+
}
73+
}
74+
75+
impl From<usize> for BorrowIndex {
76+
fn from(i: usize) -> BorrowIndex {
77+
BorrowIndex::new(i)
78+
}
79+
}
80+
81+
impl From<BorrowIndex> for usize {
82+
fn from(vid: BorrowIndex) -> usize {
83+
Idx::index(vid)
84+
}
85+
}
86+
87+
impl Atom for LocationIndex {
88+
fn index(self) -> usize {
89+
Idx::index(self)
90+
}
91+
}
92+
93+
impl From<usize> for LocationIndex {
94+
fn from(i: usize) -> LocationIndex {
95+
LocationIndex::new(i)
96+
}
97+
}
98+
99+
impl From<LocationIndex> for usize {
100+
fn from(vid: LocationIndex) -> usize {
101+
Idx::index(vid)
102+
}
103+
}
104+
82105
struct FactWriter<'w> {
83106
location_table: &'w LocationTable,
84107
dir: &'w Path,

src/librustc_mir/borrow_check/nll/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use borrow_check::borrow_set::BorrowSet;
1212
use borrow_check::location::LocationTable;
13+
use borrow_check::nll::facts::AllFactsExt;
1314
use dataflow::move_paths::MoveData;
1415
use dataflow::FlowAtLocation;
1516
use dataflow::MaybeInitializedPlaces;

src/librustc_mir/dataflow/move_paths/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ pub(crate) mod indexes {
3434

3535
macro_rules! new_index {
3636
($Index:ident, $debug_name:expr) => {
37-
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
37+
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
3838
pub struct $Index(NonZeroUsize);
3939

4040
impl Idx for $Index {

src/librustc_mir/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ extern crate arena;
3939
extern crate bitflags;
4040
#[macro_use] extern crate log;
4141
extern crate graphviz as dot;
42+
extern crate polonius_engine;
4243
#[macro_use]
4344
extern crate rustc;
4445
#[macro_use] extern crate rustc_data_structures;

src/tools/tidy/src/deps.rs

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ static WHITELIST: &'static [Crate] = &[
9494
Crate("owning_ref"),
9595
Crate("parking_lot"),
9696
Crate("parking_lot_core"),
97+
Crate("polonius-engine"),
9798
Crate("quick-error"),
9899
Crate("rand"),
99100
Crate("redox_syscall"),

0 commit comments

Comments
 (0)