diff --git a/src/Cargo.lock b/src/Cargo.lock index 0392466956e..ef545db1f29 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1424,6 +1424,11 @@ name = "pkg-config" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "polonius-engine" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "precomputed-hash" version = "0.1.1" @@ -1745,6 +1750,7 @@ dependencies = [ "jobserver 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "polonius-engine 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "proc_macro 0.0.0", "rustc_apfloat 0.0.0", "rustc_data_structures 0.0.0", @@ -2111,6 +2117,7 @@ dependencies = [ "graphviz 0.0.0", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "polonius-engine 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", "rustc_apfloat 0.0.0", "rustc_data_structures 0.0.0", @@ -3107,6 +3114,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6b07ffcc532ccc85e3afc45865469bf5d9e4ef5bfcf9622e3cfe80c2d275ec03" "checksum phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "07e24b0ca9643bdecd0632f2b3da6b1b89bbb0030e0b992afc1113b23a7bc2f2" "checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903" +"checksum polonius-engine 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6201ffe79e3da53bd065fbec2a9b391e5a0dc21038b39bb300612ddc658eb7ee" "checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" "checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6" "checksum proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "49b6a521dc81b643e9a51e0d1cf05df46d5a2f3c0280ea72bcb68276ba64a118" diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml index 8f9a8bd5c01..4223b49a5b4 100644 --- a/src/librustc/Cargo.toml +++ b/src/librustc/Cargo.toml @@ -16,6 +16,7 @@ graphviz = { path = "../libgraphviz" } jobserver = "0.1" lazy_static = "1.0.0" log = { version = "0.4", features = ["release_max_level_info", "std"] } +polonius-engine = "0.1.1" proc_macro = { path = "../libproc_macro" } rustc_apfloat = { path = "../librustc_apfloat" } rustc_target = { path = "../librustc_target" } diff --git a/src/librustc/lib.rs b/src/librustc/lib.rs index 1d53a305193..08e49ea94bf 100644 --- a/src/librustc/lib.rs +++ b/src/librustc/lib.rs @@ -80,6 +80,7 @@ extern crate graphviz; #[macro_use] extern crate lazy_static; #[cfg(windows)] extern crate libc; +extern crate polonius_engine; extern crate rustc_target; #[macro_use] extern crate rustc_data_structures; extern crate serialize; diff --git a/src/librustc/ty/sty.rs b/src/librustc/ty/sty.rs index faf93ab30b7..5980e19e699 100644 --- a/src/librustc/ty/sty.rs +++ b/src/librustc/ty/sty.rs @@ -14,6 +14,7 @@ use hir::def_id::DefId; use middle::const_val::ConstVal; use middle::region; +use polonius_engine::Atom; use rustc_data_structures::indexed_vec::Idx; use ty::subst::{Substs, Subst, Kind, UnpackedKind}; use ty::{self, AdtDef, TypeFlags, Ty, TyCtxt, TypeFoldable}; @@ -1169,6 +1170,24 @@ newtype_index!(RegionVid DEBUG_FORMAT = custom, }); +impl Atom for RegionVid { + fn index(self) -> usize { + Idx::index(self) + } +} + +impl From for RegionVid { + fn from(i: usize) -> RegionVid { + RegionVid::new(i) + } +} + +impl From for usize { + fn from(vid: RegionVid) -> usize { + Idx::index(vid) + } +} + #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] pub enum InferTy { TyVar(TyVid), diff --git a/src/librustc_mir/Cargo.toml b/src/librustc_mir/Cargo.toml index 62964745b6f..e88ff38ed7d 100644 --- a/src/librustc_mir/Cargo.toml +++ b/src/librustc_mir/Cargo.toml @@ -14,6 +14,7 @@ bitflags = "1.0" graphviz = { path = "../libgraphviz" } log = "0.4" log_settings = "0.1.1" +polonius-engine = "0.1.1" rustc = { path = "../librustc" } rustc_target = { path = "../librustc_target" } rustc_data_structures = { path = "../librustc_data_structures" } diff --git a/src/librustc_mir/borrow_check/nll/facts.rs b/src/librustc_mir/borrow_check/nll/facts.rs index 2b2aadba7f9..6cb8e64b9f5 100644 --- a/src/librustc_mir/borrow_check/nll/facts.rs +++ b/src/librustc_mir/borrow_check/nll/facts.rs @@ -10,41 +10,28 @@ use borrow_check::location::{LocationIndex, LocationTable}; use dataflow::indexes::BorrowIndex; +use polonius_engine::AllFacts as PoloniusAllFacts; +use polonius_engine::Atom; use rustc::ty::RegionVid; +use rustc_data_structures::indexed_vec::Idx; use std::error::Error; use std::fmt::Debug; use std::fs::{self, File}; use std::io::Write; use std::path::Path; -/// The "facts" which are the basis of the NLL borrow analysis. -#[derive(Default)] -crate 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 point *after* a borrow rvalue) - crate borrow_region: Vec<(RegionVid, BorrowIndex, LocationIndex)>, +crate type AllFacts = PoloniusAllFacts; - // universal_region(R) -- this is a "free region" within fn body - crate universal_region: Vec, - - // `cfg_edge(P,Q)` for each edge P -> Q in the control flow - crate cfg_edge: Vec<(LocationIndex, LocationIndex)>, - - // `killed(B,P)` when some prefix of the path borrowed at B is assigned at point P - crate killed: Vec<(BorrowIndex, LocationIndex)>, - - // `outlives(R1, R2, P)` when we require `R1@P: R2@P` - crate outlives: Vec<(RegionVid, RegionVid, LocationIndex)>, - - // `region_live_at(R, P)` when the region R appears in a live variable at P - crate region_live_at: Vec<(RegionVid, LocationIndex)>, - - // `invalidates(P, B)` when the borrow B is invalidated at point P - crate invalidates: Vec<(LocationIndex, BorrowIndex)>, +crate trait AllFactsExt { + fn write_to_dir( + &self, + dir: impl AsRef, + location_table: &LocationTable, + ) -> Result<(), Box>; } -impl AllFacts { - crate fn write_to_dir( +impl AllFactsExt for AllFacts { + fn write_to_dir( &self, dir: impl AsRef, location_table: &LocationTable, @@ -79,6 +66,42 @@ impl AllFacts { } } +impl Atom for BorrowIndex { + fn index(self) -> usize { + Idx::index(self) + } +} + +impl From for BorrowIndex { + fn from(i: usize) -> BorrowIndex { + BorrowIndex::new(i) + } +} + +impl From for usize { + fn from(vid: BorrowIndex) -> usize { + Idx::index(vid) + } +} + +impl Atom for LocationIndex { + fn index(self) -> usize { + Idx::index(self) + } +} + +impl From for LocationIndex { + fn from(i: usize) -> LocationIndex { + LocationIndex::new(i) + } +} + +impl From for usize { + fn from(vid: LocationIndex) -> usize { + Idx::index(vid) + } +} + struct FactWriter<'w> { location_table: &'w LocationTable, dir: &'w Path, diff --git a/src/librustc_mir/borrow_check/nll/mod.rs b/src/librustc_mir/borrow_check/nll/mod.rs index 04e23c6f041..a91789733a9 100644 --- a/src/librustc_mir/borrow_check/nll/mod.rs +++ b/src/librustc_mir/borrow_check/nll/mod.rs @@ -10,6 +10,7 @@ use borrow_check::borrow_set::BorrowSet; use borrow_check::location::LocationTable; +use borrow_check::nll::facts::AllFactsExt; use dataflow::move_paths::MoveData; use dataflow::FlowAtLocation; use dataflow::MaybeInitializedPlaces; diff --git a/src/librustc_mir/dataflow/move_paths/mod.rs b/src/librustc_mir/dataflow/move_paths/mod.rs index 3a49e28f041..610963af9e1 100644 --- a/src/librustc_mir/dataflow/move_paths/mod.rs +++ b/src/librustc_mir/dataflow/move_paths/mod.rs @@ -34,7 +34,7 @@ pub(crate) mod indexes { macro_rules! new_index { ($Index:ident, $debug_name:expr) => { - #[derive(Copy, Clone, PartialEq, Eq, Hash)] + #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct $Index(NonZeroUsize); impl Idx for $Index { diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index 3bf9453fb51..ace4709ba1d 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -39,6 +39,7 @@ extern crate arena; extern crate bitflags; #[macro_use] extern crate log; extern crate graphviz as dot; +extern crate polonius_engine; #[macro_use] extern crate rustc; #[macro_use] extern crate rustc_data_structures; diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 5739ec5f325..ab323843bf4 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -94,6 +94,7 @@ static WHITELIST: &'static [Crate] = &[ Crate("owning_ref"), Crate("parking_lot"), Crate("parking_lot_core"), + Crate("polonius-engine"), Crate("quick-error"), Crate("rand"), Crate("redox_syscall"),