diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index f4402843afcbe..3cc501e423c0b 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -773,6 +773,7 @@ pub struct MacroDef<'hir> { } impl MacroDef<'_> { + #[inline] pub fn hir_id(&self) -> HirId { HirId::make_owner(self.def_id) } @@ -2024,6 +2025,7 @@ pub struct TraitItemId { } impl TraitItemId { + #[inline] pub fn hir_id(&self) -> HirId { // Items are always HIR owners. HirId::make_owner(self.def_id) @@ -2045,6 +2047,7 @@ pub struct TraitItem<'hir> { } impl TraitItem<'_> { + #[inline] pub fn hir_id(&self) -> HirId { // Items are always HIR owners. HirId::make_owner(self.def_id) @@ -2086,6 +2089,7 @@ pub struct ImplItemId { } impl ImplItemId { + #[inline] pub fn hir_id(&self) -> HirId { // Items are always HIR owners. HirId::make_owner(self.def_id) @@ -2106,6 +2110,7 @@ pub struct ImplItem<'hir> { } impl ImplItem<'_> { + #[inline] pub fn hir_id(&self) -> HirId { // Items are always HIR owners. HirId::make_owner(self.def_id) @@ -2696,6 +2701,7 @@ pub struct ItemId { } impl ItemId { + #[inline] pub fn hir_id(&self) -> HirId { // Items are always HIR owners. HirId::make_owner(self.def_id) @@ -2716,6 +2722,7 @@ pub struct Item<'hir> { } impl Item<'_> { + #[inline] pub fn hir_id(&self) -> HirId { // Items are always HIR owners. HirId::make_owner(self.def_id) @@ -2900,6 +2907,7 @@ pub struct ForeignItemId { } impl ForeignItemId { + #[inline] pub fn hir_id(&self) -> HirId { // Items are always HIR owners. HirId::make_owner(self.def_id) @@ -2932,6 +2940,7 @@ pub struct ForeignItem<'hir> { } impl ForeignItem<'_> { + #[inline] pub fn hir_id(&self) -> HirId { // Items are always HIR owners. HirId::make_owner(self.def_id) diff --git a/compiler/rustc_hir/src/hir_id.rs b/compiler/rustc_hir/src/hir_id.rs index dd5cddd8525c1..e24eb5e449002 100644 --- a/compiler/rustc_hir/src/hir_id.rs +++ b/compiler/rustc_hir/src/hir_id.rs @@ -28,6 +28,7 @@ impl HirId { if self.local_id.index() == 0 { Some(self.owner) } else { None } } + #[inline] pub fn make_owner(owner: LocalDefId) -> Self { Self { owner, local_id: ItemLocalId::from_u32(0) } } diff --git a/compiler/rustc_index/src/vec.rs b/compiler/rustc_index/src/vec.rs index 2420f82c0418d..7cc4a5e9785e5 100644 --- a/compiler/rustc_index/src/vec.rs +++ b/compiler/rustc_index/src/vec.rs @@ -111,6 +111,7 @@ macro_rules! newtype_index { } impl Clone for $type { + #[inline] fn clone(&self) -> Self { *self } diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index a0381889ace06..f0b52c698819a 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -61,12 +61,14 @@ pub trait HasLocalDecls<'tcx> { } impl<'tcx> HasLocalDecls<'tcx> for LocalDecls<'tcx> { + #[inline] fn local_decls(&self) -> &LocalDecls<'tcx> { self } } impl<'tcx> HasLocalDecls<'tcx> for Body<'tcx> { + #[inline] fn local_decls(&self) -> &LocalDecls<'tcx> { &self.local_decls } @@ -1772,6 +1774,7 @@ impl<'tcx> Place<'tcx> { self.as_ref().as_local() } + #[inline] pub fn as_ref(&self) -> PlaceRef<'tcx> { PlaceRef { local: self.local, projection: &self.projection } } @@ -1783,6 +1786,7 @@ impl<'tcx> Place<'tcx> { /// - (a.b, .c) /// /// Given a place without projections, the iterator is empty. + #[inline] pub fn iter_projections( self, ) -> impl Iterator, PlaceElem<'tcx>)> + DoubleEndedIterator { diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index 1b2c1076a6880..92f46ef6a638c 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -21,6 +21,7 @@ pub struct PlaceTy<'tcx> { static_assert_size!(PlaceTy<'_>, 16); impl<'tcx> PlaceTy<'tcx> { + #[inline] pub fn from_ty(ty: Ty<'tcx>) -> PlaceTy<'tcx> { PlaceTy { ty, variant_index: None } } diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 9530efaedbce4..bb8c5f175b8c0 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -1201,6 +1201,7 @@ pub enum PlaceContext { impl PlaceContext { /// Returns `true` if this place context represents a drop. + #[inline] pub fn is_drop(&self) -> bool { matches!(self, PlaceContext::MutatingUse(MutatingUseContext::Drop)) } @@ -1218,6 +1219,7 @@ impl PlaceContext { } /// Returns `true` if this place context represents a storage live or storage dead marker. + #[inline] pub fn is_storage_marker(&self) -> bool { matches!( self, @@ -1226,16 +1228,19 @@ impl PlaceContext { } /// Returns `true` if this place context represents a use that potentially changes the value. + #[inline] pub fn is_mutating_use(&self) -> bool { matches!(self, PlaceContext::MutatingUse(..)) } /// Returns `true` if this place context represents a use that does not change the value. + #[inline] pub fn is_nonmutating_use(&self) -> bool { matches!(self, PlaceContext::NonMutatingUse(..)) } /// Returns `true` if this place context represents a use. + #[inline] pub fn is_use(&self) -> bool { !matches!(self, PlaceContext::NonUse(..)) } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index d316d595b1a44..e1d79248171a8 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -206,19 +206,26 @@ pub struct LocalTableInContext<'a, V> { /// would be in a different frame of reference and using its `local_id` /// would result in lookup errors, or worse, in silently wrong data being /// stored/returned. +#[inline] fn validate_hir_id_for_typeck_results(hir_owner: LocalDefId, hir_id: hir::HirId) { if hir_id.owner != hir_owner { - ty::tls::with(|tcx| { - bug!( - "node {} with HirId::owner {:?} cannot be placed in TypeckResults with hir_owner {:?}", - tcx.hir().node_to_string(hir_id), - hir_id.owner, - hir_owner - ) - }); + invalid_hir_id_for_typeck_results(hir_owner, hir_id); } } +#[cold] +#[inline(never)] +fn invalid_hir_id_for_typeck_results(hir_owner: LocalDefId, hir_id: hir::HirId) { + ty::tls::with(|tcx| { + bug!( + "node {} with HirId::owner {:?} cannot be placed in TypeckResults with hir_owner {:?}", + tcx.hir().node_to_string(hir_id), + hir_id.owner, + hir_owner + ) + }); +} + impl<'a, V> LocalTableInContext<'a, V> { pub fn contains_key(&self, id: hir::HirId) -> bool { validate_hir_id_for_typeck_results(self.hir_owner, id); diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index 382f3708c3d4b..4c7db4e803b8e 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -837,6 +837,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor { result } + #[inline] fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { // If the outer-exclusive-binder is *strictly greater* than // `outer_index`, that means that `t` contains some content @@ -850,6 +851,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor { } } + #[inline] fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow { // If the region is bound by `outer_index` or anything outside // of outer index, then it escapes the binders we have @@ -875,6 +877,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor { } } + #[inline] fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow { if predicate.inner.outer_exclusive_binder > self.outer_index { ControlFlow::Break(FoundEscapingVars) @@ -895,6 +898,7 @@ struct HasTypeFlagsVisitor { impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { type BreakTy = FoundFlags; + #[inline] fn visit_ty(&mut self, t: Ty<'_>) -> ControlFlow { debug!( "HasTypeFlagsVisitor: t={:?} t.flags={:?} self.flags={:?}", @@ -909,6 +913,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { } } + #[inline] fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow { let flags = r.type_flags(); debug!("HasTypeFlagsVisitor: r={:?} r.flags={:?} self.flags={:?}", r, flags, self.flags); @@ -919,6 +924,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { } } + #[inline] fn visit_const(&mut self, c: &'tcx ty::Const<'tcx>) -> ControlFlow { let flags = FlagComputation::for_const(c); debug!("HasTypeFlagsVisitor: c={:?} c.flags={:?} self.flags={:?}", c, flags, self.flags); @@ -929,6 +935,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { } } + #[inline] fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow { debug!( "HasTypeFlagsVisitor: predicate={:?} predicate.flags={:?} self.flags={:?}", diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 018d269bfd1de..154a5e54a5329 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -1055,6 +1055,7 @@ impl<'tcx> Eq for Predicate<'tcx> {} impl<'tcx> Predicate<'tcx> { /// Gets the inner `Binder>`. + #[inline] pub fn kind(self) -> Binder> { self.inner.kind } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index a7bcc198f02c9..6c074d3af5c4b 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -1256,6 +1256,7 @@ impl<'tcx> ParamTy { ParamTy::new(def.index, def.name) } + #[inline] pub fn to_ty(self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { tcx.mk_ty_param(self.index, self.name) } @@ -1561,14 +1562,17 @@ impl RegionKind { } } + #[inline] pub fn is_late_bound(&self) -> bool { matches!(*self, ty::ReLateBound(..)) } + #[inline] pub fn is_placeholder(&self) -> bool { matches!(*self, ty::RePlaceholder(..)) } + #[inline] pub fn bound_at_or_above_binder(&self, index: ty::DebruijnIndex) -> bool { match *self { ty::ReLateBound(debruijn, _) => debruijn >= index, diff --git a/compiler/rustc_mir/src/util/storage.rs b/compiler/rustc_mir/src/util/storage.rs index 4e1696cd716e1..18b8ef557d671 100644 --- a/compiler/rustc_mir/src/util/storage.rs +++ b/compiler/rustc_mir/src/util/storage.rs @@ -34,6 +34,7 @@ impl AlwaysLiveLocals { impl std::ops::Deref for AlwaysLiveLocals { type Target = BitSet; + #[inline] fn deref(&self) -> &Self::Target { &self.0 } diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 823aa61c4705d..493bbb3a76201 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -77,6 +77,7 @@ impl Limit { /// Check that `value` is within the limit. Ensures that the same comparisons are used /// throughout the compiler, as mismatches can cause ICEs, see #72540. + #[inline] pub fn value_within_limit(&self, value: usize) -> bool { value <= self.0 } @@ -347,10 +348,12 @@ impl Session { self.crate_types.set(crate_types).expect("`crate_types` was initialized twice") } + #[inline] pub fn recursion_limit(&self) -> Limit { self.recursion_limit.get().copied().unwrap() } + #[inline] pub fn type_length_limit(&self) -> Limit { self.type_length_limit.get().copied().unwrap() }