Skip to content

Commit 664fcd3

Browse files
committed
Auto merge of rust-lang#71996 - Marwes:detach_undo_log, r=nikomatsakis
perf: Revert accidental inclusion of a part of rust-lang#69218 This was accidentally included in rust-lang#69464 after a rebase and given how much `inflate` and `keccak` stresses the obligation forest seems like a likely culprit to the regression in those benchmarks. (It is necessary in rust-lang#69218 as obligation forest needs to accurately track the root variables or unifications will get lost)
2 parents 2873165 + ebc7eda commit 664fcd3

File tree

7 files changed

+41
-33
lines changed

7 files changed

+41
-33
lines changed

src/librustc_data_structures/snapshot_map/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ pub enum UndoLog<K, V> {
3737
}
3838

3939
impl<K, V, M, L> SnapshotMap<K, V, M, L> {
40+
#[inline]
4041
pub fn with_log<L2>(&mut self, undo_log: L2) -> SnapshotMap<K, V, &mut M, L2> {
4142
SnapshotMap { map: &mut self.map, undo_log, _marker: PhantomData }
4243
}

src/librustc_infer/infer/mod.rs

+11-5
Original file line numberDiff line numberDiff line change
@@ -217,18 +217,22 @@ impl<'tcx> InferCtxtInner<'tcx> {
217217
}
218218
}
219219

220+
#[inline]
220221
pub fn region_obligations(&self) -> &[(hir::HirId, RegionObligation<'tcx>)] {
221222
&self.region_obligations
222223
}
223224

225+
#[inline]
224226
pub fn projection_cache(&mut self) -> traits::ProjectionCache<'_, 'tcx> {
225227
self.projection_cache.with_log(&mut self.undo_log)
226228
}
227229

230+
#[inline]
228231
fn type_variables(&mut self) -> type_variable::TypeVariableTable<'_, 'tcx> {
229232
self.type_variable_storage.with_log(&mut self.undo_log)
230233
}
231234

235+
#[inline]
232236
fn int_unification_table(
233237
&mut self,
234238
) -> ut::UnificationTable<
@@ -241,6 +245,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
241245
self.int_unification_storage.with_log(&mut self.undo_log)
242246
}
243247

248+
#[inline]
244249
fn float_unification_table(
245250
&mut self,
246251
) -> ut::UnificationTable<
@@ -253,6 +258,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
253258
self.float_unification_storage.with_log(&mut self.undo_log)
254259
}
255260

261+
#[inline]
256262
fn const_unification_table(
257263
&mut self,
258264
) -> ut::UnificationTable<
@@ -265,6 +271,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
265271
self.const_unification_storage.with_log(&mut self.undo_log)
266272
}
267273

274+
#[inline]
268275
pub fn unwrap_region_constraints(&mut self) -> RegionConstraintCollector<'_, 'tcx> {
269276
self.region_constraint_storage
270277
.as_mut()
@@ -1602,14 +1609,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16021609
/// having to resort to storing full `GenericArg`s in `stalled_on`.
16031610
#[inline(always)]
16041611
pub fn ty_or_const_infer_var_changed(&self, infer_var: TyOrConstInferVar<'tcx>) -> bool {
1605-
let mut inner = self.inner.borrow_mut();
16061612
match infer_var {
16071613
TyOrConstInferVar::Ty(v) => {
16081614
use self::type_variable::TypeVariableValue;
16091615

16101616
// If `inlined_probe` returns a `Known` value, it never equals
16111617
// `ty::Infer(ty::TyVar(v))`.
1612-
match inner.type_variables().inlined_probe(v) {
1618+
match self.inner.borrow_mut().type_variables().inlined_probe(v) {
16131619
TypeVariableValue::Unknown { .. } => false,
16141620
TypeVariableValue::Known { .. } => true,
16151621
}
@@ -1619,23 +1625,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16191625
// If `inlined_probe_value` returns a value it's always a
16201626
// `ty::Int(_)` or `ty::UInt(_)`, which never matches a
16211627
// `ty::Infer(_)`.
1622-
inner.int_unification_table().inlined_probe_value(v).is_some()
1628+
self.inner.borrow_mut().int_unification_table().inlined_probe_value(v).is_some()
16231629
}
16241630

16251631
TyOrConstInferVar::TyFloat(v) => {
16261632
// If `probe_value` returns a value it's always a
16271633
// `ty::Float(_)`, which never matches a `ty::Infer(_)`.
16281634
//
16291635
// Not `inlined_probe_value(v)` because this call site is colder.
1630-
inner.float_unification_table().probe_value(v).is_some()
1636+
self.inner.borrow_mut().float_unification_table().probe_value(v).is_some()
16311637
}
16321638

16331639
TyOrConstInferVar::Const(v) => {
16341640
// If `probe_value` returns a `Known` value, it never equals
16351641
// `ty::ConstKind::Infer(ty::InferConst::Var(v))`.
16361642
//
16371643
// Not `inlined_probe_value(v)` because this call site is colder.
1638-
match inner.const_unification_table().probe_value(v).val {
1644+
match self.inner.borrow_mut().const_unification_table().probe_value(v).val {
16391645
ConstVariableValue::Unknown { .. } => false,
16401646
ConstVariableValue::Known { .. } => true,
16411647
}

src/librustc_infer/infer/region_constraints/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ pub struct RegionConstraintCollector<'a, 'tcx> {
6868

6969
impl std::ops::Deref for RegionConstraintCollector<'_, 'tcx> {
7070
type Target = RegionConstraintStorage<'tcx>;
71+
#[inline]
7172
fn deref(&self) -> &RegionConstraintStorage<'tcx> {
7273
self.storage
7374
}
7475
}
7576

7677
impl std::ops::DerefMut for RegionConstraintCollector<'_, 'tcx> {
78+
#[inline]
7779
fn deref_mut(&mut self) -> &mut RegionConstraintStorage<'tcx> {
7880
self.storage
7981
}
@@ -345,6 +347,7 @@ impl<'tcx> RegionConstraintStorage<'tcx> {
345347
Self::default()
346348
}
347349

350+
#[inline]
348351
pub(crate) fn with_log<'a>(
349352
&'a mut self,
350353
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
@@ -794,6 +797,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
794797
.unwrap_or(None)
795798
}
796799

800+
#[inline]
797801
fn unification_table(&mut self) -> super::UnificationTable<'_, 'tcx, ty::RegionVid> {
798802
ut::UnificationTable::with_log(&mut self.storage.unification_table, self.undo_log)
799803
}

src/librustc_infer/infer/type_variable.rs

+15-16
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,7 @@ pub struct TypeVariableStorage<'tcx> {
8787
}
8888

8989
pub struct TypeVariableTable<'a, 'tcx> {
90-
values: &'a mut sv::SnapshotVecStorage<Delegate>,
91-
92-
eq_relations: &'a mut ut::UnificationTableStorage<TyVidEqKey<'tcx>>,
93-
94-
sub_relations: &'a mut ut::UnificationTableStorage<ty::TyVid>,
90+
storage: &'a mut TypeVariableStorage<'tcx>,
9591

9692
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
9793
}
@@ -165,12 +161,12 @@ impl<'tcx> TypeVariableStorage<'tcx> {
165161
}
166162
}
167163

164+
#[inline]
168165
pub(crate) fn with_log<'a>(
169166
&'a mut self,
170167
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
171168
) -> TypeVariableTable<'a, 'tcx> {
172-
let TypeVariableStorage { values, eq_relations, sub_relations } = self;
173-
TypeVariableTable { values, eq_relations, sub_relations, undo_log }
169+
TypeVariableTable { storage: self, undo_log }
174170
}
175171
}
176172

@@ -180,15 +176,15 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
180176
/// Note that this function does not return care whether
181177
/// `vid` has been unified with something else or not.
182178
pub fn var_diverges(&self, vid: ty::TyVid) -> bool {
183-
self.values.get(vid.index as usize).diverging
179+
self.storage.values.get(vid.index as usize).diverging
184180
}
185181

186182
/// Returns the origin that was given when `vid` was created.
187183
///
188184
/// Note that this function does not return care whether
189185
/// `vid` has been unified with something else or not.
190186
pub fn var_origin(&self, vid: ty::TyVid) -> &TypeVariableOrigin {
191-
&self.values.get(vid.index as usize).origin
187+
&self.storage.values.get(vid.index as usize).origin
192188
}
193189

194190
/// Records that `a == b`, depending on `dir`.
@@ -265,7 +261,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
265261

266262
/// Returns the number of type variables created thus far.
267263
pub fn num_vars(&self) -> usize {
268-
self.values.len()
264+
self.storage.values.len()
269265
}
270266

271267
/// Returns the "root" variable of `vid` in the `eq_relations`
@@ -319,18 +315,21 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
319315
}
320316
}
321317

318+
#[inline]
322319
fn values(
323320
&mut self,
324321
) -> sv::SnapshotVec<Delegate, &mut Vec<TypeVariableData>, &mut InferCtxtUndoLogs<'tcx>> {
325-
self.values.with_log(self.undo_log)
322+
self.storage.values.with_log(self.undo_log)
326323
}
327324

325+
#[inline]
328326
fn eq_relations(&mut self) -> super::UnificationTable<'_, 'tcx, TyVidEqKey<'tcx>> {
329-
self.eq_relations.with_log(self.undo_log)
327+
self.storage.eq_relations.with_log(self.undo_log)
330328
}
331329

330+
#[inline]
332331
fn sub_relations(&mut self) -> super::UnificationTable<'_, 'tcx, ty::TyVid> {
333-
self.sub_relations.with_log(self.undo_log)
332+
self.storage.sub_relations.with_log(self.undo_log)
334333
}
335334

336335
/// Returns a range of the type variables created during the snapshot.
@@ -342,7 +341,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
342341
(
343342
range.start..range.end,
344343
(range.start.index..range.end.index)
345-
.map(|index| self.values.get(index as usize).origin)
344+
.map(|index| self.storage.values.get(index as usize).origin)
346345
.collect(),
347346
)
348347
}
@@ -378,7 +377,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
378377
// quick check to see if this variable was
379378
// created since the snapshot started or not.
380379
let mut eq_relations = ut::UnificationTable::with_log(
381-
&mut *self.eq_relations,
380+
&mut self.storage.eq_relations,
382381
&mut *self.undo_log,
383382
);
384383
let escaping_type = match eq_relations.probe_value(vid) {
@@ -400,7 +399,7 @@ impl<'tcx> TypeVariableTable<'_, 'tcx> {
400399
/// Returns indices of all variables that are not yet
401400
/// instantiated.
402401
pub fn unsolved_variables(&mut self) -> Vec<ty::TyVid> {
403-
(0..self.values.len())
402+
(0..self.storage.values.len())
404403
.filter_map(|i| {
405404
let vid = ty::TyVid { index: i as u32 };
406405
match self.probe(vid) {

src/librustc_infer/infer/undo_log.rs

+2
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,12 @@ impl<'tcx, T> UndoLogs<T> for InferCtxtUndoLogs<'tcx>
100100
where
101101
UndoLog<'tcx>: From<T>,
102102
{
103+
#[inline]
103104
fn num_open_snapshots(&self) -> usize {
104105
self.num_open_snapshots
105106
}
106107

108+
#[inline]
107109
fn push(&mut self, undo: T) {
108110
if self.in_snapshot() {
109111
self.logs.push(undo.into())

src/librustc_infer/traits/project.rs

+2
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ pub enum ProjectionCacheEntry<'tcx> {
9595
}
9696

9797
impl<'tcx> ProjectionCacheStorage<'tcx> {
98+
#[inline]
9899
pub(crate) fn with_log<'a>(
99100
&'a mut self,
100101
undo_log: &'a mut InferCtxtUndoLogs<'tcx>,
@@ -104,6 +105,7 @@ impl<'tcx> ProjectionCacheStorage<'tcx> {
104105
}
105106

106107
impl<'tcx> ProjectionCache<'_, 'tcx> {
108+
#[inline]
107109
fn map(
108110
&mut self,
109111
) -> SnapshotMapRef<

src/librustc_trait_selection/traits/fulfill.rs

+6-12
Original file line numberDiff line numberDiff line change
@@ -242,15 +242,9 @@ struct FulfillProcessor<'a, 'b, 'tcx> {
242242
register_region_obligations: bool,
243243
}
244244

245-
fn mk_pending(
246-
infcx: &InferCtxt<'_, 'tcx>,
247-
os: Vec<PredicateObligation<'tcx>>,
248-
) -> Vec<PendingPredicateObligation<'tcx>> {
245+
fn mk_pending(os: Vec<PredicateObligation<'tcx>>) -> Vec<PendingPredicateObligation<'tcx>> {
249246
os.into_iter()
250-
.map(|mut o| {
251-
o.predicate = infcx.resolve_vars_if_possible(&o.predicate);
252-
PendingPredicateObligation { obligation: o, stalled_on: vec![] }
253-
})
247+
.map(|o| PendingPredicateObligation { obligation: o, stalled_on: vec![] })
254248
.collect()
255249
}
256250

@@ -344,7 +338,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
344338
"selecting trait `{:?}` at depth {} yielded Ok(Some)",
345339
data, obligation.recursion_depth
346340
);
347-
ProcessResult::Changed(mk_pending(infcx, vtable.nested_obligations()))
341+
ProcessResult::Changed(mk_pending(vtable.nested_obligations()))
348342
}
349343
Ok(None) => {
350344
debug!(
@@ -438,7 +432,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
438432
trait_ref_infer_vars(self.selcx, data.to_poly_trait_ref(tcx));
439433
ProcessResult::Unchanged
440434
}
441-
Ok(Some(os)) => ProcessResult::Changed(mk_pending(infcx, os)),
435+
Ok(Some(os)) => ProcessResult::Changed(mk_pending(os)),
442436
Err(e) => ProcessResult::Error(CodeProjectionError(e)),
443437
}
444438
}
@@ -477,7 +471,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
477471
vec![TyOrConstInferVar::maybe_from_ty(ty).unwrap()];
478472
ProcessResult::Unchanged
479473
}
480-
Some(os) => ProcessResult::Changed(mk_pending(infcx, os)),
474+
Some(os) => ProcessResult::Changed(mk_pending(os)),
481475
}
482476
}
483477

@@ -495,7 +489,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
495489
];
496490
ProcessResult::Unchanged
497491
}
498-
Some(Ok(ok)) => ProcessResult::Changed(mk_pending(infcx, ok.obligations)),
492+
Some(Ok(ok)) => ProcessResult::Changed(mk_pending(ok.obligations)),
499493
Some(Err(err)) => {
500494
let expected_found = ExpectedFound::new(
501495
subtype.skip_binder().a_is_expected,

0 commit comments

Comments
 (0)