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

Commit 6d1fdaa

Browse files
committed
Merge branch 'cheap-stmt'
2 parents b0a57b4 + f9c1799 commit 6d1fdaa

25 files changed

+5440
-418
lines changed

compiler/rustc_mir_transform/src/cost_checker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use rustc_middle::mir::visit::*;
22
use rustc_middle::mir::*;
33
use rustc_middle::ty::{self, ParamEnv, Ty, TyCtxt};
44

5-
const INSTR_COST: usize = 5;
5+
const INSTR_COST: usize = 1;
66
const CALL_PENALTY: usize = 25;
77
const LANDINGPAD_PENALTY: usize = 50;
88
const RESUME_PENALTY: usize = 45;

library/core/src/ptr/non_null.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,13 @@ impl<T: ?Sized> NonNull<T> {
341341
/// ```
342342
#[stable(feature = "nonnull", since = "1.25.0")]
343343
#[rustc_const_stable(feature = "const_nonnull_as_ptr", since = "1.32.0")]
344+
#[rustc_allow_const_fn_unstable(const_ptr_is_null)]
344345
#[rustc_never_returns_null_ptr]
345346
#[must_use]
346347
#[inline(always)]
347348
pub const fn as_ptr(self) -> *mut T {
349+
// SAFETY: By definition of this type.
350+
unsafe { crate::intrinsics::assume(!self.pointer.is_null()) };
348351
self.pointer as *mut T
349352
}
350353

tests/coverage/partial_eq.cov-map

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,17 @@ Number of file 0 mappings: 2
2525
- Code(Zero) at (prev + 0, 32) to (start + 0, 33)
2626

2727
Function name: <partial_eq::Version as core::cmp::PartialOrd>::partial_cmp
28-
Raw bytes (22): 0x[01, 01, 04, 07, 0b, 00, 09, 0f, 15, 00, 11, 02, 01, 04, 27, 00, 28, 03, 00, 30, 00, 31]
28+
Raw bytes (20): 0x[01, 01, 03, 00, 07, 0b, 00, 00, 11, 02, 01, 04, 27, 00, 28, 03, 00, 30, 00, 31]
2929
Number of files: 1
3030
- file 0 => global file 1
31-
Number of expressions: 4
32-
- expression 0 operands: lhs = Expression(1, Add), rhs = Expression(2, Add)
33-
- expression 1 operands: lhs = Zero, rhs = Counter(2)
34-
- expression 2 operands: lhs = Expression(3, Add), rhs = Counter(5)
35-
- expression 3 operands: lhs = Zero, rhs = Counter(4)
31+
Number of expressions: 3
32+
- expression 0 operands: lhs = Zero, rhs = Expression(1, Add)
33+
- expression 1 operands: lhs = Expression(2, Add), rhs = Zero
34+
- expression 2 operands: lhs = Zero, rhs = Counter(4)
3635
Number of file 0 mappings: 2
3736
- Code(Counter(0)) at (prev + 4, 39) to (start + 0, 40)
3837
- Code(Expression(0, Add)) at (prev + 0, 48) to (start + 0, 49)
39-
= ((Zero + c2) + ((Zero + c4) + c5))
38+
= (Zero + ((Zero + c4) + Zero))
4039

4140
Function name: <partial_eq::Version as core::fmt::Debug>::fmt
4241
Raw bytes (9): 0x[01, 01, 00, 01, 01, 04, 11, 00, 16]

tests/mir-opt/inline/inline_shims.drop.Inline.panic-abort.diff

Lines changed: 141 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,80 @@
1212
+ scope 3 (inlined std::ptr::drop_in_place::<Vec<A>> - shim(Some(Vec<A>))) {
1313
+ let mut _6: &mut std::vec::Vec<A>;
1414
+ let mut _7: ();
15+
+ scope 4 (inlined <Vec<A> as Drop>::drop) {
16+
+ debug self => _6;
17+
+ let mut _8: *mut [A];
18+
+ let mut _9: *mut A;
19+
+ let mut _10: usize;
20+
+ scope 5 {
21+
+ scope 6 (inlined Vec::<A>::as_mut_ptr) {
22+
+ debug self => _6;
23+
+ scope 7 (inlined alloc::raw_vec::RawVec::<A>::ptr) {
24+
+ debug (*(self: &alloc::raw_vec::RawVec<A>)) => ((*_6).0: alloc::raw_vec::RawVec<A>);
25+
+ let mut _17: std::ptr::NonNull<A>;
26+
+ scope 8 (inlined Unique::<A>::as_ptr) {
27+
+ debug ((self: Unique<A>).0: std::ptr::NonNull<A>) => _17;
28+
+ debug ((self: Unique<A>).1: std::marker::PhantomData<A>) => const ZeroSized: PhantomData<A>;
29+
+ scope 9 (inlined NonNull::<A>::as_ptr) {
30+
+ debug self => _17;
31+
+ let mut _11: bool;
32+
+ let mut _12: bool;
33+
+ let mut _13: *const A;
34+
+ scope 10 {
35+
+ scope 11 (inlined std::ptr::const_ptr::<impl *const A>::is_null) {
36+
+ debug self => _13;
37+
+ let mut _14: *const u8;
38+
+ scope 12 {
39+
+ scope 13 (inlined std::ptr::const_ptr::<impl *const T>::is_null::runtime_impl) {
40+
+ debug ptr => _14;
41+
+ let mut _15: usize;
42+
+ scope 14 (inlined std::ptr::const_ptr::<impl *const u8>::addr) {
43+
+ debug self => _14;
44+
+ let mut _16: *const ();
45+
+ scope 15 {
46+
+ scope 16 (inlined std::ptr::const_ptr::<impl *const u8>::cast::<()>) {
47+
+ debug self => _14;
48+
+ }
49+
+ }
50+
+ }
51+
+ }
52+
+ }
53+
+ }
54+
+ }
55+
+ }
56+
+ }
57+
+ }
58+
+ }
59+
+ scope 17 (inlined slice_from_raw_parts_mut::<A>) {
60+
+ debug data => _9;
61+
+ debug len => _10;
62+
+ let mut _18: *mut ();
63+
+ scope 18 (inlined std::ptr::mut_ptr::<impl *mut A>::cast::<()>) {
64+
+ debug self => _9;
65+
+ }
66+
+ scope 19 (inlined std::ptr::from_raw_parts_mut::<[A]>) {
67+
+ debug data_address => _18;
68+
+ debug metadata => _10;
69+
+ let mut _19: std::ptr::metadata::PtrRepr<[A]>;
70+
+ let mut _20: std::ptr::metadata::PtrComponents<[A]>;
71+
+ scope 20 {
72+
+ }
73+
+ }
74+
+ }
75+
+ scope 21 (inlined std::ptr::drop_in_place::<[A]> - shim(Some([A]))) {
76+
+ let mut _21: usize;
77+
+ let mut _22: usize;
78+
+ let mut _23: *mut A;
79+
+ let mut _24: bool;
80+
+ }
81+
+ }
82+
+ }
1583
+ }
1684
}
1785
scope 2 {
18-
+ scope 4 (inlined std::ptr::drop_in_place::<Option<B>> - shim(Some(Option<B>))) {
19-
+ let mut _8: isize;
20-
+ let mut _9: isize;
86+
+ scope 22 (inlined std::ptr::drop_in_place::<Option<B>> - shim(Some(Option<B>))) {
87+
+ let mut _25: isize;
88+
+ let mut _26: isize;
2189
+ }
2290
}
2391

@@ -29,7 +97,50 @@
2997
+ StorageLive(_6);
3098
+ StorageLive(_7);
3199
+ _6 = &mut (*_4);
32-
+ _7 = <Vec<A> as Drop>::drop(move _6) -> [return: bb2, unwind unreachable];
100+
+ StorageLive(_13);
101+
+ StorageLive(_16);
102+
+ StorageLive(_8);
103+
+ StorageLive(_9);
104+
+ StorageLive(_17);
105+
+ _17 = ((((*_6).0: alloc::raw_vec::RawVec<A>).0: std::ptr::Unique<A>).0: std::ptr::NonNull<A>);
106+
+ StorageLive(_11);
107+
+ StorageLive(_12);
108+
+ _13 = (_17.0: *const A);
109+
+ StorageLive(_14);
110+
+ _14 = _13 as *const u8 (PtrToPtr);
111+
+ StorageLive(_15);
112+
+ _16 = _13 as *const () (PtrToPtr);
113+
+ _15 = _16 as usize (Transmute);
114+
+ _12 = Eq(move _15, const 0_usize);
115+
+ StorageDead(_15);
116+
+ StorageDead(_14);
117+
+ _11 = Not(move _12);
118+
+ StorageDead(_12);
119+
+ assume(move _11);
120+
+ StorageDead(_11);
121+
+ _9 = _13 as *mut A (PtrToPtr);
122+
+ StorageDead(_17);
123+
+ StorageLive(_10);
124+
+ _10 = ((*_6).1: usize);
125+
+ StorageLive(_18);
126+
+ _18 = _13 as *mut () (PtrToPtr);
127+
+ StorageLive(_19);
128+
+ StorageLive(_20);
129+
+ _20 = std::ptr::metadata::PtrComponents::<[A]> { data_address: _16, metadata: _10 };
130+
+ _19 = std::ptr::metadata::PtrRepr::<[A]> { const_ptr: move _20 };
131+
+ StorageDead(_20);
132+
+ _8 = (_19.1: *mut [A]);
133+
+ StorageDead(_19);
134+
+ StorageDead(_18);
135+
+ StorageDead(_10);
136+
+ StorageDead(_9);
137+
+ StorageLive(_21);
138+
+ StorageLive(_22);
139+
+ StorageLive(_23);
140+
+ StorageLive(_24);
141+
+ _21 = Len((*_8));
142+
+ _22 = const 0_usize;
143+
+ goto -> bb4;
33144
}
34145

35146
bb1: {
@@ -40,25 +151,43 @@
40151
StorageLive(_5);
41152
_5 = _2;
42153
- _0 = std::ptr::drop_in_place::<Option<B>>(move _5) -> [return: bb2, unwind unreachable];
43-
+ StorageLive(_8);
44-
+ StorageLive(_9);
45-
+ _8 = discriminant((*_5));
46-
+ switchInt(move _8) -> [0: bb3, otherwise: bb4];
154+
+ StorageLive(_25);
155+
+ StorageLive(_26);
156+
+ _25 = discriminant((*_5));
157+
+ switchInt(move _25) -> [0: bb5, otherwise: bb6];
47158
}
48159

49160
bb2: {
161+
+ StorageDead(_24);
162+
+ StorageDead(_23);
163+
+ StorageDead(_22);
164+
+ StorageDead(_21);
165+
+ StorageDead(_8);
166+
+ StorageDead(_16);
167+
+ StorageDead(_13);
50168
+ drop(((*_4).0: alloc::raw_vec::RawVec<A>)) -> [return: bb1, unwind unreachable];
51169
+ }
52170
+
53171
+ bb3: {
54-
+ StorageDead(_9);
55-
+ StorageDead(_8);
172+
+ _23 = &raw mut (*_8)[_22];
173+
+ _22 = Add(move _22, const 1_usize);
174+
+ drop((*_23)) -> [return: bb4, unwind unreachable];
175+
+ }
176+
+
177+
+ bb4: {
178+
+ _24 = Eq(_22, _21);
179+
+ switchInt(move _24) -> [0: bb3, otherwise: bb2];
180+
+ }
181+
+
182+
+ bb5: {
183+
+ StorageDead(_26);
184+
+ StorageDead(_25);
56185
StorageDead(_5);
57186
return;
58187
+ }
59188
+
60-
+ bb4: {
61-
+ drop((((*_5) as Some).0: B)) -> [return: bb3, unwind unreachable];
189+
+ bb6: {
190+
+ drop((((*_5) as Some).0: B)) -> [return: bb5, unwind unreachable];
62191
}
63192
}
64193

0 commit comments

Comments
 (0)