]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/borrow_check/nll/type_check/liveness.rs
make liveness generic over set of local variables
[rust.git] / src / librustc_mir / borrow_check / nll / type_check / liveness.rs
index f27de92c6215a9eecdb7bfafd7fb07ef7588efac..0eb88b7bcbfd390d2ca8009f1fd5353c23bb43fd 100644 (file)
@@ -8,7 +8,6 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use borrow_check::nll::region_infer::Cause;
 use borrow_check::nll::type_check::AtLocation;
 use dataflow::move_paths::{HasMoveData, MoveData};
 use dataflow::MaybeInitializedPlaces;
@@ -22,7 +21,7 @@
 use rustc::ty::{Ty, TypeFoldable};
 use rustc_data_structures::fx::FxHashMap;
 use std::rc::Rc;
-use util::liveness::LivenessResults;
+use util::liveness::{IdentityMap, LivenessResults};
 
 use super::TypeChecker;
 
@@ -37,7 +36,7 @@
 pub(super) fn generate<'gcx, 'tcx>(
     cx: &mut TypeChecker<'_, 'gcx, 'tcx>,
     mir: &Mir<'tcx>,
-    liveness: &LivenessResults,
+    liveness: &LivenessResults<Local>,
     flow_inits: &mut FlowAtLocation<MaybeInitializedPlaces<'_, 'gcx, 'tcx>>,
     move_data: &MoveData<'tcx>,
 ) {
@@ -48,6 +47,7 @@ pub(super) fn generate<'gcx, 'tcx>(
         flow_inits,
         move_data,
         drop_data: FxHashMap(),
+        map: &IdentityMap::new(mir),
     };
 
     for bb in mir.basic_blocks().indices() {
@@ -64,10 +64,11 @@ struct TypeLivenessGenerator<'gen, 'typeck, 'flow, 'gcx, 'tcx>
 {
     cx: &'gen mut TypeChecker<'typeck, 'gcx, 'tcx>,
     mir: &'gen Mir<'tcx>,
-    liveness: &'gen LivenessResults,
+    liveness: &'gen LivenessResults<Local>,
     flow_inits: &'gen mut FlowAtLocation<MaybeInitializedPlaces<'flow, 'gcx, 'tcx>>,
     move_data: &'gen MoveData<'tcx>,
     drop_data: FxHashMap<Ty<'tcx>, DropData<'tcx>>,
+    map: &'gen IdentityMap<'gen, 'tcx>,
 }
 
 struct DropData<'tcx> {
@@ -85,18 +86,17 @@ fn add_liveness_constraints(&mut self, bb: BasicBlock) {
 
         self.liveness
             .regular
-            .simulate_block(self.mir, bb, |location, live_locals| {
+            .simulate_block(self.mir, bb, self.map, |location, live_locals| {
                 for live_local in live_locals.iter() {
                     let live_local_ty = self.mir.local_decls[live_local].ty;
-                    let cause = Cause::LiveVar(live_local, location);
-                    Self::push_type_live_constraint(&mut self.cx, live_local_ty, location, cause);
+                    Self::push_type_live_constraint(&mut self.cx, live_local_ty, location);
                 }
             });
 
         let mut all_live_locals: Vec<(Location, Vec<Local>)> = vec![];
         self.liveness
             .drop
-            .simulate_block(self.mir, bb, |location, live_locals| {
+            .simulate_block(self.mir, bb, self.map, |location, live_locals| {
                 all_live_locals.push((location, live_locals.iter().collect()));
             });
         debug!(
@@ -161,7 +161,6 @@ fn push_type_live_constraint<T>(
         cx: &mut TypeChecker<'_, 'gcx, 'tcx>,
         value: T,
         location: Location,
-        cause: Cause,
     ) where
         T: TypeFoldable<'tcx>,
     {
@@ -171,9 +170,18 @@ fn push_type_live_constraint<T>(
         );
 
         cx.tcx().for_each_free_region(&value, |live_region| {
-            cx.constraints
-                .liveness_set
-                .push((live_region, location, cause.clone()));
+            if let Some(ref mut borrowck_context) = cx.borrowck_context {
+                let region_vid = borrowck_context.universal_regions.to_region_vid(live_region);
+                borrowck_context.constraints.liveness_constraints.add_element(region_vid, location);
+
+                if let Some(all_facts) = borrowck_context.all_facts {
+                    let start_index = borrowck_context.location_table.start_index(location);
+                    all_facts.region_live_at.push((region_vid, start_index));
+
+                    let mid_index = borrowck_context.location_table.mid_index(location);
+                    all_facts.region_live_at.push((region_vid, mid_index));
+                }
+            }
         });
     }
 
@@ -199,7 +207,7 @@ fn add_drop_live_constraint(
         });
 
         if let Some(data) = &drop_data.region_constraint_data {
-            self.cx.push_region_constraints(location.at_self(), data);
+            self.cx.push_region_constraints(location.boring(), data);
         }
 
         drop_data.dropck_result.report_overflows(
@@ -210,9 +218,8 @@ fn add_drop_live_constraint(
 
         // All things in the `outlives` array may be touched by
         // the destructor and must be live at this point.
-        let cause = Cause::DropVar(dropped_local, location);
         for &kind in &drop_data.dropck_result.kinds {
-            Self::push_type_live_constraint(&mut self.cx, kind, location, cause);
+            Self::push_type_live_constraint(&mut self.cx, kind, location);
         }
     }