Skip to content

Commit 3da2dd3

Browse files
committed
Auto merge of #82559 - tmiasko:inlined, r=petrochenkov
Miscellaneous inlining improvements Inline a few small and hot functions.
2 parents 9c09c1f + 481e1fd commit 3da2dd3

File tree

12 files changed

+52
-8
lines changed

12 files changed

+52
-8
lines changed

compiler/rustc_hir/src/hir.rs

+9
Original file line numberDiff line numberDiff line change
@@ -773,6 +773,7 @@ pub struct MacroDef<'hir> {
773773
}
774774

775775
impl MacroDef<'_> {
776+
#[inline]
776777
pub fn hir_id(&self) -> HirId {
777778
HirId::make_owner(self.def_id)
778779
}
@@ -2024,6 +2025,7 @@ pub struct TraitItemId {
20242025
}
20252026

20262027
impl TraitItemId {
2028+
#[inline]
20272029
pub fn hir_id(&self) -> HirId {
20282030
// Items are always HIR owners.
20292031
HirId::make_owner(self.def_id)
@@ -2045,6 +2047,7 @@ pub struct TraitItem<'hir> {
20452047
}
20462048

20472049
impl TraitItem<'_> {
2050+
#[inline]
20482051
pub fn hir_id(&self) -> HirId {
20492052
// Items are always HIR owners.
20502053
HirId::make_owner(self.def_id)
@@ -2086,6 +2089,7 @@ pub struct ImplItemId {
20862089
}
20872090

20882091
impl ImplItemId {
2092+
#[inline]
20892093
pub fn hir_id(&self) -> HirId {
20902094
// Items are always HIR owners.
20912095
HirId::make_owner(self.def_id)
@@ -2106,6 +2110,7 @@ pub struct ImplItem<'hir> {
21062110
}
21072111

21082112
impl ImplItem<'_> {
2113+
#[inline]
21092114
pub fn hir_id(&self) -> HirId {
21102115
// Items are always HIR owners.
21112116
HirId::make_owner(self.def_id)
@@ -2696,6 +2701,7 @@ pub struct ItemId {
26962701
}
26972702

26982703
impl ItemId {
2704+
#[inline]
26992705
pub fn hir_id(&self) -> HirId {
27002706
// Items are always HIR owners.
27012707
HirId::make_owner(self.def_id)
@@ -2716,6 +2722,7 @@ pub struct Item<'hir> {
27162722
}
27172723

27182724
impl Item<'_> {
2725+
#[inline]
27192726
pub fn hir_id(&self) -> HirId {
27202727
// Items are always HIR owners.
27212728
HirId::make_owner(self.def_id)
@@ -2900,6 +2907,7 @@ pub struct ForeignItemId {
29002907
}
29012908

29022909
impl ForeignItemId {
2910+
#[inline]
29032911
pub fn hir_id(&self) -> HirId {
29042912
// Items are always HIR owners.
29052913
HirId::make_owner(self.def_id)
@@ -2932,6 +2940,7 @@ pub struct ForeignItem<'hir> {
29322940
}
29332941

29342942
impl ForeignItem<'_> {
2943+
#[inline]
29352944
pub fn hir_id(&self) -> HirId {
29362945
// Items are always HIR owners.
29372946
HirId::make_owner(self.def_id)

compiler/rustc_hir/src/hir_id.rs

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ impl HirId {
2828
if self.local_id.index() == 0 { Some(self.owner) } else { None }
2929
}
3030

31+
#[inline]
3132
pub fn make_owner(owner: LocalDefId) -> Self {
3233
Self { owner, local_id: ItemLocalId::from_u32(0) }
3334
}

compiler/rustc_index/src/vec.rs

+1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ macro_rules! newtype_index {
111111
}
112112

113113
impl Clone for $type {
114+
#[inline]
114115
fn clone(&self) -> Self {
115116
*self
116117
}

compiler/rustc_middle/src/mir/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,14 @@ pub trait HasLocalDecls<'tcx> {
6161
}
6262

6363
impl<'tcx> HasLocalDecls<'tcx> for LocalDecls<'tcx> {
64+
#[inline]
6465
fn local_decls(&self) -> &LocalDecls<'tcx> {
6566
self
6667
}
6768
}
6869

6970
impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> {
71+
#[inline]
7072
fn local_decls(&self) -> &LocalDecls<'tcx> {
7173
&self.local_decls
7274
}
@@ -1772,6 +1774,7 @@ impl<'tcx> Place<'tcx> {
17721774
self.as_ref().as_local()
17731775
}
17741776

1777+
#[inline]
17751778
pub fn as_ref(&self) -> PlaceRef<'tcx> {
17761779
PlaceRef { local: self.local, projection: &self.projection }
17771780
}
@@ -1783,6 +1786,7 @@ impl<'tcx> Place<'tcx> {
17831786
/// - (a.b, .c)
17841787
///
17851788
/// Given a place without projections, the iterator is empty.
1789+
#[inline]
17861790
pub fn iter_projections(
17871791
self,
17881792
) -> impl Iterator<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {

compiler/rustc_middle/src/mir/tcx.rs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct PlaceTy<'tcx> {
2121
static_assert_size!(PlaceTy<'_>, 16);
2222

2323
impl<'tcx> PlaceTy<'tcx> {
24+
#[inline]
2425
pub fn from_ty(ty: Ty<'tcx>) -> PlaceTy<'tcx> {
2526
PlaceTy { ty, variant_index: None }
2627
}

compiler/rustc_middle/src/mir/visit.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,7 @@ pub enum PlaceContext {
12011201

12021202
impl PlaceContext {
12031203
/// Returns `true` if this place context represents a drop.
1204+
#[inline]
12041205
pub fn is_drop(&self) -> bool {
12051206
matches!(self, PlaceContext::MutatingUse(MutatingUseContext::Drop))
12061207
}
@@ -1218,6 +1219,7 @@ impl PlaceContext {
12181219
}
12191220

12201221
/// Returns `true` if this place context represents a storage live or storage dead marker.
1222+
#[inline]
12211223
pub fn is_storage_marker(&self) -> bool {
12221224
matches!(
12231225
self,
@@ -1226,16 +1228,19 @@ impl PlaceContext {
12261228
}
12271229

12281230
/// Returns `true` if this place context represents a use that potentially changes the value.
1231+
#[inline]
12291232
pub fn is_mutating_use(&self) -> bool {
12301233
matches!(self, PlaceContext::MutatingUse(..))
12311234
}
12321235

12331236
/// Returns `true` if this place context represents a use that does not change the value.
1237+
#[inline]
12341238
pub fn is_nonmutating_use(&self) -> bool {
12351239
matches!(self, PlaceContext::NonMutatingUse(..))
12361240
}
12371241

12381242
/// Returns `true` if this place context represents a use.
1243+
#[inline]
12391244
pub fn is_use(&self) -> bool {
12401245
!matches!(self, PlaceContext::NonUse(..))
12411246
}

compiler/rustc_middle/src/ty/context.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,26 @@ pub struct LocalTableInContext<'a, V> {
206206
/// would be in a different frame of reference and using its `local_id`
207207
/// would result in lookup errors, or worse, in silently wrong data being
208208
/// stored/returned.
209+
#[inline]
209210
fn validate_hir_id_for_typeck_results(hir_owner: LocalDefId, hir_id: hir::HirId) {
210211
if hir_id.owner != hir_owner {
211-
ty::tls::with(|tcx| {
212-
bug!(
213-
"node {} with HirId::owner {:?} cannot be placed in TypeckResults with hir_owner {:?}",
214-
tcx.hir().node_to_string(hir_id),
215-
hir_id.owner,
216-
hir_owner
217-
)
218-
});
212+
invalid_hir_id_for_typeck_results(hir_owner, hir_id);
219213
}
220214
}
221215

216+
#[cold]
217+
#[inline(never)]
218+
fn invalid_hir_id_for_typeck_results(hir_owner: LocalDefId, hir_id: hir::HirId) {
219+
ty::tls::with(|tcx| {
220+
bug!(
221+
"node {} with HirId::owner {:?} cannot be placed in TypeckResults with hir_owner {:?}",
222+
tcx.hir().node_to_string(hir_id),
223+
hir_id.owner,
224+
hir_owner
225+
)
226+
});
227+
}
228+
222229
impl<'a, V> LocalTableInContext<'a, V> {
223230
pub fn contains_key(&self, id: hir::HirId) -> bool {
224231
validate_hir_id_for_typeck_results(self.hir_owner, id);

compiler/rustc_middle/src/ty/fold.rs

+7
Original file line numberDiff line numberDiff line change
@@ -837,6 +837,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
837837
result
838838
}
839839

840+
#[inline]
840841
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
841842
// If the outer-exclusive-binder is *strictly greater* than
842843
// `outer_index`, that means that `t` contains some content
@@ -850,6 +851,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
850851
}
851852
}
852853

854+
#[inline]
853855
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
854856
// If the region is bound by `outer_index` or anything outside
855857
// of outer index, then it escapes the binders we have
@@ -875,6 +877,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
875877
}
876878
}
877879

880+
#[inline]
878881
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
879882
if predicate.inner.outer_exclusive_binder > self.outer_index {
880883
ControlFlow::Break(FoundEscapingVars)
@@ -895,6 +898,7 @@ struct HasTypeFlagsVisitor {
895898
impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
896899
type BreakTy = FoundFlags;
897900

901+
#[inline]
898902
fn visit_ty(&mut self, t: Ty<'_>) -> ControlFlow<Self::BreakTy> {
899903
debug!(
900904
"HasTypeFlagsVisitor: t={:?} t.flags={:?} self.flags={:?}",
@@ -909,6 +913,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
909913
}
910914
}
911915

916+
#[inline]
912917
fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow<Self::BreakTy> {
913918
let flags = r.type_flags();
914919
debug!("HasTypeFlagsVisitor: r={:?} r.flags={:?} self.flags={:?}", r, flags, self.flags);
@@ -919,6 +924,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
919924
}
920925
}
921926

927+
#[inline]
922928
fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow<Self::BreakTy> {
923929
let flags = FlagComputation::for_const(c);
924930
debug!("HasTypeFlagsVisitor: c={:?} c.flags={:?} self.flags={:?}", c, flags, self.flags);
@@ -929,6 +935,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor {
929935
}
930936
}
931937

938+
#[inline]
932939
fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow<Self::BreakTy> {
933940
debug!(
934941
"HasTypeFlagsVisitor: predicate={:?} predicate.flags={:?} self.flags={:?}",

compiler/rustc_middle/src/ty/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ impl<'tcx> Eq for Predicate<'tcx> {}
10551055

10561056
impl<'tcx> Predicate<'tcx> {
10571057
/// Gets the inner `Binder<PredicateKind<'tcx>>`.
1058+
#[inline]
10581059
pub fn kind(self) -> Binder<PredicateKind<'tcx>> {
10591060
self.inner.kind
10601061
}

compiler/rustc_middle/src/ty/sty.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1256,6 +1256,7 @@ impl<'tcx> ParamTy {
12561256
ParamTy::new(def.index, def.name)
12571257
}
12581258

1259+
#[inline]
12591260
pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
12601261
tcx.mk_ty_param(self.index, self.name)
12611262
}
@@ -1561,14 +1562,17 @@ impl RegionKind {
15611562
}
15621563
}
15631564

1565+
#[inline]
15641566
pub fn is_late_bound(&self) -> bool {
15651567
matches!(*self, ty::ReLateBound(..))
15661568
}
15671569

1570+
#[inline]
15681571
pub fn is_placeholder(&self) -> bool {
15691572
matches!(*self, ty::RePlaceholder(..))
15701573
}
15711574

1575+
#[inline]
15721576
pub fn bound_at_or_above_binder(&self, index: ty::DebruijnIndex) -> bool {
15731577
match *self {
15741578
ty::ReLateBound(debruijn, _) => debruijn >= index,

compiler/rustc_mir/src/util/storage.rs

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ impl AlwaysLiveLocals {
3434
impl std::ops::Deref for AlwaysLiveLocals {
3535
type Target = BitSet<Local>;
3636

37+
#[inline]
3738
fn deref(&self) -> &Self::Target {
3839
&self.0
3940
}

compiler/rustc_session/src/session.rs

+3
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ impl Limit {
7777

7878
/// Check that `value` is within the limit. Ensures that the same comparisons are used
7979
/// throughout the compiler, as mismatches can cause ICEs, see #72540.
80+
#[inline]
8081
pub fn value_within_limit(&self, value: usize) -> bool {
8182
value <= self.0
8283
}
@@ -347,10 +348,12 @@ impl Session {
347348
self.crate_types.set(crate_types).expect("`crate_types` was initialized twice")
348349
}
349350

351+
#[inline]
350352
pub fn recursion_limit(&self) -> Limit {
351353
self.recursion_limit.get().copied().unwrap()
352354
}
353355

356+
#[inline]
354357
pub fn type_length_limit(&self) -> Limit {
355358
self.type_length_limit.get().copied().unwrap()
356359
}

0 commit comments

Comments
 (0)