From 422fe7c8e80fdf56722396a0e5048654f99e5909 Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Tue, 29 May 2018 08:52:51 -0300 Subject: [PATCH 1/9] bump polonius engine --- src/Cargo.lock | 18 ++++++++++++++---- src/librustc/Cargo.toml | 2 +- src/librustc_mir/Cargo.toml | 2 +- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 7dce201505a..413ae2db2c8 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -557,6 +557,11 @@ dependencies = [ "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "datafrog" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "debug_unreachable" version = "0.1.1" @@ -1450,8 +1455,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "polonius-engine" -version = "0.1.1" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "datafrog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hash 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "precomputed-hash" @@ -1775,7 +1784,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)", + "polonius-engine 0.2.0 (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", @@ -2162,7 +2171,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)", + "polonius-engine 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", "rustc_apfloat 0.0.0", "rustc_data_structures 0.0.0", @@ -3069,6 +3078,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09de9ee0fc255ace04c7fa0763c9395a945c37c8292bb554f8d48361d1dcf1b4" "checksum curl 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "aaf20bbe084f285f215eef2165feed70d6b75ba29cad24469badb853a4a287d0" "checksum curl-sys 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "71c63a540a9ee4e15e56c3ed9b11a2f121239b9f6d7b7fe30f616e048148df9a" +"checksum datafrog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16d724bf4ffe77cdceeecd461009b5f8d9e23c5d645d68bedb4586bf43e7e142" "checksum debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9a032eac705ca39214d169f83e3d3da290af06d8d1d344d1baad2fd002dca4b3" "checksum derive-new 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ceed73957c449214f8440eec8ad7fa282b67dc9eacbb24a3085b15d60397a17a" "checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a" @@ -3162,7 +3172,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 polonius-engine 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "89be86c0ed0f63715d74d390b1a1a3df63cfca80b6eab604d7c4fecb5403cfdd" "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 83cf4469f4d..535fb2fcc3d 100644 --- a/src/librustc/Cargo.toml +++ b/src/librustc/Cargo.toml @@ -16,7 +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" +polonius-engine = "0.2.0" proc_macro = { path = "../libproc_macro" } rustc_apfloat = { path = "../librustc_apfloat" } rustc_target = { path = "../librustc_target" } diff --git a/src/librustc_mir/Cargo.toml b/src/librustc_mir/Cargo.toml index e88ff38ed7d..c2cfd3a827d 100644 --- a/src/librustc_mir/Cargo.toml +++ b/src/librustc_mir/Cargo.toml @@ -14,7 +14,7 @@ bitflags = "1.0" graphviz = { path = "../libgraphviz" } log = "0.4" log_settings = "0.1.1" -polonius-engine = "0.1.1" +polonius-engine = "0.2.0" rustc = { path = "../librustc" } rustc_target = { path = "../librustc_target" } rustc_data_structures = { path = "../librustc_data_structures" } From 4f88283869c6f1c69ed4fd56d2e9a1b065401cd4 Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Fri, 25 May 2018 22:17:04 +0000 Subject: [PATCH 2/9] expose -Zpolonius flag --- src/librustc/session/config.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index b3f1b9c8e62..755b4af1a3a 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1296,6 +1296,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "dump facts from NLL analysis into side files"), disable_nll_user_type_assert: bool = (false, parse_bool, [UNTRACKED], "disable user provided type assertion in NLL"), + polonius: bool = (false, parse_bool, [UNTRACKED], + "enable polonius-based borrow-checker"), codegen_time_graph: bool = (false, parse_bool, [UNTRACKED], "generate a graphical HTML report of time spent in codegen and LLVM"), thinlto: Option = (None, parse_opt_bool, [TRACKED], From b45aebfdf6d37599bd3771a2ba8b0b429acde005 Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Fri, 25 May 2018 23:07:33 +0000 Subject: [PATCH 3/9] it compiles, but we do not use the output yet --- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/borrow_check/nll/mod.rs | 30 +++++++++++++++++------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index ffa6fc9daec..397cf1680e0 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -198,7 +198,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( let borrow_set = Rc::new(BorrowSet::build(tcx, mir)); // If we are in non-lexical mode, compute the non-lexical lifetimes. - let (regioncx, opt_closure_req) = nll::compute_regions( + let (regioncx, _polonius_output, opt_closure_req) = nll::compute_regions( infcx, def_id, free_regions, diff --git a/src/librustc_mir/borrow_check/nll/mod.rs b/src/librustc_mir/borrow_check/nll/mod.rs index a91789733a9..ebc2800d204 100644 --- a/src/librustc_mir/borrow_check/nll/mod.rs +++ b/src/librustc_mir/borrow_check/nll/mod.rs @@ -9,11 +9,12 @@ // except according to those terms. use borrow_check::borrow_set::BorrowSet; -use borrow_check::location::LocationTable; +use borrow_check::location::{LocationIndex, LocationTable}; use borrow_check::nll::facts::AllFactsExt; use dataflow::move_paths::MoveData; use dataflow::FlowAtLocation; use dataflow::MaybeInitializedPlaces; +use dataflow::indexes::BorrowIndex; use rustc::hir::def_id::DefId; use rustc::infer::InferCtxt; use rustc::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, Mir}; @@ -22,6 +23,7 @@ use rustc::util::nodemap::FxHashMap; use std::collections::BTreeSet; use std::fmt::Debug; use std::io; +use std::rc::Rc; use std::path::PathBuf; use transform::MirSource; use util::liveness::{LivenessResults, LocalSet}; @@ -29,6 +31,7 @@ use util::liveness::{LivenessResults, LocalSet}; use self::mir_util::PassWhere; use util as mir_util; use util::pretty::{self, ALIGN}; +use polonius_engine::{Algorithm, Output}; mod constraint_generation; pub mod explain_borrow; @@ -83,6 +86,7 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>( borrow_set: &BorrowSet<'tcx>, ) -> ( RegionInferenceContext<'tcx>, + Option>>, Option>, ) { // Run the MIR type-checker. @@ -98,7 +102,9 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>( move_data, ); - let mut all_facts = if infcx.tcx.sess.opts.debugging_opts.nll_facts { + let mut all_facts = if infcx.tcx.sess.opts.debugging_opts.nll_facts + || infcx.tcx.sess.opts.debugging_opts.polonius + { Some(AllFacts::default()) } else { None @@ -142,11 +148,19 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>( ); // Dump facts if requested. - if let Some(all_facts) = all_facts { - let def_path = infcx.tcx.hir.def_path(def_id); - let dir_path = PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate()); - all_facts.write_to_dir(dir_path, location_table).unwrap(); - } + let polonius_output = all_facts.and_then(|all_facts| { + if infcx.tcx.sess.opts.debugging_opts.nll_facts { + let def_path = infcx.tcx.hir.def_path(def_id); + let dir_path = PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate()); + all_facts.write_to_dir(dir_path, location_table).unwrap(); + } + + if infcx.tcx.sess.opts.debugging_opts.polonius { + Some(Rc::new(Output::compute(&all_facts, Algorithm::DatafrogOpt, false))) + } else { + None + } + }); // Solve the region constraints. let closure_region_requirements = regioncx.solve(infcx, &mir, def_id); @@ -166,7 +180,7 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>( // information dump_annotation(infcx, &mir, def_id, ®ioncx, &closure_region_requirements); - (regioncx, closure_region_requirements) + (regioncx, polonius_output, closure_region_requirements) } fn dump_mir_results<'a, 'gcx, 'tcx>( From 2cd09f27b835d4342ce6f87eaf250eceb2718db8 Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Sat, 26 May 2018 01:14:45 +0000 Subject: [PATCH 4/9] store polonius output in MirBorrowCtx --- src/librustc_mir/borrow_check/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 397cf1680e0..e2d696e9b0f 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -11,11 +11,12 @@ //! This query borrow-checks the MIR to (further) ensure it is not broken. use borrow_check::nll::region_infer::RegionInferenceContext; +use borrow_check::location::LocationIndex; use rustc::hir; use rustc::hir::def_id::DefId; use rustc::hir::map::definitions::DefPathData; use rustc::infer::InferCtxt; -use rustc::ty::{self, ParamEnv, TyCtxt}; +use rustc::ty::{self, ParamEnv, RegionVid, TyCtxt}; use rustc::ty::maps::Providers; use rustc::lint::builtin::UNUSED_MUT; use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind}; @@ -45,6 +46,7 @@ use dataflow::move_paths::{IllegalMoveOriginKind, MoveError}; use dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MovePathIndex}; use util::borrowck_errors::{BorrowckErrors, Origin}; use util::collect_writes::FindAssignments; +use polonius_engine::Output; use self::borrow_set::{BorrowSet, BorrowData}; use self::flows::Flows; @@ -198,7 +200,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( let borrow_set = Rc::new(BorrowSet::build(tcx, mir)); // If we are in non-lexical mode, compute the non-lexical lifetimes. - let (regioncx, _polonius_output, opt_closure_req) = nll::compute_regions( + let (regioncx, polonius_output, opt_closure_req) = nll::compute_regions( infcx, def_id, free_regions, @@ -251,6 +253,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( used_mut_upvars: SmallVec::new(), borrow_set, dominators, + polonius_output, }; let mut state = Flows::new( @@ -373,6 +376,9 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> { /// Dominators for MIR dominators: Dominators, + + /// Polonius Output + polonius_output: Option>>, } // Check that: From db39ec8f9acc5b1c597c6c3de4f3515c760ce06f Mon Sep 17 00:00:00 2001 From: Douglas Campos Date: Sat, 26 May 2018 01:38:50 +0000 Subject: [PATCH 5/9] store output in FlowState --- src/librustc_mir/borrow_check/flows.rs | 11 +++++++++++ src/librustc_mir/borrow_check/mod.rs | 9 ++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/librustc_mir/borrow_check/flows.rs b/src/librustc_mir/borrow_check/flows.rs index 070dc1d09bf..61915646d6f 100644 --- a/src/librustc_mir/borrow_check/flows.rs +++ b/src/librustc_mir/borrow_check/flows.rs @@ -14,8 +14,13 @@ //! but is not as ugly as it is right now. use rustc::mir::{BasicBlock, Location}; +use rustc::ty::RegionVid; use rustc_data_structures::indexed_set::Iter; +use borrow_check::location::LocationIndex; + +use polonius_engine::Output; + use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; use dataflow::{EverInitializedPlaces, MovingOutStatements}; use dataflow::{Borrows}; @@ -23,6 +28,7 @@ use dataflow::{FlowAtLocation, FlowsAtLocation}; use dataflow::move_paths::HasMoveData; use dataflow::move_paths::indexes::BorrowIndex; use std::fmt; +use std::rc::Rc; // (forced to be `pub` due to its use as an associated type below.) crate struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> { @@ -31,6 +37,9 @@ crate struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> { pub uninits: FlowAtLocation>, pub move_outs: FlowAtLocation>, pub ever_inits: FlowAtLocation>, + + /// Polonius Output + pub polonius_output: Option>>, } impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> { @@ -40,6 +49,7 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> { uninits: FlowAtLocation>, move_outs: FlowAtLocation>, ever_inits: FlowAtLocation>, + polonius_output: Option>>, ) -> Self { Flows { borrows, @@ -47,6 +57,7 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> { uninits, move_outs, ever_inits, + polonius_output, } } diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index e2d696e9b0f..983a2ac2ec1 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -11,12 +11,11 @@ //! This query borrow-checks the MIR to (further) ensure it is not broken. use borrow_check::nll::region_infer::RegionInferenceContext; -use borrow_check::location::LocationIndex; use rustc::hir; use rustc::hir::def_id::DefId; use rustc::hir::map::definitions::DefPathData; use rustc::infer::InferCtxt; -use rustc::ty::{self, ParamEnv, RegionVid, TyCtxt}; +use rustc::ty::{self, ParamEnv, TyCtxt}; use rustc::ty::maps::Providers; use rustc::lint::builtin::UNUSED_MUT; use rustc::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind}; @@ -46,7 +45,6 @@ use dataflow::move_paths::{IllegalMoveOriginKind, MoveError}; use dataflow::move_paths::{HasMoveData, LookupResult, MoveData, MovePathIndex}; use util::borrowck_errors::{BorrowckErrors, Origin}; use util::collect_writes::FindAssignments; -use polonius_engine::Output; use self::borrow_set::{BorrowSet, BorrowData}; use self::flows::Flows; @@ -253,7 +251,6 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( used_mut_upvars: SmallVec::new(), borrow_set, dominators, - polonius_output, }; let mut state = Flows::new( @@ -262,6 +259,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>( flow_uninits, flow_move_outs, flow_ever_inits, + polonius_output, ); mbcx.analyze_results(&mut state); // entry point for DataflowResultsConsumer @@ -376,9 +374,6 @@ pub struct MirBorrowckCtxt<'cx, 'gcx: 'tcx, 'tcx: 'cx> { /// Dominators for MIR dominators: Dominators, - - /// Polonius Output - polonius_output: Option>>, } // Check that: From 9de4e342dfc84c66d4ab435adcafc930c35f5586 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Tue, 29 May 2018 08:54:15 -0300 Subject: [PATCH 6/9] Use polonius_output --- src/Cargo.lock | 9 +++++---- src/librustc/Cargo.toml | 2 +- src/librustc_mir/Cargo.toml | 3 ++- src/librustc_mir/borrow_check/flows.rs | 9 +++++++-- src/librustc_mir/borrow_check/mod.rs | 4 +++- src/librustc_mir/lib.rs | 1 + 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 413ae2db2c8..6b7c165826f 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1455,7 +1455,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "polonius-engine" -version = "0.2.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "datafrog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1784,7 +1784,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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "polonius-engine 0.4.0 (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", @@ -2168,10 +2168,11 @@ dependencies = [ "arena 0.0.0", "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "polonius-engine 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc 0.0.0", "rustc_apfloat 0.0.0", "rustc_data_structures 0.0.0", @@ -3172,7 +3173,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.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "89be86c0ed0f63715d74d390b1a1a3df63cfca80b6eab604d7c4fecb5403cfdd" +"checksum polonius-engine 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9385a6d8f8ff6fd7e48a803c6a77fb89cc929dc7e2af6bf972494bbc8ff8b9e4" "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 535fb2fcc3d..df68bf1fd9a 100644 --- a/src/librustc/Cargo.toml +++ b/src/librustc/Cargo.toml @@ -16,7 +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.2.0" +polonius-engine = "0.4.0" proc_macro = { path = "../libproc_macro" } rustc_apfloat = { path = "../librustc_apfloat" } rustc_target = { path = "../librustc_target" } diff --git a/src/librustc_mir/Cargo.toml b/src/librustc_mir/Cargo.toml index c2cfd3a827d..512ab53f401 100644 --- a/src/librustc_mir/Cargo.toml +++ b/src/librustc_mir/Cargo.toml @@ -11,10 +11,11 @@ crate-type = ["dylib"] [dependencies] arena = { path = "../libarena" } bitflags = "1.0" +either = "1.5.0" graphviz = { path = "../libgraphviz" } log = "0.4" log_settings = "0.1.1" -polonius-engine = "0.2.0" +polonius-engine = "0.4.0" rustc = { path = "../librustc" } rustc_target = { path = "../librustc_target" } rustc_data_structures = { path = "../librustc_data_structures" } diff --git a/src/librustc_mir/borrow_check/flows.rs b/src/librustc_mir/borrow_check/flows.rs index 61915646d6f..5d13eab8cf6 100644 --- a/src/librustc_mir/borrow_check/flows.rs +++ b/src/librustc_mir/borrow_check/flows.rs @@ -27,6 +27,7 @@ use dataflow::{Borrows}; use dataflow::{FlowAtLocation, FlowsAtLocation}; use dataflow::move_paths::HasMoveData; use dataflow::move_paths::indexes::BorrowIndex; +use either::Either; use std::fmt; use std::rc::Rc; @@ -61,8 +62,12 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> { } } - crate fn borrows_in_scope(&self) -> impl Iterator + '_ { - self.borrows.iter_incoming() + crate fn borrows_in_scope(&self, location: LocationIndex) -> impl Iterator + '_ { + if let Some(ref polonius) = self.polonius_output { + Either::Left(polonius.errors_at(location).iter().cloned()) + } else { + Either::Right(self.borrows.iter_incoming()) + } } crate fn with_outgoing_borrows(&self, op: impl FnOnce(Iter)) { diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 983a2ac2ec1..9bfba219ccd 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -937,6 +937,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { let mut error_reported = false; let tcx = self.tcx; let mir = self.mir; + let location_table = &LocationTable::new(mir); + let location = location_table.start_index(context.loc); let borrow_set = self.borrow_set.clone(); each_borrow_involving_path( self, @@ -945,7 +947,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> { context, (sd, place_span.0), &borrow_set, - flow_state.borrows_in_scope(), + flow_state.borrows_in_scope(location), |this, borrow_index, borrow| match (rw, borrow.kind) { // Obviously an activation is compatible with its own diff --git a/src/librustc_mir/lib.rs b/src/librustc_mir/lib.rs index ace4709ba1d..34eb444fdc0 100644 --- a/src/librustc_mir/lib.rs +++ b/src/librustc_mir/lib.rs @@ -38,6 +38,7 @@ extern crate arena; #[macro_use] extern crate bitflags; #[macro_use] extern crate log; +extern crate either; extern crate graphviz as dot; extern crate polonius_engine; #[macro_use] From a8b36c9e9a41cd3c9b8d723b486c176c73e4c010 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 28 May 2018 13:47:20 -0300 Subject: [PATCH 7/9] Run rustfmt --- src/librustc_mir/borrow_check/flows.rs | 23 ++-- src/librustc_mir/borrow_check/nll/mod.rs | 133 +++++++++++++---------- 2 files changed, 86 insertions(+), 70 deletions(-) diff --git a/src/librustc_mir/borrow_check/flows.rs b/src/librustc_mir/borrow_check/flows.rs index 5d13eab8cf6..5631356dc1e 100644 --- a/src/librustc_mir/borrow_check/flows.rs +++ b/src/librustc_mir/borrow_check/flows.rs @@ -21,12 +21,12 @@ use borrow_check::location::LocationIndex; use polonius_engine::Output; -use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; -use dataflow::{EverInitializedPlaces, MovingOutStatements}; -use dataflow::{Borrows}; -use dataflow::{FlowAtLocation, FlowsAtLocation}; -use dataflow::move_paths::HasMoveData; use dataflow::move_paths::indexes::BorrowIndex; +use dataflow::move_paths::HasMoveData; +use dataflow::Borrows; +use dataflow::{EverInitializedPlaces, MovingOutStatements}; +use dataflow::{FlowAtLocation, FlowsAtLocation}; +use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces}; use either::Either; use std::fmt; use std::rc::Rc; @@ -62,7 +62,10 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> { } } - crate fn borrows_in_scope(&self, location: LocationIndex) -> impl Iterator + '_ { + crate fn borrows_in_scope( + &self, + location: LocationIndex, + ) -> impl Iterator + '_ { if let Some(ref polonius) = self.polonius_output { Either::Left(polonius.errors_at(location).iter().cloned()) } else { @@ -82,7 +85,7 @@ macro_rules! each_flow { FlowAtLocation::$meth(&mut $this.uninits, $arg); FlowAtLocation::$meth(&mut $this.move_outs, $arg); FlowAtLocation::$meth(&mut $this.ever_inits, $arg); - } + }; } impl<'b, 'gcx, 'tcx> FlowsAtLocation for Flows<'b, 'gcx, 'tcx> { @@ -150,8 +153,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> { s.push_str(", "); }; saw_one = true; - let move_path = - &self.uninits.operator().move_data().move_paths[mpi_uninit]; + let move_path = &self.uninits.operator().move_data().move_paths[mpi_uninit]; s.push_str(&format!("{}", move_path)); }); s.push_str("] "); @@ -175,8 +177,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> { s.push_str(", "); }; saw_one = true; - let ever_init = - &self.ever_inits.operator().move_data().inits[mpi_ever_init]; + let ever_init = &self.ever_inits.operator().move_data().inits[mpi_ever_init]; s.push_str(&format!("{:?}", ever_init)); }); s.push_str("]"); diff --git a/src/librustc_mir/borrow_check/nll/mod.rs b/src/librustc_mir/borrow_check/nll/mod.rs index ebc2800d204..ec1f3dbaeeb 100644 --- a/src/librustc_mir/borrow_check/nll/mod.rs +++ b/src/librustc_mir/borrow_check/nll/mod.rs @@ -11,10 +11,10 @@ use borrow_check::borrow_set::BorrowSet; use borrow_check::location::{LocationIndex, LocationTable}; use borrow_check::nll::facts::AllFactsExt; +use dataflow::indexes::BorrowIndex; use dataflow::move_paths::MoveData; use dataflow::FlowAtLocation; use dataflow::MaybeInitializedPlaces; -use dataflow::indexes::BorrowIndex; use rustc::hir::def_id::DefId; use rustc::infer::InferCtxt; use rustc::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, Mir}; @@ -23,25 +23,25 @@ use rustc::util::nodemap::FxHashMap; use std::collections::BTreeSet; use std::fmt::Debug; use std::io; -use std::rc::Rc; use std::path::PathBuf; +use std::rc::Rc; use transform::MirSource; use util::liveness::{LivenessResults, LocalSet}; use self::mir_util::PassWhere; +use polonius_engine::{Algorithm, Output}; use util as mir_util; use util::pretty::{self, ALIGN}; -use polonius_engine::{Algorithm, Output}; mod constraint_generation; pub mod explain_borrow; mod facts; +mod invalidation; crate mod region_infer; mod renumber; mod subtype_constraint_generation; crate mod type_check; mod universal_regions; -mod invalidation; use self::facts::AllFacts; use self::region_infer::RegionInferenceContext; @@ -119,8 +119,7 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>( // Create the region inference context, taking ownership of the region inference // data that was contained in `infcx`. let var_origins = infcx.take_region_var_origins(); - let mut regioncx = - RegionInferenceContext::new(var_origins, universal_regions, mir); + let mut regioncx = RegionInferenceContext::new(var_origins, universal_regions, mir); // Generate various constraints. subtype_constraint_generation::generate( @@ -144,22 +143,27 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>( location_table, &mir, def_id, - borrow_set + borrow_set, ); // Dump facts if requested. let polonius_output = all_facts.and_then(|all_facts| { - if infcx.tcx.sess.opts.debugging_opts.nll_facts { - let def_path = infcx.tcx.hir.def_path(def_id); - let dir_path = PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate()); - all_facts.write_to_dir(dir_path, location_table).unwrap(); - } + if infcx.tcx.sess.opts.debugging_opts.nll_facts { + let def_path = infcx.tcx.hir.def_path(def_id); + let dir_path = + PathBuf::from("nll-facts").join(def_path.to_filename_friendly_no_crate()); + all_facts.write_to_dir(dir_path, location_table).unwrap(); + } - if infcx.tcx.sess.opts.debugging_opts.polonius { - Some(Rc::new(Output::compute(&all_facts, Algorithm::DatafrogOpt, false))) - } else { - None - } + if infcx.tcx.sess.opts.debugging_opts.polonius { + Some(Rc::new(Output::compute( + &all_facts, + Algorithm::DatafrogOpt, + false, + ))) + } else { + None + } }); // Solve the region constraints. @@ -195,7 +199,8 @@ fn dump_mir_results<'a, 'gcx, 'tcx>( return; } - let regular_liveness_per_location: FxHashMap<_, _> = mir.basic_blocks() + let regular_liveness_per_location: FxHashMap<_, _> = mir + .basic_blocks() .indices() .flat_map(|bb| { let mut results = vec![]; @@ -208,7 +213,8 @@ fn dump_mir_results<'a, 'gcx, 'tcx>( }) .collect(); - let drop_liveness_per_location: FxHashMap<_, _> = mir.basic_blocks() + let drop_liveness_per_location: FxHashMap<_, _> = mir + .basic_blocks() .indices() .flat_map(|bb| { let mut results = vec![]; @@ -221,47 +227,55 @@ fn dump_mir_results<'a, 'gcx, 'tcx>( }) .collect(); - mir_util::dump_mir(infcx.tcx, None, "nll", &0, source, mir, |pass_where, out| { - match pass_where { - // Before the CFG, dump out the values for each region variable. - PassWhere::BeforeCFG => { - regioncx.dump_mir(out)?; + mir_util::dump_mir( + infcx.tcx, + None, + "nll", + &0, + source, + mir, + |pass_where, out| { + match pass_where { + // Before the CFG, dump out the values for each region variable. + PassWhere::BeforeCFG => { + regioncx.dump_mir(out)?; - if let Some(closure_region_requirements) = closure_region_requirements { - writeln!(out, "|")?; - writeln!(out, "| Free Region Constraints")?; - for_each_region_constraint(closure_region_requirements, &mut |msg| { - writeln!(out, "| {}", msg) - })?; + if let Some(closure_region_requirements) = closure_region_requirements { + writeln!(out, "|")?; + writeln!(out, "| Free Region Constraints")?; + for_each_region_constraint(closure_region_requirements, &mut |msg| { + writeln!(out, "| {}", msg) + })?; + } } - } - // Before each basic block, dump out the values - // that are live on entry to the basic block. - PassWhere::BeforeBlock(bb) => { - let s = live_variable_set(&liveness.regular.ins[bb], &liveness.drop.ins[bb]); - writeln!(out, " | Live variables on entry to {:?}: {}", bb, s)?; - } + // Before each basic block, dump out the values + // that are live on entry to the basic block. + PassWhere::BeforeBlock(bb) => { + let s = live_variable_set(&liveness.regular.ins[bb], &liveness.drop.ins[bb]); + writeln!(out, " | Live variables on entry to {:?}: {}", bb, s)?; + } - PassWhere::BeforeLocation(location) => { - let s = live_variable_set( - ®ular_liveness_per_location[&location], - &drop_liveness_per_location[&location], - ); - writeln!( - out, - "{:ALIGN$} | Live variables on entry to {:?}: {}", - "", - location, - s, - ALIGN = ALIGN - )?; - } + PassWhere::BeforeLocation(location) => { + let s = live_variable_set( + ®ular_liveness_per_location[&location], + &drop_liveness_per_location[&location], + ); + writeln!( + out, + "{:ALIGN$} | Live variables on entry to {:?}: {}", + "", + location, + s, + ALIGN = ALIGN + )?; + } - PassWhere::AfterLocation(_) | PassWhere::AfterCFG => {} - } - Ok(()) - }); + PassWhere::AfterLocation(_) | PassWhere::AfterCFG => {} + } + Ok(()) + }, + ); // Also dump the inference graph constraints as a graphviz file. let _: io::Result<()> = do catch { @@ -292,7 +306,8 @@ fn dump_annotation<'a, 'gcx, 'tcx>( // better. if let Some(closure_region_requirements) = closure_region_requirements { - let mut err = tcx.sess + let mut err = tcx + .sess .diagnostic() .span_note_diag(mir.span, "External requirements"); @@ -312,7 +327,8 @@ fn dump_annotation<'a, 'gcx, 'tcx>( err.emit(); } else { - let mut err = tcx.sess + let mut err = tcx + .sess .diagnostic() .span_note_diag(mir.span, "No external requirements"); regioncx.annotate(&mut err); @@ -331,8 +347,7 @@ fn for_each_region_constraint( }; with_msg(&format!( "where {:?}: {:?}", - subject, - req.outlived_free_region, + subject, req.outlived_free_region, ))?; } Ok(()) From 4c10a65b14933ea833896d9b312ad6251def1c7e Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 28 May 2018 13:54:11 -0300 Subject: [PATCH 8/9] Whitelist datafrog on tidy --- src/tools/tidy/src/deps.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 86a600ddc2f..a4eb784fa7d 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -73,6 +73,7 @@ static WHITELIST: &'static [Crate] = &[ Crate("crossbeam-deque"), Crate("crossbeam-epoch"), Crate("crossbeam-utils"), + Crate("datafrog"), Crate("either"), Crate("ena"), Crate("env_logger"), From c3d688962d2940a033f4b4df85b8ab8417981210 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Tue, 29 May 2018 09:36:45 -0400 Subject: [PATCH 9/9] WIP fix rustc-hash cargo.lock entry for polonius-engine --- src/Cargo.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cargo.lock b/src/Cargo.lock index 6b7c165826f..d61f007b6a5 100644 --- a/src/Cargo.lock +++ b/src/Cargo.lock @@ -1459,7 +1459,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "datafrog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hash 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]]