Skip to content

Commit e9fcbb2

Browse files
committed
Use #[rustc_early_inline] on a bunch of things in core
1 parent 4bcbaf5 commit e9fcbb2

11 files changed

+214
-111
lines changed

library/core/src/cmp.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ mod impls {
19281928
($($t:ty)*) => ($(
19291929
#[stable(feature = "rust1", since = "1.0.0")]
19301930
impl PartialOrd for $t {
1931-
#[inline]
1931+
#[rustc_early_inline]
19321932
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
19331933
Some(crate::intrinsics::three_way_compare(*self, *other))
19341934
}
@@ -1938,7 +1938,7 @@ mod impls {
19381938

19391939
#[stable(feature = "rust1", since = "1.0.0")]
19401940
impl Ord for $t {
1941-
#[inline]
1941+
#[rustc_early_inline]
19421942
fn cmp(&self, other: &Self) -> Ordering {
19431943
crate::intrinsics::three_way_compare(*self, *other)
19441944
}

library/core/src/option.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,12 +2604,12 @@ impl<T> const ops::Try for Option<T> {
26042604
type Output = T;
26052605
type Residual = Option<convert::Infallible>;
26062606

2607-
#[inline]
2607+
#[rustc_early_inline]
26082608
fn from_output(output: Self::Output) -> Self {
26092609
Some(output)
26102610
}
26112611

2612-
#[inline]
2612+
#[rustc_early_inline]
26132613
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
26142614
match self {
26152615
Some(v) => ControlFlow::Continue(v),
@@ -2623,7 +2623,7 @@ impl<T> const ops::Try for Option<T> {
26232623
// Note: manually specifying the residual type instead of using the default to work around
26242624
// https://github.com/rust-lang/rust/issues/99940
26252625
impl<T> const ops::FromResidual<Option<convert::Infallible>> for Option<T> {
2626-
#[inline]
2626+
#[rustc_early_inline]
26272627
fn from_residual(residual: Option<convert::Infallible>) -> Self {
26282628
match residual {
26292629
None => None,

library/core/src/result.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,12 +2061,12 @@ impl<T, E> const ops::Try for Result<T, E> {
20612061
type Output = T;
20622062
type Residual = Result<convert::Infallible, E>;
20632063

2064-
#[inline]
2064+
#[rustc_early_inline]
20652065
fn from_output(output: Self::Output) -> Self {
20662066
Ok(output)
20672067
}
20682068

2069-
#[inline]
2069+
#[rustc_early_inline]
20702070
fn branch(self) -> ControlFlow<Self::Residual, Self::Output> {
20712071
match self {
20722072
Ok(v) => ControlFlow::Continue(v),

tests/mir-opt/pre-codegen/derived_ord_debug.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ pub struct MultiField(char, i16);
1010
// EMIT_MIR derived_ord_debug.{impl#1}-cmp.PreCodegen.after.mir
1111

1212
// CHECK-LABEL: partial_cmp(_1: &MultiField, _2: &MultiField) -> Option<std::cmp::Ordering>
13-
// CHECK: = <char as PartialOrd>::partial_cmp(
14-
// CHECK: = <i16 as PartialOrd>::partial_cmp(
13+
// CHECK: (inlined {{.+}} char>::partial_cmp)
14+
// CHECK: (inlined {{.+}} i16>::partial_cmp)
15+
// CHECK: = Cmp(
16+
// CHECK: = Cmp(
1517

1618
// CHECK-LABEL: cmp(_1: &MultiField, _2: &MultiField) -> std::cmp::Ordering
17-
// CHECK: = <char as Ord>::cmp(
18-
// CHECK: = <i16 as Ord>::cmp(
19+
// CHECK: (inlined {{.+}} char>::cmp)
20+
// CHECK: (inlined {{.+}} i16>::cmp)
21+
// CHECK: = Cmp(
22+
// CHECK: = Cmp(

tests/mir-opt/pre-codegen/derived_ord_debug.{impl#0}-partial_cmp.PreCodegen.after.panic-abort.mir

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,61 @@ fn <impl at $DIR/derived_ord_debug.rs:6:10: 6:20>::partial_cmp(_1: &MultiField,
66
let mut _0: std::option::Option<std::cmp::Ordering>;
77
let _3: &char;
88
let _4: &char;
9-
let mut _5: std::option::Option<std::cmp::Ordering>;
10-
let mut _6: isize;
11-
let mut _7: i8;
12-
let _8: &i16;
13-
let _9: &i16;
9+
let mut _8: std::option::Option<std::cmp::Ordering>;
10+
let mut _9: isize;
11+
let mut _10: i8;
12+
let _11: &i16;
13+
let _12: &i16;
1414
scope 1 {
15-
debug cmp => _5;
15+
debug cmp => _8;
16+
}
17+
scope 2 (inlined std::cmp::impls::<impl PartialOrd for char>::partial_cmp) {
18+
let mut _5: char;
19+
let mut _6: char;
20+
let mut _7: std::cmp::Ordering;
21+
}
22+
scope 3 (inlined std::cmp::impls::<impl PartialOrd for i16>::partial_cmp) {
23+
let mut _13: i16;
24+
let mut _14: i16;
25+
let mut _15: std::cmp::Ordering;
1626
}
1727

1828
bb0: {
1929
_3 = &((*_1).0: char);
2030
_4 = &((*_2).0: char);
21-
_5 = <char as PartialOrd>::partial_cmp(copy _3, copy _4) -> [return: bb1, unwind unreachable];
31+
_5 = copy (*_3);
32+
_6 = copy (*_4);
33+
_7 = Cmp(move _5, move _6);
34+
_8 = Option::<std::cmp::Ordering>::Some(move _7);
35+
_9 = discriminant(_8);
36+
switchInt(move _9) -> [1: bb1, 0: bb3, otherwise: bb5];
2237
}
2338

2439
bb1: {
25-
_6 = discriminant(_5);
26-
switchInt(move _6) -> [1: bb2, 0: bb4, otherwise: bb6];
40+
_10 = discriminant(((_8 as Some).0: std::cmp::Ordering));
41+
switchInt(move _10) -> [0: bb2, otherwise: bb3];
2742
}
2843

2944
bb2: {
30-
_7 = discriminant(((_5 as Some).0: std::cmp::Ordering));
31-
switchInt(move _7) -> [0: bb3, otherwise: bb4];
45+
_11 = &((*_1).1: i16);
46+
_12 = &((*_2).1: i16);
47+
_13 = copy (*_11);
48+
_14 = copy (*_12);
49+
_15 = Cmp(move _13, move _14);
50+
_0 = Option::<std::cmp::Ordering>::Some(move _15);
51+
goto -> bb4;
3252
}
3353

3454
bb3: {
35-
_8 = &((*_1).1: i16);
36-
_9 = &((*_2).1: i16);
37-
_0 = <i16 as PartialOrd>::partial_cmp(copy _8, copy _9) -> [return: bb5, unwind unreachable];
55+
_0 = copy _8;
56+
goto -> bb4;
3857
}
3958

4059
bb4: {
41-
_0 = copy _5;
42-
goto -> bb5;
43-
}
44-
45-
bb5: {
4660
return;
4761
}
4862

49-
bb6: {
63+
bb5: {
5064
unreachable;
5165
}
5266
}

tests/mir-opt/pre-codegen/derived_ord_debug.{impl#0}-partial_cmp.PreCodegen.after.panic-unwind.mir

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -6,47 +6,61 @@ fn <impl at $DIR/derived_ord_debug.rs:6:10: 6:20>::partial_cmp(_1: &MultiField,
66
let mut _0: std::option::Option<std::cmp::Ordering>;
77
let _3: &char;
88
let _4: &char;
9-
let mut _5: std::option::Option<std::cmp::Ordering>;
10-
let mut _6: isize;
11-
let mut _7: i8;
12-
let _8: &i16;
13-
let _9: &i16;
9+
let mut _8: std::option::Option<std::cmp::Ordering>;
10+
let mut _9: isize;
11+
let mut _10: i8;
12+
let _11: &i16;
13+
let _12: &i16;
1414
scope 1 {
15-
debug cmp => _5;
15+
debug cmp => _8;
16+
}
17+
scope 2 (inlined std::cmp::impls::<impl PartialOrd for char>::partial_cmp) {
18+
let mut _5: char;
19+
let mut _6: char;
20+
let mut _7: std::cmp::Ordering;
21+
}
22+
scope 3 (inlined std::cmp::impls::<impl PartialOrd for i16>::partial_cmp) {
23+
let mut _13: i16;
24+
let mut _14: i16;
25+
let mut _15: std::cmp::Ordering;
1626
}
1727

1828
bb0: {
1929
_3 = &((*_1).0: char);
2030
_4 = &((*_2).0: char);
21-
_5 = <char as PartialOrd>::partial_cmp(copy _3, copy _4) -> [return: bb1, unwind continue];
31+
_5 = copy (*_3);
32+
_6 = copy (*_4);
33+
_7 = Cmp(move _5, move _6);
34+
_8 = Option::<std::cmp::Ordering>::Some(move _7);
35+
_9 = discriminant(_8);
36+
switchInt(move _9) -> [1: bb1, 0: bb3, otherwise: bb5];
2237
}
2338

2439
bb1: {
25-
_6 = discriminant(_5);
26-
switchInt(move _6) -> [1: bb2, 0: bb4, otherwise: bb6];
40+
_10 = discriminant(((_8 as Some).0: std::cmp::Ordering));
41+
switchInt(move _10) -> [0: bb2, otherwise: bb3];
2742
}
2843

2944
bb2: {
30-
_7 = discriminant(((_5 as Some).0: std::cmp::Ordering));
31-
switchInt(move _7) -> [0: bb3, otherwise: bb4];
45+
_11 = &((*_1).1: i16);
46+
_12 = &((*_2).1: i16);
47+
_13 = copy (*_11);
48+
_14 = copy (*_12);
49+
_15 = Cmp(move _13, move _14);
50+
_0 = Option::<std::cmp::Ordering>::Some(move _15);
51+
goto -> bb4;
3252
}
3353

3454
bb3: {
35-
_8 = &((*_1).1: i16);
36-
_9 = &((*_2).1: i16);
37-
_0 = <i16 as PartialOrd>::partial_cmp(copy _8, copy _9) -> [return: bb5, unwind continue];
55+
_0 = copy _8;
56+
goto -> bb4;
3857
}
3958

4059
bb4: {
41-
_0 = copy _5;
42-
goto -> bb5;
43-
}
44-
45-
bb5: {
4660
return;
4761
}
4862

49-
bb6: {
63+
bb5: {
5064
unreachable;
5165
}
5266
}

tests/mir-opt/pre-codegen/derived_ord_debug.{impl#1}-cmp.PreCodegen.after.panic-abort.mir

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,47 @@ fn <impl at $DIR/derived_ord_debug.rs:6:22: 6:25>::cmp(_1: &MultiField, _2: &Mul
66
let mut _0: std::cmp::Ordering;
77
let _3: &char;
88
let _4: &char;
9-
let mut _5: std::cmp::Ordering;
10-
let mut _6: i8;
11-
let _7: &i16;
12-
let _8: &i16;
9+
let mut _7: std::cmp::Ordering;
10+
let mut _8: i8;
11+
let _9: &i16;
12+
let _10: &i16;
1313
scope 1 {
14-
debug cmp => _5;
14+
debug cmp => _7;
15+
}
16+
scope 2 (inlined std::cmp::impls::<impl Ord for char>::cmp) {
17+
let mut _5: char;
18+
let mut _6: char;
19+
}
20+
scope 3 (inlined std::cmp::impls::<impl Ord for i16>::cmp) {
21+
let mut _11: i16;
22+
let mut _12: i16;
1523
}
1624

1725
bb0: {
1826
_3 = &((*_1).0: char);
1927
_4 = &((*_2).0: char);
20-
_5 = <char as Ord>::cmp(copy _3, copy _4) -> [return: bb1, unwind unreachable];
28+
_5 = copy (*_3);
29+
_6 = copy (*_4);
30+
_7 = Cmp(move _5, move _6);
31+
_8 = discriminant(_7);
32+
switchInt(move _8) -> [0: bb1, otherwise: bb2];
2133
}
2234

2335
bb1: {
24-
_6 = discriminant(_5);
25-
switchInt(move _6) -> [0: bb2, otherwise: bb3];
36+
_9 = &((*_1).1: i16);
37+
_10 = &((*_2).1: i16);
38+
_11 = copy (*_9);
39+
_12 = copy (*_10);
40+
_0 = Cmp(move _11, move _12);
41+
goto -> bb3;
2642
}
2743

2844
bb2: {
29-
_7 = &((*_1).1: i16);
30-
_8 = &((*_2).1: i16);
31-
_0 = <i16 as Ord>::cmp(copy _7, copy _8) -> [return: bb4, unwind unreachable];
45+
_0 = copy _7;
46+
goto -> bb3;
3247
}
3348

3449
bb3: {
35-
_0 = copy _5;
36-
goto -> bb4;
37-
}
38-
39-
bb4: {
4050
return;
4151
}
4252
}

tests/mir-opt/pre-codegen/derived_ord_debug.{impl#1}-cmp.PreCodegen.after.panic-unwind.mir

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,47 @@ fn <impl at $DIR/derived_ord_debug.rs:6:22: 6:25>::cmp(_1: &MultiField, _2: &Mul
66
let mut _0: std::cmp::Ordering;
77
let _3: &char;
88
let _4: &char;
9-
let mut _5: std::cmp::Ordering;
10-
let mut _6: i8;
11-
let _7: &i16;
12-
let _8: &i16;
9+
let mut _7: std::cmp::Ordering;
10+
let mut _8: i8;
11+
let _9: &i16;
12+
let _10: &i16;
1313
scope 1 {
14-
debug cmp => _5;
14+
debug cmp => _7;
15+
}
16+
scope 2 (inlined std::cmp::impls::<impl Ord for char>::cmp) {
17+
let mut _5: char;
18+
let mut _6: char;
19+
}
20+
scope 3 (inlined std::cmp::impls::<impl Ord for i16>::cmp) {
21+
let mut _11: i16;
22+
let mut _12: i16;
1523
}
1624

1725
bb0: {
1826
_3 = &((*_1).0: char);
1927
_4 = &((*_2).0: char);
20-
_5 = <char as Ord>::cmp(copy _3, copy _4) -> [return: bb1, unwind continue];
28+
_5 = copy (*_3);
29+
_6 = copy (*_4);
30+
_7 = Cmp(move _5, move _6);
31+
_8 = discriminant(_7);
32+
switchInt(move _8) -> [0: bb1, otherwise: bb2];
2133
}
2234

2335
bb1: {
24-
_6 = discriminant(_5);
25-
switchInt(move _6) -> [0: bb2, otherwise: bb3];
36+
_9 = &((*_1).1: i16);
37+
_10 = &((*_2).1: i16);
38+
_11 = copy (*_9);
39+
_12 = copy (*_10);
40+
_0 = Cmp(move _11, move _12);
41+
goto -> bb3;
2642
}
2743

2844
bb2: {
29-
_7 = &((*_1).1: i16);
30-
_8 = &((*_2).1: i16);
31-
_0 = <i16 as Ord>::cmp(copy _7, copy _8) -> [return: bb4, unwind continue];
45+
_0 = copy _7;
46+
goto -> bb3;
3247
}
3348

3449
bb3: {
35-
_0 = copy _5;
36-
goto -> bb4;
37-
}
38-
39-
bb4: {
4050
return;
4151
}
4252
}

0 commit comments

Comments
 (0)