about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlbin Stjerna <albin.stjerna@gmail.com>2019-11-20 20:34:24 +0100
committerRemy Rakic <remy.rakic@gmail.com>2020-02-27 21:17:12 +0100
commit6f40cdb3807b25c92d32c5f7c3180958bb62f3c8 (patch)
tree45746f472ced6298d4fa53cafb4382146bf57817
parent49c68bd53f90e375bfb3cbba8c1c67a9e0adb9c0 (diff)
downloadrust-6f40cdb3807b25c92d32c5f7c3180958bb62f3c8.tar.gz
rust-6f40cdb3807b25c92d32c5f7c3180958bb62f3c8.zip
- polonius: adapt to the new fact format
- update polonius-engine dependency to 0.12.0

- rustfmt the files failing tidy
-rw-r--r--Cargo.lock4
-rw-r--r--src/librustc/Cargo.toml2
-rw-r--r--src/librustc_mir/Cargo.toml2
-rw-r--r--src/librustc_mir/borrow_check/facts.rs20
-rw-r--r--src/librustc_mir/borrow_check/nll.rs30
-rw-r--r--src/librustc_mir/borrow_check/type_check/liveness/polonius.rs45
-rw-r--r--src/librustc_mir/borrow_check/type_check/liveness/trace.rs2
7 files changed, 60 insertions, 45 deletions
diff --git a/Cargo.lock b/Cargo.lock
index beda3993353..93d7c83a036 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2494,9 +2494,9 @@ checksum = "05da548ad6865900e60eaba7f589cc0783590a92e940c26953ff81ddbab2d677"
 
 [[package]]
 name = "polonius-engine"
-version = "0.11.0"
+version = "0.12.0"
 source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1e478d7c38eb785c6416cbe58df12aa55d7aefa3759b6d3e044b2ed03f423cec"
+checksum = "04d8ef65e3f89ecaec9ca7cb0e0911b4617352d4494018bcf934992f03f2024c"
 dependencies = [
  "datafrog",
  "log",
diff --git a/src/librustc/Cargo.toml b/src/librustc/Cargo.toml
index af2be30cc0a..0fa70b76063 100644
--- a/src/librustc/Cargo.toml
+++ b/src/librustc/Cargo.toml
@@ -17,7 +17,7 @@ scoped-tls = "1.0"
 log = { version = "0.4", features = ["release_max_level_info", "std"] }
 rustc-rayon = "0.3.0"
 rustc-rayon-core = "0.3.0"
-polonius-engine = "0.11.0"
+polonius-engine = "0.12.0"
 rustc_apfloat = { path = "../librustc_apfloat" }
 rustc_attr = { path = "../librustc_attr" }
 rustc_feature = { path = "../librustc_feature" }
diff --git a/src/librustc_mir/Cargo.toml b/src/librustc_mir/Cargo.toml
index 3554fe54c45..4bbe05cf596 100644
--- a/src/librustc_mir/Cargo.toml
+++ b/src/librustc_mir/Cargo.toml
@@ -15,7 +15,7 @@ dot = { path = "../libgraphviz", package = "graphviz" }
 itertools = "0.8"
 log = "0.4"
 log_settings = "0.1.1"
-polonius-engine = "0.11.0"
+polonius-engine = "0.12.0"
 rustc = { path = "../librustc" }
 rustc_ast_pretty = { path = "../librustc_ast_pretty" }
 rustc_attr = { path = "../librustc_attr" }
diff --git a/src/librustc_mir/borrow_check/facts.rs b/src/librustc_mir/borrow_check/facts.rs
index 827ccb1c857..cd8139b17b4 100644
--- a/src/librustc_mir/borrow_check/facts.rs
+++ b/src/librustc_mir/borrow_check/facts.rs
@@ -71,16 +71,16 @@ impl AllFactsExt for AllFacts {
                 killed,
                 outlives,
                 invalidates,
-                var_used,
-                var_defined,
-                var_drop_used,
-                var_uses_region,
-                var_drops_region,
-                child,
-                path_belongs_to_var,
-                initialized_at,
-                moved_out_at,
-                path_accessed_at,
+                var_used_at,
+                var_defined_at,
+                var_dropped_at,
+                use_of_var_derefs_origin,
+                drop_of_var_derefs_origin,
+                child_path,
+                path_is_var,
+                path_assigned_at_base,
+                path_moved_at_base,
+                path_accessed_at_base,
                 known_subset,
             ])
         }
diff --git a/src/librustc_mir/borrow_check/nll.rs b/src/librustc_mir/borrow_check/nll.rs
index 2201abe4b92..ba1b322524e 100644
--- a/src/librustc_mir/borrow_check/nll.rs
+++ b/src/librustc_mir/borrow_check/nll.rs
@@ -86,15 +86,18 @@ fn populate_polonius_move_facts(
     body: &Body<'_>,
 ) {
     all_facts
-        .path_belongs_to_var
+        .path_is_var
         .extend(move_data.rev_lookup.iter_locals_enumerated().map(|(v, &m)| (m, v)));
 
     for (child, move_path) in move_data.move_paths.iter_enumerated() {
-        all_facts
-            .child
-            .extend(move_path.parents(&move_data.move_paths).map(|(parent, _)| (child, parent)));
+        if let Some(parent) = move_path.parent {
+            all_facts.child_path.push((child, parent));
+        }
     }
 
+    let fn_entry_start = location_table
+        .start_index(Location { block: BasicBlock::from_u32(0u32), statement_index: 0 });
+
     // initialized_at
     for init in move_data.inits.iter() {
         match init.location {
@@ -115,28 +118,37 @@ fn populate_polonius_move_facts(
                         // the successors, but not in the unwind block.
                         let first_statement = Location { block: successor, statement_index: 0 };
                         all_facts
-                            .initialized_at
+                            .path_assigned_at_base
                             .push((init.path, location_table.start_index(first_statement)));
                     }
                 } else {
                     // In all other cases, the initialization just happens at the
                     // midpoint, like any other effect.
-                    all_facts.initialized_at.push((init.path, location_table.mid_index(location)));
+                    all_facts
+                        .path_assigned_at_base
+                        .push((init.path, location_table.mid_index(location)));
                 }
             }
             // Arguments are initialized on function entry
             InitLocation::Argument(local) => {
                 assert!(body.local_kind(local) == LocalKind::Arg);
-                let fn_entry = Location { block: BasicBlock::from_u32(0u32), statement_index: 0 };
-                all_facts.initialized_at.push((init.path, location_table.start_index(fn_entry)));
+                all_facts.path_assigned_at_base.push((init.path, fn_entry_start));
             }
         }
     }
 
+    for (local, &path) in move_data.rev_lookup.iter_locals_enumerated() {
+        if body.local_kind(local) != LocalKind::Arg {
+            // Non-arguments start out deinitialised; we simulate this with an
+            // initial move:
+            all_facts.path_moved_at_base.push((path, fn_entry_start));
+        }
+    }
+
     // moved_out_at
     // deinitialisation is assumed to always happen!
     all_facts
-        .moved_out_at
+        .path_moved_at_base
         .extend(move_data.moves.iter().map(|mo| (mo.path, location_table.mid_index(mo.source))));
 }
 
diff --git a/src/librustc_mir/borrow_check/type_check/liveness/polonius.rs b/src/librustc_mir/borrow_check/type_check/liveness/polonius.rs
index 055415f2872..407e0628b6e 100644
--- a/src/librustc_mir/borrow_check/type_check/liveness/polonius.rs
+++ b/src/librustc_mir/borrow_check/type_check/liveness/polonius.rs
@@ -12,12 +12,12 @@ type VarPointRelation = Vec<(Local, LocationIndex)>;
 type PathPointRelation = Vec<(MovePathIndex, LocationIndex)>;
 
 struct UseFactsExtractor<'me> {
-    var_defined: &'me mut VarPointRelation,
-    var_used: &'me mut VarPointRelation,
+    var_defined_at: &'me mut VarPointRelation,
+    var_used_at: &'me mut VarPointRelation,
     location_table: &'me LocationTable,
-    var_drop_used: &'me mut Vec<(Local, Location)>,
+    var_dropped_at: &'me mut VarPointRelation,
     move_data: &'me MoveData<'me>,
-    path_accessed_at: &'me mut PathPointRelation,
+    path_accessed_at_base: &'me mut PathPointRelation,
 }
 
 // A Visitor to walk through the MIR and extract point-wise facts
@@ -28,22 +28,22 @@ impl UseFactsExtractor<'_> {
 
     fn insert_def(&mut self, local: Local, location: Location) {
         debug!("UseFactsExtractor::insert_def()");
-        self.var_defined.push((local, self.location_to_index(location)));
+        self.var_defined_at.push((local, self.location_to_index(location)));
     }
 
     fn insert_use(&mut self, local: Local, location: Location) {
         debug!("UseFactsExtractor::insert_use()");
-        self.var_used.push((local, self.location_to_index(location)));
+        self.var_used_at.push((local, self.location_to_index(location)));
     }
 
     fn insert_drop_use(&mut self, local: Local, location: Location) {
         debug!("UseFactsExtractor::insert_drop_use()");
-        self.var_drop_used.push((local, location));
+        self.var_dropped_at.push((local, self.location_to_index(location)));
     }
 
     fn insert_path_access(&mut self, path: MovePathIndex, location: Location) {
         debug!("UseFactsExtractor::insert_path_access({:?}, {:?})", path, location);
-        self.path_accessed_at.push((path, self.location_to_index(location)));
+        self.path_accessed_at_base.push((path, self.location_table.start_index(location)));
     }
 
     fn place_to_mpi(&self, place: &Place<'_>) -> Option<MovePathIndex> {
@@ -88,51 +88,54 @@ pub(super) fn populate_access_facts(
     body: ReadOnlyBodyAndCache<'_, 'tcx>,
     location_table: &LocationTable,
     move_data: &MoveData<'_>,
-    drop_used: &mut Vec<(Local, Location)>,
+    dropped_at: &mut Vec<(Local, Location)>,
 ) {
     debug!("populate_access_facts()");
 
     if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
         let mut extractor = UseFactsExtractor {
-            var_defined: &mut facts.var_defined,
-            var_used: &mut facts.var_used,
-            var_drop_used: drop_used,
-            path_accessed_at: &mut facts.path_accessed_at,
+            var_defined_at: &mut facts.var_defined_at,
+            var_used_at: &mut facts.var_used_at,
+            var_dropped_at: &mut facts.var_dropped_at,
+            path_accessed_at_base: &mut facts.path_accessed_at_base,
             location_table,
             move_data,
         };
         extractor.visit_body(body);
 
-        facts.var_drop_used.extend(
-            drop_used.iter().map(|&(local, location)| (local, location_table.mid_index(location))),
+        facts.var_dropped_at.extend(
+            dropped_at.iter().map(|&(local, location)| (local, location_table.mid_index(location))),
         );
 
         for (local, local_decl) in body.local_decls.iter_enumerated() {
-            debug!("add var_uses_regions facts - local={:?}, type={:?}", local, local_decl.ty);
+            debug!(
+                "add use_of_var_derefs_origin facts - local={:?}, type={:?}",
+                local, local_decl.ty
+            );
             let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
             let universal_regions = &typeck.borrowck_context.universal_regions;
             typeck.infcx.tcx.for_each_free_region(&local_decl.ty, |region| {
                 let region_vid = universal_regions.to_region_vid(region);
-                facts.var_uses_region.push((local, region_vid));
+                facts.use_of_var_derefs_origin.push((local, region_vid));
             });
         }
     }
 }
 
 // For every potentially drop()-touched region `region` in `local`'s type
-// (`kind`), emit a Polonius `var_drops_region(local, region)` fact.
-pub(super) fn add_var_drops_regions(
+// (`kind`), emit a Polonius `use_of_var_derefs_origin(local, origin)` fact.
+pub(super) fn add_drop_of_var_derefs_origin(
     typeck: &mut TypeChecker<'_, 'tcx>,
     local: Local,
     kind: &GenericArg<'tcx>,
 ) {
-    debug!("add_var_drops_region(local={:?}, kind={:?}", local, kind);
+    debug!("add_drop_of_var_derefs_origin(local={:?}, kind={:?}", local, kind);
     if let Some(facts) = typeck.borrowck_context.all_facts.as_mut() {
         let _prof_timer = typeck.infcx.tcx.prof.generic_activity("polonius_fact_generation");
         let universal_regions = &typeck.borrowck_context.universal_regions;
         typeck.infcx.tcx.for_each_free_region(kind, |drop_live_region| {
             let region_vid = universal_regions.to_region_vid(drop_live_region);
-            facts.var_drops_region.push((local, region_vid));
+            facts.drop_of_var_derefs_origin.push((local, region_vid));
         });
     }
 }
diff --git a/src/librustc_mir/borrow_check/type_check/liveness/trace.rs b/src/librustc_mir/borrow_check/type_check/liveness/trace.rs
index 4c8deb0ecf8..baa9d1d212e 100644
--- a/src/librustc_mir/borrow_check/type_check/liveness/trace.rs
+++ b/src/librustc_mir/borrow_check/type_check/liveness/trace.rs
@@ -484,7 +484,7 @@ impl LivenessContext<'_, '_, '_, 'tcx> {
         for &kind in &drop_data.dropck_result.kinds {
             Self::make_all_regions_live(self.elements, &mut self.typeck, kind, live_at);
 
-            polonius::add_var_drops_regions(&mut self.typeck, dropped_local, &kind);
+            polonius::add_drop_of_var_derefs_origin(&mut self.typeck, dropped_local, &kind);
         }
     }