Skip to content

Commit 1e13a9b

Browse files
committed
Auto merge of #85892 - tmiasko:i, r=oli-obk
Miscellaneous inlining improvements
2 parents 7350f65 + c1f6495 commit 1e13a9b

File tree

17 files changed

+45
-0
lines changed

17 files changed

+45
-0
lines changed

compiler/rustc_codegen_llvm/src/builder.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl abi::HasDataLayout for Builder<'_, '_, '_> {
6969
}
7070

7171
impl ty::layout::HasTyCtxt<'tcx> for Builder<'_, '_, 'tcx> {
72+
#[inline]
7273
fn tcx(&self) -> TyCtxt<'tcx> {
7374
self.cx.tcx
7475
}
@@ -81,6 +82,7 @@ impl ty::layout::HasParamEnv<'tcx> for Builder<'_, '_, 'tcx> {
8182
}
8283

8384
impl HasTargetSpec for Builder<'_, '_, 'tcx> {
85+
#[inline]
8486
fn target_spec(&self) -> &Target {
8587
&self.cx.target_spec()
8688
}
@@ -98,6 +100,7 @@ impl abi::LayoutOf for Builder<'_, '_, 'tcx> {
98100
impl Deref for Builder<'_, 'll, 'tcx> {
99101
type Target = CodegenCx<'ll, 'tcx>;
100102

103+
#[inline]
101104
fn deref(&self) -> &Self::Target {
102105
self.cx
103106
}

compiler/rustc_codegen_llvm/src/context.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -765,18 +765,21 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> {
765765
}
766766

767767
impl HasDataLayout for CodegenCx<'ll, 'tcx> {
768+
#[inline]
768769
fn data_layout(&self) -> &TargetDataLayout {
769770
&self.tcx.data_layout
770771
}
771772
}
772773

773774
impl HasTargetSpec for CodegenCx<'ll, 'tcx> {
775+
#[inline]
774776
fn target_spec(&self) -> &Target {
775777
&self.tcx.sess.target
776778
}
777779
}
778780

779781
impl ty::layout::HasTyCtxt<'tcx> for CodegenCx<'ll, 'tcx> {
782+
#[inline]
780783
fn tcx(&self) -> TyCtxt<'tcx> {
781784
self.tcx
782785
}

compiler/rustc_data_structures/src/tagged_ptr.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ pub unsafe trait Tag: Copy {
9090

9191
unsafe impl<T> Pointer for Box<T> {
9292
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
93+
#[inline]
9394
fn into_usize(self) -> usize {
9495
Box::into_raw(self) as usize
9596
}
97+
#[inline]
9698
unsafe fn from_usize(ptr: usize) -> Self {
9799
Box::from_raw(ptr as *mut T)
98100
}
@@ -104,9 +106,11 @@ unsafe impl<T> Pointer for Box<T> {
104106

105107
unsafe impl<T> Pointer for Rc<T> {
106108
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
109+
#[inline]
107110
fn into_usize(self) -> usize {
108111
Rc::into_raw(self) as usize
109112
}
113+
#[inline]
110114
unsafe fn from_usize(ptr: usize) -> Self {
111115
Rc::from_raw(ptr as *const T)
112116
}
@@ -118,9 +122,11 @@ unsafe impl<T> Pointer for Rc<T> {
118122

119123
unsafe impl<T> Pointer for Arc<T> {
120124
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
125+
#[inline]
121126
fn into_usize(self) -> usize {
122127
Arc::into_raw(self) as usize
123128
}
129+
#[inline]
124130
unsafe fn from_usize(ptr: usize) -> Self {
125131
Arc::from_raw(ptr as *const T)
126132
}
@@ -132,9 +138,11 @@ unsafe impl<T> Pointer for Arc<T> {
132138

133139
unsafe impl<'a, T: 'a> Pointer for &'a T {
134140
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
141+
#[inline]
135142
fn into_usize(self) -> usize {
136143
self as *const T as usize
137144
}
145+
#[inline]
138146
unsafe fn from_usize(ptr: usize) -> Self {
139147
&*(ptr as *const T)
140148
}
@@ -145,9 +153,11 @@ unsafe impl<'a, T: 'a> Pointer for &'a T {
145153

146154
unsafe impl<'a, T: 'a> Pointer for &'a mut T {
147155
const BITS: usize = std::mem::align_of::<T>().trailing_zeros() as usize;
156+
#[inline]
148157
fn into_usize(self) -> usize {
149158
self as *mut T as usize
150159
}
160+
#[inline]
151161
unsafe fn from_usize(ptr: usize) -> Self {
152162
&mut *(ptr as *mut T)
153163
}

compiler/rustc_errors/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,7 @@ impl Handler {
715715
self.inner.borrow_mut().bug(msg)
716716
}
717717

718+
#[inline]
718719
pub fn err_count(&self) -> usize {
719720
self.inner.borrow().err_count()
720721
}
@@ -924,6 +925,7 @@ impl HandlerInner {
924925
}
925926
}
926927

928+
#[inline]
927929
fn err_count(&self) -> usize {
928930
self.err_count + self.stashed_diagnostics.len()
929931
}

compiler/rustc_hir/src/definitions.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ impl Definitions {
305305
self.table.index_to_key.len()
306306
}
307307

308+
#[inline]
308309
pub fn def_key(&self, id: LocalDefId) -> DefKey {
309310
self.table.def_key(id.local_def_index)
310311
}

compiler/rustc_hir/src/hir.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2488,6 +2488,7 @@ pub enum FnRetTy<'hir> {
24882488
}
24892489

24902490
impl FnRetTy<'_> {
2491+
#[inline]
24912492
pub fn span(&self) -> Span {
24922493
match *self {
24932494
Self::DefaultReturn(span) => span,

compiler/rustc_middle/src/infer/canonical.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ TrivialTypeFoldableImpls! {
294294
}
295295

296296
impl<'tcx> CanonicalVarValues<'tcx> {
297+
#[inline]
297298
pub fn len(&self) -> usize {
298299
self.var_values.len()
299300
}

compiler/rustc_middle/src/mir/interpret/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ pub struct AllocDecodingState {
246246
}
247247

248248
impl AllocDecodingState {
249+
#[inline]
249250
pub fn new_decoding_session(&self) -> AllocDecodingSession<'_> {
250251
static DECODER_SESSION_ID: AtomicU32 = AtomicU32::new(0);
251252
let counter = DECODER_SESSION_ID.fetch_add(1, Ordering::SeqCst);

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,10 +1249,12 @@ impl<'tcx> BasicBlockData<'tcx> {
12491249
///
12501250
/// Terminator may not be None after construction of the basic block is complete. This accessor
12511251
/// provides a convenience way to reach the terminator.
1252+
#[inline]
12521253
pub fn terminator(&self) -> &Terminator<'tcx> {
12531254
self.terminator.as_ref().expect("invalid terminator state")
12541255
}
12551256

1257+
#[inline]
12561258
pub fn terminator_mut(&mut self) -> &mut Terminator<'tcx> {
12571259
self.terminator.as_mut().expect("invalid terminator state")
12581260
}
@@ -1870,13 +1872,15 @@ impl<'tcx> PlaceRef<'tcx> {
18701872

18711873
/// If this place represents a local variable like `_X` with no
18721874
/// projections, return `Some(_X)`.
1875+
#[inline]
18731876
pub fn as_local(&self) -> Option<Local> {
18741877
match *self {
18751878
PlaceRef { local, projection: [] } => Some(local),
18761879
_ => None,
18771880
}
18781881
}
18791882

1883+
#[inline]
18801884
pub fn last_projection(&self) -> Option<(PlaceRef<'tcx>, PlaceElem<'tcx>)> {
18811885
if let &[ref proj_base @ .., elem] = self.projection {
18821886
Some((PlaceRef { local: self.local, projection: proj_base }, elem))
@@ -2464,12 +2468,14 @@ impl Constant<'tcx> {
24642468
_ => None,
24652469
}
24662470
}
2471+
#[inline]
24672472
pub fn ty(&self) -> Ty<'tcx> {
24682473
self.literal.ty()
24692474
}
24702475
}
24712476

24722477
impl From<&'tcx ty::Const<'tcx>> for ConstantKind<'tcx> {
2478+
#[inline]
24732479
fn from(ct: &'tcx ty::Const<'tcx>) -> Self {
24742480
Self::Ty(ct)
24752481
}

compiler/rustc_middle/src/mir/mono.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,7 @@ pub enum Visibility {
267267
}
268268

269269
impl<'tcx> CodegenUnit<'tcx> {
270+
#[inline]
270271
pub fn new(name: Symbol) -> CodegenUnit<'tcx> {
271272
CodegenUnit { name, items: Default::default(), size_estimate: None, primary: false }
272273
}
@@ -311,6 +312,7 @@ impl<'tcx> CodegenUnit<'tcx> {
311312
self.size_estimate = Some(self.items.keys().map(|mi| mi.size_estimate(tcx)).sum());
312313
}
313314

315+
#[inline]
314316
pub fn size_estimate(&self) -> usize {
315317
// Should only be called if `estimate_size` has previously been called.
316318
self.size_estimate.expect("estimate_size must be called before getting a size_estimate")

0 commit comments

Comments
 (0)