Skip to content

Commit e85e8d8

Browse files
committed
Add inline(usually)
1 parent f48c99a commit e85e8d8

File tree

10 files changed

+24
-10
lines changed

10 files changed

+24
-10
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_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
@@ -546,6 +546,8 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
546546
InlineAttr::Always
547547
} else if list_contains_name(items, sym::never) {
548548
InlineAttr::Never
549+
} else if list_contains_name(items, sym::usually) {
550+
InlineAttr::Usually
549551
} else {
550552
struct_span_code_err!(tcx.dcx(), items[0].span(), E0535, "invalid argument")
551553
.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/core/src/option.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,8 @@ impl<T> Option<T> {
958958
/// let x: Option<&str> = None;
959959
/// assert_eq!(x.unwrap(), "air"); // fails
960960
/// ```
961-
#[inline(always)]
961+
#[cfg_attr(bootstrap, inline(always))]
962+
#[cfg_attr(not(bootstrap), inline(usually))]
962963
#[track_caller]
963964
#[stable(feature = "rust1", since = "1.0.0")]
964965
#[cfg_attr(not(test), rustc_diagnostic_item = "option_unwrap")]

library/core/src/result.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,8 @@ impl<T, E> Result<T, E> {
10911091
/// let x: Result<u32, &str> = Err("emergency failure");
10921092
/// x.unwrap(); // panics with `emergency failure`
10931093
/// ```
1094-
#[inline(always)]
1094+
#[cfg_attr(bootstrap, inline(always))]
1095+
#[cfg_attr(not(bootstrap), inline(usually))]
10951096
#[track_caller]
10961097
#[stable(feature = "rust1", since = "1.0.0")]
10971098
pub fn unwrap(self) -> T

library/core/src/slice/index.rs

+10-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ where
1111
{
1212
type Output = I::Output;
1313

14-
#[inline(always)]
14+
#[cfg_attr(bootstrap, inline(always))]
15+
#[cfg_attr(not(bootstrap), inline(usually))]
1516
fn index(&self, index: I) -> &I::Output {
1617
index.index(self)
1718
}
@@ -22,7 +23,8 @@ impl<T, I> ops::IndexMut<I> for [T]
2223
where
2324
I: SliceIndex<[T]>,
2425
{
25-
#[inline(always)]
26+
#[cfg_attr(bootstrap, inline(always))]
27+
#[cfg_attr(not(bootstrap), inline(usually))]
2628
fn index_mut(&mut self, index: I) -> &mut I::Output {
2729
index.index_mut(self)
2830
}
@@ -455,7 +457,8 @@ unsafe impl<T> SliceIndex<[T]> for ops::Range<usize> {
455457
}
456458
}
457459

458-
#[inline(always)]
460+
#[cfg_attr(bootstrap, inline(always))]
461+
#[cfg_attr(not(bootstrap), inline(usually))]
459462
fn index(self, slice: &[T]) -> &[T] {
460463
// Using checked_sub is a safe way to get `SubUnchecked` in MIR
461464
let Some(new_len) = usize::checked_sub(self.end, self.start) else {
@@ -507,7 +510,8 @@ unsafe impl<T> SliceIndex<[T]> for range::Range<usize> {
507510
unsafe { ops::Range::from(self).get_unchecked_mut(slice) }
508511
}
509512

510-
#[inline(always)]
513+
#[cfg_attr(bootstrap, inline(always))]
514+
#[cfg_attr(not(bootstrap), inline(usually))]
511515
fn index(self, slice: &[T]) -> &[T] {
512516
ops::Range::from(self).index(slice)
513517
}
@@ -545,7 +549,8 @@ unsafe impl<T> SliceIndex<[T]> for ops::RangeTo<usize> {
545549
unsafe { (0..self.end).get_unchecked_mut(slice) }
546550
}
547551

548-
#[inline(always)]
552+
#[cfg_attr(bootstrap, inline(always))]
553+
#[cfg_attr(not(bootstrap), inline(usually))]
549554
fn index(self, slice: &[T]) -> &[T] {
550555
(0..self.end).index(slice)
551556
}

0 commit comments

Comments
 (0)