]> git.lizzy.rs Git - rust.git/commitdiff
replace `RegionIndex` with `RegionVid` (which now impls Idx)
authorNiko Matsakis <niko@alum.mit.edu>
Mon, 6 Nov 2017 09:15:38 +0000 (04:15 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Thu, 16 Nov 2017 10:57:45 +0000 (05:57 -0500)
src/librustc_mir/dataflow/impls/borrows.rs
src/librustc_mir/transform/nll/constraint_generation.rs
src/librustc_mir/transform/nll/free_regions.rs
src/librustc_mir/transform/nll/mod.rs
src/librustc_mir/transform/nll/region_infer.rs
src/librustc_mir/transform/nll/renumber.rs
src/librustc_mir/transform/nll/subtype.rs

index 928c07b7fbc05c2c37b712a2e632fe61b345f259..2e4dddc212b31cc051f2c1fed63008146cca239f 100644 (file)
@@ -22,7 +22,7 @@
 use dataflow::{BitDenotation, BlockSets, DataflowOperator};
 pub use dataflow::indexes::BorrowIndex;
 use transform::nll::region_infer::RegionInferenceContext;
-use transform::nll::ToRegionIndex;
+use transform::nll::ToRegionVid;
 
 use syntax_pos::Span;
 
@@ -145,7 +145,7 @@ fn kill_loans_out_of_scope_at_location(&self,
                                            location: Location) {
         if let Some(regioncx) = self.nonlexical_regioncx {
             for (borrow_index, borrow_data) in self.borrows.iter_enumerated() {
-                let borrow_region = borrow_data.region.to_region_index();
+                let borrow_region = borrow_data.region.to_region_vid();
                 if !regioncx.region_contains_point(borrow_region, location) {
                     // The region checker really considers the borrow
                     // to start at the point **after** the location of
index b095a198d8f03f34320d87398603e58eeb570f25..627bc7a8324529fa4438f5053fdb8de2ef537b49 100644 (file)
@@ -23,7 +23,7 @@
 
 use super::subtype;
 use super::LivenessResults;
-use super::ToRegionIndex;
+use super::ToRegionVid;
 use super::region_infer::RegionInferenceContext;
 
 pub(super) fn generate_constraints<'a, 'gcx, 'tcx>(
@@ -102,7 +102,7 @@ fn add_regular_live_constraint<T>(&mut self, live_ty: T, location: Location)
         self.infcx
             .tcx
             .for_each_free_region(&live_ty, |live_region| {
-                let vid = live_region.to_region_index();
+                let vid = live_region.to_region_vid();
                 self.regioncx.add_live_point(vid, location);
             });
     }
@@ -197,8 +197,8 @@ fn add_borrow_constraint(
         };
 
         self.regioncx.add_outlives(span,
-                                   borrow_region.to_region_index(),
-                                   destination_region.to_region_index(),
+                                   borrow_region.to_region_vid(),
+                                   destination_region.to_region_vid(),
                                    location.successor_within_block());
     }
 
@@ -227,8 +227,8 @@ fn add_reborrow_constraint(
 
                     let span = self.mir.source_info(location).span;
                     self.regioncx.add_outlives(span,
-                                               base_region.to_region_index(),
-                                               borrow_region.to_region_index(),
+                                               base_region.to_region_vid(),
+                                               borrow_region.to_region_vid(),
                                                location.successor_within_block());
                 }
             }
index 36c14b55568fd38173245b0a8b2860e0b12c1aa5..101fed3cfa631463d478e0bb4b122f0f9dc36086 100644 (file)
 use rustc::hir::def_id::DefId;
 use rustc::infer::InferCtxt;
 use rustc::middle::free_region::FreeRegionMap;
-use rustc::ty;
+use rustc::ty::{self, RegionVid};
 use rustc::ty::subst::Substs;
 use rustc::util::nodemap::FxHashMap;
 use rustc_data_structures::indexed_vec::Idx;
 
-use super::RegionIndex;
-
 #[derive(Debug)]
 pub struct FreeRegions<'tcx> {
     /// Given a free region defined on this function (either early- or
     /// late-bound), this maps it to its internal region index. When
     /// the region context is created, the first N variables will be
     /// created based on these indices.
-    pub indices: FxHashMap<ty::Region<'tcx>, RegionIndex>,
+    pub indices: FxHashMap<ty::Region<'tcx>, RegionVid>,
 
     /// The map from the typeck tables telling us how to relate free regions.
     pub free_region_map: &'tcx FreeRegionMap<'tcx>,
@@ -81,9 +79,9 @@ pub fn free_regions<'a, 'gcx, 'tcx>(
 }
 
 fn insert_free_region<'tcx>(
-    free_regions: &mut FxHashMap<ty::Region<'tcx>, RegionIndex>,
+    free_regions: &mut FxHashMap<ty::Region<'tcx>, RegionVid>,
     region: ty::Region<'tcx>,
 ) {
-    let next = RegionIndex::new(free_regions.len());
+    let next = RegionVid::new(free_regions.len());
     free_regions.entry(region).or_insert(next);
 }
index f27d0a8da16ccfcd8b6d6326356477aee04ad2dd..f3e24e925890da97dff02992734e44d86e0d924a 100644 (file)
@@ -11,9 +11,8 @@
 use rustc::hir::def_id::DefId;
 use rustc::mir::Mir;
 use rustc::infer::InferCtxt;
-use rustc::ty::{self, RegionKind};
+use rustc::ty::{self, RegionKind, RegionVid};
 use rustc::util::nodemap::FxHashMap;
-use rustc_data_structures::indexed_vec::Idx;
 use std::collections::BTreeSet;
 use transform::MirSource;
 use util::liveness::{self, LivenessMode, LivenessResult, LocalSet};
@@ -152,23 +151,19 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
     });
 }
 
-newtype_index!(RegionIndex {
-    DEBUG_FORMAT = "'_#{}r",
-});
-
 /// Right now, we piggy back on the `ReVar` to store our NLL inference
-/// regions. These are indexed with `RegionIndex`. This method will
-/// assert that the region is a `ReVar` and convert the internal index
-/// into a `RegionIndex`. This is reasonable because in our MIR we
-/// replace all free regions with inference variables.
-pub trait ToRegionIndex {
-    fn to_region_index(&self) -> RegionIndex;
+/// regions. These are indexed with `RegionVid`. This method will
+/// assert that the region is a `ReVar` and extract its interal index.
+/// This is reasonable because in our MIR we replace all free regions
+/// with inference variables.
+pub trait ToRegionVid {
+    fn to_region_vid(&self) -> RegionVid;
 }
 
-impl ToRegionIndex for RegionKind {
-    fn to_region_index(&self) -> RegionIndex {
+impl ToRegionVid for RegionKind {
+    fn to_region_vid(&self) -> RegionVid {
         if let &ty::ReVar(vid) = self {
-            RegionIndex::new(vid.index as usize)
+            vid
         } else {
             bug!("region is not an ReVar: {:?}", self)
         }
index f5731255449eca6b1a05e890fc363c01e5f30c0b..add48a9600a510059e30eef8a3d53836b6211e7e 100644 (file)
@@ -8,11 +8,10 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use super::RegionIndex;
 use super::free_regions::FreeRegions;
 use rustc::infer::InferCtxt;
 use rustc::mir::{Location, Mir};
-use rustc::ty;
+use rustc::ty::{self, RegionVid};
 use rustc_data_structures::indexed_vec::IndexVec;
 use rustc_data_structures::fx::FxHashSet;
 use std::collections::BTreeSet;
 
 pub struct RegionInferenceContext<'tcx> {
     /// Contains the definition for every region variable.  Region
-    /// variables are identified by their index (`RegionIndex`). The
+    /// variables are identified by their index (`RegionVid`). The
     /// definition contains information about where the region came
     /// from as well as its final inferred value.
-    definitions: IndexVec<RegionIndex, RegionDefinition<'tcx>>,
+    definitions: IndexVec<RegionVid, RegionDefinition<'tcx>>,
 
     /// The indices of all "free regions" in scope. These are the
     /// lifetime parameters (anonymous and named) declared in the
@@ -35,7 +34,7 @@ pub struct RegionInferenceContext<'tcx> {
     ///
     /// These indices will be from 0..N, as it happens, but we collect
     /// them into a vector for convenience.
-    free_regions: Vec<RegionIndex>,
+    free_regions: Vec<RegionVid>,
 
     /// The constraints we have accumulated and used during solving.
     constraints: Vec<Constraint>,
@@ -66,7 +65,7 @@ struct RegionDefinition<'tcx> {
 #[derive(Clone, Default, PartialEq, Eq)]
 struct Region {
     points: BTreeSet<Location>,
-    free_regions: BTreeSet<RegionIndex>,
+    free_regions: BTreeSet<RegionVid>,
 }
 
 impl fmt::Debug for Region {
@@ -84,7 +83,7 @@ fn add_point(&mut self, point: Location) -> bool {
         self.points.insert(point)
     }
 
-    fn add_free_region(&mut self, region: RegionIndex) -> bool {
+    fn add_free_region(&mut self, region: RegionVid) -> bool {
         self.free_regions.insert(region)
     }
 
@@ -99,10 +98,10 @@ pub struct Constraint {
     span: Span,
 
     /// The region SUP must outlive SUB...
-    sup: RegionIndex,
+    sup: RegionVid,
 
     /// Region that must be outlived.
-    sub: RegionIndex,
+    sub: RegionVid,
 
     /// At this location.
     point: Location,
@@ -198,24 +197,24 @@ fn init_free_regions(&mut self, free_regions: &FreeRegions<'tcx>, mir: &Mir<'tcx
     }
 
     /// Returns an iterator over all the region indices.
-    pub fn regions(&self) -> impl Iterator<Item = RegionIndex> {
+    pub fn regions(&self) -> impl Iterator<Item = RegionVid> {
         self.definitions.indices()
     }
 
     /// Returns true if the region `r` contains the point `p`.
     ///
     /// Until `solve()` executes, this value is not particularly meaningful.
-    pub fn region_contains_point(&self, r: RegionIndex, p: Location) -> bool {
+    pub fn region_contains_point(&self, r: RegionVid, p: Location) -> bool {
         self.definitions[r].value.contains_point(p)
     }
 
     /// Returns access to the value of `r` for debugging purposes.
-    pub(super) fn region_value(&self, r: RegionIndex) -> &fmt::Debug {
+    pub(super) fn region_value(&self, r: RegionVid) -> &fmt::Debug {
         &self.definitions[r].value
     }
 
     /// Indicates that the region variable `v` is live at the point `point`.
-    pub(super) fn add_live_point(&mut self, v: RegionIndex, point: Location) {
+    pub(super) fn add_live_point(&mut self, v: RegionVid, point: Location) {
         debug!("add_live_point({:?}, {:?})", v, point);
         let definition = &mut self.definitions[v];
         if !definition.constant {
@@ -231,8 +230,8 @@ pub(super) fn add_live_point(&mut self, v: RegionIndex, point: Location) {
     pub(super) fn add_outlives(
         &mut self,
         span: Span,
-        sup: RegionIndex,
-        sub: RegionIndex,
+        sup: RegionVid,
+        sub: RegionVid,
         point: Location,
     ) {
         debug!("add_outlives({:?}: {:?} @ {:?}", sup, sub, point);
@@ -268,7 +267,7 @@ pub(super) fn solve(&mut self, infcx: &InferCtxt<'a, 'gcx, 'tcx>, mir: &Mir<'tcx
     fn propagate_constraints(
         &mut self,
         mir: &Mir<'tcx>,
-    ) -> Vec<(RegionIndex, Span, RegionIndex)> {
+    ) -> Vec<(RegionVid, Span, RegionVid)> {
         let mut changed = true;
         let mut dfs = Dfs::new(mir);
         let mut error_regions = FxHashSet();
index c0d6e0cbe657b58dc7c1046ee046c9507ff02a13..7cdcb106c8c246ff8b073d8e3a7586a7ffd103f6 100644 (file)
@@ -17,7 +17,6 @@
 use syntax_pos::DUMMY_SP;
 use std::collections::HashMap;
 
-use super::RegionIndex;
 use super::free_regions::FreeRegions;
 
 /// Replaces all free regions appearing in the MIR with fresh
@@ -52,7 +51,7 @@ struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
     num_region_variables: usize,
     infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
     free_regions: &'a FreeRegions<'tcx>,
-    free_region_inference_vars: IndexVec<RegionIndex, ty::Region<'tcx>>,
+    free_region_inference_vars: IndexVec<RegionVid, ty::Region<'tcx>>,
     arg_count: usize,
 }
 
index 953fc0eb733c2187159a690fde5025f9b7dfe5c7..bb41477dcbf9e579892e9a19d2b8a3c5a2da4834 100644 (file)
@@ -8,15 +8,14 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use super::RegionIndex;
-use transform::nll::ToRegionIndex;
-use rustc::ty::{self, Ty, TyCtxt};
+use transform::nll::ToRegionVid;
+use rustc::ty::{self, Ty, TyCtxt, RegionVid};
 use rustc::ty::relate::{self, Relate, RelateResult, TypeRelation};
 
 pub fn outlives_pairs<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
                       a: Ty<'tcx>,
                       b: Ty<'tcx>)
-                      -> Vec<(RegionIndex, RegionIndex)>
+                      -> Vec<(RegionVid, RegionVid)>
 {
     let mut subtype = Subtype::new(tcx);
     match subtype.relate(&a, &b) {
@@ -28,7 +27,7 @@ pub fn outlives_pairs<'a, 'gcx, 'tcx>(tcx: TyCtxt<'a, 'gcx, 'tcx>,
 
 struct Subtype<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
     tcx: TyCtxt<'a, 'gcx, 'tcx>,
-    outlives_pairs: Vec<(RegionIndex, RegionIndex)>,
+    outlives_pairs: Vec<(RegionVid, RegionVid)>,
     ambient_variance: ty::Variance,
 }
 
@@ -67,8 +66,8 @@ fn tys(&mut self, t: Ty<'tcx>, t2: Ty<'tcx>) -> RelateResult<'tcx, Ty<'tcx>> {
 
     fn regions(&mut self, r_a: ty::Region<'tcx>, r_b: ty::Region<'tcx>)
                -> RelateResult<'tcx, ty::Region<'tcx>> {
-        let a = r_a.to_region_index();
-        let b = r_b.to_region_index();
+        let a = r_a.to_region_vid();
+        let b = r_b.to_region_vid();
 
         match self.ambient_variance {
             ty::Covariant => {