Skip to content

Make borrowck use polonius output #51133

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

Merged
merged 9 commits into from
May 29, 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
19 changes: 15 additions & 4 deletions src/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -1450,8 +1455,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "polonius-engine"
version = "0.1.1"
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.1 (registry+https://github.com/rust-lang/crates.io-index)",
]

[[package]]
name = "precomputed-hash"
Expand Down Expand Up @@ -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.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",
Expand Down Expand Up @@ -2159,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.1.1 (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",
Expand Down Expand Up @@ -3069,6 +3079,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"
Expand Down Expand Up @@ -3162,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.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6201ffe79e3da53bd065fbec2a9b391e5a0dc21038b39bb300612ddc658eb7ee"
"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"
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.4.0"
proc_macro = { path = "../libproc_macro" }
rustc_apfloat = { path = "../librustc_apfloat" }
rustc_target = { path = "../librustc_target" }
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> = (None, parse_opt_bool, [TRACKED],
Expand Down
3 changes: 2 additions & 1 deletion src/librustc_mir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.1.1"
polonius-engine = "0.4.0"
rustc = { path = "../librustc" }
rustc_target = { path = "../librustc_target" }
rustc_data_structures = { path = "../librustc_data_structures" }
Expand Down
39 changes: 28 additions & 11 deletions src/librustc_mir/borrow_check/flows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@
//! 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 dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
use borrow_check::location::LocationIndex;

use polonius_engine::Output;

use dataflow::move_paths::indexes::BorrowIndex;
use dataflow::move_paths::HasMoveData;
use dataflow::Borrows;
use dataflow::{EverInitializedPlaces, MovingOutStatements};
use dataflow::{Borrows};
use dataflow::{FlowAtLocation, FlowsAtLocation};
use dataflow::move_paths::HasMoveData;
use dataflow::move_paths::indexes::BorrowIndex;
use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
use either::Either;
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> {
Expand All @@ -31,6 +38,9 @@ crate struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> {
pub uninits: FlowAtLocation<MaybeUninitializedPlaces<'b, 'gcx, 'tcx>>,
pub move_outs: FlowAtLocation<MovingOutStatements<'b, 'gcx, 'tcx>>,
pub ever_inits: FlowAtLocation<EverInitializedPlaces<'b, 'gcx, 'tcx>>,

/// Polonius Output
pub polonius_output: Option<Rc<Output<RegionVid, BorrowIndex, LocationIndex>>>,
}

impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> {
Expand All @@ -40,18 +50,27 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> {
uninits: FlowAtLocation<MaybeUninitializedPlaces<'b, 'gcx, 'tcx>>,
move_outs: FlowAtLocation<MovingOutStatements<'b, 'gcx, 'tcx>>,
ever_inits: FlowAtLocation<EverInitializedPlaces<'b, 'gcx, 'tcx>>,
polonius_output: Option<Rc<Output<RegionVid, BorrowIndex, LocationIndex>>>,
) -> Self {
Flows {
borrows,
inits,
uninits,
move_outs,
ever_inits,
polonius_output,
}
}

crate fn borrows_in_scope(&self) -> impl Iterator<Item = BorrowIndex> + '_ {
self.borrows.iter_incoming()
crate fn borrows_in_scope(
&self,
location: LocationIndex,
) -> impl Iterator<Item = BorrowIndex> + '_ {
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<BorrowIndex>)) {
Expand All @@ -66,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> {
Expand Down Expand Up @@ -134,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("] ");
Expand All @@ -159,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("]");
Expand Down
7 changes: 5 additions & 2 deletions src/librustc_mir/borrow_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -259,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
Expand Down Expand Up @@ -936,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,
Expand All @@ -944,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
Expand Down
Loading