Use AllFacts from polonius-engine

This commit is contained in:
Santiago Pastorino 2018-05-24 18:52:01 -03:00
parent 07465222ca
commit 8429d11a0b
No known key found for this signature in database
GPG Key ID: 88C941CDA1D46432
10 changed files with 82 additions and 26 deletions

View File

@ -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"

View File

@ -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" }

View File

@ -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;

View File

@ -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<usize> for RegionVid {
fn from(i: usize) -> RegionVid {
RegionVid::new(i)
}
}
impl From<RegionVid> 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),

View File

@ -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" }

View File

@ -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<RegionVid, BorrowIndex, LocationIndex>;
// universal_region(R) -- this is a "free region" within fn body
crate universal_region: Vec<RegionVid>,
// `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<Path>,
location_table: &LocationTable,
) -> Result<(), Box<dyn Error>>;
}
impl AllFacts {
crate fn write_to_dir(
impl AllFactsExt for AllFacts {
fn write_to_dir(
&self,
dir: impl AsRef<Path>,
location_table: &LocationTable,
@ -79,6 +66,42 @@ impl AllFacts {
}
}
impl Atom for BorrowIndex {
fn index(self) -> usize {
Idx::index(self)
}
}
impl From<usize> for BorrowIndex {
fn from(i: usize) -> BorrowIndex {
BorrowIndex::new(i)
}
}
impl From<BorrowIndex> for usize {
fn from(vid: BorrowIndex) -> usize {
Idx::index(vid)
}
}
impl Atom for LocationIndex {
fn index(self) -> usize {
Idx::index(self)
}
}
impl From<usize> for LocationIndex {
fn from(i: usize) -> LocationIndex {
LocationIndex::new(i)
}
}
impl From<LocationIndex> for usize {
fn from(vid: LocationIndex) -> usize {
Idx::index(vid)
}
}
struct FactWriter<'w> {
location_table: &'w LocationTable,
dir: &'w Path,

View File

@ -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;

View File

@ -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 {

View File

@ -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;

View File

@ -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"),