Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Westerlind committed May 5, 2020
1 parent f45d852 commit e6d7f15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 20 deletions.
11 changes: 5 additions & 6 deletions src/librustc_infer/infer/mod.rs
Expand Up @@ -347,7 +347,7 @@ pub(crate) type UnificationTable<'a, 'tcx, T> =
ut::UnificationTable<ut::InPlace<T, &'a mut ut::UnificationStorage<T>, &'a mut Logs<'tcx>>>;

struct RollbackView<'tcx, 'a> {
type_variables: type_variable::RollbackView<'tcx, 'a>,
type_variables: &'a mut type_variable::TypeVariableStorage<'tcx>,
const_unification_table: &'a mut ut::UnificationStorage<ty::ConstVid<'tcx>>,
int_unification_table: &'a mut ut::UnificationStorage<ty::IntVid>,
float_unification_table: &'a mut ut::UnificationStorage<ty::FloatVid>,
Expand Down Expand Up @@ -420,7 +420,8 @@ impl<'tcx> Snapshots<UndoLog<'tcx>> for Logs<'tcx> {
}

fn start_snapshot(&mut self) -> Self::Snapshot {
unreachable!()
self.num_open_snapshots += 1;
Snapshot { undo_len: self.logs.len(), _marker: PhantomData }
}

fn rollback_to<R>(&mut self, values: impl FnOnce() -> R, snapshot: Self::Snapshot)
Expand Down Expand Up @@ -1056,10 +1057,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {

let mut inner = self.inner.borrow_mut();

inner.undo_log.num_open_snapshots += 1;
let undo_snapshot = Snapshot { undo_len: inner.undo_log.logs.len(), _marker: PhantomData };
CombinedSnapshot {
undo_snapshot,
undo_snapshot: inner.undo_log.start_snapshot(),
universe: self.universe(),
was_in_snapshot: in_snapshot,
// Borrow tables "in progress" (i.e., during typeck)
Expand Down Expand Up @@ -1089,7 +1088,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
} = &mut *self.inner.borrow_mut();
undo_log.rollback_to(
|| RollbackView {
type_variables: type_variable::RollbackView::from(type_variables),
type_variables,
const_unification_table,
int_unification_table,
float_unification_table,
Expand Down
15 changes: 1 addition & 14 deletions src/librustc_infer/infer/type_variable.rs
Expand Up @@ -43,20 +43,7 @@ impl<'tcx> From<Instantiate> for UndoLog<'tcx> {
}
}

pub(crate) struct RollbackView<'tcx, 'a> {
pub(crate) eq_relations: &'a mut ut::UnificationStorage<TyVidEqKey<'tcx>>,
pub(crate) sub_relations: &'a mut ut::UnificationStorage<ty::TyVid>,
pub(crate) values: &'a mut Vec<TypeVariableData>,
}

impl<'tcx, 'a> From<&'a mut TypeVariableStorage<'tcx>> for RollbackView<'tcx, 'a> {
fn from(l: &'a mut TypeVariableStorage<'tcx>) -> Self {
let TypeVariableStorage { eq_relations, sub_relations, values } = l;
Self { eq_relations, sub_relations, values }
}
}

impl<'tcx> Rollback<UndoLog<'tcx>> for RollbackView<'tcx, '_> {
impl<'tcx> Rollback<UndoLog<'tcx>> for TypeVariableStorage<'tcx> {
fn reverse(&mut self, undo: UndoLog<'tcx>) {
match undo {
UndoLog::EqRelation(undo) => self.eq_relations.reverse(undo),
Expand Down

0 comments on commit e6d7f15

Please sign in to comment.