]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_infer/infer/mod.rs
Fix review comments
[rust.git] / src / librustc_infer / infer / mod.rs
index 1210d561311621afd560586d5490d3e2edcab06e..67d330ac89255ac576de1e9dd37609d317a46d35 100644 (file)
@@ -13,7 +13,7 @@
 use rustc_ast::ast;
 use rustc_data_structures::fx::{FxHashMap, FxHashSet};
 use rustc_data_structures::sync::Lrc;
-use rustc_data_structures::undo_log::{Rollback, Snapshots};
+use rustc_data_structures::undo_log::Rollback;
 use rustc_data_structures::unify as ut;
 use rustc_errors::DiagnosticBuilder;
 use rustc_hir as hir;
@@ -151,16 +151,16 @@ pub struct InferCtxtInner<'tcx> {
     /// We instantiate `UnificationTable` with `bounds<Ty>` because the types
     /// that might instantiate a general type variable have an order,
     /// represented by its upper and lower bounds.
-    type_variables: type_variable::TypeVariableStorage<'tcx>,
+    type_variable_storage: type_variable::TypeVariableStorage<'tcx>,
 
     /// Map from const parameter variable to the kind of const it represents.
-    const_unification_table: ut::UnificationTableStorage<ty::ConstVid<'tcx>>,
+    const_unification_storage: ut::UnificationTableStorage<ty::ConstVid<'tcx>>,
 
     /// Map from integral variable to the kind of integer it represents.
-    int_unification_table: ut::UnificationTableStorage<ty::IntVid>,
+    int_unification_storage: ut::UnificationTableStorage<ty::IntVid>,
 
     /// Map from floating variable to the kind of float it represents.
-    float_unification_table: ut::UnificationTableStorage<ty::FloatVid>,
+    float_unification_storage: ut::UnificationTableStorage<ty::FloatVid>,
 
     /// Tracks the set of region variables and the constraints between them.
     /// This is initially `Some(_)` but when
@@ -209,11 +209,11 @@ impl<'tcx> InferCtxtInner<'tcx> {
     fn new() -> InferCtxtInner<'tcx> {
         InferCtxtInner {
             projection_cache: Default::default(),
-            type_variables: type_variable::TypeVariableStorage::new(),
+            type_variable_storage: type_variable::TypeVariableStorage::new(),
             undo_log: InferCtxtUndoLogs::default(),
-            const_unification_table: ut::UnificationTableStorage::new(),
-            int_unification_table: ut::UnificationTableStorage::new(),
-            float_unification_table: ut::UnificationTableStorage::new(),
+            const_unification_storage: ut::UnificationTableStorage::new(),
+            int_unification_storage: ut::UnificationTableStorage::new(),
+            float_unification_storage: ut::UnificationTableStorage::new(),
             region_constraints: Some(RegionConstraintStorage::new()),
             region_obligations: vec![],
         }
@@ -223,12 +223,12 @@ pub fn region_obligations(&self) -> &[(hir::HirId, RegionObligation<'tcx>)] {
         &self.region_obligations
     }
 
-    pub(crate) fn projection_cache(&mut self) -> traits::ProjectionCache<'tcx, '_> {
+    pub fn projection_cache(&mut self) -> traits::ProjectionCache<'_, 'tcx> {
         self.projection_cache.with_log(&mut self.undo_log)
     }
 
-    fn type_variables(&mut self) -> type_variable::TypeVariableTable<'tcx, '_> {
-        self.type_variables.with_log(&mut self.undo_log)
+    fn type_variables(&mut self) -> type_variable::TypeVariableTable<'_, 'tcx> {
+        self.type_variable_storage.with_log(&mut self.undo_log)
     }
 
     fn int_unification_table(
@@ -240,7 +240,7 @@ fn int_unification_table(
             &mut InferCtxtUndoLogs<'tcx>,
         >,
     > {
-        self.int_unification_table.with_log(&mut self.undo_log)
+        self.int_unification_storage.with_log(&mut self.undo_log)
     }
 
     fn float_unification_table(
@@ -252,7 +252,7 @@ fn float_unification_table(
             &mut InferCtxtUndoLogs<'tcx>,
         >,
     > {
-        self.float_unification_table.with_log(&mut self.undo_log)
+        self.float_unification_storage.with_log(&mut self.undo_log)
     }
 
     fn const_unification_table(
@@ -264,7 +264,7 @@ fn const_unification_table(
             &mut InferCtxtUndoLogs<'tcx>,
         >,
     > {
-        self.const_unification_table.with_log(&mut self.undo_log)
+        self.const_unification_storage.with_log(&mut self.undo_log)
     }
 
     pub fn unwrap_region_constraints(&mut self) -> RegionConstraintCollector<'tcx, '_> {
@@ -868,29 +868,7 @@ fn rollback_to(&self, cause: &str, snapshot: CombinedSnapshot<'a, 'tcx>) {
         self.in_snapshot.set(was_in_snapshot);
         self.universe.set(universe);
 
-        let InferCtxtInner {
-            type_variables,
-            const_unification_table,
-            int_unification_table,
-            float_unification_table,
-            region_constraints,
-            projection_cache,
-            region_obligations,
-            undo_log,
-            ..
-        } = &mut *self.inner.borrow_mut();
-        undo_log.rollback_to(
-            || undo_log::RollbackView {
-                type_variables,
-                const_unification_table,
-                int_unification_table,
-                float_unification_table,
-                region_constraints: region_constraints.as_mut().unwrap(),
-                projection_cache,
-                region_obligations,
-            },
-            undo_snapshot,
-        );
+        self.inner.borrow_mut().rollback_to(undo_snapshot);
     }
 
     fn commit_from(&self, snapshot: CombinedSnapshot<'a, 'tcx>) {
@@ -900,8 +878,7 @@ fn commit_from(&self, snapshot: CombinedSnapshot<'a, 'tcx>) {
 
         self.in_snapshot.set(was_in_snapshot);
 
-        let mut inner = self.inner.borrow_mut();
-        inner.undo_log.commit(undo_snapshot);
+        self.inner.borrow_mut().commit(undo_snapshot);
     }
 
     /// Executes `f` and commit the bindings.
@@ -1308,19 +1285,21 @@ pub fn resolve_regions_and_report_errors(
         outlives_env: &OutlivesEnvironment<'tcx>,
         mode: RegionckMode,
     ) {
-        assert!(
-            self.is_tainted_by_errors() || self.inner.borrow().region_obligations.is_empty(),
-            "region_obligations not empty: {:#?}",
-            self.inner.borrow().region_obligations
-        );
-        let (var_infos, data) = self
-            .inner
-            .borrow_mut()
-            .region_constraints
-            .take()
-            .expect("regions already resolved")
-            .with_log(&mut inner.undo_log)
-            .into_infos_and_data();
+        let (var_infos, data) = {
+            let mut inner = self.inner.borrow_mut();
+            let inner = &mut *inner;
+            assert!(
+                self.is_tainted_by_errors() || inner.region_obligations.is_empty(),
+                "region_obligations not empty: {:#?}",
+                inner.region_obligations
+            );
+            inner
+                .region_constraints
+                .take()
+                .expect("regions already resolved")
+                .with_log(&mut inner.undo_log)
+                .into_infos_and_data()
+        };
 
         let region_rels = &RegionRelations::new(
             self.tcx,
@@ -1686,13 +1665,14 @@ fn shallow_resolve_ty(&self, typ: Ty<'tcx>) -> Ty<'tcx> {
     /// having to resort to storing full `GenericArg`s in `stalled_on`.
     #[inline(always)]
     pub fn ty_or_const_infer_var_changed(&self, infer_var: TyOrConstInferVar<'tcx>) -> bool {
+        let mut inner = self.inner.borrow_mut();
         match infer_var {
             TyOrConstInferVar::Ty(v) => {
                 use self::type_variable::TypeVariableValue;
 
                 // If `inlined_probe` returns a `Known` value, it never equals
                 // `ty::Infer(ty::TyVar(v))`.
-                match self.inner.borrow_mut().type_variables().inlined_probe(v) {
+                match inner.type_variables().inlined_probe(v) {
                     TypeVariableValue::Unknown { .. } => false,
                     TypeVariableValue::Known { .. } => true,
                 }
@@ -1702,7 +1682,7 @@ pub fn ty_or_const_infer_var_changed(&self, infer_var: TyOrConstInferVar<'tcx>)
                 // If `inlined_probe_value` returns a value it's always a
                 // `ty::Int(_)` or `ty::UInt(_)`, which never matches a
                 // `ty::Infer(_)`.
-                self.inner.borrow_mut().int_unification_table().inlined_probe_value(v).is_some()
+                inner.int_unification_table().inlined_probe_value(v).is_some()
             }
 
             TyOrConstInferVar::TyFloat(v) => {
@@ -1710,7 +1690,7 @@ pub fn ty_or_const_infer_var_changed(&self, infer_var: TyOrConstInferVar<'tcx>)
                 // `ty::Float(_)`, which never matches a `ty::Infer(_)`.
                 //
                 // Not `inlined_probe_value(v)` because this call site is colder.
-                self.inner.borrow_mut().float_unification_table().probe_value(v).is_some()
+                inner.float_unification_table().probe_value(v).is_some()
             }
 
             TyOrConstInferVar::Const(v) => {
@@ -1718,7 +1698,7 @@ pub fn ty_or_const_infer_var_changed(&self, infer_var: TyOrConstInferVar<'tcx>)
                 // `ty::ConstKind::Infer(ty::InferConst::Var(v))`.
                 //
                 // Not `inlined_probe_value(v)` because this call site is colder.
-                match self.inner.borrow_mut().const_unification_table.probe_value(v).val {
+                match inner.const_unification_table().probe_value(v).val {
                     ConstVariableValue::Unknown { .. } => false,
                     ConstVariableValue::Known { .. } => true,
                 }