1
Fork 0

Miscellaneous inlining improvements

Inline a few small and hot functions.
This commit is contained in:
Tomasz Miąsko 2021-02-26 00:00:00 +00:00
parent cecdb181ad
commit 481e1fd3a8
12 changed files with 52 additions and 8 deletions

View file

@ -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 {

View file

@ -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 }
}

View file

@ -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(..))
}

View file

@ -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);

View file

@ -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={:?}",

View file

@ -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
}

View file

@ -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,