Skip to content

Commit c7cc53c

Browse files
committed
Remove bow_new intrinsic.
1 parent 00ce295 commit c7cc53c

File tree

41 files changed

+1353
-1696
lines changed

Some content is hidden

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

41 files changed

+1353
-1696
lines changed

library/alloc/src/boxed.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -233,14 +233,6 @@ pub struct Box<
233233
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global,
234234
>(Unique<T>, A);
235235

236-
/// Constructs a `Box<T>` by calling the `exchange_malloc` lang item and moving the argument into
237-
/// the newly allocated memory. This is an intrinsic to avoid unnecessary copies.
238-
///
239-
/// This is the surface syntax for `box <expr>` expressions.
240-
#[rustc_intrinsic]
241-
#[unstable(feature = "liballoc_internals", issue = "none")]
242-
pub fn box_new<T>(x: T) -> Box<T>;
243-
244236
impl<T> Box<T> {
245237
/// Allocates memory on the heap and then places `x` into it.
246238
///
@@ -252,13 +244,13 @@ impl<T> Box<T> {
252244
/// let five = Box::new(5);
253245
/// ```
254246
#[cfg(not(no_global_oom_handling))]
255-
#[inline(always)]
247+
#[rustc_force_inline]
256248
#[stable(feature = "rust1", since = "1.0.0")]
257249
#[must_use]
258250
#[rustc_diagnostic_item = "box_new"]
259251
#[cfg_attr(miri, track_caller)] // even without panics, this helps for Miri backtraces
260252
pub fn new(x: T) -> Self {
261-
return box_new(x);
253+
return Self::new_in(x, Global);
262254
}
263255

264256
/// Constructs a new box with uninitialized contents.
@@ -404,7 +396,7 @@ impl<T, A: Allocator> Box<T, A> {
404396
#[cfg(not(no_global_oom_handling))]
405397
#[unstable(feature = "allocator_api", issue = "32838")]
406398
#[must_use]
407-
#[inline]
399+
#[rustc_force_inline]
408400
pub fn new_in(x: T, alloc: A) -> Self
409401
where
410402
A: Allocator,

library/alloc/src/macros.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ macro_rules! vec {
5050
<[_]>::into_vec(
5151
// Using the intrinsic produces a dramatic improvement in stack usage for
5252
// unoptimized programs using this code path to construct large Vecs.
53-
$crate::boxed::box_new([$($x),+])
53+
$crate::boxed::Box::new([$($x),+])
5454
)
5555
);
5656
}

tests/mir-opt/box_expr.main.ElaborateDrops.diff

Lines changed: 25 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,90 +4,61 @@
44
fn main() -> () {
55
let mut _0: ();
66
let _1: std::boxed::Box<S>;
7-
let mut _2: usize;
8-
let mut _3: usize;
9-
let mut _4: *mut u8;
10-
let mut _5: std::boxed::Box<S>;
11-
let _6: ();
12-
let mut _7: std::boxed::Box<S>;
13-
+ let mut _8: &mut std::boxed::Box<S>;
14-
+ let mut _9: ();
15-
+ let mut _10: *const S;
7+
let mut _2: S;
8+
let _3: ();
9+
let mut _4: std::boxed::Box<S>;
1610
scope 1 {
1711
debug x => _1;
1812
}
1913

2014
bb0: {
2115
StorageLive(_1);
22-
_2 = SizeOf(S);
23-
_3 = AlignOf(S);
24-
_4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue];
16+
StorageLive(_2);
17+
_2 = S::new() -> [return: bb1, unwind continue];
2518
}
2619

2720
bb1: {
28-
StorageLive(_5);
29-
_5 = ShallowInitBox(move _4, S);
30-
(*_5) = S::new() -> [return: bb2, unwind: bb8];
21+
_1 = Box::<S>::new(move _2) -> [return: bb2, unwind: bb7];
3122
}
3223

3324
bb2: {
34-
_1 = move _5;
35-
- drop(_5) -> [return: bb3, unwind continue];
36-
+ goto -> bb3;
25+
StorageDead(_2);
26+
StorageLive(_3);
27+
StorageLive(_4);
28+
_4 = move _1;
29+
_3 = std::mem::drop::<Box<S>>(move _4) -> [return: bb3, unwind: bb5];
3730
}
3831

3932
bb3: {
40-
StorageDead(_5);
41-
StorageLive(_6);
42-
StorageLive(_7);
43-
_7 = move _1;
44-
_6 = std::mem::drop::<Box<S>>(move _7) -> [return: bb4, unwind: bb6];
45-
}
46-
47-
bb4: {
48-
StorageDead(_7);
49-
StorageDead(_6);
33+
StorageDead(_4);
34+
StorageDead(_3);
5035
_0 = const ();
51-
- drop(_1) -> [return: bb5, unwind continue];
52-
+ goto -> bb5;
36+
- drop(_1) -> [return: bb4, unwind continue];
37+
+ goto -> bb4;
5338
}
5439

55-
bb5: {
40+
bb4: {
5641
StorageDead(_1);
5742
return;
5843
}
5944

45+
bb5 (cleanup): {
46+
- drop(_4) -> [return: bb6, unwind terminate(cleanup)];
47+
+ goto -> bb6;
48+
}
49+
6050
bb6 (cleanup): {
61-
- drop(_7) -> [return: bb7, unwind terminate(cleanup)];
62-
+ goto -> bb7;
51+
- drop(_1) -> [return: bb8, unwind terminate(cleanup)];
52+
+ goto -> bb8;
6353
}
6454

6555
bb7 (cleanup): {
66-
- drop(_1) -> [return: bb9, unwind terminate(cleanup)];
67-
+ goto -> bb9;
56+
- drop(_2) -> [return: bb8, unwind terminate(cleanup)];
57+
+ goto -> bb8;
6858
}
6959

7060
bb8 (cleanup): {
71-
- drop(_5) -> [return: bb9, unwind terminate(cleanup)];
72-
+ goto -> bb12;
73-
}
74-
75-
bb9 (cleanup): {
7661
resume;
77-
+ }
78-
+
79-
+ bb10 (cleanup): {
80-
+ _8 = &mut _5;
81-
+ _9 = <Box<S> as Drop>::drop(move _8) -> [return: bb9, unwind terminate(cleanup)];
82-
+ }
83-
+
84-
+ bb11 (cleanup): {
85-
+ goto -> bb10;
86-
+ }
87-
+
88-
+ bb12 (cleanup): {
89-
+ _10 = copy ((_5.0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
90-
+ goto -> bb11;
9162
}
9263
}
9364

tests/mir-opt/box_expr.move_from_inner.ElaborateDrops.diff

Lines changed: 48 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -4,135 +4,106 @@
44
fn move_from_inner() -> () {
55
let mut _0: ();
66
let _1: std::boxed::Box<S>;
7-
let mut _2: usize;
8-
let mut _3: usize;
9-
let mut _4: *mut u8;
10-
let mut _5: std::boxed::Box<S>;
11-
let _6: ();
12-
let mut _7: S;
13-
+ let mut _8: &mut std::boxed::Box<S>;
14-
+ let mut _9: ();
7+
let mut _2: S;
8+
let _3: ();
9+
let mut _4: S;
10+
+ let mut _5: &mut std::boxed::Box<S>;
11+
+ let mut _6: ();
12+
+ let mut _7: &mut std::boxed::Box<S>;
13+
+ let mut _8: ();
14+
+ let mut _9: *const S;
1515
+ let mut _10: &mut std::boxed::Box<S>;
1616
+ let mut _11: ();
1717
+ let mut _12: *const S;
18-
+ let mut _13: &mut std::boxed::Box<S>;
19-
+ let mut _14: ();
20-
+ let mut _15: *const S;
21-
+ let mut _16: &mut std::boxed::Box<S>;
22-
+ let mut _17: ();
23-
+ let mut _18: *const S;
2418
scope 1 {
2519
debug x => _1;
2620
}
2721

2822
bb0: {
2923
StorageLive(_1);
30-
_2 = SizeOf(S);
31-
_3 = AlignOf(S);
32-
_4 = alloc::alloc::exchange_malloc(move _2, move _3) -> [return: bb1, unwind continue];
24+
StorageLive(_2);
25+
_2 = S::new() -> [return: bb1, unwind continue];
3326
}
3427

3528
bb1: {
36-
StorageLive(_5);
37-
_5 = ShallowInitBox(move _4, S);
38-
(*_5) = S::new() -> [return: bb2, unwind: bb8];
29+
_1 = Box::<S>::new(move _2) -> [return: bb2, unwind: bb7];
3930
}
4031

4132
bb2: {
42-
_1 = move _5;
43-
- drop(_5) -> [return: bb3, unwind continue];
44-
+ goto -> bb3;
33+
StorageDead(_2);
34+
StorageLive(_3);
35+
StorageLive(_4);
36+
_4 = move (*_1);
37+
_3 = std::mem::drop::<S>(move _4) -> [return: bb3, unwind: bb5];
4538
}
4639

4740
bb3: {
48-
StorageDead(_5);
49-
StorageLive(_6);
50-
StorageLive(_7);
51-
_7 = move (*_1);
52-
_6 = std::mem::drop::<S>(move _7) -> [return: bb4, unwind: bb6];
53-
}
54-
55-
bb4: {
56-
StorageDead(_7);
57-
StorageDead(_6);
41+
StorageDead(_4);
42+
StorageDead(_3);
5843
_0 = const ();
59-
- drop(_1) -> [return: bb5, unwind continue];
60-
+ goto -> bb14;
44+
- drop(_1) -> [return: bb4, unwind continue];
45+
+ goto -> bb13;
6146
}
6247

63-
bb5: {
48+
bb4: {
6449
StorageDead(_1);
6550
return;
6651
}
6752

53+
bb5 (cleanup): {
54+
- drop(_4) -> [return: bb6, unwind terminate(cleanup)];
55+
+ goto -> bb6;
56+
}
57+
6858
bb6 (cleanup): {
69-
- drop(_7) -> [return: bb7, unwind terminate(cleanup)];
70-
+ goto -> bb7;
59+
- drop(_1) -> [return: bb8, unwind terminate(cleanup)];
60+
+ goto -> bb16;
7161
}
7262

7363
bb7 (cleanup): {
74-
- drop(_1) -> [return: bb9, unwind terminate(cleanup)];
75-
+ goto -> bb17;
64+
- drop(_2) -> [return: bb8, unwind terminate(cleanup)];
65+
+ goto -> bb8;
7666
}
7767

7868
bb8 (cleanup): {
79-
- drop(_5) -> [return: bb9, unwind terminate(cleanup)];
80-
+ goto -> bb20;
81-
}
82-
83-
bb9 (cleanup): {
8469
resume;
8570
+ }
8671
+
72+
+ bb9: {
73+
+ goto -> bb4;
74+
+ }
75+
+
8776
+ bb10: {
88-
+ goto -> bb5;
77+
+ _5 = &mut _1;
78+
+ _6 = <Box<S> as Drop>::drop(move _5) -> [return: bb9, unwind: bb8];
8979
+ }
9080
+
91-
+ bb11: {
92-
+ _8 = &mut _1;
93-
+ _9 = <Box<S> as Drop>::drop(move _8) -> [return: bb10, unwind: bb9];
81+
+ bb11 (cleanup): {
82+
+ _7 = &mut _1;
83+
+ _8 = <Box<S> as Drop>::drop(move _7) -> [return: bb8, unwind terminate(cleanup)];
9484
+ }
9585
+
96-
+ bb12 (cleanup): {
97-
+ _10 = &mut _1;
98-
+ _11 = <Box<S> as Drop>::drop(move _10) -> [return: bb9, unwind terminate(cleanup)];
86+
+ bb12: {
87+
+ goto -> bb10;
9988
+ }
10089
+
10190
+ bb13: {
102-
+ goto -> bb11;
91+
+ _9 = copy ((_1.0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
92+
+ goto -> bb12;
10393
+ }
10494
+
105-
+ bb14: {
106-
+ _12 = copy ((_1.0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
107-
+ goto -> bb13;
95+
+ bb14 (cleanup): {
96+
+ _10 = &mut _1;
97+
+ _11 = <Box<S> as Drop>::drop(move _10) -> [return: bb8, unwind terminate(cleanup)];
10898
+ }
10999
+
110100
+ bb15 (cleanup): {
111-
+ _13 = &mut _1;
112-
+ _14 = <Box<S> as Drop>::drop(move _13) -> [return: bb9, unwind terminate(cleanup)];
101+
+ goto -> bb14;
113102
+ }
114103
+
115104
+ bb16 (cleanup): {
105+
+ _12 = copy ((_1.0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
116106
+ goto -> bb15;
117-
+ }
118-
+
119-
+ bb17 (cleanup): {
120-
+ _15 = copy ((_1.0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
121-
+ goto -> bb16;
122-
+ }
123-
+
124-
+ bb18 (cleanup): {
125-
+ _16 = &mut _5;
126-
+ _17 = <Box<S> as Drop>::drop(move _16) -> [return: bb9, unwind terminate(cleanup)];
127-
+ }
128-
+
129-
+ bb19 (cleanup): {
130-
+ goto -> bb18;
131-
+ }
132-
+
133-
+ bb20 (cleanup): {
134-
+ _18 = copy ((_5.0: std::ptr::Unique<S>).0: std::ptr::NonNull<S>) as *const S (Transmute);
135-
+ goto -> bb19;
136107
}
137108
}
138109

0 commit comments

Comments
 (0)