Skip to content

Commit b1c8db0

Browse files
authored
Rollup 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 97452d9 + f30ba07 commit b1c8db0

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -1587,7 +1587,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
15871587

15881588
[[package]]
15891589
name = "polonius-engine"
1590-
version = "0.5.0"
1590+
version = "0.6.0"
15911591
source = "registry+https://github.com/rust-lang/crates.io-index"
15921592
dependencies = [
15931593
"datafrog 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -1966,7 +1966,7 @@ dependencies = [
19661966
"lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
19671967
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
19681968
"parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
1969-
"polonius-engine 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
1969+
"polonius-engine 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
19701970
"rustc-rayon 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
19711971
"rustc-rayon-core 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
19721972
"rustc_apfloat 0.0.0",
@@ -2406,7 +2406,7 @@ dependencies = [
24062406
"graphviz 0.0.0",
24072407
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
24082408
"log_settings 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
2409-
"polonius-engine 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
2409+
"polonius-engine 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
24102410
"rustc 0.0.0",
24112411
"rustc_apfloat 0.0.0",
24122412
"rustc_data_structures 0.0.0",
@@ -3427,7 +3427,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
34273427
"checksum phf_generator 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "05a079dd052e7b674d21cb31cbb6c05efd56a2cd2827db7692e2f1a507ebd998"
34283428
"checksum phf_shared 0.7.22 (registry+https://github.com/rust-lang/crates.io-index)" = "c2261d544c2bb6aa3b10022b0be371b9c7c64f762ef28c6f5d4f1ef6d97b5930"
34293429
"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c"
3430-
"checksum polonius-engine 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a5b6b0a7f5f4278b991ffd14abce1d01b013121ad297460237ef0a2f08d43201"
3430+
"checksum polonius-engine 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "494cc28002fae8ce2604c31c5cc1e73009318a0f6d2bb539a018dc22420a2dd0"
34313431
"checksum precomputed-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c"
34323432
"checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6"
34333433
"checksum pretty_env_logger 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ed8d1e63042e889b85228620629b51c011d380eed2c7e0015f8a644def280c28"

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.0"
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.0"
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)