Skip to content

Commit 5e7a352

Browse files
committed
Auto merge of rust-lang#130685 - workingjubilee:inline-usually-thats-what-she-sed, r=<try>
try `inline(usually)` more see rust-lang#130679 figured I'd see what happens if you sed it in to the library.
2 parents 55043f0 + e2999d9 commit 5e7a352

File tree

60 files changed

+400
-385
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+400
-385
lines changed

compiler/rustc_attr/src/builtin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ pub enum InlineAttr {
4646
Hint,
4747
Always,
4848
Never,
49+
Usually,
4950
}
5051

5152
#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic)]

compiler/rustc_codegen_gcc/src/attributes.rs

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ fn inline_attr<'gcc, 'tcx>(
3131
}
3232
}
3333
InlineAttr::None => None,
34+
InlineAttr::Usually => None,
3435
}
3536
}
3637

compiler/rustc_codegen_llvm/src/attributes.rs

+3
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ fn inline_attr<'ll>(cx: &CodegenCx<'ll, '_>, inline: InlineAttr) -> Option<&'ll
4747
}
4848
}
4949
InlineAttr::None => None,
50+
InlineAttr::Usually => {
51+
Some(llvm::CreateAttrStringValue(cx.llcx, "function-inline-cost", "0"))
52+
}
5053
}
5154
}
5255

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+2
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
528528
InlineAttr::Always
529529
} else if list_contains_name(items, sym::never) {
530530
InlineAttr::Never
531+
} else if list_contains_name(items, sym::usually) {
532+
InlineAttr::Usually
531533
} else {
532534
struct_span_code_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument")
533535
.with_help("valid inline arguments are `always` and `never`")

compiler/rustc_middle/src/mir/mono.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ impl<'tcx> MonoItem<'tcx> {
138138
// conflict with upstream crates as it could be an exported
139139
// symbol.
140140
match tcx.codegen_fn_attrs(instance.def_id()).inline {
141-
InlineAttr::Always => InstantiationMode::LocalCopy,
141+
InlineAttr::Always | InlineAttr::Usually => InstantiationMode::LocalCopy,
142142
_ => InstantiationMode::GloballyShared { may_conflict: true },
143143
}
144144
}

compiler/rustc_mir_transform/src/cross_crate_inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn cross_crate_inlinable(tcx: TyCtxt<'_>, def_id: LocalDefId) -> bool {
4646
// #[inline(never)] to force code generation.
4747
match codegen_fn_attrs.inline {
4848
InlineAttr::Never => return false,
49-
InlineAttr::Hint | InlineAttr::Always => return true,
49+
InlineAttr::Hint | InlineAttr::Always | InlineAttr::Usually => return true,
5050
_ => {}
5151
}
5252

compiler/rustc_mir_transform/src/inline.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn inline<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> bool {
106106
changed: false,
107107
caller_is_inline_forwarder: matches!(
108108
codegen_fn_attrs.inline,
109-
InlineAttr::Hint | InlineAttr::Always
109+
InlineAttr::Hint | InlineAttr::Always | InlineAttr::Usually
110110
) && body_is_forwarder(body),
111111
};
112112
let blocks = START_BLOCK..body.basic_blocks.next_index();

compiler/rustc_span/src/symbol.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2101,6 +2101,7 @@ symbols! {
21012101
usize_legacy_fn_max_value,
21022102
usize_legacy_fn_min_value,
21032103
usize_legacy_mod,
2104+
usually,
21042105
va_arg,
21052106
va_copy,
21062107
va_end,

library/alloc/src/boxed.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ impl<T> Box<T> {
246246
/// let five = Box::new(5);
247247
/// ```
248248
#[cfg(not(no_global_oom_handling))]
249-
#[inline(always)]
249+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
250250
#[stable(feature = "rust1", since = "1.0.0")]
251251
#[must_use]
252252
#[rustc_diagnostic_item = "box_new"]
@@ -316,7 +316,7 @@ impl<T> Box<T> {
316316
#[cfg(not(no_global_oom_handling))]
317317
#[stable(feature = "pin", since = "1.33.0")]
318318
#[must_use]
319-
#[inline(always)]
319+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
320320
pub fn pin(x: T) -> Pin<Box<T>> {
321321
Box::new(x).into()
322322
}
@@ -609,7 +609,7 @@ impl<T, A: Allocator> Box<T, A> {
609609
#[cfg(not(no_global_oom_handling))]
610610
#[unstable(feature = "allocator_api", issue = "32838")]
611611
#[must_use]
612-
#[inline(always)]
612+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
613613
pub fn pin_in(x: T, alloc: A) -> Pin<Self>
614614
where
615615
A: 'static + Allocator,

library/alloc/src/collections/binary_heap/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ impl<T: Ord, A: Allocator> BinaryHeap<T, A> {
801801

802802
let tail_len = self.len() - start;
803803

804-
#[inline(always)]
804+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
805805
fn log2_fast(x: usize) -> usize {
806806
(usize::BITS - x.leading_zeros() - 1) as usize
807807
}

library/alloc/src/collections/linked_list.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ impl<'a, T, A: Allocator> Cursor<'a, T, A> {
14971497

14981498
/// Provides a reference to the cursor's parent list.
14991499
#[must_use]
1500-
#[inline(always)]
1500+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
15011501
#[unstable(feature = "linked_list_cursors", issue = "58533")]
15021502
pub fn as_list(&self) -> &'a LinkedList<T, A> {
15031503
self.list
@@ -1619,7 +1619,7 @@ impl<'a, T, A: Allocator> CursorMut<'a, T, A> {
16191619
/// `CursorMut`, which means it cannot outlive the `CursorMut` and that the
16201620
/// `CursorMut` is frozen for the lifetime of the reference.
16211621
#[must_use]
1622-
#[inline(always)]
1622+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
16231623
#[unstable(feature = "linked_list_cursors", issue = "58533")]
16241624
pub fn as_list(&self) -> &LinkedList<T, A> {
16251625
self.list

library/alloc/src/ffi/c_str.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ impl CString {
273273
}
274274

275275
// Specialization for avoiding reallocation
276-
#[inline(always)] // Without that it is not inlined into specializations
276+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))] // Without that it is not inlined into specializations
277277
fn spec_new_impl_bytes(bytes: &[u8]) -> Result<CString, NulError> {
278278
// We cannot have such large slice that we would overflow here
279279
// but using `checked_add` allows LLVM to assume that capacity never overflows

library/alloc/src/rc.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl<T: ?Sized> Rc<T> {
354354
}
355355

356356
impl<T: ?Sized, A: Allocator> Rc<T, A> {
357-
#[inline(always)]
357+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
358358
fn inner(&self) -> &RcBox<T> {
359359
// This unsafety is ok because while this Rc is alive we're guaranteed
360360
// that the inner pointer is valid.
@@ -2207,7 +2207,7 @@ impl<T: Copy> RcFromSlice<T> for Rc<[T]> {
22072207
impl<T: ?Sized, A: Allocator> Deref for Rc<T, A> {
22082208
type Target = T;
22092209

2210-
#[inline(always)]
2210+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
22112211
fn deref(&self) -> &T {
22122212
&self.inner().value
22132213
}
@@ -2453,7 +2453,7 @@ impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Rc<T, A> {
24532453
///
24542454
/// assert_eq!(Some(Ordering::Less), five.partial_cmp(&Rc::new(6)));
24552455
/// ```
2456-
#[inline(always)]
2456+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
24572457
fn partial_cmp(&self, other: &Rc<T, A>) -> Option<Ordering> {
24582458
(**self).partial_cmp(&**other)
24592459
}
@@ -2471,7 +2471,7 @@ impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Rc<T, A> {
24712471
///
24722472
/// assert!(five < Rc::new(6));
24732473
/// ```
2474-
#[inline(always)]
2474+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
24752475
fn lt(&self, other: &Rc<T, A>) -> bool {
24762476
**self < **other
24772477
}
@@ -2489,7 +2489,7 @@ impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Rc<T, A> {
24892489
///
24902490
/// assert!(five <= Rc::new(5));
24912491
/// ```
2492-
#[inline(always)]
2492+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
24932493
fn le(&self, other: &Rc<T, A>) -> bool {
24942494
**self <= **other
24952495
}
@@ -2507,7 +2507,7 @@ impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Rc<T, A> {
25072507
///
25082508
/// assert!(five > Rc::new(4));
25092509
/// ```
2510-
#[inline(always)]
2510+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
25112511
fn gt(&self, other: &Rc<T, A>) -> bool {
25122512
**self > **other
25132513
}
@@ -2525,7 +2525,7 @@ impl<T: ?Sized + PartialOrd, A: Allocator> PartialOrd for Rc<T, A> {
25252525
///
25262526
/// assert!(five >= Rc::new(5));
25272527
/// ```
2528-
#[inline(always)]
2528+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
25292529
fn ge(&self, other: &Rc<T, A>) -> bool {
25302530
**self >= **other
25312531
}
@@ -3527,24 +3527,24 @@ trait RcInnerPtr {
35273527
}
35283528

35293529
impl<T: ?Sized> RcInnerPtr for RcBox<T> {
3530-
#[inline(always)]
3530+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
35313531
fn weak_ref(&self) -> &Cell<usize> {
35323532
&self.weak
35333533
}
35343534

3535-
#[inline(always)]
3535+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
35363536
fn strong_ref(&self) -> &Cell<usize> {
35373537
&self.strong
35383538
}
35393539
}
35403540

35413541
impl<'a> RcInnerPtr for WeakInner<'a> {
3542-
#[inline(always)]
3542+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
35433543
fn weak_ref(&self) -> &Cell<usize> {
35443544
self.weak
35453545
}
35463546

3547-
#[inline(always)]
3547+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
35483548
fn strong_ref(&self) -> &Cell<usize> {
35493549
self.strong
35503550
}

library/alloc/src/task.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -133,18 +133,18 @@ impl<W: Wake + Send + Sync + 'static> From<Arc<W>> for RawWaker {
133133
// trait dispatch - instead both impls call this function directly and
134134
// explicitly.
135135
#[cfg(target_has_atomic = "ptr")]
136-
#[inline(always)]
136+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
137137
fn raw_waker<W: Wake + Send + Sync + 'static>(waker: Arc<W>) -> RawWaker {
138138
// Increment the reference count of the arc to clone it.
139139
//
140-
// The #[inline(always)] is to ensure that raw_waker and clone_waker are
140+
// The #[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))] is to ensure that raw_waker and clone_waker are
141141
// always generated in the same code generation unit as one another, and
142142
// therefore that the structurally identical const-promoted RawWakerVTable
143143
// within both functions is deduplicated at LLVM IR code generation time.
144144
// This allows optimizing Waker::will_wake to a single pointer comparison of
145145
// the vtable pointers, rather than comparing all four function pointers
146146
// within the vtables.
147-
#[inline(always)]
147+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
148148
unsafe fn clone_waker<W: Wake + Send + Sync + 'static>(waker: *const ()) -> RawWaker {
149149
unsafe { Arc::increment_strong_count(waker as *const W) };
150150
RawWaker::new(
@@ -310,13 +310,13 @@ impl<W: LocalWake + 'static> From<Rc<W>> for RawWaker {
310310
// the safety of `From<Rc<W>> for Waker` does not depend on the correct
311311
// trait dispatch - instead both impls call this function directly and
312312
// explicitly.
313-
#[inline(always)]
313+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
314314
fn local_raw_waker<W: LocalWake + 'static>(waker: Rc<W>) -> RawWaker {
315315
// Increment the reference count of the Rc to clone it.
316316
//
317317
// Refer to the comment on raw_waker's clone_waker regarding why this is
318318
// always inline.
319-
#[inline(always)]
319+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
320320
unsafe fn clone_waker<W: LocalWake + 'static>(waker: *const ()) -> RawWaker {
321321
unsafe { Rc::increment_strong_count(waker as *const W) };
322322
RawWaker::new(

library/core/src/alloc/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ impl Layout {
8484
true
8585
}
8686

87-
#[inline(always)]
87+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
8888
const fn max_size_for_align(align: Alignment) -> usize {
8989
// (power-of-two implies align != 0.)
9090

library/core/src/alloc/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ pub unsafe trait Allocator {
360360
/// Creates a "by reference" adapter for this instance of `Allocator`.
361361
///
362362
/// The returned adapter also implements `Allocator` and will simply borrow this.
363-
#[inline(always)]
363+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
364364
fn by_ref(&self) -> &Self
365365
where
366366
Self: Sized,

library/core/src/cell.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -813,12 +813,12 @@ fn panic_already_mutably_borrowed(err: BorrowError) -> ! {
813813
type BorrowFlag = isize;
814814
const UNUSED: BorrowFlag = 0;
815815

816-
#[inline(always)]
816+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
817817
fn is_writing(x: BorrowFlag) -> bool {
818818
x < UNUSED
819819
}
820820

821-
#[inline(always)]
821+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
822822
fn is_reading(x: BorrowFlag) -> bool {
823823
x > UNUSED
824824
}
@@ -2079,7 +2079,7 @@ impl<T> UnsafeCell<T> {
20792079
/// ```
20802080
#[stable(feature = "rust1", since = "1.0.0")]
20812081
#[rustc_const_stable(feature = "const_unsafe_cell_new", since = "1.32.0")]
2082-
#[inline(always)]
2082+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
20832083
pub const fn new(value: T) -> UnsafeCell<T> {
20842084
UnsafeCell { value }
20852085
}
@@ -2095,7 +2095,7 @@ impl<T> UnsafeCell<T> {
20952095
///
20962096
/// let five = uc.into_inner();
20972097
/// ```
2098-
#[inline(always)]
2098+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
20992099
#[stable(feature = "rust1", since = "1.0.0")]
21002100
// When this is const stabilized, please remove `primitive_into_inner` below.
21012101
#[rustc_const_unstable(feature = "const_cell_into_inner", issue = "78729")]
@@ -2119,7 +2119,7 @@ impl<T: ?Sized> UnsafeCell<T> {
21192119
/// *uc.get_mut() -= 1;
21202120
/// assert_eq!(*uc.get_mut(), 41);
21212121
/// ```
2122-
#[inline(always)]
2122+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
21232123
#[unstable(feature = "unsafe_cell_from_mut", issue = "111645")]
21242124
pub const fn from_mut(value: &mut T) -> &mut UnsafeCell<T> {
21252125
// SAFETY: `UnsafeCell<T>` has the same memory layout as `T` due to #[repr(transparent)].
@@ -2142,7 +2142,7 @@ impl<T: ?Sized> UnsafeCell<T> {
21422142
///
21432143
/// let five = uc.get();
21442144
/// ```
2145-
#[inline(always)]
2145+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
21462146
#[stable(feature = "rust1", since = "1.0.0")]
21472147
#[rustc_const_stable(feature = "const_unsafecell_get", since = "1.32.0")]
21482148
#[rustc_never_returns_null_ptr]
@@ -2168,7 +2168,7 @@ impl<T: ?Sized> UnsafeCell<T> {
21682168
///
21692169
/// assert_eq!(*c.get_mut(), 6);
21702170
/// ```
2171-
#[inline(always)]
2171+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
21722172
#[stable(feature = "unsafe_cell_get_mut", since = "1.50.0")]
21732173
#[rustc_const_unstable(feature = "const_unsafecell_get_mut", issue = "88836")]
21742174
pub const fn get_mut(&mut self) -> &mut T {
@@ -2203,7 +2203,7 @@ impl<T: ?Sized> UnsafeCell<T> {
22032203
///
22042204
/// assert_eq!(uc.into_inner(), 5);
22052205
/// ```
2206-
#[inline(always)]
2206+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
22072207
#[stable(feature = "unsafe_cell_raw_get", since = "1.56.0")]
22082208
#[rustc_const_stable(feature = "unsafe_cell_raw_get", since = "1.56.0")]
22092209
#[rustc_diagnostic_item = "unsafe_cell_raw_get"]

library/core/src/clone.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ mod impls {
321321
$(
322322
#[stable(feature = "rust1", since = "1.0.0")]
323323
impl Clone for $t {
324-
#[inline(always)]
324+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
325325
fn clone(&self) -> Self {
326326
*self
327327
}
@@ -347,15 +347,15 @@ mod impls {
347347

348348
#[stable(feature = "rust1", since = "1.0.0")]
349349
impl<T: ?Sized> Clone for *const T {
350-
#[inline(always)]
350+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
351351
fn clone(&self) -> Self {
352352
*self
353353
}
354354
}
355355

356356
#[stable(feature = "rust1", since = "1.0.0")]
357357
impl<T: ?Sized> Clone for *mut T {
358-
#[inline(always)]
358+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
359359
fn clone(&self) -> Self {
360360
*self
361361
}
@@ -364,7 +364,7 @@ mod impls {
364364
/// Shared references can be cloned, but mutable references *cannot*!
365365
#[stable(feature = "rust1", since = "1.0.0")]
366366
impl<T: ?Sized> Clone for &T {
367-
#[inline(always)]
367+
#[cfg_attr(bootstrap, inline(always))]#[cfg_attr(not(bootstrap), inline(usually))]
368368
#[rustc_diagnostic_item = "noop_method_clone"]
369369
fn clone(&self) -> Self {
370370
*self

0 commit comments

Comments
 (0)