Skip to content

Commit 729d16f

Browse files
author
Markus Westerlind
committed
Prevent modifications without an undo log
1 parent 6e06535 commit 729d16f

File tree

4 files changed

+25
-25
lines changed

4 files changed

+25
-25
lines changed

src/librustc_infer/infer/mod.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,13 @@ pub struct InferCtxtInner<'tcx> {
155155
type_variables: type_variable::TypeVariableStorage<'tcx>,
156156

157157
/// Map from const parameter variable to the kind of const it represents.
158-
const_unification_table: ut::UnificationStorage<ty::ConstVid<'tcx>>,
158+
const_unification_table: ut::UnificationTableStorage<ty::ConstVid<'tcx>>,
159159

160160
/// Map from integral variable to the kind of integer it represents.
161-
int_unification_table: ut::UnificationStorage<ty::IntVid>,
161+
int_unification_table: ut::UnificationTableStorage<ty::IntVid>,
162162

163163
/// Map from floating variable to the kind of float it represents.
164-
float_unification_table: ut::UnificationStorage<ty::FloatVid>,
164+
float_unification_table: ut::UnificationTableStorage<ty::FloatVid>,
165165

166166
/// Tracks the set of region variables and the constraints between them.
167167
/// This is initially `Some(_)` but when
@@ -212,9 +212,9 @@ impl<'tcx> InferCtxtInner<'tcx> {
212212
projection_cache: Default::default(),
213213
type_variables: type_variable::TypeVariableStorage::new(),
214214
undo_log: InferCtxtUndoLogs::default(),
215-
const_unification_table: ut::UnificationStorage::new(),
216-
int_unification_table: ut::UnificationStorage::new(),
217-
float_unification_table: ut::UnificationStorage::new(),
215+
const_unification_table: ut::UnificationTableStorage::new(),
216+
int_unification_table: ut::UnificationTableStorage::new(),
217+
float_unification_table: ut::UnificationTableStorage::new(),
218218
region_constraints: Some(RegionConstraintStorage::new()),
219219
region_obligations: vec![],
220220
}

src/librustc_infer/infer/region_constraints/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct RegionConstraintStorage<'tcx> {
5454
/// is iterating to a fixed point, because otherwise we sometimes
5555
/// would wind up with a fresh stream of region variables that
5656
/// have been equated but appear distinct.
57-
pub(super) unification_table: ut::UnificationStorage<ty::RegionVid>,
57+
pub(super) unification_table: ut::UnificationTableStorage<ty::RegionVid>,
5858

5959
/// a flag set to true when we perform any unifications; this is used
6060
/// to micro-optimize `take_and_reset_data`

src/librustc_infer/infer/type_variable.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,12 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for TypeVariableStorage<'tcx> {
5454
}
5555

5656
pub struct TypeVariableStorage<'tcx> {
57-
values: Vec<TypeVariableData>,
57+
values: sv::SnapshotVecStorage<Delegate>,
5858

5959
/// Two variables are unified in `eq_relations` when we have a
6060
/// constraint `?X == ?Y`. This table also stores, for each key,
6161
/// the known value.
62-
eq_relations: ut::UnificationStorage<TyVidEqKey<'tcx>>,
62+
eq_relations: ut::UnificationTableStorage<TyVidEqKey<'tcx>>,
6363

6464
/// Two variables are unified in `sub_relations` when we have a
6565
/// constraint `?X <: ?Y` *or* a constraint `?Y <: ?X`. This second
@@ -78,15 +78,15 @@ pub struct TypeVariableStorage<'tcx> {
7878
/// This is reasonable because, in Rust, subtypes have the same
7979
/// "skeleton" and hence there is no possible type such that
8080
/// (e.g.) `Box<?3> <: ?3` for any `?3`.
81-
sub_relations: ut::UnificationStorage<ty::TyVid>,
81+
sub_relations: ut::UnificationTableStorage<ty::TyVid>,
8282
}
8383

8484
pub struct TypeVariableTable<'tcx, 'a> {
85-
values: &'a mut Vec<TypeVariableData>,
85+
values: &'a mut sv::SnapshotVecStorage<Delegate>,
8686

87-
eq_relations: &'a mut ut::UnificationStorage<TyVidEqKey<'tcx>>,
87+
eq_relations: &'a mut ut::UnificationTableStorage<TyVidEqKey<'tcx>>,
8888

89-
sub_relations: &'a mut ut::UnificationStorage<ty::TyVid>,
89+
sub_relations: &'a mut ut::UnificationTableStorage<ty::TyVid>,
9090

9191
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
9292
}
@@ -159,9 +159,9 @@ pub(crate) struct Delegate;
159159
impl<'tcx> TypeVariableStorage<'tcx> {
160160
pub fn new() -> TypeVariableStorage<'tcx> {
161161
TypeVariableStorage {
162-
values: Vec::new(),
163-
eq_relations: ut::UnificationStorage::new(),
164-
sub_relations: ut::UnificationStorage::new(),
162+
values: sv::SnapshotVecStorage::new(),
163+
eq_relations: ut::UnificationTableStorage::new(),
164+
sub_relations: ut::UnificationTableStorage::new(),
165165
}
166166
}
167167

@@ -180,15 +180,15 @@ impl<'tcx> TypeVariableTable<'tcx, '_> {
180180
/// Note that this function does not return care whether
181181
/// `vid` has been unified with something else or not.
182182
pub fn var_diverges(&self, vid: ty::TyVid) -> bool {
183-
self.values.get(vid.index as usize).unwrap().diverging
183+
self.values.get(vid.index as usize).diverging
184184
}
185185

186186
/// Returns the origin that was given when `vid` was created.
187187
///
188188
/// Note that this function does not return care whether
189189
/// `vid` has been unified with something else or not.
190190
pub fn var_origin(&self, vid: ty::TyVid) -> &TypeVariableOrigin {
191-
&self.values.get(vid.index as usize).unwrap().origin
191+
&self.values.get(vid.index as usize).origin
192192
}
193193

194194
/// Records that `a == b`, depending on `dir`.
@@ -330,15 +330,15 @@ impl<'tcx> TypeVariableTable<'tcx, '_> {
330330
fn values(
331331
&mut self,
332332
) -> sv::SnapshotVec<Delegate, &mut Vec<TypeVariableData>, &mut InferCtxtUndoLogs<'tcx>> {
333-
sv::SnapshotVec::with_log(self.values, self.undo_log)
333+
self.values.with_log(self.undo_log)
334334
}
335335

336336
fn eq_relations(&mut self) -> super::UnificationTable<'_, 'tcx, TyVidEqKey<'tcx>> {
337-
ut::UnificationTable::with_log(self.eq_relations, self.undo_log)
337+
self.eq_relations.with_log(self.undo_log)
338338
}
339339

340340
fn sub_relations(&mut self) -> super::UnificationTable<'_, 'tcx, ty::TyVid> {
341-
ut::UnificationTable::with_log(self.sub_relations, self.undo_log)
341+
self.sub_relations.with_log(self.undo_log)
342342
}
343343

344344
/// Returns a range of the type variables created during the snapshot.
@@ -351,7 +351,7 @@ impl<'tcx> TypeVariableTable<'tcx, '_> {
351351
(
352352
range.start..range.end,
353353
(range.start.index..range.end.index)
354-
.map(|index| self.values.get(index as usize).unwrap().origin)
354+
.map(|index| self.values.get(index as usize).origin)
355355
.collect(),
356356
)
357357
}

src/librustc_infer/infer/undo_log.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,9 @@ impl<'tcx> From<traits::UndoLog<'tcx>> for UndoLog<'tcx> {
9898

9999
pub(super) struct RollbackView<'tcx, 'a> {
100100
pub(super) type_variables: &'a mut type_variable::TypeVariableStorage<'tcx>,
101-
pub(super) const_unification_table: &'a mut ut::UnificationStorage<ty::ConstVid<'tcx>>,
102-
pub(super) int_unification_table: &'a mut ut::UnificationStorage<ty::IntVid>,
103-
pub(super) float_unification_table: &'a mut ut::UnificationStorage<ty::FloatVid>,
101+
pub(super) const_unification_table: &'a mut ut::UnificationTableStorage<ty::ConstVid<'tcx>>,
102+
pub(super) int_unification_table: &'a mut ut::UnificationTableStorage<ty::IntVid>,
103+
pub(super) float_unification_table: &'a mut ut::UnificationTableStorage<ty::FloatVid>,
104104
pub(super) region_constraints: &'a mut RegionConstraintStorage<'tcx>,
105105
pub(super) projection_cache: &'a mut traits::ProjectionCacheStorage<'tcx>,
106106
pub(super) region_obligations: &'a mut Vec<(hir::HirId, RegionObligation<'tcx>)>,

0 commit comments

Comments
 (0)