Auto merge of #85892 - tmiasko:i, r=oli-obk

Miscellaneous inlining improvements
This commit is contained in:
bors 2021-06-02 10:47:58 +00:00
commit 1e13a9bb33
17 changed files with 45 additions and 0 deletions

View File

@ -69,6 +69,7 @@ impl abi::HasDataLayout for Builder<'_, '_, '_> {
} }
impl ty::layout::HasTyCtxt<'tcx> for Builder<'_, '_, 'tcx> { impl ty::layout::HasTyCtxt<'tcx> for Builder<'_, '_, 'tcx> {
#[inline]
fn tcx(&self) -> TyCtxt<'tcx> { fn tcx(&self) -> TyCtxt<'tcx> {
self.cx.tcx self.cx.tcx
} }
@ -81,6 +82,7 @@ impl ty::layout::HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> {
} }
impl HasTargetSpec for Builder<'_, '_, 'tcx> { impl HasTargetSpec for Builder<'_, '_, 'tcx> {
#[inline]
fn target_spec(&self) -> &Target { fn target_spec(&self) -> &Target {
&self.cx.target_spec() &self.cx.target_spec()
} }
@ -98,6 +100,7 @@ impl abi::LayoutOf for Builder<'_, '_, 'tcx> {
impl Deref for Builder<'_, 'll, 'tcx> { impl Deref for Builder<'_, 'll, 'tcx> {
type Target = CodegenCx<'ll, 'tcx>; type Target = CodegenCx<'ll, 'tcx>;
#[inline]
fn deref(&self) -> &Self::Target { fn deref(&self) -> &Self::Target {
self.cx self.cx
} }

View File

@ -765,18 +765,21 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
} }
impl HasDataLayout for CodegenCx<'ll, 'tcx> { impl HasDataLayout for CodegenCx<'ll, 'tcx> {
#[inline]
fn data_layout(&self) -> &TargetDataLayout { fn data_layout(&self) -> &TargetDataLayout {
&self.tcx.data_layout &self.tcx.data_layout
} }
} }
impl HasTargetSpec for CodegenCx<'ll, 'tcx> { impl HasTargetSpec for CodegenCx<'ll, 'tcx> {
#[inline]
fn target_spec(&self) -> &Target { fn target_spec(&self) -> &Target {
&self.tcx.sess.target &self.tcx.sess.target
} }
} }
impl ty::layout::HasTyCtxt<'tcx> for CodegenCx<'ll, 'tcx> { impl ty::layout::HasTyCtxt<'tcx> for CodegenCx<'ll, 'tcx> {
#[inline]
fn tcx(&self) -> TyCtxt<'tcx> { fn tcx(&self) -> TyCtxt<'tcx> {
self.tcx self.tcx
} }

View File

@ -90,9 +90,11 @@ pub unsafe trait Tag: Copy {
unsafe impl<T> Pointer for Box<T> { unsafe impl<T> Pointer for Box<T> {
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize; const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
#[inline]
fn into_usize(self) -> usize { fn into_usize(self) -> usize {
Box::into_raw(self) as usize Box::into_raw(self) as usize
} }
#[inline]
unsafe fn from_usize(ptr: usize) -> Self { unsafe fn from_usize(ptr: usize) -> Self {
Box::from_raw(ptr as *mut T) Box::from_raw(ptr as *mut T)
} }
@ -104,9 +106,11 @@ unsafe impl<T> Pointer for Box<T> {
unsafe impl<T> Pointer for Rc<T> { unsafe impl<T> Pointer for Rc<T> {
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize; const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
#[inline]
fn into_usize(self) -> usize { fn into_usize(self) -> usize {
Rc::into_raw(self) as usize Rc::into_raw(self) as usize
} }
#[inline]
unsafe fn from_usize(ptr: usize) -> Self { unsafe fn from_usize(ptr: usize) -> Self {
Rc::from_raw(ptr as *const T) Rc::from_raw(ptr as *const T)
} }
@ -118,9 +122,11 @@ unsafe impl<T> Pointer for Rc<T> {
unsafe impl<T> Pointer for Arc<T> { unsafe impl<T> Pointer for Arc<T> {
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize; const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
#[inline]
fn into_usize(self) -> usize { fn into_usize(self) -> usize {
Arc::into_raw(self) as usize Arc::into_raw(self) as usize
} }
#[inline]
unsafe fn from_usize(ptr: usize) -> Self { unsafe fn from_usize(ptr: usize) -> Self {
Arc::from_raw(ptr as *const T) Arc::from_raw(ptr as *const T)
} }
@ -132,9 +138,11 @@ unsafe impl<T> Pointer for Arc<T> {
unsafe impl<'a, T: 'a> Pointer for &'a T { unsafe impl<'a, T: 'a> Pointer for &'a T {
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize; const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
#[inline]
fn into_usize(self) -> usize { fn into_usize(self) -> usize {
self as *const T as usize self as *const T as usize
} }
#[inline]
unsafe fn from_usize(ptr: usize) -> Self { unsafe fn from_usize(ptr: usize) -> Self {
&*(ptr as *const T) &*(ptr as *const T)
} }
@ -145,9 +153,11 @@ unsafe impl<'a, T: 'a> Pointer for &'a T {
unsafe impl<'a, T: 'a> Pointer for &'a mut T { unsafe impl<'a, T: 'a> Pointer for &'a mut T {
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize; const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
#[inline]
fn into_usize(self) -> usize { fn into_usize(self) -> usize {
self as *mut T as usize self as *mut T as usize
} }
#[inline]
unsafe fn from_usize(ptr: usize) -> Self { unsafe fn from_usize(ptr: usize) -> Self {
&mut *(ptr as *mut T) &mut *(ptr as *mut T)
} }

View File

@ -715,6 +715,7 @@ impl Handler {
self.inner.borrow_mut().bug(msg) self.inner.borrow_mut().bug(msg)
} }
#[inline]
pub fn err_count(&self) -> usize { pub fn err_count(&self) -> usize {
self.inner.borrow().err_count() self.inner.borrow().err_count()
} }
@ -924,6 +925,7 @@ impl HandlerInner {
} }
} }
#[inline]
fn err_count(&self) -> usize { fn err_count(&self) -> usize {
self.err_count + self.stashed_diagnostics.len() self.err_count + self.stashed_diagnostics.len()
} }

View File

@ -305,6 +305,7 @@ impl Definitions {
self.table.index_to_key.len() self.table.index_to_key.len()
} }
#[inline]
pub fn def_key(&self, id: LocalDefId) -> DefKey { pub fn def_key(&self, id: LocalDefId) -> DefKey {
self.table.def_key(id.local_def_index) self.table.def_key(id.local_def_index)
} }

View File

@ -2488,6 +2488,7 @@ pub enum FnRetTy<'hir> {
} }
impl FnRetTy<'_> { impl FnRetTy<'_> {
#[inline]
pub fn span(&self) -> Span { pub fn span(&self) -> Span {
match *self { match *self {
Self::DefaultReturn(span) => span, Self::DefaultReturn(span) => span,

View File

@ -294,6 +294,7 @@ TrivialTypeFoldableImpls! {
} }
impl<'tcx> CanonicalVarValues<'tcx> { impl<'tcx> CanonicalVarValues<'tcx> {
#[inline]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
self.var_values.len() self.var_values.len()
} }

View File

@ -246,6 +246,7 @@ pub struct AllocDecodingState {
} }
impl AllocDecodingState { impl AllocDecodingState {
#[inline]
pub fn new_decoding_session(&self) -> AllocDecodingSession<'_> { pub fn new_decoding_session(&self) -> AllocDecodingSession<'_> {
static DECODER_SESSION_ID: AtomicU32 = AtomicU32::new(0); static DECODER_SESSION_ID: AtomicU32 = AtomicU32::new(0);
let counter = DECODER_SESSION_ID.fetch_add(1, Ordering::SeqCst); let counter = DECODER_SESSION_ID.fetch_add(1, Ordering::SeqCst);

View File

@ -1249,10 +1249,12 @@ impl<'tcx> BasicBlockData<'tcx> {
/// ///
/// Terminator may not be None after construction of the basic block is complete. This accessor /// Terminator may not be None after construction of the basic block is complete. This accessor
/// provides a convenience way to reach the terminator. /// provides a convenience way to reach the terminator.
#[inline]
pub fn terminator(&self) -> &Terminator<'tcx> { pub fn terminator(&self) -> &Terminator<'tcx> {
self.terminator.as_ref().expect("invalid terminator state") self.terminator.as_ref().expect("invalid terminator state")
} }
#[inline]
pub fn terminator_mut(&mut self) -> &mut Terminator<'tcx> { pub fn terminator_mut(&mut self) -> &mut Terminator<'tcx> {
self.terminator.as_mut().expect("invalid terminator state") self.terminator.as_mut().expect("invalid terminator state")
} }
@ -1870,6 +1872,7 @@ impl<'tcx> PlaceRef<'tcx> {
/// If this place represents a local variable like `_X` with no /// If this place represents a local variable like `_X` with no
/// projections, return `Some(_X)`. /// projections, return `Some(_X)`.
#[inline]
pub fn as_local(&self) -> Option<Local> { pub fn as_local(&self) -> Option<Local> {
match *self { match *self {
PlaceRef { local, projection: [] } => Some(local), PlaceRef { local, projection: [] } => Some(local),
@ -1877,6 +1880,7 @@ impl<'tcx> PlaceRef<'tcx> {
} }
} }
#[inline]
pub fn last_projection(&self) -> Option<(PlaceRef<'tcx>, PlaceElem<'tcx>)> { pub fn last_projection(&self) -> Option<(PlaceRef<'tcx>, PlaceElem<'tcx>)> {
if let &[ref proj_base @ .., elem] = self.projection { if let &[ref proj_base @ .., elem] = self.projection {
Some((PlaceRef { local: self.local, projection: proj_base }, elem)) Some((PlaceRef { local: self.local, projection: proj_base }, elem))
@ -2464,12 +2468,14 @@ impl Constant<'tcx> {
_ => None, _ => None,
} }
} }
#[inline]
pub fn ty(&self) -> Ty<'tcx> { pub fn ty(&self) -> Ty<'tcx> {
self.literal.ty() self.literal.ty()
} }
} }
impl From<&'tcx ty::Const<'tcx>> for ConstantKind<'tcx> { impl From<&'tcx ty::Const<'tcx>> for ConstantKind<'tcx> {
#[inline]
fn from(ct: &'tcx ty::Const<'tcx>) -> Self { fn from(ct: &'tcx ty::Const<'tcx>) -> Self {
Self::Ty(ct) Self::Ty(ct)
} }

View File

@ -267,6 +267,7 @@ pub enum Visibility {
} }
impl<'tcx> CodegenUnit<'tcx> { impl<'tcx> CodegenUnit<'tcx> {
#[inline]
pub fn new(name: Symbol) -> CodegenUnit<'tcx> { pub fn new(name: Symbol) -> CodegenUnit<'tcx> {
CodegenUnit { name, items: Default::default(), size_estimate: None, primary: false } CodegenUnit { name, items: Default::default(), size_estimate: None, primary: false }
} }
@ -311,6 +312,7 @@ impl<'tcx> CodegenUnit<'tcx> {
self.size_estimate = Some(self.items.keys().map(|mi| mi.size_estimate(tcx)).sum()); self.size_estimate = Some(self.items.keys().map(|mi| mi.size_estimate(tcx)).sum());
} }
#[inline]
pub fn size_estimate(&self) -> usize { pub fn size_estimate(&self) -> usize {
// Should only be called if `estimate_size` has previously been called. // Should only be called if `estimate_size` has previously been called.
self.size_estimate.expect("estimate_size must be called before getting a size_estimate") self.size_estimate.expect("estimate_size must be called before getting a size_estimate")

View File

@ -93,6 +93,7 @@ pub struct Generics {
} }
impl<'tcx> Generics { impl<'tcx> Generics {
#[inline]
pub fn count(&self) -> usize { pub fn count(&self) -> usize {
self.parent_count + self.params.len() self.parent_count + self.params.len()
} }

View File

@ -37,9 +37,11 @@ pub struct List<T> {
unsafe impl<'a, T: 'a> rustc_data_structures::tagged_ptr::Pointer for &'a List<T> { unsafe impl<'a, T: 'a> rustc_data_structures::tagged_ptr::Pointer for &'a List<T> {
const BITS: usize = std::mem::align_of::<usize>().trailing_zeros() as usize; const BITS: usize = std::mem::align_of::<usize>().trailing_zeros() as usize;
#[inline]
fn into_usize(self) -> usize { fn into_usize(self) -> usize {
self as *const List<T> as usize self as *const List<T> as usize
} }
#[inline]
unsafe fn from_usize(ptr: usize) -> Self { unsafe fn from_usize(ptr: usize) -> Self {
&*(ptr as *const List<T>) &*(ptr as *const List<T>)
} }

View File

@ -1097,12 +1097,14 @@ pub struct ParamEnv<'tcx> {
unsafe impl rustc_data_structures::tagged_ptr::Tag for traits::Reveal { unsafe impl rustc_data_structures::tagged_ptr::Tag for traits::Reveal {
const BITS: usize = 1; const BITS: usize = 1;
#[inline]
fn into_usize(self) -> usize { fn into_usize(self) -> usize {
match self { match self {
traits::Reveal::UserFacing => 0, traits::Reveal::UserFacing => 0,
traits::Reveal::All => 1, traits::Reveal::All => 1,
} }
} }
#[inline]
unsafe fn from_usize(ptr: usize) -> Self { unsafe fn from_usize(ptr: usize) -> Self {
match ptr { match ptr {
0 => traits::Reveal::UserFacing, 0 => traits::Reveal::UserFacing,
@ -1200,6 +1202,7 @@ impl<'tcx> ParamEnv<'tcx> {
} }
/// Returns this same environment but with no caller bounds. /// Returns this same environment but with no caller bounds.
#[inline]
pub fn without_caller_bounds(self) -> Self { pub fn without_caller_bounds(self) -> Self {
Self::new(List::empty(), self.reveal()) Self::new(List::empty(), self.reveal())
} }

View File

@ -452,6 +452,7 @@ impl Session {
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) { pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) {
err.into_diagnostic(self).emit() err.into_diagnostic(self).emit()
} }
#[inline]
pub fn err_count(&self) -> usize { pub fn err_count(&self) -> usize {
self.diagnostic().err_count() self.diagnostic().err_count()
} }
@ -524,6 +525,7 @@ impl Session {
self.diagnostic().struct_note_without_error(msg) self.diagnostic().struct_note_without_error(msg)
} }
#[inline]
pub fn diagnostic(&self) -> &rustc_errors::Handler { pub fn diagnostic(&self) -> &rustc_errors::Handler {
&self.parse_sess.span_diagnostic &self.parse_sess.span_diagnostic
} }

View File

@ -20,10 +20,12 @@ rustc_index::newtype_index! {
pub const LOCAL_CRATE: CrateNum = CrateNum::from_u32(0); pub const LOCAL_CRATE: CrateNum = CrateNum::from_u32(0);
impl CrateNum { impl CrateNum {
#[inline]
pub fn new(x: usize) -> CrateNum { pub fn new(x: usize) -> CrateNum {
CrateNum::from_usize(x) CrateNum::from_usize(x)
} }
#[inline]
pub fn as_def_id(&self) -> DefId { pub fn as_def_id(&self) -> DefId {
DefId { krate: *self, index: CRATE_DEF_INDEX } DefId { krate: *self, index: CRATE_DEF_INDEX }
} }

View File

@ -222,6 +222,7 @@ pub trait HasDataLayout {
} }
impl HasDataLayout for TargetDataLayout { impl HasDataLayout for TargetDataLayout {
#[inline]
fn data_layout(&self) -> &TargetDataLayout { fn data_layout(&self) -> &TargetDataLayout {
self self
} }
@ -862,6 +863,7 @@ pub enum Abi {
impl Abi { impl Abi {
/// Returns `true` if the layout corresponds to an unsized type. /// Returns `true` if the layout corresponds to an unsized type.
#[inline]
pub fn is_unsized(&self) -> bool { pub fn is_unsized(&self) -> bool {
match *self { match *self {
Abi::Uninhabited | Abi::Scalar(_) | Abi::ScalarPair(..) | Abi::Vector { .. } => false, Abi::Uninhabited | Abi::Scalar(_) | Abi::ScalarPair(..) | Abi::Vector { .. } => false,
@ -881,11 +883,13 @@ impl Abi {
} }
/// Returns `true` if this is an uninhabited type /// Returns `true` if this is an uninhabited type
#[inline]
pub fn is_uninhabited(&self) -> bool { pub fn is_uninhabited(&self) -> bool {
matches!(*self, Abi::Uninhabited) matches!(*self, Abi::Uninhabited)
} }
/// Returns `true` is this is a scalar type /// Returns `true` is this is a scalar type
#[inline]
pub fn is_scalar(&self) -> bool { pub fn is_scalar(&self) -> bool {
matches!(*self, Abi::Scalar(_)) matches!(*self, Abi::Scalar(_))
} }

View File

@ -922,6 +922,7 @@ pub trait HasTargetSpec {
} }
impl HasTargetSpec for Target { impl HasTargetSpec for Target {
#[inline]
fn target_spec(&self) -> &Target { fn target_spec(&self) -> &Target {
self self
} }