Skip to content

Commit 53de634

Browse files
committed
Remove uninit drops right after building MIR.
1 parent 9a6d973 commit 53de634

87 files changed

Lines changed: 3258 additions & 4730 deletions

File tree

Some content is hidden

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

‎compiler/rustc_mir_transform/src/lib.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ fn mir_built(tcx: TyCtxt<'_>, def: LocalDefId) -> &Steal<Body<'_>> {
412412
// This used to be part of MIR building,
413413
// now done separately to separate concerns.
414414
&lint_and_remove_uninhabited::LintAndRemoveUninhabited,
415+
&remove_uninit_drops::RemoveUninitDrops,
415416
// MIR-level lints.
416417
&Lint(check_inline::CheckForceInline),
417418
&Lint(check_call_recursion::CheckCallRecursion),
@@ -649,7 +650,6 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) {
649650
&post_analysis_normalize::PostAnalysisNormalize,
650651
// Calling this after `PostAnalysisNormalize` ensures that we don't deal with opaque types.
651652
&add_subtyping_projections::Subtyper,
652-
&remove_uninit_drops::RemoveUninitDrops,
653653
&elaborate_drops::ElaborateDrops,
654654
// Needs to happen after drop elaboration.
655655
&Lint(check_call_recursion::CheckDropRecursion),

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

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,47 +35,23 @@
3535
StorageLive(_5);
3636
StorageLive(_6);
3737
_6 = move _4;
38-
goto -> bb1;
39-
}
40-
41-
bb1: {
4238
_5 = move _6;
43-
goto -> bb3;
44-
}
45-
46-
bb2 (cleanup): {
47-
_5 = move _6;
48-
goto -> bb6;
49-
}
50-
51-
bb3: {
5239
StorageDead(_6);
5340
_0 = const ();
54-
drop(_5) -> [return: bb4, unwind: bb7];
41+
- drop(_5) -> [return: bb1, unwind continue];
42+
+ drop(_5) -> [return: bb1, unwind: bb2];
5543
}
5644

57-
bb4: {
45+
bb1: {
5846
StorageDead(_5);
59-
goto -> bb5;
60-
}
61-
62-
bb5: {
6347
StorageDead(_4);
6448
StorageDead(_2);
6549
StorageDead(_1);
6650
return;
67-
}
68-
69-
bb6 (cleanup): {
70-
drop(_5) -> [return: bb7, unwind terminate(cleanup)];
71-
}
72-
73-
bb7 (cleanup): {
74-
goto -> bb8;
75-
}
76-
77-
bb8 (cleanup): {
78-
resume;
51+
+ }
52+
+
53+
+ bb2 (cleanup): {
54+
+ resume;
7955
}
8056
}
8157

‎tests/mir-opt/basic_assignment.main.SimplifyCfg-initial.after.mir‎

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,46 +41,21 @@ fn main() -> () {
4141
StorageLive(_5);
4242
StorageLive(_6);
4343
_6 = move _4;
44-
drop(_5) -> [return: bb1, unwind: bb2];
45-
}
46-
47-
bb1: {
48-
_5 = move _6;
49-
drop(_6) -> [return: bb3, unwind: bb6];
50-
}
51-
52-
bb2 (cleanup): {
5344
_5 = move _6;
54-
drop(_6) -> [return: bb6, unwind terminate(cleanup)];
55-
}
56-
57-
bb3: {
5845
StorageDead(_6);
5946
_0 = const ();
60-
drop(_5) -> [return: bb4, unwind: bb7];
47+
drop(_5) -> [return: bb1, unwind: bb2];
6148
}
6249

63-
bb4: {
50+
bb1: {
6451
StorageDead(_5);
65-
drop(_4) -> [return: bb5, unwind: bb8];
66-
}
67-
68-
bb5: {
6952
StorageDead(_4);
7053
StorageDead(_2);
7154
StorageDead(_1);
7255
return;
7356
}
7457

75-
bb6 (cleanup): {
76-
drop(_5) -> [return: bb7, unwind terminate(cleanup)];
77-
}
78-
79-
bb7 (cleanup): {
80-
drop(_4) -> [return: bb8, unwind terminate(cleanup)];
81-
}
82-
83-
bb8 (cleanup): {
58+
bb2 (cleanup): {
8459
resume;
8560
}
8661
}

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

Lines changed: 37 additions & 53 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,98 +85,82 @@
8585
}
8686

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

9192
bb9 (cleanup): {
92-
goto -> bb10;
93-
}
94-
95-
bb10 (cleanup): {
96-
- drop(_1) -> [return: bb13, unwind terminate(cleanup)];
97-
+ goto -> bb29;
98-
}
99-
100-
bb11 (cleanup): {
101-
goto -> bb12;
102-
}
103-
104-
bb12 (cleanup): {
105-
goto -> bb13;
106-
}
107-
108-
bb13 (cleanup): {
10993
resume;
11094
+ }
11195
+
112-
+ bb14: {
96+
+ bb10: {
11397
+ _9 = const false;
11498
+ goto -> bb7;
11599
+ }
116100
+
117-
+ bb15 (cleanup): {
118-
+ drop((_1.1: DropAllocator)) -> [return: bb13, unwind terminate(cleanup)];
101+
+ bb11 (cleanup): {
102+
+ drop((_1.1: DropAllocator)) -> [return: bb9, unwind terminate(cleanup)];
119103
+ }
120104
+
121-
+ bb16 (cleanup): {
122-
+ switchInt(copy _9) -> [0: bb13, otherwise: bb15];
105+
+ bb12 (cleanup): {
106+
+ switchInt(copy _9) -> [0: bb9, otherwise: bb11];
123107
+ }
124108
+
125-
+ bb17: {
126-
+ drop((_1.1: DropAllocator)) -> [return: bb14, unwind: bb13];
109+
+ bb13: {
110+
+ drop((_1.1: DropAllocator)) -> [return: bb10, unwind: bb9];
127111
+ }
128112
+
129-
+ bb18: {
130-
+ switchInt(copy _9) -> [0: bb14, otherwise: bb17];
113+
+ bb14: {
114+
+ switchInt(copy _9) -> [0: bb10, otherwise: bb13];
131115
+ }
132116
+
133-
+ bb19: {
117+
+ bb15: {
134118
+ _10 = &mut _1;
135-
+ _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];
136120
+ }
137121
+
138-
+ bb20 (cleanup): {
122+
+ bb16 (cleanup): {
139123
+ _12 = &mut _1;
140-
+ _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)];
141125
+ }
142126
+
143-
+ bb21: {
144-
+ goto -> bb19;
127+
+ bb17: {
128+
+ goto -> bb15;
145129
+ }
146130
+
147-
+ bb22: {
131+
+ bb18: {
148132
+ _14 = copy ((_1.0: std::ptr::Unique<HasDrop>).0: std::ptr::NonNull<HasDrop>) as *const HasDrop (Transmute);
149-
+ goto -> bb21;
133+
+ goto -> bb17;
150134
+ }
151135
+
152-
+ bb23: {
153-
+ switchInt(copy _9) -> [0: bb18, otherwise: bb22];
136+
+ bb19: {
137+
+ switchInt(copy _9) -> [0: bb14, otherwise: bb18];
154138
+ }
155139
+
156-
+ bb24 (cleanup): {
157-
+ drop((_1.1: DropAllocator)) -> [return: bb13, unwind terminate(cleanup)];
140+
+ bb20 (cleanup): {
141+
+ drop((_1.1: DropAllocator)) -> [return: bb9, unwind terminate(cleanup)];
158142
+ }
159143
+
160-
+ bb25 (cleanup): {
161-
+ switchInt(copy _9) -> [0: bb13, otherwise: bb24];
144+
+ bb21 (cleanup): {
145+
+ switchInt(copy _9) -> [0: bb9, otherwise: bb20];
162146
+ }
163147
+
164-
+ bb26 (cleanup): {
148+
+ bb22 (cleanup): {
165149
+ _15 = &mut _1;
166-
+ _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)];
167151
+ }
168152
+
169-
+ bb27 (cleanup): {
170-
+ goto -> bb26;
153+
+ bb23 (cleanup): {
154+
+ goto -> bb22;
171155
+ }
172156
+
173-
+ bb28 (cleanup): {
157+
+ bb24 (cleanup): {
174158
+ _17 = copy ((_1.0: std::ptr::Unique<HasDrop>).0: std::ptr::NonNull<HasDrop>) as *const HasDrop (Transmute);
175-
+ goto -> bb27;
159+
+ goto -> bb23;
176160
+ }
177161
+
178-
+ bb29 (cleanup): {
179-
+ switchInt(copy _9) -> [0: bb25, otherwise: bb28];
162+
+ bb25 (cleanup): {
163+
+ switchInt(copy _9) -> [0: bb21, otherwise: bb24];
180164
}
181165
}
182166

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

Lines changed: 24 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -19,70 +19,62 @@
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-
goto -> bb2;
31-
}
32-
33-
bb2: {
3430
StorageDead(_4);
35-
goto -> bb4;
31+
goto -> bb3;
3632
}
3733

38-
bb3: {
34+
bb2: {
3935
_0 = Option::<String>::None;
40-
goto -> bb4;
36+
goto -> bb3;
4137
}
4238

43-
bb4: {
39+
bb3: {
4440
StorageDead(_3);
45-
- drop(_2) -> [return: bb5, unwind continue];
46-
+ goto -> bb13;
41+
- drop(_2) -> [return: bb4, unwind continue];
42+
+ goto -> bb11;
4743
}
4844

49-
bb5: {
45+
bb4: {
5046
return;
51-
}
52-
53-
bb6 (cleanup): {
54-
drop(_2) -> [return: bb7, unwind terminate(cleanup)];
55-
}
56-
57-
bb7 (cleanup): {
58-
resume;
5947
+ }
6048
+
61-
+ bb8: {
49+
+ bb5 (cleanup): {
50+
+ resume;
51+
+ }
52+
+
53+
+ bb6: {
6254
+ _6 = &mut _2;
63-
+ _7 = <Box<String> as Drop>::drop(move _6) -> [return: bb5, unwind: bb7];
55+
+ _7 = <Box<String> as Drop>::drop(move _6) -> [return: bb4, unwind: bb5];
6456
+ }
6557
+
66-
+ bb9 (cleanup): {
58+
+ bb7 (cleanup): {
6759
+ _8 = &mut _2;
68-
+ _9 = <Box<String> as Drop>::drop(move _8) -> [return: bb7, unwind terminate(cleanup)];
60+
+ _9 = <Box<String> as Drop>::drop(move _8) -> [return: bb5, unwind terminate(cleanup)];
6961
+ }
7062
+
71-
+ bb10: {
72-
+ goto -> bb12;
63+
+ bb8: {
64+
+ goto -> bb10;
7365
+ }
7466
+
75-
+ bb11: {
76-
+ drop((*_10)) -> [return: bb8, unwind: bb9];
67+
+ bb9: {
68+
+ drop((*_10)) -> [return: bb6, unwind: bb7];
7769
+ }
7870
+
79-
+ bb12: {
80-
+ switchInt(copy _5) -> [0: bb8, otherwise: bb11];
71+
+ bb10: {
72+
+ switchInt(copy _5) -> [0: bb6, otherwise: bb9];
8173
+ }
8274
+
83-
+ bb13: {
75+
+ bb11: {
8476
+ _10 = copy ((_2.0: std::ptr::Unique<std::string::String>).0: std::ptr::NonNull<std::string::String>) as *const std::string::String (Transmute);
85-
+ goto -> bb10;
77+
+ goto -> bb8;
8678
}
8779
}
8880

0 commit comments

Comments
 (0)