]> git.lizzy.rs Git - rust.git/commitdiff
Use Ranges for vars_since_snapshot
authorvarkor <github@varkor.com>
Thu, 21 Mar 2019 12:37:31 +0000 (12:37 +0000)
committervarkor <github@varkor.com>
Wed, 27 Mar 2019 09:44:55 +0000 (09:44 +0000)
src/librustc/infer/fudge.rs
src/librustc/infer/region_constraints/mod.rs
src/librustc/infer/type_variable.rs
src/librustc/lib.rs

index 4dc4341d4c88c7f9c87055c03a8d478741ff78f0..d8107e64d28b03ace3fffa250e0410065f7fd0d1 100644 (file)
@@ -1,10 +1,11 @@
-use crate::infer::type_variable::TypeVariableMap;
-use crate::ty::{self, Ty, TyCtxt};
+use crate::ty::{self, Ty, TyCtxt, TyVid, RegionVid};
 use crate::ty::fold::{TypeFoldable, TypeFolder};
 
 use super::InferCtxt;
 use super::RegionVariableOrigin;
 
+use std::ops::Range;
+
 impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
     /// This rather funky routine is used while processing expected
     /// types. What happens here is that we want to propagate a
@@ -42,12 +43,14 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
     /// regions in question are not particularly important. We will
     /// use the expected types to guide coercions, but we will still
     /// type-check the resulting types from those coercions against
-    /// the actual types (`?T`, `Option<?T`) -- and remember that
+    /// the actual types (`?T`, `Option<?T>`) -- and remember that
     /// after the snapshot is popped, the variable `?T` is no longer
     /// unified.
-    pub fn fudge_regions_if_ok<T, E, F>(&self,
-                                        origin: &RegionVariableOrigin,
-                                        f: F) -> Result<T, E> where
+    pub fn fudge_regions_if_ok<T, E, F>(
+        &self,
+        origin: &RegionVariableOrigin,
+        f: F,
+    ) -> Result<T, E> where
         F: FnOnce() -> Result<T, E>,
         T: TypeFoldable<'tcx>,
     {
@@ -101,8 +104,8 @@ pub fn fudge_regions_if_ok<T, E, F>(&self,
 
 pub struct RegionFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
     infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
-    type_variables: &'a TypeVariableMap,
-    region_vars: &'a Vec<ty::RegionVid>,
+    type_variables: &'a Range<TyVid>,
+    region_vars: &'a Range<RegionVid>,
     origin: &'a RegionVariableOrigin,
 }
 
@@ -114,25 +117,21 @@ fn tcx<'b>(&'b self) -> TyCtxt<'b, 'gcx, 'tcx> {
     fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
         match ty.sty {
             ty::Infer(ty::InferTy::TyVar(vid)) => {
-                match self.type_variables.get(&vid) {
-                    None => {
-                        // This variable was created before the
-                        // "fudging".  Since we refresh all type
-                        // variables to their binding anyhow, we know
-                        // that it is unbound, so we can just return
-                        // it.
-                        debug_assert!(self.infcx.type_variables.borrow_mut()
-                                      .probe(vid)
-                                      .is_unknown());
-                        ty
-                    }
-
-                    Some(&origin) => {
-                        // This variable was created during the
-                        // fudging. Recreate it with a fresh variable
-                        // here.
-                        self.infcx.next_ty_var(origin)
-                    }
+                if self.type_variables.contains(&vid) {
+                    // This variable was created during the fudging.
+                    // Recreate it with a fresh variable here.
+                    let origin = self.infcx.type_variables.borrow().var_origin(vid).clone();
+                    self.infcx.next_ty_var(origin)
+                } else {
+                    // This variable was created before the
+                    // "fudging".  Since we refresh all type
+                    // variables to their binding anyhow, we know
+                    // that it is unbound, so we can just return
+                    // it.
+                    debug_assert!(self.infcx.type_variables.borrow_mut()
+                                  .probe(vid)
+                                  .is_unknown());
+                    ty
                 }
             }
             _ => ty.super_fold_with(self),
@@ -141,12 +140,10 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
 
     fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
         match *r {
-            ty::ReVar(v) if self.region_vars.contains(&v) => {
+            ty::ReVar(vid) if self.region_vars.contains(&vid) => {
                 self.infcx.next_region_var(self.origin.clone())
             }
-            _ => {
-                r
-            }
+            _ => r,
         }
     }
 }
index c0d118eed86ab4512571ae48080c64bbc8588a19..51d8a0edc81d3fcca4250f7b9234b843758cadf7 100644 (file)
@@ -16,6 +16,7 @@
 
 use std::collections::BTreeMap;
 use std::{cmp, fmt, mem, u32};
+use std::ops::Range;
 
 mod leak_check;
 
@@ -840,8 +841,8 @@ pub fn universe(&self, region: Region<'tcx>) -> ty::UniverseIndex {
         }
     }
 
-    pub fn vars_since_snapshot(&self, mark: &RegionSnapshot) -> Vec<RegionVid> {
-        self.unification_table.vars_since_snapshot(&mark.region_snapshot).collect()
+    pub fn vars_since_snapshot(&self, mark: &RegionSnapshot) -> Range<RegionVid> {
+        self.unification_table.vars_since_snapshot(&mark.region_snapshot)
     }
 
     /// See [`RegionInference::region_constraints_added_in_snapshot`].
index 422dd24eb0b45e13db6c1f87e9b379292eb6eaa6..a5b2e591f91bbdefb40bd13443a752a4e4cca50a 100644 (file)
@@ -1,13 +1,15 @@
 use syntax::symbol::InternedString;
 use syntax_pos::Span;
-use crate::ty::{self, Ty};
+use crate::ty::{self, Ty, TyVid};
 
 use std::cmp;
 use std::marker::PhantomData;
+use std::ops::Range;
 use std::u32;
 use rustc_data_structures::fx::FxHashMap;
 use rustc_data_structures::snapshot_vec as sv;
 use rustc_data_structures::unify as ut;
+use ut::UnifyKey;
 
 pub struct TypeVariableTable<'tcx> {
     values: sv::SnapshotVec<Delegate>,
@@ -294,11 +296,9 @@ pub fn commit(&mut self, s: Snapshot<'tcx>) {
 
     /// Returns a map from the type variables created during the
     /// snapshot to the origin of the type variable.
-    pub fn vars_since_snapshot(&mut self, s: &Snapshot<'tcx>) -> TypeVariableMap {
-        self.values.values_since_snapshot(&s.snapshot).map(|idx| {
-            let origin = self.values.get(idx).origin.clone();
-            (ty::TyVid { index: idx as u32 }, origin)
-        }).collect()
+    pub fn vars_since_snapshot(&mut self, s: &Snapshot<'tcx>) -> Range<TyVid> {
+        let range = self.values.values_since_snapshot(&s.snapshot);
+        TyVid::from_index(range.start as u32)..TyVid::from_index(range.end as u32)
     }
 
     /// Finds the set of type variables that existed *before* `s`
index 4b2fda3b02f9d140db5ffef84d2935c2cf8fae35..e905c3688518bd21e0c0b207d3ffff530bd0fa68 100644 (file)
@@ -44,6 +44,7 @@
 #![feature(non_exhaustive)]
 #![feature(proc_macro_internals)]
 #![feature(optin_builtin_traits)]
+#![feature(range_is_empty)]
 #![feature(refcell_replace_swap)]
 #![feature(rustc_diagnostic_macros)]
 #![feature(rustc_attrs)]