Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 2 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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
}

0 commit comments

Comments
 (0)