Skip to content

Commit

Permalink
perf: Lazily recive the Rollback argument in rollback_to
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus Westerlind committed May 5, 2020
1 parent a457566 commit eb7ed0c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/librustc_data_structures/snapshot_map/mod.rs
Expand Up @@ -94,7 +94,8 @@ where
}

pub fn rollback_to(&mut self, snapshot: Snapshot) {
self.undo_log.rollback_to(&mut self.map, snapshot)
let map = &mut self.map;
self.undo_log.rollback_to(|| map, snapshot)
}
}

Expand Down
24 changes: 15 additions & 9 deletions src/librustc_infer/infer/mod.rs
Expand Up @@ -414,12 +414,18 @@ impl<'tcx> Snapshots<UndoLog<'tcx>> for Logs<'tcx> {
unreachable!()
}

fn rollback_to(&mut self, values: &mut impl Rollback<UndoLog<'tcx>>, snapshot: Self::Snapshot) {
fn rollback_to<R>(&mut self, values: impl FnOnce() -> R, snapshot: Self::Snapshot)
where
R: Rollback<UndoLog<'tcx>>,
{
debug!("rollback_to({})", snapshot.undo_len);
self.assert_open_snapshot(&snapshot);

while self.logs.len() > snapshot.undo_len {
values.reverse(self.logs.pop().unwrap());
if self.logs.len() > snapshot.undo_len {
let mut values = values();
while self.logs.len() > snapshot.undo_len {
values.reverse(self.logs.pop().unwrap());
}
}

if self.num_open_snapshots == 1 {
Expand Down Expand Up @@ -1072,19 +1078,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
self.universe.set(universe);
self.skip_leak_check.set(was_skip_leak_check);

let mut inner = self.inner.borrow_mut();
let inner = &mut *inner;
let InferCtxtInner {
type_variables,
const_unification_table,
int_unification_table,
float_unification_table,
region_constraints,
projection_cache,
region_obligations,
undo_log,
..
} = inner;
inner.undo_log.rollback_to(
&mut RollbackView {
} = &mut *self.inner.borrow_mut();
undo_log.rollback_to(
|| RollbackView {
type_variables: type_variable::RollbackView::from(type_variables),
const_unification_table,
int_unification_table,
Expand All @@ -1094,7 +1100,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
},
undo_snapshot,
);
inner.region_obligations.truncate(region_obligations_snapshot);
region_obligations.truncate(region_obligations_snapshot);
}

fn commit_from(&self, snapshot: CombinedSnapshot<'a, 'tcx>) {
Expand Down

0 comments on commit eb7ed0c

Please sign in to comment.