]> git.lizzy.rs Git - rust.git/commitdiff
Wrap `InferCtxt::universe` in a cell
authorSean Griffin <sean@seantheprogrammer.com>
Thu, 8 Feb 2018 20:14:24 +0000 (13:14 -0700)
committerSean Griffin <sean@seantheprogrammer.com>
Wed, 2 May 2018 14:36:07 +0000 (08:36 -0600)
We'll need this in order to start tracking skolemizatoins here, and it's
easier to update all the field accesses now rather than later.

src/librustc/infer/mod.rs

index e40282aea089ed9cf3a7743e584b973e59b8e546..e5311ccfb7d63f96d72ed82e8b8b2b69b94f6777 100644 (file)
@@ -193,7 +193,7 @@ pub struct InferCtxt<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
     /// part of the root universe. So this would only get incremented
     /// when we enter into a higher-ranked (`for<..>`) type or trait
     /// bound.
-    pub universe: ty::UniverseIndex,
+    universe: Cell<ty::UniverseIndex>,
 }
 
 /// A map returned by `skolemize_late_bound_regions()` indicating the skolemized
@@ -466,7 +466,7 @@ pub fn enter<F, R>(&'tcx mut self, f: F) -> R
             err_count_on_creation: tcx.sess.err_count(),
             in_snapshot: Cell::new(false),
             region_obligations: RefCell::new(vec![]),
-            universe: ty::UniverseIndex::ROOT,
+            universe: Cell::new(ty::UniverseIndex::ROOT),
         }))
     }
 }
@@ -853,7 +853,7 @@ pub fn region_outlives_predicate(&self,
     pub fn next_ty_var_id(&self, diverging: bool, origin: TypeVariableOrigin) -> TyVid {
         self.type_variables
             .borrow_mut()
-            .new_var(self.universe, diverging, origin)
+            .new_var(self.universe(), diverging, origin)
     }
 
     pub fn next_ty_var(&self, origin: TypeVariableOrigin) -> Ty<'tcx> {
@@ -885,7 +885,7 @@ pub fn next_float_var_id(&self) -> FloatVid {
     pub fn next_region_var(&self, origin: RegionVariableOrigin)
                            -> ty::Region<'tcx> {
         let region_var = self.borrow_region_constraints()
-            .new_region_var(self.universe, origin);
+            .new_region_var(self.universe(), origin);
         self.tcx.mk_region(ty::ReVar(region_var))
     }
 
@@ -923,7 +923,7 @@ pub fn type_var_for_def(&self,
                             -> Ty<'tcx> {
         let ty_var_id = self.type_variables
                             .borrow_mut()
-                            .new_var(self.universe,
+                            .new_var(self.universe(),
                                      false,
                                      TypeVariableOrigin::TypeParameterDefinition(span, def.name));
 
@@ -1371,6 +1371,10 @@ pub fn clear_caches(&self) {
         self.evaluation_cache.clear();
         self.projection_cache.borrow_mut().clear();
     }
+
+    fn universe(&self) -> ty::UniverseIndex {
+        self.universe.get()
+    }
 }
 
 impl<'a, 'gcx, 'tcx> TypeTrace<'tcx> {