Skip to content

Commit 5b6aa44

Browse files
committed
Run RemoveDeadDrops everywhere
1 parent 3c2bae3 commit 5b6aa44

31 files changed

Lines changed: 372 additions & 673 deletions

File tree

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -487,13 +487,16 @@ fn mir_promoted(
487487
(tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted))
488488
}
489489

490-
fn mir_post_borrowck_cleanup(
491-
tcx: TyCtxt<'_>,
492-
def: LocalDefId,
493-
) -> &Steal<Body<'_>> {
490+
fn mir_post_borrowck_cleanup(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal<Body<'_>> {
494491
let (body, _) = tcx.mir_promoted(def);
495492
let mut body = body.borrow().clone();
496-
remove_dead_drops::RemoveDeadDrops.run_pass(tcx, &mut body);
493+
pm::run_passes(
494+
tcx,
495+
&mut body,
496+
&[&remove_dead_drops::RemoveDeadDrops],
497+
None,
498+
pm::Optimizations::Allowed,
499+
);
497500
tcx.alloc_steal_mir(body)
498501
}
499502

compiler/rustc_mir_transform/src/remove_dead_drops.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,6 @@ impl<'tcx> crate::MirPass<'tcx> for RemoveDeadDrops {
1212
}
1313

1414
fn run_pass(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
15-
if body.coroutine.is_none() {
16-
return;
17-
}
18-
1915
let move_data = MoveData::gather_moves(body, tcx, |_| true);
2016

2117
let mut maybe_init_cursor = MaybeInitializedPlaces::new(tcx, body, &move_data)

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

Lines changed: 7 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,53 +35,23 @@
3535
StorageLive(_5);
3636
StorageLive(_6);
3737
_6 = move _4;
38-
- drop(_5) -> [return: bb1, unwind: bb2];
39-
+ goto -> bb1;
40-
}
41-
42-
bb1: {
4338
_5 = move _6;
44-
- drop(_6) -> [return: bb3, unwind: bb6];
45-
+ goto -> bb3;
46-
}
47-
48-
bb2 (cleanup): {
49-
_5 = move _6;
50-
- drop(_6) -> [return: bb6, unwind terminate(cleanup)];
51-
+ goto -> bb6;
52-
}
53-
54-
bb3: {
5539
StorageDead(_6);
5640
_0 = const ();
57-
drop(_5) -> [return: bb4, unwind: bb7];
41+
- drop(_5) -> [return: bb1, unwind continue];
42+
+ drop(_5) -> [return: bb1, unwind: bb2];
5843
}
5944

60-
bb4: {
45+
bb1: {
6146
StorageDead(_5);
62-
- drop(_4) -> [return: bb5, unwind continue];
63-
+ goto -> bb5;
64-
}
65-
66-
bb5: {
6747
StorageDead(_4);
6848
StorageDead(_2);
6949
StorageDead(_1);
7050
return;
71-
}
72-
73-
bb6 (cleanup): {
74-
- drop(_5) -> [return: bb7, unwind terminate(cleanup)];
75-
+ goto -> bb7;
76-
}
77-
78-
bb7 (cleanup): {
79-
- drop(_4) -> [return: bb8, unwind terminate(cleanup)];
80-
+ goto -> bb8;
81-
}
82-
83-
bb8 (cleanup): {
84-
resume;
51+
+ }
52+
+
53+
+ bb2 (cleanup): {
54+
+ resume;
8555
}
8656
}
8757

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

Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@
3131
_2 = HasDrop;
3232
StorageLive(_3);
3333
_3 = DropAllocator;
34-
_1 = Box::<HasDrop, DropAllocator>::new_in(move _2, move _3) -> [return: bb1, unwind: bb11];
34+
+ _9 = const true;
35+
_1 = Box::<HasDrop, DropAllocator>::new_in(move _2, move _3) -> [return: bb1, unwind continue];
3536
}
3637

3738
bb1: {
38-
+ _9 = const true;
3939
StorageDead(_3);
4040
StorageDead(_2);
4141
StorageLive(_4);
@@ -47,7 +47,7 @@
4747
StorageLive(_5);
4848
StorageLive(_6);
4949
_6 = move (*_1);
50-
_5 = std::mem::drop::<HasDrop>(move _6) -> [return: bb3, unwind: bb9];
50+
_5 = std::mem::drop::<HasDrop>(move _6) -> [return: bb3, unwind: bb8];
5151
}
5252

5353
bb3: {
@@ -75,7 +75,7 @@
7575
bb6: {
7676
StorageDead(_4);
7777
- drop(_1) -> [return: bb7, unwind continue];
78-
+ goto -> bb23;
78+
+ goto -> bb19;
7979
}
8080

8181
bb7: {
@@ -85,102 +85,82 @@
8585
}
8686

8787
bb8 (cleanup): {
88-
- drop(_8) -> [return: bb10, unwind terminate(cleanup)];
89-
+ goto -> bb10;
88+
- drop(_1) -> [return: bb9, unwind terminate(cleanup)];
89+
+ goto -> bb25;
9090
}
9191

9292
bb9 (cleanup): {
93-
- drop(_6) -> [return: bb10, unwind terminate(cleanup)];
94-
+ goto -> bb10;
95-
}
96-
97-
bb10 (cleanup): {
98-
- drop(_1) -> [return: bb13, unwind terminate(cleanup)];
99-
+ goto -> bb29;
100-
}
101-
102-
bb11 (cleanup): {
103-
- drop(_3) -> [return: bb12, unwind terminate(cleanup)];
104-
+ goto -> bb12;
105-
}
106-
107-
bb12 (cleanup): {
108-
- drop(_2) -> [return: bb13, unwind terminate(cleanup)];
109-
+ goto -> bb13;
110-
}
111-
112-
bb13 (cleanup): {
11393
resume;
11494
+ }
11595
+
116-
+ bb14: {
96+
+ bb10: {
11797
+ _9 = const false;
11898
+ goto -> bb7;
11999
+ }
120100
+
121-
+ bb15 (cleanup): {
122-
+ drop((_1.1: DropAllocator)) -> [return: bb13, unwind terminate(cleanup)];
101+
+ bb11 (cleanup): {
102+
+ drop((_1.1: DropAllocator)) -> [return: bb9, unwind terminate(cleanup)];
123103
+ }
124104
+
125-
+ bb16 (cleanup): {
126-
+ switchInt(copy _9) -> [0: bb13, otherwise: bb15];
105+
+ bb12 (cleanup): {
106+
+ switchInt(copy _9) -> [0: bb9, otherwise: bb11];
127107
+ }
128108
+
129-
+ bb17: {
130-
+ drop((_1.1: DropAllocator)) -> [return: bb14, unwind: bb13];
109+
+ bb13: {
110+
+ drop((_1.1: DropAllocator)) -> [return: bb10, unwind: bb9];
131111
+ }
132112
+
133-
+ bb18: {
134-
+ switchInt(copy _9) -> [0: bb14, otherwise: bb17];
113+
+ bb14: {
114+
+ switchInt(copy _9) -> [0: bb10, otherwise: bb13];
135115
+ }
136116
+
137-
+ bb19: {
117+
+ bb15: {
138118
+ _10 = &mut _1;
139-
+ _11 = <Box<HasDrop, DropAllocator> as Drop>::drop(move _10) -> [return: bb18, unwind: bb16];
119+
+ _11 = <Box<HasDrop, DropAllocator> as Drop>::drop(move _10) -> [return: bb14, unwind: bb12];
140120
+ }
141121
+
142-
+ bb20 (cleanup): {
122+
+ bb16 (cleanup): {
143123
+ _12 = &mut _1;
144-
+ _13 = <Box<HasDrop, DropAllocator> as Drop>::drop(move _12) -> [return: bb16, unwind terminate(cleanup)];
124+
+ _13 = <Box<HasDrop, DropAllocator> as Drop>::drop(move _12) -> [return: bb12, unwind terminate(cleanup)];
145125
+ }
146126
+
147-
+ bb21: {
148-
+ goto -> bb19;
127+
+ bb17: {
128+
+ goto -> bb15;
149129
+ }
150130
+
151-
+ bb22: {
131+
+ bb18: {
152132
+ _14 = copy ((_1.0: std::ptr::Unique<HasDrop>).0: std::ptr::NonNull<HasDrop>) as *const HasDrop (Transmute);
153-
+ goto -> bb21;
133+
+ goto -> bb17;
154134
+ }
155135
+
156-
+ bb23: {
157-
+ switchInt(copy _9) -> [0: bb18, otherwise: bb22];
136+
+ bb19: {
137+
+ switchInt(copy _9) -> [0: bb14, otherwise: bb18];
158138
+ }
159139
+
160-
+ bb24 (cleanup): {
161-
+ drop((_1.1: DropAllocator)) -> [return: bb13, unwind terminate(cleanup)];
140+
+ bb20 (cleanup): {
141+
+ drop((_1.1: DropAllocator)) -> [return: bb9, unwind terminate(cleanup)];
162142
+ }
163143
+
164-
+ bb25 (cleanup): {
165-
+ switchInt(copy _9) -> [0: bb13, otherwise: bb24];
144+
+ bb21 (cleanup): {
145+
+ switchInt(copy _9) -> [0: bb9, otherwise: bb20];
166146
+ }
167147
+
168-
+ bb26 (cleanup): {
148+
+ bb22 (cleanup): {
169149
+ _15 = &mut _1;
170-
+ _16 = <Box<HasDrop, DropAllocator> as Drop>::drop(move _15) -> [return: bb25, unwind terminate(cleanup)];
150+
+ _16 = <Box<HasDrop, DropAllocator> as Drop>::drop(move _15) -> [return: bb21, unwind terminate(cleanup)];
171151
+ }
172152
+
173-
+ bb27 (cleanup): {
174-
+ goto -> bb26;
153+
+ bb23 (cleanup): {
154+
+ goto -> bb22;
175155
+ }
176156
+
177-
+ bb28 (cleanup): {
157+
+ bb24 (cleanup): {
178158
+ _17 = copy ((_1.0: std::ptr::Unique<HasDrop>).0: std::ptr::NonNull<HasDrop>) as *const HasDrop (Transmute);
179-
+ goto -> bb27;
159+
+ goto -> bb23;
180160
+ }
181161
+
182-
+ bb29 (cleanup): {
183-
+ switchInt(copy _9) -> [0: bb25, otherwise: bb28];
162+
+ bb25 (cleanup): {
163+
+ switchInt(copy _9) -> [0: bb21, otherwise: bb24];
184164
}
185165
}
186166

tests/mir-opt/box_partial_move.maybe_move.ElaborateDrops.diff

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -19,76 +19,66 @@
1919
+ _5 = const true;
2020
StorageLive(_3);
2121
_3 = copy _1;
22-
switchInt(move _3) -> [0: bb3, otherwise: bb1];
22+
switchInt(move _3) -> [0: bb2, otherwise: bb1];
2323
}
2424

2525
bb1: {
2626
StorageLive(_4);
2727
+ _5 = const false;
2828
_4 = move (*_2);
2929
_0 = Option::<String>::Some(move _4);
30-
- drop(_4) -> [return: bb2, unwind: bb6];
31-
+ goto -> bb2;
32-
}
33-
34-
bb2: {
3530
StorageDead(_4);
36-
goto -> bb4;
31+
goto -> bb3;
3732
}
3833

39-
bb3: {
34+
bb2: {
4035
_0 = Option::<String>::None;
41-
goto -> bb4;
36+
goto -> bb3;
4237
}
4338

44-
bb4: {
39+
bb3: {
4540
StorageDead(_3);
46-
- drop(_2) -> [return: bb5, unwind continue];
47-
+ goto -> bb14;
41+
- drop(_2) -> [return: bb4, unwind continue];
42+
+ goto -> bb12;
4843
}
4944

50-
bb5: {
45+
bb4: {
5146
return;
52-
}
53-
54-
bb6 (cleanup): {
55-
- drop(_2) -> [return: bb7, unwind terminate(cleanup)];
56-
+ goto -> bb7;
57-
}
58-
59-
bb7 (cleanup): {
60-
resume;
6147
+ }
6248
+
63-
+ bb8: {
64-
+ goto -> bb5;
49+
+ bb5 (cleanup): {
50+
+ resume;
6551
+ }
6652
+
67-
+ bb9: {
53+
+ bb6: {
54+
+ goto -> bb4;
55+
+ }
56+
+
57+
+ bb7: {
6858
+ _6 = &mut _2;
69-
+ _7 = <Box<String> as Drop>::drop(move _6) -> [return: bb8, unwind: bb7];
59+
+ _7 = <Box<String> as Drop>::drop(move _6) -> [return: bb6, unwind: bb5];
7060
+ }
7161
+
72-
+ bb10 (cleanup): {
62+
+ bb8 (cleanup): {
7363
+ _8 = &mut _2;
74-
+ _9 = <Box<String> as Drop>::drop(move _8) -> [return: bb7, unwind terminate(cleanup)];
64+
+ _9 = <Box<String> as Drop>::drop(move _8) -> [return: bb5, unwind terminate(cleanup)];
7565
+ }
7666
+
77-
+ bb11: {
78-
+ goto -> bb13;
67+
+ bb9: {
68+
+ goto -> bb11;
7969
+ }
8070
+
81-
+ bb12: {
82-
+ drop((*_10)) -> [return: bb9, unwind: bb10];
71+
+ bb10: {
72+
+ drop((*_10)) -> [return: bb7, unwind: bb8];
8373
+ }
8474
+
85-
+ bb13: {
86-
+ switchInt(copy _5) -> [0: bb9, otherwise: bb12];
75+
+ bb11: {
76+
+ switchInt(copy _5) -> [0: bb7, otherwise: bb10];
8777
+ }
8878
+
89-
+ bb14: {
79+
+ bb12: {
9080
+ _10 = copy ((_2.0: std::ptr::Unique<std::string::String>).0: std::ptr::NonNull<std::string::String>) as *const std::string::String (Transmute);
91-
+ goto -> bb11;
81+
+ goto -> bb9;
9282
}
9383
}
9484

tests/mir-opt/building/uniform_array_move_out.move_out_by_subslice.CleanupPostBorrowck.after.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ fn move_out_by_subslice() -> () {
2626

2727
bb2: {
2828
_1 = [move _2, move _3];
29-
drop(_3) -> [return: bb3, unwind: bb8];
29+
goto -> bb3;
3030
}
3131

3232
bb3: {
3333
StorageDead(_3);
34-
drop(_2) -> [return: bb4, unwind: bb9];
34+
goto -> bb4;
3535
}
3636

3737
bb4: {

tests/mir-opt/building/uniform_array_move_out.move_out_from_end.CleanupPostBorrowck.after.mir

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ fn move_out_from_end() -> () {
2626

2727
bb2: {
2828
_1 = [move _2, move _3];
29-
drop(_3) -> [return: bb3, unwind: bb8];
29+
goto -> bb3;
3030
}
3131

3232
bb3: {
3333
StorageDead(_3);
34-
drop(_2) -> [return: bb4, unwind: bb9];
34+
goto -> bb4;
3535
}
3636

3737
bb4: {

0 commit comments

Comments
 (0)