mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-21 22:34:05 +00:00
Miscellaneous inlining improvements
Inline a few small and hot functions.
This commit is contained in:
parent
cecdb181ad
commit
481e1fd3a8
@ -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)
|
||||
|
@ -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) }
|
||||
}
|
||||
|
@ -111,6 +111,7 @@ macro_rules! newtype_index {
|
||||
}
|
||||
|
||||
impl Clone for $type {
|
||||
#[inline]
|
||||
fn clone(&self) -> Self {
|
||||
*self
|
||||
}
|
||||
|
@ -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<Item = (PlaceRef<'tcx>, PlaceElem<'tcx>)> + DoubleEndedIterator {
|
||||
|
@ -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 }
|
||||
}
|
||||
|
@ -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(..))
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -837,6 +837,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasEscapingVarsVisitor {
|
||||
result
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
|
||||
// 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<Self::BreakTy> {
|
||||
// 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<Self::BreakTy> {
|
||||
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<Self::BreakTy> {
|
||||
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<Self::BreakTy> {
|
||||
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<Self::BreakTy> {
|
||||
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<Self::BreakTy> {
|
||||
debug!(
|
||||
"HasTypeFlagsVisitor: predicate={:?} predicate.flags={:?} self.flags={:?}",
|
||||
|
@ -1055,6 +1055,7 @@ impl<'tcx> Eq for Predicate<'tcx> {}
|
||||
|
||||
impl<'tcx> Predicate<'tcx> {
|
||||
/// Gets the inner `Binder<PredicateKind<'tcx>>`.
|
||||
#[inline]
|
||||
pub fn kind(self) -> Binder<PredicateKind<'tcx>> {
|
||||
self.inner.kind
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -34,6 +34,7 @@ impl AlwaysLiveLocals {
|
||||
impl std::ops::Deref for AlwaysLiveLocals {
|
||||
type Target = BitSet<Local>;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
|
@ -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()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user