]> git.lizzy.rs Git - rust.git/commitdiff
Prevent modifications without an undo log
authorMarkus Westerlind <markus.westerlind@distilnetworks.com>
Wed, 26 Feb 2020 09:43:24 +0000 (10:43 +0100)
committerMarkus Westerlind <markus.westerlind@distilnetworks.com>
Tue, 5 May 2020 09:25:12 +0000 (11:25 +0200)
src/librustc_infer/infer/mod.rs
src/librustc_infer/infer/region_constraints/mod.rs
src/librustc_infer/infer/type_variable.rs
src/librustc_infer/infer/undo_log.rs

index 7bf13c90bf7362df71842138e6254cae2b9bca2c..93b6a0220bf0688bd09609ca3a380ca4c5138eeb 100644 (file)
@@ -155,13 +155,13 @@ pub struct InferCtxtInner<'tcx> {
     type_variables: type_variable::TypeVariableStorage<'tcx>,
 
     /// Map from const parameter variable to the kind of const it represents.
-    const_unification_table: ut::UnificationStorage<ty::ConstVid<'tcx>>,
+    const_unification_table: ut::UnificationTableStorage<ty::ConstVid<'tcx>>,
 
     /// Map from integral variable to the kind of integer it represents.
-    int_unification_table: ut::UnificationStorage<ty::IntVid>,
+    int_unification_table: ut::UnificationTableStorage<ty::IntVid>,
 
     /// Map from floating variable to the kind of float it represents.
-    float_unification_table: ut::UnificationStorage<ty::FloatVid>,
+    float_unification_table: ut::UnificationTableStorage<ty::FloatVid>,
 
     /// Tracks the set of region variables and the constraints between them.
     /// This is initially `Some(_)` but when
@@ -212,9 +212,9 @@ fn new() -> InferCtxtInner<'tcx> {
             projection_cache: Default::default(),
             type_variables: type_variable::TypeVariableStorage::new(),
             undo_log: InferCtxtUndoLogs::default(),
-            const_unification_table: ut::UnificationStorage::new(),
-            int_unification_table: ut::UnificationStorage::new(),
-            float_unification_table: ut::UnificationStorage::new(),
+            const_unification_table: ut::UnificationTableStorage::new(),
+            int_unification_table: ut::UnificationTableStorage::new(),
+            float_unification_table: ut::UnificationTableStorage::new(),
             region_constraints: Some(RegionConstraintStorage::new()),
             region_obligations: vec![],
         }
index ead2494756ce29d23baae6cbd9970c8f47afaf8e..74d31e744fc182a4b13ec0671e522933d6e7eecc 100644 (file)
@@ -54,7 +54,7 @@ pub struct RegionConstraintStorage<'tcx> {
     /// is iterating to a fixed point, because otherwise we sometimes
     /// would wind up with a fresh stream of region variables that
     /// have been equated but appear distinct.
-    pub(super) unification_table: ut::UnificationStorage<ty::RegionVid>,
+    pub(super) unification_table: ut::UnificationTableStorage<ty::RegionVid>,
 
     /// a flag set to true when we perform any unifications; this is used
     /// to micro-optimize `take_and_reset_data`
index 69afb605b344fb7336ed36f141b30385cfeca4a1..78803eea3bc6845da61e506a05b50648a15f81ac 100644 (file)
@@ -54,12 +54,12 @@ fn reverse(&mut self, undo: UndoLog<'tcx>) {
 }
 
 pub struct TypeVariableStorage<'tcx> {
-    values: Vec<TypeVariableData>,
+    values: sv::SnapshotVecStorage<Delegate>,
 
     /// Two variables are unified in `eq_relations` when we have a
     /// constraint `?X == ?Y`. This table also stores, for each key,
     /// the known value.
-    eq_relations: ut::UnificationStorage<TyVidEqKey<'tcx>>,
+    eq_relations: ut::UnificationTableStorage<TyVidEqKey<'tcx>>,
 
     /// Two variables are unified in `sub_relations` when we have a
     /// constraint `?X <: ?Y` *or* a constraint `?Y <: ?X`. This second
@@ -78,15 +78,15 @@ pub struct TypeVariableStorage<'tcx> {
     /// This is reasonable because, in Rust, subtypes have the same
     /// "skeleton" and hence there is no possible type such that
     /// (e.g.)  `Box<?3> <: ?3` for any `?3`.
-    sub_relations: ut::UnificationStorage<ty::TyVid>,
+    sub_relations: ut::UnificationTableStorage<ty::TyVid>,
 }
 
 pub struct TypeVariableTable<'tcx, 'a> {
-    values: &'a mut Vec<TypeVariableData>,
+    values: &'a mut sv::SnapshotVecStorage<Delegate>,
 
-    eq_relations: &'a mut ut::UnificationStorage<TyVidEqKey<'tcx>>,
+    eq_relations: &'a mut ut::UnificationTableStorage<TyVidEqKey<'tcx>>,
 
-    sub_relations: &'a mut ut::UnificationStorage<ty::TyVid>,
+    sub_relations: &'a mut ut::UnificationTableStorage<ty::TyVid>,
 
     undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
 }
@@ -159,9 +159,9 @@ pub(crate) struct Instantiate {
 impl<'tcx> TypeVariableStorage<'tcx> {
     pub fn new() -> TypeVariableStorage<'tcx> {
         TypeVariableStorage {
-            values: Vec::new(),
-            eq_relations: ut::UnificationStorage::new(),
-            sub_relations: ut::UnificationStorage::new(),
+            values: sv::SnapshotVecStorage::new(),
+            eq_relations: ut::UnificationTableStorage::new(),
+            sub_relations: ut::UnificationTableStorage::new(),
         }
     }
 
@@ -180,7 +180,7 @@ impl<'tcx> TypeVariableTable<'tcx, '_> {
     /// Note that this function does not return care whether
     /// `vid` has been unified with something else or not.
     pub fn var_diverges(&self, vid: ty::TyVid) -> bool {
-        self.values.get(vid.index as usize).unwrap().diverging
+        self.values.get(vid.index as usize).diverging
     }
 
     /// Returns the origin that was given when `vid` was created.
@@ -188,7 +188,7 @@ pub fn var_diverges(&self, vid: ty::TyVid) -> bool {
     /// Note that this function does not return care whether
     /// `vid` has been unified with something else or not.
     pub fn var_origin(&self, vid: ty::TyVid) -> &TypeVariableOrigin {
-        &self.values.get(vid.index as usize).unwrap().origin
+        &self.values.get(vid.index as usize).origin
     }
 
     /// Records that `a == b`, depending on `dir`.
@@ -330,15 +330,15 @@ pub fn snapshot(&mut self) -> Snapshot<'tcx> {
     fn values(
         &mut self,
     ) -> sv::SnapshotVec<Delegate, &mut Vec<TypeVariableData>, &mut InferCtxtUndoLogs<'tcx>> {
-        sv::SnapshotVec::with_log(self.values, self.undo_log)
+        self.values.with_log(self.undo_log)
     }
 
     fn eq_relations(&mut self) -> super::UnificationTable<'_, 'tcx, TyVidEqKey<'tcx>> {
-        ut::UnificationTable::with_log(self.eq_relations, self.undo_log)
+        self.eq_relations.with_log(self.undo_log)
     }
 
     fn sub_relations(&mut self) -> super::UnificationTable<'_, 'tcx, ty::TyVid> {
-        ut::UnificationTable::with_log(self.sub_relations, self.undo_log)
+        self.sub_relations.with_log(self.undo_log)
     }
 
     /// Returns a range of the type variables created during the snapshot.
@@ -351,7 +351,7 @@ pub fn vars_since_snapshot(
         (
             range.start..range.end,
             (range.start.index..range.end.index)
-                .map(|index| self.values.get(index as usize).unwrap().origin)
+                .map(|index| self.values.get(index as usize).origin)
                 .collect(),
         )
     }
index beb71e9e2e865793f21d7824ae608f6a75413e47..a63f1b030bb7e52b49d24ae01783b2dff59f6761 100644 (file)
@@ -98,9 +98,9 @@ fn from(l: traits::UndoLog<'tcx>) -> Self {
 
 pub(super) struct RollbackView<'tcx, 'a> {
     pub(super) type_variables: &'a mut type_variable::TypeVariableStorage<'tcx>,
-    pub(super) const_unification_table: &'a mut ut::UnificationStorage<ty::ConstVid<'tcx>>,
-    pub(super) int_unification_table: &'a mut ut::UnificationStorage<ty::IntVid>,
-    pub(super) float_unification_table: &'a mut ut::UnificationStorage<ty::FloatVid>,
+    pub(super) const_unification_table: &'a mut ut::UnificationTableStorage<ty::ConstVid<'tcx>>,
+    pub(super) int_unification_table: &'a mut ut::UnificationTableStorage<ty::IntVid>,
+    pub(super) float_unification_table: &'a mut ut::UnificationTableStorage<ty::FloatVid>,
     pub(super) region_constraints: &'a mut RegionConstraintStorage<'tcx>,
     pub(super) projection_cache: &'a mut traits::ProjectionCacheStorage<'tcx>,
     pub(super) region_obligations: &'a mut Vec<(hir::HirId, RegionObligation<'tcx>)>,