Skip to content

Commit 8667b2b

Browse files
authored
Rollup merge of rust-lang#56507 - nikomatsakis:polonius-integrate, r=MatthewJasper
polonius tweaks - bump polonius to 0.6.0 - fix 2-phase-borrow activations r? @matthewjasper
2 parents 93c8c5e + 8ee2c06 commit 8667b2b

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
@@ -614,7 +614,7 @@ dependencies = [
614614

615615
[[package]]
616616
name = "datafrog"
617-
version = "0.1.0"
617+
version = "1.0.0"
618618
source = "registry+https://github.com/rust-lang/crates.io-index"
619619

620620
[[package]]
@@ -1625,10 +1625,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
16251625

16261626
[[package]]
16271627
name = "polonius-engine"
1628-
version = "0.5.0"
1628+
version = "0.6.1"
16291629
source = "registry+https://github.com/rust-lang/crates.io-index"
16301630
dependencies = [
1631-
"datafrog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
1631+
"datafrog 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
16321632
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
16331633
"rustc-hash 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
16341634
]
@@ -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.1 (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",
@@ -2518,7 +2518,7 @@ dependencies = [
25182518
"graphviz 0.0.0",
25192519
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
25202520
"log_settings 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
2521-
"polonius-engine 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
2521+
"polonius-engine 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
25222522
"rustc 0.0.0",
25232523
"rustc_apfloat 0.0.0",
25242524
"rustc_data_structures 0.0.0",
@@ -3419,7 +3419,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
34193419
"checksum crypto-hash 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09de9ee0fc255ace04c7fa0763c9395a945c37c8292bb554f8d48361d1dcf1b4"
34203420
"checksum curl 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "c7c9d851c825e0c033979d4516c9173bc19a78a96eb4d6ae51d4045440eafa16"
34213421
"checksum curl-sys 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)" = "721c204978be2143fab0a84b708c49d79d1f6100b8785610f456043a90708870"
3422-
"checksum datafrog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "16d724bf4ffe77cdceeecd461009b5f8d9e23c5d645d68bedb4586bf43e7e142"
3422+
"checksum datafrog 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71a3eacc779bb35090718501c2de27bb679dee18f6c28e6589590e4ed8b9fa08"
34233423
"checksum derive-new 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ca414e896ae072546f4d789f452daaecf60ddee4c9df5dc6d5936d769e3d87c"
34243424
"checksum derive_more 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f57d78cf3bd45270dad4e70c21ec77a960b36c7a841ff9db76aaa775a8fb871"
34253425
"checksum diff 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3c2b69f912779fbb121ceb775d74d51e915af17aaebc38d28a592843a2dd0a3a"
@@ -3529,7 +3529,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
35293529
"checksum phf_generator 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "05a079dd052e7b674d21cb31cbb6c05efd56a2cd2827db7692e2f1a507ebd998"
35303530
"checksum phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "c2261d544c2bb6aa3b10022b0be371b9c7c64f762ef28c6f5d4f1ef6d97b5930"
35313531
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
3532-
"checksum polonius-engine 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b6b0a7f5f4278b991ffd14abce1d01b013121ad297460237ef0a2f08d43201"
3532+
"checksum polonius-engine 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d9274a1db7bffb87f7e810ef480a75b67eed0f1a3838f80c652e881f4b4970fd"
35333533
"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
35343534
"checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6"
35353535
"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.1"
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.1"
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
@@ -66,10 +66,14 @@ struct InvalidationGenerator<'cx, 'tcx: 'cx, 'gcx: 'tcx> {
6666
/// Visits the whole MIR and generates invalidates() facts
6767
/// Most of the code implementing this was stolen from borrow_check/mod.rs
6868
impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
69-
fn visit_statement(&mut self,
70-
block: BasicBlock,
71-
statement: &Statement<'tcx>,
72-
location: Location) {
69+
fn visit_statement(
70+
&mut self,
71+
block: BasicBlock,
72+
statement: &Statement<'tcx>,
73+
location: Location,
74+
) {
75+
self.check_activations(location);
76+
7377
match statement.kind {
7478
StatementKind::Assign(ref lhs, ref rhs) => {
7579
self.consume_rvalue(
@@ -159,6 +163,8 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
159163
terminator: &Terminator<'tcx>,
160164
location: Location
161165
) {
166+
self.check_activations(location);
167+
162168
match terminator.kind {
163169
TerminatorKind::SwitchInt {
164170
ref discr,
@@ -482,5 +488,41 @@ impl<'cg, 'cx, 'tcx, 'gcx> InvalidationGenerator<'cx, 'tcx, 'gcx> {
482488
let lidx = self.location_table.start_index(l);
483489
self.all_facts.invalidates.push((lidx, b));
484490
}
491+
492+
fn check_activations(
493+
&mut self,
494+
location: Location,
495+
) {
496+
if !self.tcx.two_phase_borrows() {
497+
return;
498+
}
499+
500+
// Two-phase borrow support: For each activation that is newly
501+
// generated at this statement, check if it interferes with
502+
// another borrow.
503+
for &borrow_index in self.borrow_set.activations_at_location(location) {
504+
let borrow = &self.borrow_set[borrow_index];
505+
506+
// only mutable borrows should be 2-phase
507+
assert!(match borrow.kind {
508+
BorrowKind::Shared | BorrowKind::Shallow => false,
509+
BorrowKind::Unique | BorrowKind::Mut { .. } => true,
510+
});
511+
512+
self.access_place(
513+
ContextKind::Activation.new(location),
514+
&borrow.borrowed_place,
515+
(
516+
Deep,
517+
Activation(WriteKind::MutableBorrow(borrow.kind), borrow_index),
518+
),
519+
LocalMutationIsAllowed::No,
520+
);
521+
522+
// We do not need to call `check_if_path_or_subpath_is_moved`
523+
// again, as we already called it when we made the
524+
// initial reservation.
525+
}
526+
}
485527
}
486528

0 commit comments

Comments
 (0)