about summary refs log tree commit diff
diff options
context:
space:
mode:
authorvarkor <github@varkor.com>2019-03-25 21:28:15 +0000
committervarkor <github@varkor.com>2019-03-27 09:44:55 +0000
commit2d48ffa9c63255eafa25639142f3b5601d42ae05 (patch)
tree757570298fb0a6e6827dab1d70dd4d2ca4706064
parent58a04f06cb6522040af4d9352c3a25dd66547acc (diff)
downloadrust-2d48ffa9c63255eafa25639142f3b5601d42ae05.tar.gz
rust-2d48ffa9c63255eafa25639142f3b5601d42ae05.zip
Store type variable origins in InferenceFudger
-rw-r--r--src/librustc/infer/fudge.rs7
-rw-r--r--src/librustc/infer/type_variable.rs12
2 files changed, 13 insertions, 6 deletions
diff --git a/src/librustc/infer/fudge.rs b/src/librustc/infer/fudge.rs
index 18573b9ce17..4c603cb5455 100644
--- a/src/librustc/infer/fudge.rs
+++ b/src/librustc/infer/fudge.rs
@@ -3,8 +3,10 @@ use crate::ty::fold::{TypeFoldable, TypeFolder};
 
 use super::InferCtxt;
 use super::RegionVariableOrigin;
+use super::type_variable::TypeVariableOrigin;
 
 use std::ops::Range;
+use rustc_data_structures::fx::FxHashMap;
 
 impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
     /// This rather funky routine is used while processing expected
@@ -115,7 +117,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
 
 pub struct InferenceFudger<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
     infcx: &'a InferCtxt<'a, 'gcx, 'tcx>,
-    type_vars: Range<TyVid>,
+    type_vars: FxHashMap<TyVid, TypeVariableOrigin>,
     int_vars: Range<IntVid>,
     float_vars: Range<FloatVid>,
     region_vars: Range<RegionVid>,
@@ -130,10 +132,9 @@ impl<'a, 'gcx, 'tcx> TypeFolder<'gcx, 'tcx> for InferenceFudger<'a, 'gcx, 'tcx>
     fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
         match ty.sty {
             ty::Infer(ty::InferTy::TyVar(vid)) => {
-                if self.type_vars.contains(&vid) {
+                if let Some(&origin) = self.type_vars.get(&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
diff --git a/src/librustc/infer/type_variable.rs b/src/librustc/infer/type_variable.rs
index 5b9c3f25b20..cde695aefc1 100644
--- a/src/librustc/infer/type_variable.rs
+++ b/src/librustc/infer/type_variable.rs
@@ -4,8 +4,8 @@ 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;
 
@@ -291,9 +291,15 @@ impl<'tcx> TypeVariableTable<'tcx> {
     }
 
     /// Returns a range of the type variables created during the snapshot.
-    pub fn vars_since_snapshot(&mut self, s: &Snapshot<'tcx>) -> Range<TyVid> {
+    pub fn vars_since_snapshot(
+        &mut self,
+        s: &Snapshot<'tcx>,
+    ) -> FxHashMap<TyVid, TypeVariableOrigin> {
         let range = self.eq_relations.vars_since_snapshot(&s.eq_snapshot);
-        range.start.vid..range.end.vid
+        (range.start.vid.index..range.end.vid.index).map(|index| {
+            let origin = self.values.get(index as usize).origin.clone();
+            (TyVid { index }, origin)
+        }).collect()
     }
 
     /// Finds the set of type variables that existed *before* `s`