Skip to content

Commit ebc7eda

Browse files
author
Markus Westerlind
committed
perf: Add inline on commonly used methods added in 69464
Reclaims most of the regression in inflate
1 parent 1d8489c commit ebc7eda

File tree

6 files changed

+35
-21
lines changed

6 files changed

+35
-21
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
@@ -219,18 +219,22 @@ impl<'tcx> InferCtxtInner<'tcx> {
219219
}
220220
}
221221

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

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

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

237+
#[inline]
234238
fn int_unification_table(
235239
&mut self,
236240
) -> ut::UnificationTable<
@@ -243,6 +247,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
243247
self.int_unification_storage.with_log(&mut self.undo_log)
244248
}
245249

250+
#[inline]
246251
fn float_unification_table(
247252
&mut self,
248253
) -> ut::UnificationTable<
@@ -255,6 +260,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
255260
self.float_unification_storage.with_log(&mut self.undo_log)
256261
}
257262

263+
#[inline]
258264
fn const_unification_table(
259265
&mut self,
260266
) -> ut::UnificationTable<
@@ -267,6 +273,7 @@ impl<'tcx> InferCtxtInner<'tcx> {
267273
self.const_unification_storage.with_log(&mut self.undo_log)
268274
}
269275

276+
#[inline]
270277
pub fn unwrap_region_constraints(&mut self) -> RegionConstraintCollector<'_, 'tcx> {
271278
self.region_constraint_storage
272279
.as_mut()
@@ -1645,14 +1652,13 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16451652
/// having to resort to storing full `GenericArg`s in `stalled_on`.
16461653
#[inline(always)]
16471654
pub fn ty_or_const_infer_var_changed(&self, infer_var: TyOrConstInferVar<'tcx>) -> bool {
1648-
let mut inner = self.inner.borrow_mut();
16491655
match infer_var {
16501656
TyOrConstInferVar::Ty(v) => {
16511657
use self::type_variable::TypeVariableValue;
16521658

16531659
// If `inlined_probe` returns a `Known` value, it never equals
16541660
// `ty::Infer(ty::TyVar(v))`.
1655-
match inner.type_variables().inlined_probe(v) {
1661+
match self.inner.borrow_mut().type_variables().inlined_probe(v) {
16561662
TypeVariableValue::Unknown { .. } => false,
16571663
TypeVariableValue::Known { .. } => true,
16581664
}
@@ -1662,23 +1668,23 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
16621668
// If `inlined_probe_value` returns a value it's always a
16631669
// `ty::Int(_)` or `ty::UInt(_)`, which never matches a
16641670
// `ty::Infer(_)`.
1665-
inner.int_unification_table().inlined_probe_value(v).is_some()
1671+
self.inner.borrow_mut().int_unification_table().inlined_probe_value(v).is_some()
16661672
}
16671673

16681674
TyOrConstInferVar::TyFloat(v) => {
16691675
// If `probe_value` returns a value it's always a
16701676
// `ty::Float(_)`, which never matches a `ty::Infer(_)`.
16711677
//
16721678
// Not `inlined_probe_value(v)` because this call site is colder.
1673-
inner.float_unification_table().probe_value(v).is_some()
1679+
self.inner.borrow_mut().float_unification_table().probe_value(v).is_some()
16741680
}
16751681

16761682
TyOrConstInferVar::Const(v) => {
16771683
// If `probe_value` returns a `Known` value, it never equals
16781684
// `ty::ConstKind::Infer(ty::InferConst::Var(v))`.
16791685
//
16801686
// Not `inlined_probe_value(v)` because this call site is colder.
1681-
match inner.const_unification_table().probe_value(v).val {
1687+
match self.inner.borrow_mut().const_unification_table().probe_value(v).val {
16821688
ConstVariableValue::Unknown { .. } => false,
16831689
ConstVariableValue::Known { .. } => true,
16841690
}

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>,
@@ -796,6 +799,7 @@ impl<'tcx> RegionConstraintCollector<'_, 'tcx> {
796799
.unwrap_or(None)
797800
}
798801

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

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<

0 commit comments

Comments
 (0)