diff options
| author | Markus Westerlind <markus.westerlind@distilnetworks.com> | 2020-02-25 14:08:34 +0100 |
|---|---|---|
| committer | Markus Westerlind <markus.westerlind@distilnetworks.com> | 2020-05-05 11:24:36 +0200 |
| commit | eb7ed0c917310592a05c5e2257986c6ba13d18b6 (patch) | |
| tree | e60063796e41ffd7f73b4ae0ae406e331364eb92 | |
| parent | a457566154994c4f75347cbf697382e261700bd7 (diff) | |
| download | rust-eb7ed0c917310592a05c5e2257986c6ba13d18b6.tar.gz rust-eb7ed0c917310592a05c5e2257986c6ba13d18b6.zip | |
perf: Lazily recive the Rollback argument in rollback_to
| -rw-r--r-- | src/librustc_data_structures/snapshot_map/mod.rs | 3 | ||||
| -rw-r--r-- | src/librustc_infer/infer/mod.rs | 24 |
2 files changed, 17 insertions, 10 deletions
diff --git a/src/librustc_data_structures/snapshot_map/mod.rs b/src/librustc_data_structures/snapshot_map/mod.rs index fe3c5a8afc9..52865f55f78 100644 --- a/src/librustc_data_structures/snapshot_map/mod.rs +++ b/src/librustc_data_structures/snapshot_map/mod.rs @@ -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) } } diff --git a/src/librustc_infer/infer/mod.rs b/src/librustc_infer/infer/mod.rs index 5c899e34850..fbba96fbe99 100644 --- a/src/librustc_infer/infer/mod.rs +++ b/src/librustc_infer/infer/mod.rs @@ -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 { @@ -1072,8 +1078,6 @@ 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, @@ -1081,10 +1085,12 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { 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, @@ -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>) { |
