Skip to content

Commit 6000502

Browse files
committed
Auto merge of #156343 - traviscross:TC/add-inline-on-trivial-accessors, r=<try>
[PERF CHECK ONLY] Add `inline` to trivial cross-crate accessors
2 parents 8068e2f + 79b2027 commit 6000502

10 files changed

Lines changed: 41 additions & 0 deletions

File tree

compiler/rustc_index_macros/src/newtype.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,14 @@ impl Parse for Newtype {
101101
quote! {
102102
#gate_rustc_only
103103
impl<D: ::rustc_serialize::Decoder> ::rustc_serialize::Decodable<D> for #name {
104+
#[inline]
104105
fn decode(d: &mut D) -> Self {
105106
Self::from_u32(d.read_u32())
106107
}
107108
}
108109
#gate_rustc_only
109110
impl<E: ::rustc_serialize::Encoder> ::rustc_serialize::Encodable<E> for #name {
111+
#[inline]
110112
fn encode(&self, e: &mut E) {
111113
e.emit_u32(self.as_u32());
112114
}
@@ -138,11 +140,13 @@ impl Parse for Newtype {
138140
}
139141
}
140142
impl ::std::cmp::Ord for #name {
143+
#[inline]
141144
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
142145
self.as_u32().cmp(&other.as_u32())
143146
}
144147
}
145148
impl ::std::cmp::PartialOrd for #name {
149+
#[inline]
146150
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
147151
self.as_u32().partial_cmp(&other.as_u32())
148152
}
@@ -156,6 +160,7 @@ impl Parse for Newtype {
156160
quote! {
157161
#gate_rustc_only
158162
impl ::rustc_data_structures::stable_hasher::StableHash for #name {
163+
#[inline]
159164
fn stable_hash<
160165
__Hcx: ::rustc_data_structures::stable_hasher::StableHashCtxt
161166
>(
@@ -340,6 +345,7 @@ impl Parse for Newtype {
340345
impl ::std::cmp::Eq for #name {}
341346

342347
impl ::std::cmp::PartialEq for #name {
348+
#[inline]
343349
fn eq(&self, other: &Self) -> bool {
344350
self.as_u32().eq(&other.as_u32())
345351
}
@@ -349,6 +355,7 @@ impl Parse for Newtype {
349355
impl ::std::marker::StructuralPartialEq for #name {}
350356

351357
impl ::std::hash::Hash for #name {
358+
#[inline]
352359
fn hash<H: ::std::hash::Hasher>(&self, state: &mut H) {
353360
self.as_u32().hash(state)
354361
}

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,10 +263,12 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
263263
self.is_struct()
264264
}
265265

266+
#[inline]
266267
fn is_packed(self) -> bool {
267268
self.repr().packed()
268269
}
269270

271+
#[inline]
270272
fn struct_tail_ty(self, interner: TyCtxt<'tcx>) -> Option<ty::EarlyBinder<'tcx, Ty<'tcx>>> {
271273
Some(interner.type_of(self.non_enum_variant().tail_opt()?.did))
272274
}

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
178178
Const::new_bound(interner, debruijn, bound_const)
179179
}
180180

181+
#[inline]
181182
fn new_anon_bound(tcx: TyCtxt<'tcx>, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self {
182183
Const::new_bound(tcx, debruijn, ty::BoundConst::new(var))
183184
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
114114
self.coroutine_clone()
115115
}
116116

117+
#[inline]
117118
fn feature_bound_holds_in_crate(self, symbol: Symbol) -> bool {
118119
// We don't consider feature bounds to hold in the crate when `staged_api` feature is
119120
// enabled, even if it is enabled through `#[feature]`.

compiler/rustc_middle/src/ty/predicate.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,17 +156,20 @@ impl<'tcx> rustc_type_ir::inherent::IntoKind for Clause<'tcx> {
156156
}
157157

158158
impl<'tcx> Clause<'tcx> {
159+
#[inline]
159160
pub fn as_predicate(self) -> Predicate<'tcx> {
160161
Predicate(self.0)
161162
}
162163

164+
#[inline]
163165
pub fn kind(self) -> ty::Binder<'tcx, ClauseKind<'tcx>> {
164166
self.0.internee.map_bound(|kind| match kind {
165167
PredicateKind::Clause(clause) => clause,
166168
_ => unreachable!(),
167169
})
168170
}
169171

172+
#[inline]
170173
pub fn as_trait_clause(self) -> Option<ty::Binder<'tcx, TraitPredicate<'tcx>>> {
171174
let clause = self.kind();
172175
if let ty::ClauseKind::Trait(trait_clause) = clause.skip_binder() {
@@ -176,6 +179,7 @@ impl<'tcx> Clause<'tcx> {
176179
}
177180
}
178181

182+
#[inline]
179183
pub fn as_projection_clause(self) -> Option<ty::Binder<'tcx, ProjectionPredicate<'tcx>>> {
180184
let clause = self.kind();
181185
if let ty::ClauseKind::Projection(projection_clause) = clause.skip_binder() {
@@ -185,6 +189,7 @@ impl<'tcx> Clause<'tcx> {
185189
}
186190
}
187191

192+
#[inline]
188193
pub fn as_type_outlives_clause(self) -> Option<ty::Binder<'tcx, TypeOutlivesPredicate<'tcx>>> {
189194
let clause = self.kind();
190195
if let ty::ClauseKind::TypeOutlives(o) = clause.skip_binder() {
@@ -194,6 +199,7 @@ impl<'tcx> Clause<'tcx> {
194199
}
195200
}
196201

202+
#[inline]
197203
pub fn as_region_outlives_clause(
198204
self,
199205
) -> Option<ty::Binder<'tcx, RegionOutlivesPredicate<'tcx>>> {
@@ -603,6 +609,7 @@ impl<'tcx> UpcastFrom<TyCtxt<'tcx>, NormalizesTo<'tcx>> for Predicate<'tcx> {
603609
}
604610

605611
impl<'tcx> Predicate<'tcx> {
612+
#[inline]
606613
pub fn as_trait_clause(self) -> Option<PolyTraitPredicate<'tcx>> {
607614
let predicate = self.kind();
608615
match predicate.skip_binder() {
@@ -611,6 +618,7 @@ impl<'tcx> Predicate<'tcx> {
611618
}
612619
}
613620

621+
#[inline]
614622
pub fn as_projection_clause(self) -> Option<PolyProjectionPredicate<'tcx>> {
615623
let predicate = self.kind();
616624
match predicate.skip_binder() {
@@ -620,6 +628,7 @@ impl<'tcx> Predicate<'tcx> {
620628
}
621629

622630
/// Matches a `PredicateKind::Clause` and turns it into a `Clause`, otherwise returns `None`.
631+
#[inline]
623632
pub fn as_clause(self) -> Option<Clause<'tcx>> {
624633
match self.kind().skip_binder() {
625634
PredicateKind::Clause(..) => Some(self.expect_clause()),
@@ -628,6 +637,7 @@ impl<'tcx> Predicate<'tcx> {
628637
}
629638

630639
/// Assert that the predicate is a clause.
640+
#[inline]
631641
pub fn expect_clause(self) -> Clause<'tcx> {
632642
match self.kind().skip_binder() {
633643
PredicateKind::Clause(..) => Clause(self.0),

compiler/rustc_middle/src/ty/region.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ impl<'tcx> rustc_type_ir::Flags for Region<'tcx> {
2929
self.type_flags()
3030
}
3131

32+
#[inline]
3233
fn outer_exclusive_binder(&self) -> ty::DebruijnIndex {
3334
match self.kind() {
3435
ty::ReBound(ty::BoundVarIndexKind::Bound(debruijn), _) => debruijn.shifted_in(1),

compiler/rustc_middle/src/ty/structural_impls.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,13 +509,15 @@ impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ty::Predicate<'tcx> {
509509

510510
// FIXME(clause): This is wonky
511511
impl<'tcx> TypeFoldable<TyCtxt<'tcx>> for ty::Clause<'tcx> {
512+
#[inline]
512513
fn try_fold_with<F: FallibleTypeFolder<TyCtxt<'tcx>>>(
513514
self,
514515
folder: &mut F,
515516
) -> Result<Self, F::Error> {
516517
Ok(folder.try_fold_predicate(self.as_predicate())?.expect_clause())
517518
}
518519

520+
#[inline]
519521
fn fold_with<F: TypeFolder<TyCtxt<'tcx>>>(self, folder: &mut F) -> Self {
520522
folder.fold_predicate(self.as_predicate()).expect_clause()
521523
}
@@ -541,6 +543,7 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::Predicate<'tcx> {
541543
}
542544

543545
impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for ty::Clause<'tcx> {
546+
#[inline]
544547
fn visit_with<V: TypeVisitor<TyCtxt<'tcx>>>(&self, visitor: &mut V) -> V::Result {
545548
visitor.visit_predicate(self.as_predicate())
546549
}

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2146,10 +2146,12 @@ impl<'tcx> Ty<'tcx> {
21462146
}
21472147

21482148
impl<'tcx> rustc_type_ir::inherent::Tys<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx>> {
2149+
#[inline]
21492150
fn inputs(self) -> &'tcx [Ty<'tcx>] {
21502151
self.split_last().unwrap().1
21512152
}
21522153

2154+
#[inline]
21532155
fn output(self) -> Ty<'tcx> {
21542156
*self.split_last().unwrap().0
21552157
}

compiler/rustc_type_ir/src/binder.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ where
109109
Binder { value, bound_vars: Default::default() }
110110
}
111111

112+
#[inline]
112113
pub fn bind_with_vars(value: T, bound_vars: I::BoundVarKinds) -> Binder<I, T> {
113114
if cfg!(debug_assertions) {
114115
let mut validator = ValidateBoundVars::new(bound_vars);
@@ -186,13 +187,15 @@ impl<I: Interner, T> Binder<I, T> {
186187
Binder { value: &self.value, bound_vars: self.bound_vars }
187188
}
188189

190+
#[inline]
189191
pub fn map_bound_ref<F, U: TypeVisitable<I>>(&self, f: F) -> Binder<I, U>
190192
where
191193
F: FnOnce(&T) -> U,
192194
{
193195
self.as_ref().map_bound(f)
194196
}
195197

198+
#[inline]
196199
pub fn map_bound<F, U: TypeVisitable<I>>(self, f: F) -> Binder<I, U>
197200
where
198201
F: FnOnce(T) -> U,
@@ -206,6 +209,7 @@ impl<I: Interner, T> Binder<I, T> {
206209
Binder { value, bound_vars }
207210
}
208211

212+
#[inline]
209213
pub fn try_map_bound<F, U: TypeVisitable<I>, E>(self, f: F) -> Result<Binder<I, U>, E>
210214
where
211215
F: FnOnce(T) -> Result<U, E>,
@@ -245,6 +249,7 @@ impl<I: Interner, T> Binder<I, T> {
245249
/// binders, but that would require adjusting the debruijn
246250
/// indices, and given the shallow binding structure we often use,
247251
/// would not be that useful.)
252+
#[inline]
248253
pub fn no_bound_vars(self) -> Option<T>
249254
where
250255
T: TypeVisitable<I>,
@@ -396,13 +401,15 @@ impl<I: Interner, T> EarlyBinder<I, T> {
396401
EarlyBinder { value: &self.value, _tcx: PhantomData }
397402
}
398403

404+
#[inline]
399405
pub fn map_bound_ref<F, U>(&self, f: F) -> EarlyBinder<I, U>
400406
where
401407
F: FnOnce(&T) -> U,
402408
{
403409
self.as_ref().map_bound(f)
404410
}
405411

412+
#[inline]
406413
pub fn map_bound<F, U>(self, f: F) -> EarlyBinder<I, U>
407414
where
408415
F: FnOnce(T) -> U,
@@ -411,6 +418,7 @@ impl<I: Interner, T> EarlyBinder<I, T> {
411418
EarlyBinder { value, _tcx: PhantomData }
412419
}
413420

421+
#[inline]
414422
pub fn try_map_bound<F, U, E>(self, f: F) -> Result<EarlyBinder<I, U>, E>
415423
where
416424
F: FnOnce(T) -> Result<U, E>,

compiler/rustc_type_ir/src/predicate.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ impl<I: Interner> TraitRef<I> {
180180
}
181181

182182
impl<I: Interner> ty::Binder<I, TraitRef<I>> {
183+
#[inline]
183184
pub fn self_ty(&self) -> ty::Binder<I, I::Ty> {
184185
self.map_bound_ref(|tr| tr.self_ty())
185186
}
@@ -233,11 +234,13 @@ impl<I: Interner> TraitPredicate<I> {
233234
}
234235

235236
impl<I: Interner> ty::Binder<I, TraitPredicate<I>> {
237+
#[inline]
236238
pub fn def_id(self) -> I::TraitId {
237239
// Ok to skip binder since trait `DefId` does not care about regions.
238240
self.skip_binder().def_id()
239241
}
240242

243+
#[inline]
241244
pub fn self_ty(self) -> ty::Binder<I, I::Ty> {
242245
self.map_bound(|trait_ref| trait_ref.self_ty())
243246
}
@@ -946,6 +949,7 @@ impl<I: Interner> ty::Binder<I, ProjectionPredicate<I>> {
946949
///
947950
/// Note that this is not the `DefId` of the `TraitRef` containing this
948951
/// associated type, which is in `tcx.associated_item(projection_def_id()).container`.
952+
#[inline]
949953
pub fn item_def_id(&self) -> I::DefId {
950954
// Ok to skip binder since trait `DefId` does not care about regions.
951955
self.skip_binder().projection_term.def_id()
@@ -1025,11 +1029,13 @@ impl<I: Interner> HostEffectPredicate<I> {
10251029
}
10261030

10271031
impl<I: Interner> ty::Binder<I, HostEffectPredicate<I>> {
1032+
#[inline]
10281033
pub fn def_id(self) -> I::TraitId {
10291034
// Ok to skip binder since trait `DefId` does not care about regions.
10301035
self.skip_binder().def_id()
10311036
}
10321037

1038+
#[inline]
10331039
pub fn self_ty(self) -> ty::Binder<I, I::Ty> {
10341040
self.map_bound(|trait_ref| trait_ref.self_ty())
10351041
}

0 commit comments

Comments
 (0)