Skip to content

Commit 596a06f

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 86b8c93 commit 596a06f

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
}
@@ -131,6 +133,7 @@ impl<'tcx> rustc_type_ir::inherent::Features<TyCtxt<'tcx>> for &'tcx rustc_featu
131133
}
132134

133135
impl<'tcx> rustc_type_ir::inherent::Span<TyCtxt<'tcx>> for Span {
136+
#[inline]
134137
fn dummy() -> Self {
135138
DUMMY_SP
136139
}

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
@@ -285,6 +285,7 @@ pub struct ParamTy {
285285
}
286286

287287
impl rustc_type_ir::inherent::ParamLike for ParamTy {
288+
#[inline]
288289
fn index(self) -> u32 {
289290
self.index
290291
}
@@ -319,6 +320,7 @@ pub struct ParamConst {
319320
}
320321

321322
impl rustc_type_ir::inherent::ParamLike for ParamConst {
323+
#[inline]
322324
fn index(self) -> u32 {
323325
self.index
324326
}
@@ -927,10 +929,12 @@ impl<'tcx> Ty<'tcx> {
927929
}
928930

929931
impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
932+
#[inline]
930933
fn new_bool(tcx: TyCtxt<'tcx>) -> Self {
931934
tcx.types.bool
932935
}
933936

937+
#[inline]
934938
fn new_u8(tcx: TyCtxt<'tcx>) -> Self {
935939
tcx.types.u8
936940
}
@@ -1130,10 +1134,12 @@ impl<'tcx> rustc_type_ir::inherent::Ty<TyCtxt<'tcx>> for Ty<'tcx> {
11301134
Ty::new_unsafe_binder(interner, ty)
11311135
}
11321136

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

1142+
#[inline]
11371143
fn new_usize(interner: TyCtxt<'tcx>) -> Self {
11381144
interner.types.usize
11391145
}
@@ -2191,6 +2197,7 @@ impl<'tcx> rustc_type_ir::inherent::Tys<TyCtxt<'tcx>> for &'tcx ty::List<Ty<'tcx
21912197
}
21922198

21932199
impl<'tcx> rustc_type_ir::inherent::Symbol<TyCtxt<'tcx>> for Symbol {
2200+
#[inline]
21942201
fn is_kw_underscore_lifetime(self) -> bool {
21952202
self == kw::UnderscoreLifetime
21962203
}

0 commit comments

Comments
 (0)