Skip to content

Commit 59c0f59

Browse files
committed
Auto merge of #51133 - spastorino:make_borrowck_use_output, r=nikomatsakis
Make borrowck use polonius output
2 parents 889d8dc + c3d6889 commit 59c0f59

File tree

9 files changed

+139
-74
lines changed

9 files changed

+139
-74
lines changed

src/Cargo.lock

+15-4
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,11 @@ dependencies = [
557557
"winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
558558
]
559559

560+
[[package]]
561+
name = "datafrog"
562+
version = "0.1.0"
563+
source = "registry+https://github.com/rust-lang/crates.io-index"
564+
560565
[[package]]
561566
name = "debug_unreachable"
562567
version = "0.1.1"
@@ -1450,8 +1455,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
14501455

14511456
[[package]]
14521457
name = "polonius-engine"
1453-
version = "0.1.1"
1458+
version = "0.4.0"
14541459
source = "registry+https://github.com/rust-lang/crates.io-index"
1460+
dependencies = [
1461+
"datafrog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
1462+
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
1463+
]
14551464

14561465
[[package]]
14571466
name = "precomputed-hash"
@@ -1775,7 +1784,7 @@ dependencies = [
17751784
"jobserver 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
17761785
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
17771786
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
1778-
"polonius-engine 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
1787+
"polonius-engine 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
17791788
"proc_macro 0.0.0",
17801789
"rustc_apfloat 0.0.0",
17811790
"rustc_data_structures 0.0.0",
@@ -2159,10 +2168,11 @@ dependencies = [
21592168
"arena 0.0.0",
21602169
"bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
21612170
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
2171+
"either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
21622172
"graphviz 0.0.0",
21632173
"log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
21642174
"log_settings 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
2165-
"polonius-engine 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
2175+
"polonius-engine 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
21662176
"rustc 0.0.0",
21672177
"rustc_apfloat 0.0.0",
21682178
"rustc_data_structures 0.0.0",
@@ -3069,6 +3079,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
30693079
"checksum crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09de9ee0fc255ace04c7fa0763c9395a945c37c8292bb554f8d48361d1dcf1b4"
30703080
"checksum curl 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "aaf20bbe084f285f215eef2165feed70d6b75ba29cad24469badb853a4a287d0"
30713081
"checksum curl-sys 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "71c63a540a9ee4e15e56c3ed9b11a2f121239b9f6d7b7fe30f616e048148df9a"
3082+
"checksum datafrog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16d724bf4ffe77cdceeecd461009b5f8d9e23c5d645d68bedb4586bf43e7e142"
30723083
"checksum debug_unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9a032eac705ca39214d169f83e3d3da290af06d8d1d344d1baad2fd002dca4b3"
30733084
"checksum derive-new 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ceed73957c449214f8440eec8ad7fa282b67dc9eacbb24a3085b15d60397a17a"
30743085
"checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a"
@@ -3162,7 +3173,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
31623173
"checksum phf_generator 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "6b07ffcc532ccc85e3afc45865469bf5d9e4ef5bfcf9622e3cfe80c2d275ec03"
31633174
"checksum phf_shared 0.7.21 (registry+https://github.com/rust-lang/crates.io-index)" = "07e24b0ca9643bdecd0632f2b3da6b1b89bbb0030e0b992afc1113b23a7bc2f2"
31643175
"checksum pkg-config 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3a8b4c6b8165cd1a1cd4b9b120978131389f64bdaf456435caa41e630edba903"
3165-
"checksum polonius-engine 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6201ffe79e3da53bd065fbec2a9b391e5a0dc21038b39bb300612ddc658eb7ee"
3176+
"checksum polonius-engine 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9385a6d8f8ff6fd7e48a803c6a77fb89cc929dc7e2af6bf972494bbc8ff8b9e4"
31663177
"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
31673178
"checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6"
31683179
"checksum proc-macro2 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "49b6a521dc81b643e9a51e0d1cf05df46d5a2f3c0280ea72bcb68276ba64a118"

src/librustc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +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"
19+
polonius-engine = "0.4.0"
2020
proc_macro = { path = "../libproc_macro" }
2121
rustc_apfloat = { path = "../librustc_apfloat" }
2222
rustc_target = { path = "../librustc_target" }

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1296,6 +1296,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12961296
"dump facts from NLL analysis into side files"),
12971297
disable_nll_user_type_assert: bool = (false, parse_bool, [UNTRACKED],
12981298
"disable user provided type assertion in NLL"),
1299+
polonius: bool = (false, parse_bool, [UNTRACKED],
1300+
"enable polonius-based borrow-checker"),
12991301
codegen_time_graph: bool = (false, parse_bool, [UNTRACKED],
13001302
"generate a graphical HTML report of time spent in codegen and LLVM"),
13011303
thinlto: Option<bool> = (None, parse_opt_bool, [TRACKED],

src/librustc_mir/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ crate-type = ["dylib"]
1111
[dependencies]
1212
arena = { path = "../libarena" }
1313
bitflags = "1.0"
14+
either = "1.5.0"
1415
graphviz = { path = "../libgraphviz" }
1516
log = "0.4"
1617
log_settings = "0.1.1"
17-
polonius-engine = "0.1.1"
18+
polonius-engine = "0.4.0"
1819
rustc = { path = "../librustc" }
1920
rustc_target = { path = "../librustc_target" }
2021
rustc_data_structures = { path = "../librustc_data_structures" }

src/librustc_mir/borrow_check/flows.rs

+28-11
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,22 @@
1414
//! but is not as ugly as it is right now.
1515
1616
use rustc::mir::{BasicBlock, Location};
17+
use rustc::ty::RegionVid;
1718
use rustc_data_structures::indexed_set::Iter;
1819

19-
use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
20+
use borrow_check::location::LocationIndex;
21+
22+
use polonius_engine::Output;
23+
24+
use dataflow::move_paths::indexes::BorrowIndex;
25+
use dataflow::move_paths::HasMoveData;
26+
use dataflow::Borrows;
2027
use dataflow::{EverInitializedPlaces, MovingOutStatements};
21-
use dataflow::{Borrows};
2228
use dataflow::{FlowAtLocation, FlowsAtLocation};
23-
use dataflow::move_paths::HasMoveData;
24-
use dataflow::move_paths::indexes::BorrowIndex;
29+
use dataflow::{MaybeInitializedPlaces, MaybeUninitializedPlaces};
30+
use either::Either;
2531
use std::fmt;
32+
use std::rc::Rc;
2633

2734
// (forced to be `pub` due to its use as an associated type below.)
2835
crate struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> {
@@ -31,6 +38,9 @@ crate struct Flows<'b, 'gcx: 'tcx, 'tcx: 'b> {
3138
pub uninits: FlowAtLocation<MaybeUninitializedPlaces<'b, 'gcx, 'tcx>>,
3239
pub move_outs: FlowAtLocation<MovingOutStatements<'b, 'gcx, 'tcx>>,
3340
pub ever_inits: FlowAtLocation<EverInitializedPlaces<'b, 'gcx, 'tcx>>,
41+
42+
/// Polonius Output
43+
pub polonius_output: Option<Rc<Output<RegionVid, BorrowIndex, LocationIndex>>>,
3444
}
3545

3646
impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> {
@@ -40,18 +50,27 @@ impl<'b, 'gcx, 'tcx> Flows<'b, 'gcx, 'tcx> {
4050
uninits: FlowAtLocation<MaybeUninitializedPlaces<'b, 'gcx, 'tcx>>,
4151
move_outs: FlowAtLocation<MovingOutStatements<'b, 'gcx, 'tcx>>,
4252
ever_inits: FlowAtLocation<EverInitializedPlaces<'b, 'gcx, 'tcx>>,
53+
polonius_output: Option<Rc<Output<RegionVid, BorrowIndex, LocationIndex>>>,
4354
) -> Self {
4455
Flows {
4556
borrows,
4657
inits,
4758
uninits,
4859
move_outs,
4960
ever_inits,
61+
polonius_output,
5062
}
5163
}
5264

53-
crate fn borrows_in_scope(&self) -> impl Iterator<Item = BorrowIndex> + '_ {
54-
self.borrows.iter_incoming()
65+
crate fn borrows_in_scope(
66+
&self,
67+
location: LocationIndex,
68+
) -> impl Iterator<Item = BorrowIndex> + '_ {
69+
if let Some(ref polonius) = self.polonius_output {
70+
Either::Left(polonius.errors_at(location).iter().cloned())
71+
} else {
72+
Either::Right(self.borrows.iter_incoming())
73+
}
5574
}
5675

5776
crate fn with_outgoing_borrows(&self, op: impl FnOnce(Iter<BorrowIndex>)) {
@@ -66,7 +85,7 @@ macro_rules! each_flow {
6685
FlowAtLocation::$meth(&mut $this.uninits, $arg);
6786
FlowAtLocation::$meth(&mut $this.move_outs, $arg);
6887
FlowAtLocation::$meth(&mut $this.ever_inits, $arg);
69-
}
88+
};
7089
}
7190

7291
impl<'b, 'gcx, 'tcx> FlowsAtLocation for Flows<'b, 'gcx, 'tcx> {
@@ -134,8 +153,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
134153
s.push_str(", ");
135154
};
136155
saw_one = true;
137-
let move_path =
138-
&self.uninits.operator().move_data().move_paths[mpi_uninit];
156+
let move_path = &self.uninits.operator().move_data().move_paths[mpi_uninit];
139157
s.push_str(&format!("{}", move_path));
140158
});
141159
s.push_str("] ");
@@ -159,8 +177,7 @@ impl<'b, 'gcx, 'tcx> fmt::Display for Flows<'b, 'gcx, 'tcx> {
159177
s.push_str(", ");
160178
};
161179
saw_one = true;
162-
let ever_init =
163-
&self.ever_inits.operator().move_data().inits[mpi_ever_init];
180+
let ever_init = &self.ever_inits.operator().move_data().inits[mpi_ever_init];
164181
s.push_str(&format!("{:?}", ever_init));
165182
});
166183
s.push_str("]");

src/librustc_mir/borrow_check/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
198198
let borrow_set = Rc::new(BorrowSet::build(tcx, mir));
199199

200200
// If we are in non-lexical mode, compute the non-lexical lifetimes.
201-
let (regioncx, opt_closure_req) = nll::compute_regions(
201+
let (regioncx, polonius_output, opt_closure_req) = nll::compute_regions(
202202
infcx,
203203
def_id,
204204
free_regions,
@@ -259,6 +259,7 @@ fn do_mir_borrowck<'a, 'gcx, 'tcx>(
259259
flow_uninits,
260260
flow_move_outs,
261261
flow_ever_inits,
262+
polonius_output,
262263
);
263264

264265
mbcx.analyze_results(&mut state); // entry point for DataflowResultsConsumer
@@ -936,6 +937,8 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
936937
let mut error_reported = false;
937938
let tcx = self.tcx;
938939
let mir = self.mir;
940+
let location_table = &LocationTable::new(mir);
941+
let location = location_table.start_index(context.loc);
939942
let borrow_set = self.borrow_set.clone();
940943
each_borrow_involving_path(
941944
self,
@@ -944,7 +947,7 @@ impl<'cx, 'gcx, 'tcx> MirBorrowckCtxt<'cx, 'gcx, 'tcx> {
944947
context,
945948
(sd, place_span.0),
946949
&borrow_set,
947-
flow_state.borrows_in_scope(),
950+
flow_state.borrows_in_scope(location),
948951
|this, borrow_index, borrow|
949952
match (rw, borrow.kind) {
950953
// Obviously an activation is compatible with its own

0 commit comments

Comments
 (0)