Skip to content

Commit 5878c57

Browse files
committed
Make a dedicated coroutine mir-opt test directory.
1 parent 6368fd5 commit 5878c57

34 files changed

Lines changed: 347 additions & 77 deletions

File tree

tests/mir-opt/building/async_await.rs

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir renamed to tests/mir-opt/coroutine/async_await.a-{closure#0}.coroutine_resume.0.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) ->
3838
}
3939

4040
bb4: {
41-
assert(const false, "`async fn` resumed after completion") -> [success: bb4, unwind unreachable];
41+
assert(const false, "`async fn` resumed after completion") -> [success: bb4, unwind continue];
4242
}
4343

4444
bb5: {

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

Lines changed: 115 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
),
1515
source_info: SourceInfo {
16-
span: $DIR/async_await.rs:16:5: 16:14 (#9),
16+
span: $DIR/async_await.rs:27:5: 27:14 (#9),
1717
scope: scope[0],
1818
},
1919
ignore_for_traits: false,
@@ -30,7 +30,7 @@
3030
],
3131
),
3232
source_info: SourceInfo {
33-
span: $DIR/async_await.rs:17:5: 17:14 (#11),
33+
span: $DIR/async_await.rs:28:5: 28:14 (#11),
3434
scope: scope[0],
3535
},
3636
ignore_for_traits: false,
@@ -105,18 +105,18 @@ 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: bb47, 2: bb46, 3: bb44, 4: bb45, otherwise: bb8];
109109
}
110110

111111
bb1: {
112112
StorageLive(_3);
113113
StorageLive(_4);
114114
StorageLive(_5);
115-
_5 = a() -> [return: bb2, unwind unreachable];
115+
_5 = a() -> [return: bb2, unwind: bb38];
116116
}
117117

118118
bb2: {
119-
_4 = <{async fn body of a()} as IntoFuture>::into_future(move _5) -> [return: bb3, unwind unreachable];
119+
_4 = <{async fn body of a()} as IntoFuture>::into_future(move _5) -> [return: bb3, unwind: bb37];
120120
}
121121

122122
bb3: {
@@ -135,7 +135,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
135135
StorageLive(_12);
136136
_12 = &mut (((*_39) as variant#3).0: {async fn body of a()});
137137
_11 = &mut (*_12);
138-
_10 = Pin::<&mut {async fn body of a()}>::new_unchecked(move _11) -> [return: bb5, unwind unreachable];
138+
_10 = Pin::<&mut {async fn body of a()}>::new_unchecked(move _11) -> [return: bb5, unwind: bb34];
139139
}
140140

141141
bb5: {
@@ -151,7 +151,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
151151
bb6: {
152152
_13 = &mut (*_14);
153153
StorageDead(_15);
154-
_9 = <{async fn body of a()} as Future>::poll(move _10, move _13) -> [return: bb7, unwind unreachable];
154+
_9 = <{async fn body of a()} as Future>::poll(move _10, move _13) -> [return: bb7, unwind: bb33];
155155
}
156156

157157
bb7: {
@@ -193,7 +193,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
193193
StorageDead(_12);
194194
StorageDead(_9);
195195
StorageDead(_8);
196-
drop((((*_39) as variant#3).0: {async fn body of a()})) -> [return: bb12, unwind unreachable];
196+
drop((((*_39) as variant#3).0: {async fn body of a()})) -> [return: bb12, unwind: bb36];
197197
}
198198

199199
bb11: {
@@ -214,11 +214,11 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
214214
StorageDead(_3);
215215
StorageLive(_21);
216216
StorageLive(_22);
217-
_22 = a() -> [return: bb14, unwind unreachable];
217+
_22 = a() -> [return: bb14, unwind: bb31];
218218
}
219219

220220
bb14: {
221-
_21 = <{async fn body of a()} as IntoFuture>::into_future(move _22) -> [return: bb15, unwind unreachable];
221+
_21 = <{async fn body of a()} as IntoFuture>::into_future(move _22) -> [return: bb15, unwind: bb30];
222222
}
223223

224224
bb15: {
@@ -237,7 +237,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
237237
StorageLive(_28);
238238
_28 = &mut (((*_39) as variant#4).0: {async fn body of a()});
239239
_27 = &mut (*_28);
240-
_26 = Pin::<&mut {async fn body of a()}>::new_unchecked(move _27) -> [return: bb17, unwind unreachable];
240+
_26 = Pin::<&mut {async fn body of a()}>::new_unchecked(move _27) -> [return: bb17, unwind: bb27];
241241
}
242242

243243
bb17: {
@@ -253,7 +253,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
253253
bb18: {
254254
_29 = &mut (*_30);
255255
StorageDead(_31);
256-
_25 = <{async fn body of a()} as Future>::poll(move _26, move _29) -> [return: bb19, unwind unreachable];
256+
_25 = <{async fn body of a()} as Future>::poll(move _26, move _29) -> [return: bb19, unwind: bb26];
257257
}
258258

259259
bb19: {
@@ -290,7 +290,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
290290
StorageDead(_28);
291291
StorageDead(_25);
292292
StorageDead(_24);
293-
drop((((*_39) as variant#4).0: {async fn body of a()})) -> [return: bb23, unwind unreachable];
293+
drop((((*_39) as variant#4).0: {async fn body of a()})) -> [return: bb23, unwind: bb29];
294294
}
295295

296296
bb22: {
@@ -308,7 +308,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
308308

309309
bb24: {
310310
StorageDead(_21);
311-
goto -> bb26;
311+
goto -> bb42;
312312
}
313313

314314
bb25: {
@@ -317,11 +317,103 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
317317
return;
318318
}
319319

320-
bb26: {
320+
bb26 (cleanup): {
321+
StorageDead(_29);
322+
StorageDead(_26);
323+
StorageDead(_30);
324+
goto -> bb28;
325+
}
326+
327+
bb27 (cleanup): {
328+
StorageDead(_27);
329+
StorageDead(_26);
330+
goto -> bb28;
331+
}
332+
333+
bb28 (cleanup): {
334+
StorageDead(_28);
335+
StorageDead(_25);
336+
StorageDead(_24);
337+
drop((((*_39) as variant#4).0: {async fn body of a()})) -> [return: bb29, unwind terminate(cleanup)];
338+
}
339+
340+
bb29 (cleanup): {
341+
nop;
342+
goto -> bb32;
343+
}
344+
345+
bb30 (cleanup): {
346+
goto -> bb31;
347+
}
348+
349+
bb31 (cleanup): {
350+
StorageDead(_22);
351+
goto -> bb32;
352+
}
353+
354+
bb32 (cleanup): {
355+
StorageDead(_21);
356+
goto -> bb40;
357+
}
358+
359+
bb33 (cleanup): {
360+
StorageDead(_13);
361+
StorageDead(_10);
362+
StorageDead(_14);
363+
goto -> bb35;
364+
}
365+
366+
bb34 (cleanup): {
367+
StorageDead(_11);
368+
StorageDead(_10);
369+
goto -> bb35;
370+
}
371+
372+
bb35 (cleanup): {
373+
StorageDead(_12);
374+
StorageDead(_9);
375+
StorageDead(_8);
376+
drop((((*_39) as variant#3).0: {async fn body of a()})) -> [return: bb36, unwind terminate(cleanup)];
377+
}
378+
379+
bb36 (cleanup): {
380+
nop;
381+
goto -> bb39;
382+
}
383+
384+
bb37 (cleanup): {
385+
goto -> bb38;
386+
}
387+
388+
bb38 (cleanup): {
389+
StorageDead(_5);
390+
goto -> bb39;
391+
}
392+
393+
bb39 (cleanup): {
394+
StorageDead(_4);
395+
StorageDead(_3);
396+
goto -> bb40;
397+
}
398+
399+
bb40 (cleanup): {
400+
goto -> bb41;
401+
}
402+
403+
bb41 (cleanup): {
404+
goto -> bb43;
405+
}
406+
407+
bb42: {
321408
goto -> bb25;
322409
}
323410

324-
bb27: {
411+
bb43 (cleanup): {
412+
discriminant((*_39)) = 2;
413+
resume;
414+
}
415+
416+
bb44: {
325417
StorageLive(_3);
326418
StorageLive(_4);
327419
StorageLive(_19);
@@ -330,15 +422,19 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) ->
330422
goto -> bb11;
331423
}
332424

333-
bb28: {
425+
bb45: {
334426
StorageLive(_21);
335427
StorageLive(_35);
336428
StorageLive(_36);
337429
_35 = move _2;
338430
goto -> bb22;
339431
}
340432

341-
bb29: {
342-
assert(const false, "`async fn` resumed after completion") -> [success: bb29, unwind unreachable];
433+
bb46: {
434+
assert(const false, "`async fn` resumed after panicking") -> [success: bb46, unwind continue];
435+
}
436+
437+
bb47: {
438+
assert(const false, "`async fn` resumed after completion") -> [success: bb47, unwind continue];
343439
}
344440
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This test makes sure that the coroutine MIR pass eliminates all calls to
2+
// `get_context`, and that the MIR argument type for an async fn and all locals
3+
// related to `yield` are `&mut Context`, and its return type is `Poll`.
4+
5+
//@ edition:2018
6+
//@ compile-flags: -Zmir-opt-level=0
7+
//@ needs-unwind
8+
9+
#![crate_type = "lib"]
10+
11+
// EMIT_MIR async_await.a-{closure#0}.coroutine_resume.0.mir
12+
async fn a() {
13+
// CHECK-LABEL: fn a::{closure#0}(
14+
// CHECK-SAME: _1: Pin<&mut {async fn body of a()}>
15+
// CHECK-SAME: _2: &mut Context<'_>
16+
// CHECK-SAME: -> Poll<()>
17+
// CHECK-NOT: get_context
18+
}
19+
20+
// EMIT_MIR async_await.b-{closure#0}.coroutine_resume.0.mir
21+
pub async fn b() {
22+
// CHECK-LABEL: fn b::{closure#0}(
23+
// CHECK-SAME: _1: Pin<&mut {async fn body of b()}>
24+
// CHECK-SAME: _2: &mut Context<'_>
25+
// CHECK-SAME: -> Poll<()>
26+
// CHECK-NOT: get_context
27+
a().await;
28+
a().await
29+
}

tests/mir-opt/async_closure_fake_read_for_by_move.foo-{closure#0}-{closure#0}.built.after.mir renamed to tests/mir-opt/coroutine/async_closure_fake_read_for_by_move.foo-{closure#0}-{closure#0}.built.after.mir

File renamed without changes.

tests/mir-opt/async_closure_fake_read_for_by_move.foo-{closure#0}-{synthetic#0}.built.after.mir renamed to tests/mir-opt/coroutine/async_closure_fake_read_for_by_move.foo-{closure#0}-{synthetic#0}.built.after.mir

File renamed without changes.

tests/mir-opt/async_closure_fake_read_for_by_move.rs renamed to tests/mir-opt/coroutine/async_closure_fake_read_for_by_move.rs

File renamed without changes.

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.built.after.mir renamed to tests/mir-opt/coroutine/async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.built.after.mir

File renamed without changes.

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}-{synthetic#0}.built.after.mir renamed to tests/mir-opt/coroutine/async_closure_shims.main-{closure#0}-{closure#0}-{synthetic#0}.built.after.mir

File renamed without changes.

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.mir renamed to tests/mir-opt/coroutine/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.mir

File renamed without changes.

0 commit comments

Comments
 (0)