Skip to content

Miscellaneous inlining improvements #85892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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()
}
Expand All @@ -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
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 10 additions & 0 deletions compiler/rustc_data_structures/src/tagged_ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,7 @@ impl Handler {
self.inner.borrow_mut().bug(msg)
}

#[inline]
pub fn err_count(&self) -> usize {
self.inner.borrow().err_count()
}
Expand Down Expand Up @@ -924,6 +925,7 @@ impl HandlerInner {
}
}

#[inline]
fn err_count(&self) -> usize {
self.err_count + self.stashed_diagnostics.len()
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2485,6 +2485,7 @@ pub enum FnRetTy<'hir> {
}

impl FnRetTy<'_> {
#[inline]
pub fn span(&self) -> Span {
match *self {
Self::DefaultReturn(span) => span,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/infer/canonical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ TrivialTypeFoldableImpls! {
}

impl<'tcx> CanonicalVarValues<'tcx> {
#[inline]
pub fn len(&self) -> usize {
self.var_values.len()
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -1870,13 +1872,15 @@ 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),
_ => None,
}
}

#[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))
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/mir/mono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_middle/src/ty/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ pub struct Generics {
}

impl<'tcx> Generics {
#[inline]
pub fn count(&self) -> usize {
self.parent_count + self.params.len()
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/ty/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
}
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
}
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_span/src/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_target/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ pub trait HasDataLayout {
}

impl HasDataLayout for TargetDataLayout {
#[inline]
fn data_layout(&self) -> &TargetDataLayout {
self
}
Expand Down Expand Up @@ -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,
Expand All @@ -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(_))
}
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_target/src/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,7 @@ pub trait HasTargetSpec {
}

impl HasTargetSpec for Target {
#[inline]
fn target_spec(&self) -> &Target {
self
}
Expand Down