Skip to content

Commit eb7ed0c

Browse files
author
Markus Westerlind
committed
perf: Lazily recive the Rollback argument in rollback_to
1 parent a457566 commit eb7ed0c

File tree

2 files changed

+17
-10
lines changed
  • src
    • librustc_data_structures/snapshot_map
    • librustc_infer/infer

2 files changed

+17
-10
lines changed

src/librustc_data_structures/snapshot_map/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ where
9494
}
9595

9696
pub fn rollback_to(&mut self, snapshot: Snapshot) {
97-
self.undo_log.rollback_to(&mut self.map, snapshot)
97+
let map = &mut self.map;
98+
self.undo_log.rollback_to(|| map, snapshot)
9899
}
99100
}
100101

src/librustc_infer/infer/mod.rs

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,18 @@ impl<'tcx> Snapshots<UndoLog<'tcx>> for Logs<'tcx> {
414414
unreachable!()
415415
}
416416

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

421-
while self.logs.len() > snapshot.undo_len {
422-
values.reverse(self.logs.pop().unwrap());
424+
if self.logs.len() > snapshot.undo_len {
425+
let mut values = values();
426+
while self.logs.len() > snapshot.undo_len {
427+
values.reverse(self.logs.pop().unwrap());
428+
}
423429
}
424430

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

1075-
let mut inner = self.inner.borrow_mut();
1076-
let inner = &mut *inner;
10771081
let InferCtxtInner {
10781082
type_variables,
10791083
const_unification_table,
10801084
int_unification_table,
10811085
float_unification_table,
10821086
region_constraints,
10831087
projection_cache,
1088+
region_obligations,
1089+
undo_log,
10841090
..
1085-
} = inner;
1086-
inner.undo_log.rollback_to(
1087-
&mut RollbackView {
1091+
} = &mut *self.inner.borrow_mut();
1092+
undo_log.rollback_to(
1093+
|| RollbackView {
10881094
type_variables: type_variable::RollbackView::from(type_variables),
10891095
const_unification_table,
10901096
int_unification_table,
@@ -1094,7 +1100,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10941100
},
10951101
undo_snapshot,
10961102
);
1097-
inner.region_obligations.truncate(region_obligations_snapshot);
1103+
region_obligations.truncate(region_obligations_snapshot);
10981104
}
10991105

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

0 commit comments

Comments
 (0)