about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLucas Molas <schomatis@gmail.com>2019-02-14 21:33:31 -0300
committerLucas Molas <schomatis@gmail.com>2019-02-15 20:54:46 -0300
commit200bc02a5e41e763175b5fa9eb97f27a472c777f (patch)
tree6fa9cbcb1f88721a35688bc5e48ae80f24a200d4
parenta9410cd1af7c1194fbda1457c74b8ab25547e1e6 (diff)
downloadrust-200bc02a5e41e763175b5fa9eb97f27a472c777f.tar.gz
rust-200bc02a5e41e763175b5fa9eb97f27a472c777f.zip
nll: remove `NllLivenessMap` from `LivenessContext`
It was used in `compute_for_all_locals` to iterate only the `Local`s that need
liveness analysis (filtered through `compute`). Instead, explicitly extract that
reduced set (as `live_locals`) in `trace` and pass it to
`compute_for_all_locals`.

Change the variable type used in `compute_for_all_locals` from `LiveVar` to
`Local` and do the same for its helper functions (and the functions in
`LocalUseMap` they rely on):

* `add_defs_for`                 -> `LocalUseMap::defs`
* `compute_use_live_points_for`  -> `LocalUseMap::uses`
* `compute_drop_live_points_for` -> `LocalUseMap::drops`

Push back the use of `LiveVar` to the `LocalUseMap` (where the other
`NllLivenessMap` remains embedded) functions which internally do the
`from_local` conversion.
-rw-r--r--src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs15
-rw-r--r--src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs44
2 files changed, 27 insertions, 32 deletions
diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs
index e9765d2798c..fccd633aaa1 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs
@@ -73,18 +73,21 @@ impl LocalUseMap<'me> {
         local_use_map
     }
 
-    crate fn defs(&self, local: LiveVar) -> impl Iterator<Item = PointIndex> + '_ {
-        vll::iter(self.first_def_at[local], &self.appearances)
+    crate fn defs(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
+        let live_var = self.liveness_map.from_local(local).unwrap();
+        vll::iter(self.first_def_at[live_var], &self.appearances)
             .map(move |aa| self.appearances[aa].point_index)
     }
 
-    crate fn uses(&self, local: LiveVar) -> impl Iterator<Item = PointIndex> + '_ {
-        vll::iter(self.first_use_at[local], &self.appearances)
+    crate fn uses(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
+        let live_var = self.liveness_map.from_local(local).unwrap();
+        vll::iter(self.first_use_at[live_var], &self.appearances)
             .map(move |aa| self.appearances[aa].point_index)
     }
 
-    crate fn drops(&self, local: LiveVar) -> impl Iterator<Item = PointIndex> + '_ {
-        vll::iter(self.first_drop_at[local], &self.appearances)
+    crate fn drops(&self, local: Local) -> impl Iterator<Item = PointIndex> + '_ {
+        let live_var = self.liveness_map.from_local(local).unwrap();
+        vll::iter(self.first_drop_at[live_var], &self.appearances)
             .map(move |aa| self.appearances[aa].point_index)
     }
 }
diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs
index 4a0b4b7c205..67dcf255f56 100644
--- a/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs
+++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/trace.rs
@@ -1,13 +1,12 @@
 use crate::borrow_check::location::LocationTable;
 use crate::borrow_check::nll::region_infer::values::{self, PointIndex, RegionValueElements};
-use crate::borrow_check::nll::type_check::liveness::liveness_map::{LiveVar, NllLivenessMap};
+use crate::borrow_check::nll::type_check::liveness::liveness_map::NllLivenessMap;
 use crate::borrow_check::nll::type_check::liveness::local_use_map::LocalUseMap;
 use crate::borrow_check::nll::type_check::NormalizeLocation;
 use crate::borrow_check::nll::type_check::TypeChecker;
 use crate::dataflow::move_paths::indexes::MovePathIndex;
 use crate::dataflow::move_paths::MoveData;
 use crate::dataflow::{FlowAtLocation, FlowsAtLocation, MaybeInitializedPlaces};
-use crate::util::liveness::LiveVariableMap;
 use rustc::infer::canonical::QueryRegionConstraint;
 use rustc::mir::{BasicBlock, ConstraintCategory, Local, Location, Mir};
 use rustc::traits::query::dropck_outlives::DropckOutlivesResult;
@@ -56,12 +55,12 @@ pub(super) fn trace(
         elements,
         local_use_map,
         move_data,
-        liveness_map,
         drop_data: FxHashMap::default(),
         location_table,
     };
 
-    LivenessResults::new(cx).compute_for_all_locals();
+    let live_locals: Vec<Local> = liveness_map.to_local.clone().into_iter().collect();
+    LivenessResults::new(cx).compute_for_all_locals(live_locals);
 }
 
 /// Contextual state for the type-liveness generator.
@@ -95,9 +94,6 @@ where
     /// dropped.
     local_use_map: &'me LocalUseMap<'me>,
 
-    /// Map tracking which variables need liveness computation.
-    liveness_map: &'me NllLivenessMap,
-
     /// Maps between a MIR Location and a LocationIndex
     location_table: &'me LocationTable,
 }
@@ -148,15 +144,12 @@ impl LivenessResults<'me, 'typeck, 'flow, 'gcx, 'tcx> {
         }
     }
 
-    fn compute_for_all_locals(&mut self) {
-        for live_local in self.cx.liveness_map.to_local.indices() {
-            let local = self.cx.liveness_map.from_live_var(live_local);
-            debug!("local={:?} live_local={:?}", local, live_local);
-
+    fn compute_for_all_locals(&mut self, live_locals: Vec<Local>) {
+        for local in live_locals {
             self.reset_local_state();
-            self.add_defs_for(live_local);
-            self.compute_use_live_points_for(live_local);
-            self.compute_drop_live_points_for(live_local);
+            self.add_defs_for(local);
+            self.compute_use_live_points_for(local);
+            self.compute_drop_live_points_for(local);
 
             let local_ty = self.cx.mir.local_decls[local].ty;
 
@@ -185,8 +178,8 @@ impl LivenessResults<'me, 'typeck, 'flow, 'gcx, 'tcx> {
     }
 
     /// Adds the definitions of `local` into `self.defs`.
-    fn add_defs_for(&mut self, live_local: LiveVar) {
-        for def in self.cx.local_use_map.defs(live_local) {
+    fn add_defs_for(&mut self, local: Local) {
+        for def in self.cx.local_use_map.defs(local) {
             debug!("- defined at {:?}", def);
             self.defs.insert(def);
         }
@@ -194,14 +187,14 @@ impl LivenessResults<'me, 'typeck, 'flow, 'gcx, 'tcx> {
 
     /// Computes all points where local is "use live" -- meaning its
     /// current value may be used later (except by a drop). This is
-    /// done by walking backwards from each use of `live_local` until we
+    /// done by walking backwards from each use of `local` until we
     /// find a `def` of local.
     ///
-    /// Requires `add_defs_for(live_local)` to have been executed.
-    fn compute_use_live_points_for(&mut self, live_local: LiveVar) {
-        debug!("compute_use_live_points_for(live_local={:?})", live_local);
+    /// Requires `add_defs_for(local)` to have been executed.
+    fn compute_use_live_points_for(&mut self, local: Local) {
+        debug!("compute_use_live_points_for(local={:?})", local);
 
-        self.stack.extend(self.cx.local_use_map.uses(live_local));
+        self.stack.extend(self.cx.local_use_map.uses(local));
         while let Some(p) = self.stack.pop() {
             if self.defs.contains(p) {
                 continue;
@@ -224,15 +217,14 @@ impl LivenessResults<'me, 'typeck, 'flow, 'gcx, 'tcx> {
     ///
     /// Requires `compute_use_live_points_for` and `add_defs_for` to
     /// have been executed.
-    fn compute_drop_live_points_for(&mut self, live_local: LiveVar) {
-        debug!("compute_drop_live_points_for(live_local={:?})", live_local);
+    fn compute_drop_live_points_for(&mut self, local: Local) {
+        debug!("compute_drop_live_points_for(local={:?})", local);
 
-        let local = self.cx.liveness_map.from_live_var(live_local);
         let mpi = self.cx.move_data.rev_lookup.find_local(local);
         debug!("compute_drop_live_points_for: mpi = {:?}", mpi);
 
         // Find the drops where `local` is initialized.
-        for drop_point in self.cx.local_use_map.drops(live_local) {
+        for drop_point in self.cx.local_use_map.drops(local) {
             let location = self.cx.elements.to_location(drop_point);
             debug_assert_eq!(self.cx.mir.terminator_loc(location.block), location,);