Skip to content

Commit f45d852

Browse files
author
Markus Westerlind
committed
perf: Merge region_obligations snapshotting into the undo log
1 parent 04f5d54 commit f45d852

File tree

3 files changed

+23
-21
lines changed

3 files changed

+23
-21
lines changed

src/librustc_infer/infer/mod.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ pub struct InferCtxtInner<'tcx> {
196196
/// for each body-id in this map, which will process the
197197
/// obligations within. This is expected to be done 'late enough'
198198
/// that all type inference variables have been bound and so forth.
199-
pub region_obligations: Vec<(hir::HirId, RegionObligation<'tcx>)>,
199+
region_obligations: Vec<(hir::HirId, RegionObligation<'tcx>)>,
200200
}
201201

202202
impl<'tcx> InferCtxtInner<'tcx> {
@@ -213,6 +213,10 @@ impl<'tcx> InferCtxtInner<'tcx> {
213213
}
214214
}
215215

216+
pub fn region_obligations(&self) -> &[(hir::HirId, RegionObligation<'tcx>)] {
217+
&self.region_obligations
218+
}
219+
216220
pub(crate) fn projection_cache(&mut self) -> traits::ProjectionCache<'tcx, '_> {
217221
self.projection_cache.with_log(&mut self.undo_log)
218222
}
@@ -270,6 +274,7 @@ pub(crate) enum UndoLog<'tcx> {
270274
RegionConstraintCollector(region_constraints::UndoLog<'tcx>),
271275
RegionUnificationTable(sv::UndoLog<ut::Delegate<ty::RegionVid>>),
272276
ProjectionCache(traits::UndoLog<'tcx>),
277+
PushRegionObligation,
273278
}
274279

275280
impl<'tcx> From<region_constraints::UndoLog<'tcx>> for UndoLog<'tcx> {
@@ -348,6 +353,7 @@ struct RollbackView<'tcx, 'a> {
348353
float_unification_table: &'a mut ut::UnificationStorage<ty::FloatVid>,
349354
region_constraints: &'a mut RegionConstraintStorage<'tcx>,
350355
projection_cache: &'a mut traits::ProjectionCacheStorage<'tcx>,
356+
region_obligations: &'a mut Vec<(hir::HirId, RegionObligation<'tcx>)>,
351357
}
352358

353359
impl<'tcx> Rollback<UndoLog<'tcx>> for RollbackView<'tcx, '_> {
@@ -362,6 +368,9 @@ impl<'tcx> Rollback<UndoLog<'tcx>> for RollbackView<'tcx, '_> {
362368
self.region_constraints.unification_table.reverse(undo)
363369
}
364370
UndoLog::ProjectionCache(undo) => self.projection_cache.reverse(undo),
371+
UndoLog::PushRegionObligation => {
372+
self.region_obligations.pop();
373+
}
365374
}
366375
}
367376
}
@@ -915,7 +924,6 @@ pub struct FullSnapshot<'a, 'tcx> {
915924
#[must_use = "once you start a snapshot, you should always consume it"]
916925
pub struct CombinedSnapshot<'a, 'tcx> {
917926
undo_snapshot: Snapshot<'tcx>,
918-
region_obligations_snapshot: usize,
919927
universe: ty::UniverseIndex,
920928
was_in_snapshot: bool,
921929
_in_progress_tables: Option<Ref<'a, ty::TypeckTables<'tcx>>>,
@@ -1052,7 +1060,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10521060
let undo_snapshot = Snapshot { undo_len: inner.undo_log.logs.len(), _marker: PhantomData };
10531061
CombinedSnapshot {
10541062
undo_snapshot,
1055-
region_obligations_snapshot: inner.region_obligations.len(),
10561063
universe: self.universe(),
10571064
was_in_snapshot: in_snapshot,
10581065
// Borrow tables "in progress" (i.e., during typeck)
@@ -1063,13 +1070,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10631070

10641071
fn rollback_to(&self, cause: &str, snapshot: CombinedSnapshot<'a, 'tcx>) {
10651072
debug!("rollback_to(cause={})", cause);
1066-
let CombinedSnapshot {
1067-
undo_snapshot,
1068-
region_obligations_snapshot,
1069-
universe,
1070-
was_in_snapshot,
1071-
_in_progress_tables,
1072-
} = snapshot;
1073+
let CombinedSnapshot { undo_snapshot, universe, was_in_snapshot, _in_progress_tables } =
1074+
snapshot;
10731075

10741076
self.in_snapshot.set(was_in_snapshot);
10751077
self.universe.set(universe);
@@ -1093,21 +1095,16 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
10931095
float_unification_table,
10941096
region_constraints: region_constraints.as_mut().unwrap(),
10951097
projection_cache,
1098+
region_obligations,
10961099
},
10971100
undo_snapshot,
10981101
);
1099-
region_obligations.truncate(region_obligations_snapshot);
11001102
}
11011103

11021104
fn commit_from(&self, snapshot: CombinedSnapshot<'a, 'tcx>) {
11031105
debug!("commit_from()");
1104-
let CombinedSnapshot {
1105-
undo_snapshot,
1106-
region_obligations_snapshot: _,
1107-
universe: _,
1108-
was_in_snapshot,
1109-
_in_progress_tables,
1110-
} = snapshot;
1106+
let CombinedSnapshot { undo_snapshot, universe: _, was_in_snapshot, _in_progress_tables } =
1107+
snapshot;
11111108

11121109
self.in_snapshot.set(was_in_snapshot);
11131110

src/librustc_infer/infer/outlives/obligations.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@
6161
6262
use crate::infer::outlives::env::RegionBoundPairs;
6363
use crate::infer::outlives::verify::VerifyBoundCx;
64-
use crate::infer::{self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, VerifyBound};
64+
use crate::infer::{
65+
self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, UndoLog, VerifyBound,
66+
};
67+
use crate::rustc_data_structures::undo_log::UndoLogs;
6568
use crate::traits::ObligationCause;
6669
use rustc_middle::ty::outlives::Component;
6770
use rustc_middle::ty::subst::GenericArgKind;
@@ -84,7 +87,9 @@ impl<'cx, 'tcx> InferCtxt<'cx, 'tcx> {
8487
) {
8588
debug!("register_region_obligation(body_id={:?}, obligation={:?})", body_id, obligation);
8689

87-
self.inner.borrow_mut().region_obligations.push((body_id, obligation));
90+
let mut inner = self.inner.borrow_mut();
91+
inner.undo_log.push(UndoLog::PushRegionObligation);
92+
inner.region_obligations.push((body_id, obligation));
8893
}
8994

9095
pub fn register_region_obligation_with_cause(

src/librustc_trait_selection/traits/auto_trait.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'tcx> AutoTraitFinder<'tcx> {
195195
let body_id_map: FxHashMap<_, _> = infcx
196196
.inner
197197
.borrow()
198-
.region_obligations
198+
.region_obligations()
199199
.iter()
200200
.map(|&(id, _)| (id, vec![]))
201201
.collect();

0 commit comments

Comments
 (0)