From 729d16f0104887a0b37b8e5bb9f0f495e4efdd10 Mon Sep 17 00:00:00 2001 From: Markus Westerlind Date: Wed, 26 Feb 2020 10:43:24 +0100 Subject: [PATCH] Prevent modifications without an undo log --- src/librustc_infer/infer/mod.rs | 12 ++++---- .../infer/region_constraints/mod.rs | 2 +- src/librustc_infer/infer/type_variable.rs | 30 +++++++++---------- src/librustc_infer/infer/undo_log.rs | 6 ++-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/src/librustc_infer/infer/mod.rs b/src/librustc_infer/infer/mod.rs index 7bf13c90bf7..93b6a0220bf 100644 --- a/src/librustc_infer/infer/mod.rs +++ b/src/librustc_infer/infer/mod.rs @@ -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>, + const_unification_table: ut::UnificationTableStorage>, /// Map from integral variable to the kind of integer it represents. - int_unification_table: ut::UnificationStorage, + int_unification_table: ut::UnificationTableStorage, /// Map from floating variable to the kind of float it represents. - float_unification_table: ut::UnificationStorage, + float_unification_table: ut::UnificationTableStorage, /// 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![], } diff --git a/src/librustc_infer/infer/region_constraints/mod.rs b/src/librustc_infer/infer/region_constraints/mod.rs index ead2494756c..74d31e744fc 100644 --- a/src/librustc_infer/infer/region_constraints/mod.rs +++ b/src/librustc_infer/infer/region_constraints/mod.rs @@ -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, + pub(super) unification_table: ut::UnificationTableStorage, /// a flag set to true when we perform any unifications; this is used /// to micro-optimize `take_and_reset_data` diff --git a/src/librustc_infer/infer/type_variable.rs b/src/librustc_infer/infer/type_variable.rs index 69afb605b34..78803eea3bc 100644 --- a/src/librustc_infer/infer/type_variable.rs +++ b/src/librustc_infer/infer/type_variable.rs @@ -54,12 +54,12 @@ fn reverse(&mut self, undo: UndoLog<'tcx>) { } pub struct TypeVariableStorage<'tcx> { - values: Vec, + values: sv::SnapshotVecStorage, /// 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>, + eq_relations: ut::UnificationTableStorage>, /// 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` for any `?3`. - sub_relations: ut::UnificationStorage, + sub_relations: ut::UnificationTableStorage, } pub struct TypeVariableTable<'tcx, 'a> { - values: &'a mut Vec, + values: &'a mut sv::SnapshotVecStorage, - eq_relations: &'a mut ut::UnificationStorage>, + eq_relations: &'a mut ut::UnificationTableStorage>, - sub_relations: &'a mut ut::UnificationStorage, + sub_relations: &'a mut ut::UnificationTableStorage, 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, &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(), ) } diff --git a/src/librustc_infer/infer/undo_log.rs b/src/librustc_infer/infer/undo_log.rs index beb71e9e2e8..a63f1b030bb 100644 --- a/src/librustc_infer/infer/undo_log.rs +++ b/src/librustc_infer/infer/undo_log.rs @@ -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>, - pub(super) int_unification_table: &'a mut ut::UnificationStorage, - pub(super) float_unification_table: &'a mut ut::UnificationStorage, + pub(super) const_unification_table: &'a mut ut::UnificationTableStorage>, + pub(super) int_unification_table: &'a mut ut::UnificationTableStorage, + pub(super) float_unification_table: &'a mut ut::UnificationTableStorage, 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>)>, -- 2.44.0