Skip to content

Commit 3c2bae3

Browse files
committed
Use mir_post_borrowck_cleanup from everywhere else (coroutines only)
1 parent c9bcdce commit 3c2bae3

7 files changed

Lines changed: 109 additions & 161 deletions

compiler/rustc_mir_transform/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ fn mir_drops_elaborated_and_const_checked(tcx: TyCtxt<'_>, def: LocalDefId) -> &
555555

556556
tcx.ensure_done().check_liveness(def);
557557

558-
let (body, _) = tcx.mir_promoted(def);
558+
let body = tcx.mir_post_borrowck_cleanup(def);
559559
let mut body = body.steal();
560560

561561
if let Some(error_reported) = tainted_by_errors {

compiler/rustc_mir_transform/src/remove_dead_drops.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ 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+
1519
let move_data = MoveData::gather_moves(body, tcx, |_| true);
1620

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

tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir

Lines changed: 29 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
105105
bb0: {
106106
_39 = copy (_1.0: &mut {async fn body of b()});
107107
_38 = discriminant((*_39));
108-
switchInt(move _38) -> [0: bb1, 1: bb29, 3: bb27, 4: bb28, otherwise: bb8];
108+
switchInt(move _38) -> [0: bb1, 1: bb27, 3: bb25, 4: bb26, otherwise: bb8];
109109
}
110110

111111
bb1: {
@@ -206,65 +206,61 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
206206

207207
bb12: {
208208
nop;
209-
goto -> bb13;
210-
}
211-
212-
bb13: {
213209
StorageDead(_4);
214210
StorageDead(_3);
215211
StorageLive(_21);
216212
StorageLive(_22);
217-
_22 = a() -> [return: bb14, unwind unreachable];
213+
_22 = a() -> [return: bb13, unwind unreachable];
218214
}
219215

220-
bb14: {
221-
_21 = <{async fn body of a()} as IntoFuture>::into_future(move _22) -> [return: bb15, unwind unreachable];
216+
bb13: {
217+
_21 = <{async fn body of a()} as IntoFuture>::into_future(move _22) -> [return: bb14, unwind unreachable];
222218
}
223219

224-
bb15: {
220+
bb14: {
225221
StorageDead(_22);
226222
PlaceMention(_21);
227223
nop;
228224
(((*_39) as variant#4).0: {async fn body of a()}) = move _21;
229-
goto -> bb16;
225+
goto -> bb15;
230226
}
231227

232-
bb16: {
228+
bb15: {
233229
StorageLive(_24);
234230
StorageLive(_25);
235231
StorageLive(_26);
236232
StorageLive(_27);
237233
StorageLive(_28);
238234
_28 = &mut (((*_39) as variant#4).0: {async fn body of a()});
239235
_27 = &mut (*_28);
240-
_26 = Pin::<&mut {async fn body of a()}>::new_unchecked(move _27) -> [return: bb17, unwind unreachable];
236+
_26 = Pin::<&mut {async fn body of a()}>::new_unchecked(move _27) -> [return: bb16, unwind unreachable];
241237
}
242238

243-
bb17: {
239+
bb16: {
244240
StorageDead(_27);
245241
StorageLive(_29);
246242
StorageLive(_30);
247243
StorageLive(_31);
248244
_31 = copy _2;
249245
_30 = move _31;
250-
goto -> bb18;
246+
goto -> bb17;
251247
}
252248

253-
bb18: {
249+
bb17: {
254250
_29 = &mut (*_30);
255251
StorageDead(_31);
256-
_25 = <{async fn body of a()} as Future>::poll(move _26, move _29) -> [return: bb19, unwind unreachable];
252+
_25 = <{async fn body of a()} as Future>::poll(move _26, move _29) -> [return: bb18, unwind unreachable];
257253
}
258254

259-
bb19: {
255+
bb18: {
260256
StorageDead(_29);
261257
StorageDead(_26);
262258
PlaceMention(_25);
263259
_32 = discriminant(_25);
264-
switchInt(move _32) -> [0: bb21, 1: bb20, otherwise: bb8];
260+
switchInt(move _32) -> [0: bb20, 1: bb19, otherwise: bb8];
265261
}
266262

267-
bb20: {
263+
bb19: {
268264
_24 = const ();
269265
StorageDead(_30);
270266
StorageDead(_28);
@@ -281,7 +277,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
281277
return;
282278
}
283279

284-
bb21: {
280+
bb20: {
285281
StorageLive(_33);
286282
_33 = copy ((_25 as Ready).0: ());
287283
_37 = copy _33;
@@ -290,38 +286,34 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
290286
StorageDead(_28);
291287
StorageDead(_25);
292288
StorageDead(_24);
293-
drop((((*_39) as variant#4).0: {async fn body of a()})) -> [return: bb23, unwind unreachable];
289+
drop((((*_39) as variant#4).0: {async fn body of a()})) -> [return: bb22, unwind unreachable];
294290
}
295291

296-
bb22: {
292+
bb21: {
297293
StorageDead(_36);
298294
_2 = move _35;
299295
StorageDead(_35);
300296
_7 = const ();
301-
goto -> bb16;
297+
goto -> bb15;
302298
}
303299

304-
bb23: {
300+
bb22: {
305301
nop;
306-
goto -> bb24;
307-
}
308-
309-
bb24: {
310302
StorageDead(_21);
311-
goto -> bb26;
303+
goto -> bb24;
312304
}
313305

314-
bb25: {
306+
bb23: {
315307
_0 = Poll::<()>::Ready(move _37);
316308
discriminant((*_39)) = 1;
317309
return;
318310
}
319311

320-
bb26: {
321-
goto -> bb25;
312+
bb24: {
313+
goto -> bb23;
322314
}
323315

324-
bb27: {
316+
bb25: {
325317
StorageLive(_3);
326318
StorageLive(_4);
327319
StorageLive(_19);
@@ -330,15 +322,15 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
330322
goto -> bb11;
331323
}
332324

333-
bb28: {
325+
bb26: {
334326
StorageLive(_21);
335327
StorageLive(_35);
336328
StorageLive(_36);
337329
_35 = move _2;
338-
goto -> bb22;
330+
goto -> bb21;
339331
}
340332

341-
bb29: {
342-
assert(const false, "`async fn` resumed after completion") -> [success: bb29, unwind unreachable];
333+
bb27: {
334+
assert(const false, "`async fn` resumed after completion") -> [success: bb27, unwind unreachable];
343335
}
344336
}

tests/mir-opt/building/coroutine.main-{closure#0}.StateTransform.after.mir

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2
4545
bb0: {
4646
_18 = copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18});
4747
_17 = discriminant((*_18));
48-
switchInt(move _17) -> [0: bb1, 1: bb19, 3: bb17, 4: bb18, otherwise: bb20];
48+
switchInt(move _17) -> [0: bb1, 1: bb15, 3: bb13, 4: bb14, otherwise: bb16];
4949
}
5050

5151
bb1: {
@@ -67,10 +67,6 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2
6767
bb3: {
6868
_4 = (const "first", move _5, move _7);
6969
StorageDead(_7);
70-
goto -> bb4;
71-
}
72-
73-
bb4: {
7470
StorageDead(_5);
7571
_0 = CoroutineState::<(&str, String, &Location<'_>), ()>::Yielded(move _4);
7672
StorageDead(_3);
@@ -79,16 +75,12 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2
7975
return;
8076
}
8177

82-
bb5: {
83-
goto -> bb6;
84-
}
85-
86-
bb6: {
78+
bb4: {
8779
StorageDead(_4);
88-
drop(_3) -> [return: bb7, unwind unreachable];
80+
drop(_3) -> [return: bb5, unwind unreachable];
8981
}
9082

91-
bb7: {
83+
bb5: {
9284
StorageDead(_3);
9385
StorageLive(_8);
9486
StorageLive(_9);
@@ -99,24 +91,20 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2
9991
StorageLive(_12);
10092
StorageLive(_13);
10193
_13 = &(((*_18) as variant#4).0: std::string::String);
102-
_12 = <String as Clone>::clone(move _13) -> [return: bb8, unwind unreachable];
94+
_12 = <String as Clone>::clone(move _13) -> [return: bb6, unwind unreachable];
10395
}
10496

105-
bb8: {
97+
bb6: {
10698
StorageDead(_13);
10799
StorageLive(_14);
108100
StorageLive(_15);
109-
_15 = Location::<'_>::caller() -> [return: bb9, unwind unreachable];
101+
_15 = Location::<'_>::caller() -> [return: bb7, unwind unreachable];
110102
}
111103

112-
bb9: {
104+
bb7: {
113105
_14 = &(*_15);
114106
_9 = (move _10, move _12, move _14);
115107
StorageDead(_14);
116-
goto -> bb10;
117-
}
118-
119-
bb10: {
120108
StorageDead(_12);
121109
StorageDead(_10);
122110
_0 = CoroutineState::<(&str, String, &Location<'_>), ()>::Yielded(move _9);
@@ -128,58 +116,54 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2
128116
return;
129117
}
130118

131-
bb11: {
132-
goto -> bb12;
133-
}
134-
135-
bb12: {
119+
bb8: {
136120
StorageDead(_9);
137-
drop(_8) -> [return: bb13, unwind unreachable];
121+
drop(_8) -> [return: bb9, unwind unreachable];
138122
}
139123

140-
bb13: {
124+
bb9: {
141125
StorageDead(_15);
142126
StorageDead(_11);
143127
StorageDead(_8);
144128
_16 = const ();
145-
drop((((*_18) as variant#4).0: std::string::String)) -> [return: bb14, unwind unreachable];
129+
drop((((*_18) as variant#4).0: std::string::String)) -> [return: bb10, unwind unreachable];
146130
}
147131

148-
bb14: {
149-
goto -> bb16;
132+
bb10: {
133+
goto -> bb12;
150134
}
151135

152-
bb15: {
136+
bb11: {
153137
_0 = CoroutineState::<(&str, String, &Location<'_>), ()>::Complete(move _16);
154138
discriminant((*_18)) = 1;
155139
return;
156140
}
157141

158-
bb16: {
159-
goto -> bb15;
142+
bb12: {
143+
goto -> bb11;
160144
}
161145

162-
bb17: {
146+
bb13: {
163147
StorageLive(_3);
164148
StorageLive(_4);
165149
_3 = move _2;
166-
goto -> bb5;
150+
goto -> bb4;
167151
}
168152

169-
bb18: {
153+
bb14: {
170154
StorageLive(_8);
171155
StorageLive(_9);
172156
StorageLive(_11);
173157
StorageLive(_15);
174158
_8 = move _2;
175-
goto -> bb11;
159+
goto -> bb8;
176160
}
177161

178-
bb19: {
179-
assert(const false, "coroutine resumed after completion") -> [success: bb19, unwind unreachable];
162+
bb15: {
163+
assert(const false, "coroutine resumed after completion") -> [success: bb15, unwind unreachable];
180164
}
181165

182-
bb20: {
166+
bb16: {
183167
unreachable;
184168
}
185169
}

0 commit comments

Comments
 (0)