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

+3
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

+3
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

+10
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

+2
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

+1
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

+1
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

+1
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

+1
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

+6
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

+2
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")

compiler/rustc_middle/src/ty/generics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ pub struct Generics {
9393
}
9494

9595
impl<'tcx> Generics {
96+
#[inline]
9697
pub fn count(&self) -> usize {
9798
self.parent_count + self.params.len()
9899
}

compiler/rustc_middle/src/ty/list.rs

+2
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@ pub struct List<T> {
3737

3838
unsafe impl<'a, T: 'a> rustc_data_structures::tagged_ptr::Pointer for &'a List<T> {
3939
const BITS: usize = std::mem::align_of::<usize>().trailing_zeros() as usize;
40+
#[inline]
4041
fn into_usize(self) -> usize {
4142
self as *const List<T> as usize
4243
}
44+
#[inline]
4345
unsafe fn from_usize(ptr: usize) -> Self {
4446
&*(ptr as *const List<T>)
4547
}

compiler/rustc_middle/src/ty/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1097,12 +1097,14 @@ pub struct ParamEnv<'tcx> {
10971097

10981098
unsafe impl rustc_data_structures::tagged_ptr::Tag for traits::Reveal {
10991099
const BITS: usize = 1;
1100+
#[inline]
11001101
fn into_usize(self) -> usize {
11011102
match self {
11021103
traits::Reveal::UserFacing => 0,
11031104
traits::Reveal::All => 1,
11041105
}
11051106
}
1107+
#[inline]
11061108
unsafe fn from_usize(ptr: usize) -> Self {
11071109
match ptr {
11081110
0 => traits::Reveal::UserFacing,
@@ -1200,6 +1202,7 @@ impl<'tcx> ParamEnv<'tcx> {
12001202
}
12011203

12021204
/// Returns this same environment but with no caller bounds.
1205+
#[inline]
12031206
pub fn without_caller_bounds(self) -> Self {
12041207
Self::new(List::empty(), self.reveal())
12051208
}

compiler/rustc_session/src/session.rs

+2
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ impl Session {
452452
pub fn emit_err<'a>(&'a self, err: impl SessionDiagnostic<'a>) {
453453
err.into_diagnostic(self).emit()
454454
}
455+
#[inline]
455456
pub fn err_count(&self) -> usize {
456457
self.diagnostic().err_count()
457458
}
@@ -524,6 +525,7 @@ impl Session {
524525
self.diagnostic().struct_note_without_error(msg)
525526
}
526527

528+
#[inline]
527529
pub fn diagnostic(&self) -> &rustc_errors::Handler {
528530
&self.parse_sess.span_diagnostic
529531
}

compiler/rustc_span/src/def_id.rs

+2
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@ rustc_index::newtype_index! {
2020
pub const LOCAL_CRATE: CrateNum = CrateNum::from_u32(0);
2121

2222
impl CrateNum {
23+
#[inline]
2324
pub fn new(x: usize) -> CrateNum {
2425
CrateNum::from_usize(x)
2526
}
2627

28+
#[inline]
2729
pub fn as_def_id(&self) -> DefId {
2830
DefId { krate: *self, index: CRATE_DEF_INDEX }
2931
}

compiler/rustc_target/src/abi/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ pub trait HasDataLayout {
222222
}
223223

224224
impl HasDataLayout for TargetDataLayout {
225+
#[inline]
225226
fn data_layout(&self) -> &TargetDataLayout {
226227
self
227228
}
@@ -862,6 +863,7 @@ pub enum Abi {
862863

863864
impl Abi {
864865
/// Returns `true` if the layout corresponds to an unsized type.
866+
#[inline]
865867
pub fn is_unsized(&self) -> bool {
866868
match *self {
867869
Abi::Uninhabited | Abi::Scalar(_) | Abi::ScalarPair(..) | Abi::Vector { .. } => false,
@@ -881,11 +883,13 @@ impl Abi {
881883
}
882884

883885
/// Returns `true` if this is an uninhabited type
886+
#[inline]
884887
pub fn is_uninhabited(&self) -> bool {
885888
matches!(*self, Abi::Uninhabited)
886889
}
887890

888891
/// Returns `true` is this is a scalar type
892+
#[inline]
889893
pub fn is_scalar(&self) -> bool {
890894
matches!(*self, Abi::Scalar(_))
891895
}

compiler/rustc_target/src/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ pub trait HasTargetSpec {
922922
}
923923

924924
impl HasTargetSpec for Target {
925+
#[inline]
925926
fn target_spec(&self) -> &Target {
926927
self
927928
}

0 commit comments

Comments
 (0)