Skip to content

Commit 86b8c93

Browse files
committed
Add inline to single-call accessor trampolines
Some trivial accessors have a single call, like `fn def_id(self) -> DefId { self.did() }`. After MIR inlining the inner call, the auto-inline heuristic from Rust PR 116505 might already cover these, but the heuristic is conservative. Let's annotate explicitly and profile.
1 parent d859bbd commit 86b8c93

13 files changed

Lines changed: 109 additions & 0 deletions

File tree

compiler/rustc_middle/src/ty/adt.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,12 @@ impl<'tcx> AdtDef<'tcx> {
255255
}
256256

257257
impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
258+
#[inline]
258259
fn def_id(self) -> DefId {
259260
self.did()
260261
}
261262

263+
#[inline]
262264
fn is_struct(self) -> bool {
263265
self.is_struct()
264266
}
@@ -273,14 +275,17 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
273275
Some(interner.type_of(self.non_enum_variant().tail_opt()?.did))
274276
}
275277

278+
#[inline]
276279
fn is_phantom_data(self) -> bool {
277280
self.is_phantom_data()
278281
}
279282

283+
#[inline]
280284
fn is_manually_drop(self) -> bool {
281285
self.is_manually_drop()
282286
}
283287

288+
#[inline]
284289
fn field_representing_type_info(
285290
self,
286291
tcx: TyCtxt<'tcx>,
@@ -298,6 +303,7 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
298303
)
299304
}
300305

306+
#[inline]
301307
fn sizedness_constraint(
302308
self,
303309
tcx: TyCtxt<'tcx>,
@@ -306,6 +312,7 @@ impl<'tcx> rustc_type_ir::inherent::AdtDef<TyCtxt<'tcx>> for AdtDef<'tcx> {
306312
self.sizedness_constraint(tcx, sizedness)
307313
}
308314

315+
#[inline]
309316
fn is_fundamental(self) -> bool {
310317
self.is_fundamental()
311318
}

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub struct Const<'tcx>(pub(super) Interned<'tcx, WithCachedTypeInfo<ConstKind<'t
3333
impl<'tcx> rustc_type_ir::inherent::IntoKind for Const<'tcx> {
3434
type Kind = ConstKind<'tcx>;
3535

36+
#[inline]
3637
fn kind(self) -> ConstKind<'tcx> {
3738
self.kind()
3839
}
@@ -162,14 +163,17 @@ impl<'tcx> Const<'tcx> {
162163
}
163164

164165
impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
166+
#[inline]
165167
fn new_infer(tcx: TyCtxt<'tcx>, infer: ty::InferConst) -> Self {
166168
Const::new_infer(tcx, infer)
167169
}
168170

171+
#[inline]
169172
fn new_var(tcx: TyCtxt<'tcx>, vid: ty::ConstVid) -> Self {
170173
Const::new_var(tcx, vid)
171174
}
172175

176+
#[inline]
173177
fn new_bound(
174178
interner: TyCtxt<'tcx>,
175179
debruijn: ty::DebruijnIndex,
@@ -183,22 +187,27 @@ impl<'tcx> rustc_type_ir::inherent::Const<TyCtxt<'tcx>> for Const<'tcx> {
183187
Const::new_bound(tcx, debruijn, ty::BoundConst::new(var))
184188
}
185189

190+
#[inline]
186191
fn new_canonical_bound(tcx: TyCtxt<'tcx>, var: rustc_type_ir::BoundVar) -> Self {
187192
Const::new_canonical_bound(tcx, var)
188193
}
189194

195+
#[inline]
190196
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderConst<'tcx>) -> Self {
191197
Const::new_placeholder(tcx, placeholder)
192198
}
193199

200+
#[inline]
194201
fn new_unevaluated(interner: TyCtxt<'tcx>, uv: ty::UnevaluatedConst<'tcx>) -> Self {
195202
Const::new_unevaluated(interner, uv)
196203
}
197204

205+
#[inline]
198206
fn new_expr(interner: TyCtxt<'tcx>, expr: ty::Expr<'tcx>) -> Self {
199207
Const::new_expr(interner, expr)
200208
}
201209

210+
#[inline]
202211
fn new_error(interner: TyCtxt<'tcx>, guar: ErrorGuaranteed) -> Self {
203212
Const::new_error(interner, guar)
204213
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ use crate::ty::{
7474
};
7575

7676
impl<'tcx> rustc_type_ir::inherent::DefId<TyCtxt<'tcx>> for DefId {
77+
#[inline]
7778
fn is_local(self) -> bool {
7879
self.is_local()
7980
}
8081

82+
#[inline]
8183
fn as_local(self) -> Option<LocalDefId> {
8284
self.as_local()
8385
}
@@ -92,24 +94,29 @@ impl<'tcx> rustc_type_ir::inherent::Safety<TyCtxt<'tcx>> for hir::Safety {
9294
hir::Safety::Unsafe
9395
}
9496

97+
#[inline]
9598
fn is_safe(self) -> bool {
9699
self.is_safe()
97100
}
98101

102+
#[inline]
99103
fn prefix_str(self) -> &'static str {
100104
self.prefix_str()
101105
}
102106
}
103107

104108
impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_feature::Features {
109+
#[inline]
105110
fn generic_const_exprs(self) -> bool {
106111
self.generic_const_exprs()
107112
}
108113

114+
#[inline]
109115
fn generic_const_args(self) -> bool {
110116
self.generic_const_args()
111117
}
112118

119+
#[inline]
113120
fn coroutine_clone(self) -> bool {
114121
self.coroutine_clone()
115122
}

compiler/rustc_middle/src/ty/generic_args.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub struct GenericArg<'tcx> {
4141
impl<'tcx> rustc_type_ir::inherent::GenericArg<TyCtxt<'tcx>> for GenericArg<'tcx> {}
4242

4343
impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArgsRef<'tcx> {
44+
#[inline]
4445
fn rebase_onto(
4546
self,
4647
tcx: TyCtxt<'tcx>,
@@ -51,24 +52,29 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg
5152
}
5253

5354
#[track_caller]
55+
#[inline]
5456
fn type_at(self, i: usize) -> Ty<'tcx> {
5557
self.type_at(i)
5658
}
5759

5860
#[track_caller]
61+
#[inline]
5962
fn region_at(self, i: usize) -> ty::Region<'tcx> {
6063
self.region_at(i)
6164
}
6265

6366
#[track_caller]
67+
#[inline]
6468
fn const_at(self, i: usize) -> ty::Const<'tcx> {
6569
self.const_at(i)
6670
}
6771

72+
#[inline]
6873
fn identity_for_item(tcx: TyCtxt<'tcx>, def_id: DefId) -> ty::GenericArgsRef<'tcx> {
6974
GenericArgs::identity_for_item(tcx, def_id)
7075
}
7176

77+
#[inline]
7278
fn extend_with_error(
7379
tcx: TyCtxt<'tcx>,
7480
def_id: DefId,
@@ -130,6 +136,7 @@ impl<'tcx> rustc_type_ir::inherent::GenericArgs<TyCtxt<'tcx>> for ty::GenericArg
130136
impl<'tcx> rustc_type_ir::inherent::IntoKind for GenericArg<'tcx> {
131137
type Kind = GenericArgKind<'tcx>;
132138

139+
#[inline]
133140
fn kind(self) -> Self::Kind {
134141
self.kind()
135142
}

compiler/rustc_middle/src/ty/generics.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ pub struct Generics {
129129
}
130130

131131
impl<'tcx> rustc_type_ir::inherent::GenericsOf<TyCtxt<'tcx>> for &'tcx Generics {
132+
#[inline]
132133
fn count(&self) -> usize {
133134
self.parent_count + self.own_params.len()
134135
}

compiler/rustc_middle/src/ty/list.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,12 @@ impl<'a, H, T: Copy> rustc_type_ir::inherent::SliceLike for &'a RawList<H, T> {
144144

145145
type IntoIter = iter::Copied<<&'a [T] as IntoIterator>::IntoIter>;
146146

147+
#[inline]
147148
fn iter(self) -> Self::IntoIter {
148149
(*self).iter()
149150
}
150151

152+
#[inline]
151153
fn as_slice(&self) -> &[Self::Item] {
152154
(*self).as_slice()
153155
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -480,6 +480,7 @@ pub struct Ty<'tcx>(Interned<'tcx, WithCachedTypeInfo<TyKind<'tcx>>>);
480480
impl<'tcx> rustc_type_ir::inherent::IntoKind for Ty<'tcx> {
481481
type Kind = TyKind<'tcx>;
482482

483+
#[inline]
483484
fn kind(self) -> TyKind<'tcx> {
484485
*self.kind()
485486
}
@@ -520,6 +521,7 @@ impl<'tcx> rustc_type_ir::inherent::Term<TyCtxt<'tcx>> for Term<'tcx> {}
520521
impl<'tcx> rustc_type_ir::inherent::IntoKind for Term<'tcx> {
521522
type Kind = TermKind<'tcx>;
522523

524+
#[inline]
523525
fn kind(self) -> Self::Kind {
524526
self.kind()
525527
}
@@ -947,10 +949,12 @@ impl<'tcx> DefinitionSiteHiddenType<'tcx> {
947949
pub type Clauses<'tcx> = &'tcx ListWithCachedTypeInfo<Clause<'tcx>>;
948950

949951
impl<'tcx> rustc_type_ir::Flags for Clauses<'tcx> {
952+
#[inline]
950953
fn flags(&self) -> TypeFlags {
951954
(**self).flags()
952955
}
953956

957+
#[inline]
954958
fn outer_exclusive_binder(&self) -> DebruijnIndex {
955959
(**self).outer_exclusive_binder()
956960
}
@@ -973,6 +977,7 @@ pub struct ParamEnv<'tcx> {
973977
}
974978

975979
impl<'tcx> rustc_type_ir::inherent::ParamEnv<TyCtxt<'tcx>> for ParamEnv<'tcx> {
980+
#[inline]
976981
fn caller_bounds(self) -> impl inherent::SliceLike<Item = ty::Clause<'tcx>> {
977982
self.caller_bounds()
978983
}

compiler/rustc_middle/src/ty/predicate.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ pub struct Predicate<'tcx>(
4747
);
4848

4949
impl<'tcx> rustc_type_ir::inherent::Predicate<TyCtxt<'tcx>> for Predicate<'tcx> {
50+
#[inline]
5051
fn as_clause(self) -> Option<ty::Clause<'tcx>> {
5152
self.as_clause()
5253
}
@@ -55,6 +56,7 @@ impl<'tcx> rustc_type_ir::inherent::Predicate<TyCtxt<'tcx>> for Predicate<'tcx>
5556
impl<'tcx> rustc_type_ir::inherent::IntoKind for Predicate<'tcx> {
5657
type Kind = ty::Binder<'tcx, ty::PredicateKind<'tcx>>;
5758

59+
#[inline]
5860
fn kind(self) -> Self::Kind {
5961
self.kind()
6062
}
@@ -138,10 +140,12 @@ pub struct Clause<'tcx>(
138140
);
139141

140142
impl<'tcx> rustc_type_ir::inherent::Clause<TyCtxt<'tcx>> for Clause<'tcx> {
143+
#[inline]
141144
fn as_predicate(self) -> Predicate<'tcx> {
142145
self.as_predicate()
143146
}
144147

148+
#[inline]
145149
fn instantiate_supertrait(self, tcx: TyCtxt<'tcx>, trait_ref: ty::PolyTraitRef<'tcx>) -> Self {
146150
self.instantiate_supertrait(tcx, trait_ref)
147151
}
@@ -150,6 +154,7 @@ impl<'tcx> rustc_type_ir::inherent::Clause<TyCtxt<'tcx>> for Clause<'tcx> {
150154
impl<'tcx> rustc_type_ir::inherent::IntoKind for Clause<'tcx> {
151155
type Kind = ty::Binder<'tcx, ClauseKind<'tcx>>;
152156

157+
#[inline]
153158
fn kind(self) -> Self::Kind {
154159
self.kind()
155160
}

compiler/rustc_middle/src/ty/region.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ impl<'tcx> rustc_type_ir::inherent::IntoKind for Region<'tcx> {
2525
}
2626

2727
impl<'tcx> rustc_type_ir::Flags for Region<'tcx> {
28+
#[inline]
2829
fn flags(&self) -> TypeFlags {
2930
self.type_flags()
3031
}
@@ -158,6 +159,7 @@ impl<'tcx> Region<'tcx> {
158159
}
159160

160161
impl<'tcx> rustc_type_ir::inherent::Region<TyCtxt<'tcx>> for Region<'tcx> {
162+
#[inline]
161163
fn new_bound(
162164
interner: TyCtxt<'tcx>,
163165
debruijn: ty::DebruijnIndex,
@@ -166,14 +168,17 @@ impl<'tcx> rustc_type_ir::inherent::Region<TyCtxt<'tcx>> for Region<'tcx> {
166168
Region::new_bound(interner, debruijn, var)
167169
}
168170

171+
#[inline]
169172
fn new_anon_bound(tcx: TyCtxt<'tcx>, debruijn: ty::DebruijnIndex, var: ty::BoundVar) -> Self {
170173
Region::new_bound(tcx, debruijn, ty::BoundRegion { var, kind: ty::BoundRegionKind::Anon })
171174
}
172175

176+
#[inline]
173177
fn new_canonical_bound(tcx: TyCtxt<'tcx>, var: rustc_type_ir::BoundVar) -> Self {
174178
Region::new_canonical_bound(tcx, var)
175179
}
176180

181+
#[inline]
177182
fn new_placeholder(tcx: TyCtxt<'tcx>, placeholder: ty::PlaceholderRegion<'tcx>) -> Self {
178183
Region::new_placeholder(tcx, placeholder)
179184
}

0 commit comments

Comments
 (0)