Skip to content

Commit 2442823

Browse files
committed
Auto merge of #56507 - nikomatsakis:polonius-integrate, r=MatthewJasper
polonius tweaks - bump polonius to 0.6.0 - fix 2-phase-borrow activations r? @matthewjasper
2 parents 1409363 + 826fb1d commit 2442823

File tree

4 files changed

+55
-13
lines changed

4 files changed

+55
-13
lines changed

Cargo.lock

+7-7
Original file line numberDiff line numberDiff line change
@@ -617,7 +617,7 @@ dependencies = [
617617

618618
[[package]]
619619
name = "datafrog"
620-
version = "0.1.0"
620+
version = "2.0.1"
621621
source = "registry+https://github.com/rust-lang/crates.io-index"
622622

623623
[[package]]
@@ -1622,10 +1622,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
16221622

16231623
[[package]]
16241624
name = "polonius-engine"
1625-
version = "0.5.0"
1625+
version = "0.6.2"
16261626
source = "registry+https://github.com/rust-lang/crates.io-index"
16271627
dependencies = [
1628-
"datafrog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
1628+
"datafrog 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
16291629
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
16301630
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
16311631
]
@@ -2071,7 +2071,7 @@ dependencies = [
20712071
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
20722072
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
20732073
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
2074-
"polonius-engine 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
2074+
"polonius-engine 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
20752075
"rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
20762076
"rustc-rayon-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
20772077
"rustc_apfloat 0.0.0",
@@ -2523,7 +2523,7 @@ dependencies = [
25232523
"graphviz 0.0.0",
25242524
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
25252525
"log_settings 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
2526-
"polonius-engine 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
2526+
"polonius-engine 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)",
25272527
"rustc 0.0.0",
25282528
"rustc_apfloat 0.0.0",
25292529
"rustc_data_structures 0.0.0",
@@ -3428,7 +3428,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
34283428
"checksum crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09de9ee0fc255ace04c7fa0763c9395a945c37c8292bb554f8d48361d1dcf1b4"
34293429
"checksum curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "c7c9d851c825e0c033979d4516c9173bc19a78a96eb4d6ae51d4045440eafa16"
34303430
"checksum curl-sys 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)" = "721c204978be2143fab0a84b708c49d79d1f6100b8785610f456043a90708870"
3431-
"checksum datafrog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16d724bf4ffe77cdceeecd461009b5f8d9e23c5d645d68bedb4586bf43e7e142"
3431+
"checksum datafrog 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a0afaad2b26fa326569eb264b1363e8ae3357618c43982b3f285f0774ce76b69"
34323432
"checksum derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ca414e896ae072546f4d789f452daaecf60ddee4c9df5dc6d5936d769e3d87c"
34333433
"checksum derive_more 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f57d78cf3bd45270dad4e70c21ec77a960b36c7a841ff9db76aaa775a8fb871"
34343434
"checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a"
@@ -3537,7 +3537,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
35373537
"checksum phf_generator 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "05a079dd052e7b674d21cb31cbb6c05efd56a2cd2827db7692e2f1a507ebd998"
35383538
"checksum phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "c2261d544c2bb6aa3b10022b0be371b9c7c64f762ef28c6f5d4f1ef6d97b5930"
35393539
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
3540-
"checksum polonius-engine 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b6b0a7f5f4278b991ffd14abce1d01b013121ad297460237ef0a2f08d43201"
3540+
"checksum polonius-engine 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2490c396085801abf88df91758bad806b0890354f0875d624e62ecf0579a8145"
35413541
"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
35423542
"checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6"
35433543
"checksum pretty_env_logger 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df8b3f4e0475def7d9c2e5de8e5a1306949849761e107b360d03e98eafaffd61"

src/librustc/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobserver = "0.1"
1717
lazy_static = "1.0.0"
1818
scoped-tls = { version = "0.1.1", features = ["nightly"] }
1919
log = { version = "0.4", features = ["release_max_level_info", "std"] }
20-
polonius-engine = "0.5.0"
20+
polonius-engine = "0.6.2"
2121
rustc-rayon = "0.1.1"
2222
rustc-rayon-core = "0.1.1"
2323
rustc_apfloat = { path = "../librustc_apfloat" }

src/librustc_mir/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ either = "1.5.0"
1515
graphviz = { path = "../libgraphviz" }
1616
log = "0.4"
1717
log_settings = "0.1.1"
18-
polonius-engine = "0.5.0"
18+
polonius-engine = "0.6.2"
1919
rustc = { path = "../librustc" }
2020
rustc_target = { path = "../librustc_target" }
2121
rustc_data_structures = { path = "../librustc_data_structures" }

src/librustc_mir/borrow_check/nll/invalidation.rs

+46-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,14 @@ struct InvalidationGenerator<'cx, 'tcx: 'cx, 'gcx: 'tcx> {
5656
/// Visits the whole MIR and generates invalidates() facts
5757
/// Most of the code implementing this was stolen from borrow_check/mod.rs
5858
impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
59-
fn visit_statement(&mut self,
60-
block: BasicBlock,
61-
statement: &Statement<'tcx>,
62-
location: Location) {
59+
fn visit_statement(
60+
&mut self,
61+
block: BasicBlock,
62+
statement: &Statement<'tcx>,
63+
location: Location,
64+
) {
65+
self.check_activations(location);
66+
6367
match statement.kind {
6468
StatementKind::Assign(ref lhs, ref rhs) => {
6569
self.consume_rvalue(
@@ -148,6 +152,8 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
148152
terminator: &Terminator<'tcx>,
149153
location: Location
150154
) {
155+
self.check_activations(location);
156+
151157
match terminator.kind {
152158
TerminatorKind::SwitchInt {
153159
ref discr,
@@ -471,5 +477,41 @@ impl<'cg, 'cx, 'tcx, 'gcx> InvalidationGenerator<'cx, 'tcx, 'gcx> {
471477
let lidx = self.location_table.start_index(l);
472478
self.all_facts.invalidates.push((lidx, b));
473479
}
480+
481+
fn check_activations(
482+
&mut self,
483+
location: Location,
484+
) {
485+
if !self.tcx.two_phase_borrows() {
486+
return;
487+
}
488+
489+
// Two-phase borrow support: For each activation that is newly
490+
// generated at this statement, check if it interferes with
491+
// another borrow.
492+
for &borrow_index in self.borrow_set.activations_at_location(location) {
493+
let borrow = &self.borrow_set[borrow_index];
494+
495+
// only mutable borrows should be 2-phase
496+
assert!(match borrow.kind {
497+
BorrowKind::Shared | BorrowKind::Shallow => false,
498+
BorrowKind::Unique | BorrowKind::Mut { .. } => true,
499+
});
500+
501+
self.access_place(
502+
ContextKind::Activation.new(location),
503+
&borrow.borrowed_place,
504+
(
505+
Deep,
506+
Activation(WriteKind::MutableBorrow(borrow.kind), borrow_index),
507+
),
508+
LocalMutationIsAllowed::No,
509+
);
510+
511+
// We do not need to call `check_if_path_or_subpath_is_moved`
512+
// again, as we already called it when we made the
513+
// initial reservation.
514+
}
515+
}
474516
}
475517

0 commit comments

Comments
 (0)