diff options
| author | Markus Westerlind <markus.westerlind@distilnetworks.com> | 2020-02-25 13:32:58 +0100 |
|---|---|---|
| committer | Markus Westerlind <markus.westerlind@distilnetworks.com> | 2020-05-05 11:24:23 +0200 |
| commit | a457566154994c4f75347cbf697382e261700bd7 (patch) | |
| tree | 78fffc2f8ff9474bd08c35c1151fbc279316df37 | |
| parent | 0c5d8338120ebf85e68d2f63670fac05fda97de6 (diff) | |
| download | rust-a457566154994c4f75347cbf697382e261700bd7.tar.gz rust-a457566154994c4f75347cbf697382e261700bd7.zip | |
perf: Separate CombinedSnapshot into a FullSnapshot for probing
| -rw-r--r-- | src/librustc_infer/infer/fudge.rs | 2 | ||||
| -rw-r--r-- | src/librustc_infer/infer/mod.rs | 50 |
2 files changed, 33 insertions, 19 deletions
diff --git a/src/librustc_infer/infer/fudge.rs b/src/librustc_infer/infer/fudge.rs index 0046dba0b04..a105a7704fa 100644 --- a/src/librustc_infer/infer/fudge.rs +++ b/src/librustc_infer/infer/fudge.rs @@ -82,7 +82,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { { debug!("fudge_inference_if_ok()"); - let (mut fudger, value) = self.probe(|snapshot| { + let (mut fudger, value) = self.probe_full(|snapshot| { match f() { Ok(value) => { let value = self.resolve_vars_if_possible(&value); diff --git a/src/librustc_infer/infer/mod.rs b/src/librustc_infer/infer/mod.rs index 685dc1ab8a4..5c899e34850 100644 --- a/src/librustc_infer/infer/mod.rs +++ b/src/librustc_infer/infer/mod.rs @@ -897,13 +897,18 @@ impl<'tcx> InferOk<'tcx, ()> { } #[must_use = "once you start a snapshot, you should always consume it"] -pub struct CombinedSnapshot<'a, 'tcx> { - undo_snapshot: Snapshot<'tcx>, +pub struct FullSnapshot<'a, 'tcx> { + snapshot: CombinedSnapshot<'a, 'tcx>, + region_constraints_snapshot: RegionSnapshot, type_snapshot: type_variable::Snapshot<'tcx>, const_snapshot: usize, int_snapshot: usize, float_snapshot: usize, - region_constraints_snapshot: RegionSnapshot, +} + +#[must_use = "once you start a snapshot, you should always consume it"] +pub struct CombinedSnapshot<'a, 'tcx> { + undo_snapshot: Snapshot<'tcx>, region_obligations_snapshot: usize, universe: ty::UniverseIndex, was_in_snapshot: bool, @@ -1018,6 +1023,19 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { result } + fn start_full_snapshot(&self) -> FullSnapshot<'a, 'tcx> { + let snapshot = self.start_snapshot(); + let mut inner = self.inner.borrow_mut(); + FullSnapshot { + snapshot, + type_snapshot: inner.type_variables().snapshot(), + const_snapshot: inner.const_unification_table().len(), + int_snapshot: inner.int_unification_table().len(), + float_snapshot: inner.float_unification_table().len(), + region_constraints_snapshot: inner.unwrap_region_constraints().start_snapshot(), + } + } + fn start_snapshot(&self) -> CombinedSnapshot<'a, 'tcx> { debug!("start_snapshot()"); @@ -1029,11 +1047,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let undo_snapshot = Snapshot { undo_len: inner.undo_log.logs.len(), _marker: PhantomData }; CombinedSnapshot { undo_snapshot, - type_snapshot: inner.type_variables().snapshot(), - const_snapshot: inner.const_unification_table().len(), - int_snapshot: inner.int_unification_table().len(), - float_snapshot: inner.float_unification_table().len(), - region_constraints_snapshot: inner.unwrap_region_constraints().start_snapshot(), region_obligations_snapshot: inner.region_obligations.len(), universe: self.universe(), was_in_snapshot: in_snapshot, @@ -1048,11 +1061,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { debug!("rollback_to(cause={})", cause); let CombinedSnapshot { undo_snapshot, - type_snapshot: _, - const_snapshot: _, - int_snapshot: _, - float_snapshot: _, - region_constraints_snapshot: _, region_obligations_snapshot, universe, was_in_snapshot, @@ -1093,11 +1101,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { debug!("commit_from()"); let CombinedSnapshot { undo_snapshot, - type_snapshot: _, - const_snapshot: _, - int_snapshot: _, - float_snapshot: _, - region_constraints_snapshot: _, region_obligations_snapshot: _, universe: _, was_in_snapshot, @@ -1156,6 +1159,17 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { r } + pub fn probe_full<R, F>(&self, f: F) -> R + where + F: FnOnce(&FullSnapshot<'a, 'tcx>) -> R, + { + debug!("probe()"); + let snapshot = self.start_full_snapshot(); + let r = f(&snapshot); + self.rollback_to("probe", snapshot.snapshot); + r + } + /// If `should_skip` is true, then execute `f` then unroll any bindings it creates. pub fn probe_maybe_skip_leak_check<R, F>(&self, should_skip: bool, f: F) -> R where |
