mirror of
https://github.com/rust-lang/rust.git
synced 2025-01-22 12:43:36 +00:00
Auto merge of #85892 - tmiasko:i, r=oli-obk
Miscellaneous inlining improvements
This commit is contained in:
commit
1e13a9bb33
@ -69,6 +69,7 @@ impl abi::HasDataLayout for Builder<'_, '_, '_> {
|
||||
}
|
||||
|
||||
impl ty::layout::HasTyCtxt<'tcx> for Builder<'_, '_, 'tcx> {
|
||||
#[inline]
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.cx.tcx
|
||||
}
|
||||
@ -81,6 +82,7 @@ impl ty::layout::HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> {
|
||||
}
|
||||
|
||||
impl HasTargetSpec for Builder<'_, '_, 'tcx> {
|
||||
#[inline]
|
||||
fn target_spec(&self) -> &Target {
|
||||
&self.cx.target_spec()
|
||||
}
|
||||
@ -98,6 +100,7 @@ impl abi::LayoutOf for Builder<'_, '_, 'tcx> {
|
||||
impl Deref for Builder<'_, 'll, 'tcx> {
|
||||
type Target = CodegenCx<'ll, 'tcx>;
|
||||
|
||||
#[inline]
|
||||
fn deref(&self) -> &Self::Target {
|
||||
self.cx
|
||||
}
|
||||
|
@ -765,18 +765,21 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
|
||||
}
|
||||
|
||||
impl HasDataLayout for CodegenCx<'ll, 'tcx> {
|
||||
#[inline]
|
||||
fn data_layout(&self) -> &TargetDataLayout {
|
||||
&self.tcx.data_layout
|
||||
}
|
||||
}
|
||||
|
||||
impl HasTargetSpec for CodegenCx<'ll, 'tcx> {
|
||||
#[inline]
|
||||
fn target_spec(&self) -> &Target {
|
||||
&self.tcx.sess.target
|
||||
}
|
||||
}
|
||||
|
||||
impl ty::layout::HasTyCtxt<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||
#[inline]
|
||||
fn tcx(&self) -> TyCtxt<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
@ -90,9 +90,11 @@ pub unsafe trait Tag: Copy {
|
||||
|
||||
unsafe impl<T> Pointer for Box<T> {
|
||||
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
|
||||
#[inline]
|
||||
fn into_usize(self) -> usize {
|
||||
Box::into_raw(self) as usize
|
||||
}
|
||||
#[inline]
|
||||
unsafe fn from_usize(ptr: usize) -> Self {
|
||||
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> {
|
||||
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
|
||||
#[inline]
|
||||
fn into_usize(self) -> usize {
|
||||
Rc::into_raw(self) as usize
|
||||
}
|
||||
#[inline]
|
||||
unsafe fn from_usize(ptr: usize) -> Self {
|
||||
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> {
|
||||
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
|
||||
#[inline]
|
||||
fn into_usize(self) -> usize {
|
||||
Arc::into_raw(self) as usize
|
||||
}
|
||||
#[inline]
|
||||
unsafe fn from_usize(ptr: usize) -> Self {
|
||||
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 {
|
||||
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
|
||||
#[inline]
|
||||
fn into_usize(self) -> usize {
|
||||
self as *const T as usize
|
||||
}
|
||||
#[inline]
|
||||
unsafe fn from_usize(ptr: usize) -> Self {
|
||||
&*(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 {
|
||||
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
|
||||
#[inline]
|
||||
fn into_usize(self) -> usize {
|
||||
self as *mut T as usize
|
||||
}
|
||||
#[inline]
|
||||
unsafe fn from_usize(ptr: usize) -> Self {
|
||||
&mut *(ptr as *mut T)
|
||||
}
|
||||
|
@ -715,6 +715,7 @@ impl Handler {
|
||||
self.inner.borrow_mut().bug(msg)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn err_count(&self) -> usize {
|
||||
self.inner.borrow().err_count()
|
||||
}
|
||||
@ -924,6 +925,7 @@ impl HandlerInner {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn err_count(&self) -> usize {
|
||||
self.err_count + self.stashed_diagnostics.len()
|
||||
}
|
||||
|
@ -305,6 +305,7 @@ impl Definitions {
|
||||
self.table.index_to_key.len()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn def_key(&self, id: LocalDefId) -> DefKey {
|
||||
self.table.def_key(id.local_def_index)
|
||||
}
|
||||
|
@ -2488,6 +2488,7 @@ pub enum FnRetTy<'hir> {
|
||||
}
|
||||
|
||||
impl FnRetTy<'_> {
|
||||
#[inline]
|
||||
pub fn span(&self) -> Span {
|
||||
match *self {
|
||||
Self::DefaultReturn(span) => span,
|
||||
|
@ -294,6 +294,7 @@ TrivialTypeFoldableImpls! {
|
||||
}
|
||||
|
||||
impl<'tcx> CanonicalVarValues<'tcx> {
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize {
|
||||
self.var_values.len()
|
||||
}
|
||||
|
@ -246,6 +246,7 @@ pub struct AllocDecodingState {
|
||||
}
|
||||
|
||||
impl AllocDecodingState {
|
||||
#[inline]
|
||||
pub fn new_decoding_session(&self) -> AllocDecodingSession<'_> {
|
||||
static DECODER_SESSION_ID: AtomicU32 = AtomicU32::new(0);
|
||||
let counter = DECODER_SESSION_ID.fetch_add(1, Ordering::SeqCst);
|
||||
|
@ -1249,10 +1249,12 @@ impl<'tcx> BasicBlockData<'tcx> {
|
||||
///
|
||||
/// Terminator may not be None after construction of the basic block is complete. This accessor
|
||||
/// provides a convenience way to reach the terminator.
|
||||
#[inline]
|
||||
pub fn terminator(&self) -> &Terminator<'tcx> {
|
||||
self.terminator.as_ref().expect("invalid terminator state")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn terminator_mut(&mut self) -> &mut Terminator<'tcx> {
|
||||
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
|
||||
/// projections, return `Some(_X)`.
|
||||
#[inline]
|
||||
pub fn as_local(&self) -> Option<Local> {
|
||||
match *self {
|
||||
PlaceRef { local, projection: [] } => Some(local),
|
||||
@ -1877,6 +1880,7 @@ impl<'tcx> PlaceRef<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn last_projection(&self) -> Option<(PlaceRef<'tcx>, PlaceElem<'tcx>)> {
|
||||
if let &[ref proj_base @ .., elem] = self.projection {
|
||||
Some((PlaceRef { local: self.local, projection: proj_base }, elem))
|
||||
@ -2464,12 +2468,14 @@ impl Constant<'tcx> {
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
pub fn ty(&self) -> Ty<'tcx> {
|
||||
self.literal.ty()
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&'tcx ty::Const<'tcx>> for ConstantKind<'tcx> {
|
||||
#[inline]
|
||||
fn from(ct: &'tcx ty::Const<'tcx>) -> Self {
|
||||
Self::Ty(ct)
|
||||
}
|
||||
|
@ -267,6 +267,7 @@ pub enum Visibility {
|
||||
}
|
||||
|
||||
impl<'tcx> CodegenUnit<'tcx> {
|
||||
#[inline]
|
||||
pub fn new(name: Symbol) -> CodegenUnit<'tcx> {
|
||||
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());
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn size_estimate(&self) -> usize {
|
||||
// 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")
|
||||
|
@ -93,6 +93,7 @@ pub struct Generics {
|
||||
}
|
||||
|
||||
impl<'tcx> Generics {
|
||||
#[inline]
|
||||
pub fn count(&self) -> usize {
|
||||
self.parent_count + self.params.len()
|
||||
}
|
||||
|
@ -37,9 +37,11 @@ pub struct 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;
|
||||
#[inline]
|
||||
fn into_usize(self) -> usize {
|
||||
self as *const List<T> as usize
|
||||
}
|
||||
#[inline]
|
||||
unsafe fn from_usize(ptr: usize) -> Self {
|
||||
&*(ptr as *const List<T>)
|
||||
}
|
||||
|
@ -1097,12 +1097,14 @@ pub struct ParamEnv<'tcx> {
|
||||
|
||||
unsafe impl rustc_data_structures::tagged_ptr::Tag for traits::Reveal {
|
||||
const BITS: usize = 1;
|
||||
#[inline]
|
||||
fn into_usize(self) -> usize {
|
||||
match self {
|
||||
traits::Reveal::UserFacing => 0,
|
||||
traits::Reveal::All => 1,
|
||||
}
|
||||
}
|
||||
#[inline]
|
||||
unsafe fn from_usize(ptr: usize) -> Self {
|
||||
match ptr {
|
||||
0 => traits::Reveal::UserFacing,
|
||||
@ -1200,6 +1202,7 @@ impl<'tcx> ParamEnv<'tcx> {
|
||||
}
|
||||
|
||||
/// Returns this same environment but with no caller bounds.
|
||||
#[inline]
|
||||
pub fn without_caller_bounds(self) -> Self {
|
||||
Self::new(List::empty(), self.reveal())
|
||||
}
|
||||
|
@ -452,6 +452,7 @@ impl Session {
|
||||
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) {
|
||||
err.into_diagnostic(self).emit()
|
||||
}
|
||||
#[inline]
|
||||
pub fn err_count(&self) -> usize {
|
||||
self.diagnostic().err_count()
|
||||
}
|
||||
@ -524,6 +525,7 @@ impl Session {
|
||||
self.diagnostic().struct_note_without_error(msg)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn diagnostic(&self) -> &rustc_errors::Handler {
|
||||
&self.parse_sess.span_diagnostic
|
||||
}
|
||||
|
@ -20,10 +20,12 @@ rustc_index::newtype_index! {
|
||||
pub const LOCAL_CRATE: CrateNum = CrateNum::from_u32(0);
|
||||
|
||||
impl CrateNum {
|
||||
#[inline]
|
||||
pub fn new(x: usize) -> CrateNum {
|
||||
CrateNum::from_usize(x)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_def_id(&self) -> DefId {
|
||||
DefId { krate: *self, index: CRATE_DEF_INDEX }
|
||||
}
|
||||
|
@ -222,6 +222,7 @@ pub trait HasDataLayout {
|
||||
}
|
||||
|
||||
impl HasDataLayout for TargetDataLayout {
|
||||
#[inline]
|
||||
fn data_layout(&self) -> &TargetDataLayout {
|
||||
self
|
||||
}
|
||||
@ -862,6 +863,7 @@ pub enum Abi {
|
||||
|
||||
impl Abi {
|
||||
/// Returns `true` if the layout corresponds to an unsized type.
|
||||
#[inline]
|
||||
pub fn is_unsized(&self) -> bool {
|
||||
match *self {
|
||||
Abi::Uninhabited | Abi::Scalar(_) | Abi::ScalarPair(..) | Abi::Vector { .. } => false,
|
||||
@ -881,11 +883,13 @@ impl Abi {
|
||||
}
|
||||
|
||||
/// Returns `true` if this is an uninhabited type
|
||||
#[inline]
|
||||
pub fn is_uninhabited(&self) -> bool {
|
||||
matches!(*self, Abi::Uninhabited)
|
||||
}
|
||||
|
||||
/// Returns `true` is this is a scalar type
|
||||
#[inline]
|
||||
pub fn is_scalar(&self) -> bool {
|
||||
matches!(*self, Abi::Scalar(_))
|
||||
}
|
||||
|
@ -922,6 +922,7 @@ pub trait HasTargetSpec {
|
||||
}
|
||||
|
||||
impl HasTargetSpec for Target {
|
||||
#[inline]
|
||||
fn target_spec(&self) -> &Target {
|
||||
self
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user