Skip to content

Commit 4873dc4

Browse files
committed
Add inline to pure field-access accessors
These accessors have pure field/index accesses -- no calls. The auto-inline heuristic from Rust PR 116505 should already cover these. Let's annotate to confirm that in profiling. Maybe or maybe not we'd want to add these anyway as documentation of intent and a safety net against later changes that would cause the heuristic to fail.
1 parent ad47421 commit 4873dc4

12 files changed

Lines changed: 42 additions & 0 deletions

File tree

compiler/rustc_ast_ir/src/visit.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,13 @@ impl VisitorResult for () {
1616
#[cfg(not(feature = "nightly"))]
1717
type Residual = core::convert::Infallible;
1818

19+
#[inline]
1920
fn output() -> Self {}
21+
#[inline]
2022
fn from_residual(_: Self::Residual) -> Self {}
23+
#[inline]
2124
fn from_branch(_: ControlFlow<Self::Residual>) -> Self {}
25+
#[inline]
2226
fn branch(self) -> ControlFlow<Self::Residual> {
2327
ControlFlow::Continue(())
2428
}
@@ -27,15 +31,19 @@ impl VisitorResult for () {
2731
impl<T> VisitorResult for ControlFlow<T> {
2832
type Residual = T;
2933

34+
#[inline]
3035
fn output() -> Self {
3136
ControlFlow::Continue(())
3237
}
38+
#[inline]
3339
fn from_residual(residual: Self::Residual) -> Self {
3440
ControlFlow::Break(residual)
3541
}
42+
#[inline]
3643
fn from_branch(b: Self) -> Self {
3744
b
3845
}
46+
#[inline]
3947
fn branch(self) -> Self {
4048
self
4149
}

compiler/rustc_middle/src/ty/consts.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ impl<'tcx> rustc_type_ir::inherent::IntoKind for Const<'tcx> {
4040
}
4141

4242
impl<'tcx> rustc_type_ir::Flags for Const<'tcx> {
43+
#[inline]
4344
fn flags(&self) -> TypeFlags {
4445
self.0.flags
4546
}
4647

48+
#[inline]
4749
fn outer_exclusive_binder(&self) -> rustc_type_ir::DebruijnIndex {
4850
self.0.outer_exclusive_binder
4951
}

compiler/rustc_middle/src/ty/consts/kind.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub struct Expr<'tcx> {
2323
}
2424

2525
impl<'tcx> rustc_type_ir::inherent::ExprConst<TyCtxt<'tcx>> for Expr<'tcx> {
26+
#[inline]
2627
fn args(self) -> ty::GenericArgsRef<'tcx> {
2728
self.args
2829
}

compiler/rustc_middle/src/ty/consts/valtree.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ impl fmt::Debug for ValTree<'_> {
8080
impl<'tcx> rustc_type_ir::inherent::IntoKind for ty::ValTree<'tcx> {
8181
type Kind = ty::ValTreeKind<TyCtxt<'tcx>>;
8282

83+
#[inline]
8384
fn kind(self) -> Self::Kind {
8485
*self.0
8586
}
@@ -226,10 +227,12 @@ impl<'tcx> Value<'tcx> {
226227
}
227228

228229
impl<'tcx> rustc_type_ir::inherent::ValueConst<TyCtxt<'tcx>> for Value<'tcx> {
230+
#[inline]
229231
fn ty(self) -> Ty<'tcx> {
230232
self.ty
231233
}
232234

235+
#[inline]
233236
fn valtree(self) -> ValTree<'tcx> {
234237
self.valtree
235238
}

compiler/rustc_middle/src/ty/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,12 @@ impl<'tcx> rustc_type_ir::inherent::DefId<TyCtxt<'tcx>> for DefId {
8686
}
8787

8888
impl<'tcx> rustc_type_ir::inherent::Safety<TyCtxt<'tcx>> for hir::Safety {
89+
#[inline]
8990
fn safe() -> Self {
9091
hir::Safety::Safe
9192
}
9293

94+
#[inline]
9395
fn unsafe_mode() -> Self {
9496
hir::Safety::Unsafe
9597
}
@@ -126,6 +128,7 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
126128
}
127129

128130
impl<'tcx> rustc_type_ir::inherent::Span<TyCtxt<'tcx>> for Span {
131+
#[inline]
129132
fn dummy() -> Self {
130133
DUMMY_SP
131134
}

compiler/rustc_middle/src/ty/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,10 +487,12 @@ impl<'tcx> rustc_type_ir::inherent::IntoKind for Ty<'tcx> {
487487
}
488488

489489
impl<'tcx> rustc_type_ir::Flags for Ty<'tcx> {
490+
#[inline]
490491
fn flags(&self) -> TypeFlags {
491492
self.0.flags
492493
}
493494

495+
#[inline]
494496
fn outer_exclusive_binder(&self) -> DebruijnIndex {
495497
self.0.outer_exclusive_binder
496498
}

compiler/rustc_middle/src/ty/pattern.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ impl<'tcx> IrPrint<PatternKind<'tcx>> for TyCtxt<'tcx> {
115115

116116
impl<'tcx> rustc_type_ir::inherent::IntoKind for Pattern<'tcx> {
117117
type Kind = PatternKind<'tcx>;
118+
#[inline]
118119
fn kind(self) -> Self::Kind {
119120
*self
120121
}

compiler/rustc_middle/src/ty/predicate.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,12 @@ impl<'tcx> rustc_type_ir::inherent::IntoKind for Predicate<'tcx> {
6363
}
6464

6565
impl<'tcx> rustc_type_ir::Flags for Predicate<'tcx> {
66+
#[inline]
6667
fn flags(&self) -> TypeFlags {
6768
self.0.flags
6869
}
6970

71+
#[inline]
7072
fn outer_exclusive_binder(&self) -> ty::DebruijnIndex {
7173
self.0.outer_exclusive_binder
7274
}

compiler/rustc_middle/src/ty/region.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ pub struct Region<'tcx>(pub Interned<'tcx, RegionKind<'tcx>>);
1919
impl<'tcx> rustc_type_ir::inherent::IntoKind for Region<'tcx> {
2020
type Kind = RegionKind<'tcx>;
2121

22+
#[inline]
2223
fn kind(self) -> RegionKind<'tcx> {
2324
*self.0.0
2425
}
@@ -183,6 +184,7 @@ impl<'tcx> rustc_type_ir::inherent::Region<TyCtxt<'tcx>> for Region<'tcx> {
183184
Region::new_placeholder(tcx, placeholder)
184185
}
185186

187+
#[inline]
186188
fn new_static(tcx: TyCtxt<'tcx>) -> Self {
187189
tcx.lifetimes.re_static
188190
}
@@ -368,6 +370,7 @@ impl EarlyParamRegion {
368370
}
369371

370372
impl rustc_type_ir::inherent::ParamLike for EarlyParamRegion {
373+
#[inline]
371374
fn index(self) -> u32 {
372375
self.index
373376
}

compiler/rustc_middle/src/ty/sty.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ pub struct ParamTy {
283283
}
284284

285285
impl rustc_type_ir::inherent::ParamLike for ParamTy {
286+
#[inline]
286287
fn index(self) -> u32 {
287288
self.index
288289
}
@@ -317,6 +318,7 @@ pub struct ParamConst {
317318
}
318319

319320
impl rustc_type_ir::inherent::ParamLike for ParamConst {
321+
#[inline]
320322
fn index(self) -> u32 {
321323
self.index
322324
}
@@ -925,10 +927,12 @@ impl<'tcx> Ty<'tcx> {
925927
}
926928

927929
impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
930+
#[inline]
928931
fn new_bool(tcx: TyCtxt<'tcx>) -> Self {
929932
tcx.types.bool
930933
}
931934

935+
#[inline]
932936
fn new_u8(tcx: TyCtxt<'tcx>) -> Self {
933937
tcx.types.u8
934938
}
@@ -1128,10 +1132,12 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
11281132
Ty::new_unsafe_binder(interner, ty)
11291133
}
11301134

1135+
#[inline]
11311136
fn new_unit(interner: TyCtxt<'tcx>) -> Self {
11321137
interner.types.unit
11331138
}
11341139

1140+
#[inline]
11351141
fn new_usize(interner: TyCtxt<'tcx>) -> Self {
11361142
interner.types.usize
11371143
}
@@ -2189,6 +2195,7 @@ impl<'tcx> rustc_type_ir::inherent::Tys<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx
21892195
}
21902196

21912197
impl<'tcx> rustc_type_ir::inherent::Symbol<TyCtxt<'tcx>> for Symbol {
2198+
#[inline]
21922199
fn is_kw_underscore_lifetime(self) -> bool {
21932200
self == kw::UnderscoreLifetime
21942201
}

0 commit comments

Comments
 (0)