Skip to content

Commit dbd3515

Browse files
authored
Unrolled build for rust-lang#129706
Rollup merge of rust-lang#129706 - compiler-errors:scratch, r=estebank Rename dump of coroutine by-move-body to be more consistent, fix ICE in dump_mir First, we add a missing match for `DefKind::SyntheticCoroutineBody` in `dump_mir`. Fixes rust-lang#129703. The second commit (directly below) serves as a test. Second, we reorder the `dump_mir` in `coroutine_by_move_body_def_id` to be *after* we adjust the body source, and change the disambiguator so it reads more like any other MIR body. This also serves as a test for the ICE, since we're dumping the MIR of a body with `DefKind::SyntheticCoroutineBody`. Third, we change the parenting of the synthetic MIR body to have the *coroutine-closure* (i.e. async closure) as its parent, so we don't have long strings of `{closure#0}-{closure#0}-{closure#0}`. try-job: test-various
2 parents eb33b43 + 8860008 commit dbd3515

13 files changed

+31
-57
lines changed

compiler/rustc_middle/src/mir/pretty.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,9 @@ fn write_mir_sig(tcx: TyCtxt<'_>, body: &Body<'_>, w: &mut dyn io::Write) -> io:
612612
let def_id = body.source.def_id();
613613
let kind = tcx.def_kind(def_id);
614614
let is_function = match kind {
615-
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) => true,
615+
DefKind::Fn | DefKind::AssocFn | DefKind::Ctor(..) | DefKind::SyntheticCoroutineBody => {
616+
true
617+
}
616618
_ => tcx.is_closure_like(def_id),
617619
};
618620
match (kind, body.source.promoted) {

compiler/rustc_mir_transform/src/coroutine/by_move_body.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,12 @@ pub fn coroutine_by_move_body_def_id<'tcx>(
207207

208208
let mut by_move_body = body.clone();
209209
MakeByMoveBody { tcx, field_remapping, by_move_coroutine_ty }.visit_body(&mut by_move_body);
210-
dump_mir(tcx, false, "coroutine_by_move", &0, &by_move_body, |_, _| Ok(()));
211210

212-
let body_def = tcx.create_def(coroutine_def_id, kw::Empty, DefKind::SyntheticCoroutineBody);
211+
// This will always be `{closure#1}`, since the original coroutine is `{closure#0}`.
212+
let body_def = tcx.create_def(parent_def_id, kw::Empty, DefKind::SyntheticCoroutineBody);
213213
by_move_body.source =
214214
mir::MirSource::from_instance(InstanceKind::Item(body_def.def_id().to_def_id()));
215+
dump_mir(tcx, false, "built", &"after", &by_move_body, |_, _| Ok(()));
215216

216217
// Inherited from the by-ref coroutine.
217218
body_def.codegen_fn_attrs(tcx.codegen_fn_attrs(coroutine_def_id).clone());
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// MIR for `main::{closure#0}::{closure#0}::{closure#0}` 0 coroutine_by_move
1+
// MIR for `main::{closure#0}::{closure#0}::{closure#0}` after built
22

3-
fn main::{closure#0}::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:53:53: 56:10}, _2: ResumeTy) -> ()
3+
fn main::{closure#0}::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:54:53: 57:10}, _2: ResumeTy) -> ()
44
yields ()
55
{
66
debug _task_context => _2;
77
debug a => (_1.0: i32);
8-
debug b => (_1.1: i32);
8+
debug b => (*(_1.1: &i32));
99
let mut _0: ();
1010
let _3: i32;
1111
scope 1 {
@@ -28,7 +28,7 @@ yields ()
2828
_4 = &_3;
2929
FakeRead(ForLet(None), _4);
3030
StorageLive(_5);
31-
_5 = &(_1.1: i32);
31+
_5 = &(*(_1.1: &i32));
3232
FakeRead(ForLet(None), _5);
3333
_0 = const ();
3434
StorageDead(_5);
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// MIR for `main::{closure#0}::{closure#0}::{closure#0}` 0 coroutine_by_move
1+
// MIR for `main::{closure#0}::{closure#0}::{closure#1}` after built
22

3-
fn main::{closure#0}::{closure#0}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:53:53: 56:10}, _2: ResumeTy) -> ()
3+
fn main::{closure#0}::{closure#0}::{closure#1}(_1: {async closure body@$DIR/async_closure_shims.rs:54:53: 57:10}, _2: ResumeTy) -> ()
44
yields ()
55
{
66
debug _task_context => _2;
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// MIR for `main::{closure#0}::{closure#0}` 0 coroutine_closure_by_move
22

3-
fn main::{closure#0}::{closure#0}(_1: {async closure@$DIR/async_closure_shims.rs:53:33: 53:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:53:53: 56:10} {
4-
let mut _0: {async closure body@$DIR/async_closure_shims.rs:53:53: 56:10};
3+
fn main::{closure#0}::{closure#0}(_1: {async closure@$DIR/async_closure_shims.rs:54:33: 54:52}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:54:53: 57:10} {
4+
let mut _0: {async closure body@$DIR/async_closure_shims.rs:54:53: 57:10};
55

66
bb0: {
7-
_0 = {coroutine@$DIR/async_closure_shims.rs:53:53: 56:10 (#0)} { a: move _2, b: move (_1.0: i32) };
7+
_0 = {coroutine@$DIR/async_closure_shims.rs:54:53: 57:10 (#0)} { a: move _2, b: move (_1.0: i32) };
88
return;
99
}
1010
}

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.panic-unwind.mir

-10
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// MIR for `main::{closure#0}::{closure#1}::{closure#0}` 0 coroutine_by_move
1+
// MIR for `main::{closure#0}::{closure#1}::{closure#0}` after built
22

3-
fn main::{closure#0}::{closure#1}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10}, _2: ResumeTy) -> ()
3+
fn main::{closure#0}::{closure#1}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:63:48: 66:10}, _2: ResumeTy) -> ()
44
yields ()
55
{
66
debug _task_context => _2;
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
// MIR for `main::{closure#0}::{closure#1}::{closure#0}` 0 coroutine_by_move
1+
// MIR for `main::{closure#0}::{closure#1}::{closure#1}` after built
22

3-
fn main::{closure#0}::{closure#1}::{closure#0}(_1: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10}, _2: ResumeTy) -> ()
3+
fn main::{closure#0}::{closure#1}::{closure#1}(_1: {async closure body@$DIR/async_closure_shims.rs:63:48: 66:10}, _2: ResumeTy) -> ()
44
yields ()
55
{
66
debug _task_context => _2;
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// MIR for `main::{closure#0}::{closure#1}` 0 coroutine_closure_by_move
22

3-
fn main::{closure#0}::{closure#1}(_1: {async closure@$DIR/async_closure_shims.rs:62:33: 62:47}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10} {
4-
let mut _0: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10};
3+
fn main::{closure#0}::{closure#1}(_1: {async closure@$DIR/async_closure_shims.rs:63:33: 63:47}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:63:48: 66:10} {
4+
let mut _0: {async closure body@$DIR/async_closure_shims.rs:63:48: 66:10};
55

66
bb0: {
7-
_0 = {coroutine@$DIR/async_closure_shims.rs:62:48: 65:10 (#0)} { a: move _2, b: move (_1.0: &i32) };
7+
_0 = {coroutine@$DIR/async_closure_shims.rs:63:48: 66:10 (#0)} { a: move _2, b: move (_1.0: &i32) };
88
return;
99
}
1010
}

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_move.0.panic-unwind.mir

-10
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// MIR for `main::{closure#0}::{closure#1}` 0 coroutine_closure_by_ref
22

3-
fn main::{closure#0}::{closure#1}(_1: &{async closure@$DIR/async_closure_shims.rs:62:33: 62:47}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10} {
4-
let mut _0: {async closure body@$DIR/async_closure_shims.rs:62:48: 65:10};
3+
fn main::{closure#0}::{closure#1}(_1: &{async closure@$DIR/async_closure_shims.rs:63:33: 63:47}, _2: i32) -> {async closure body@$DIR/async_closure_shims.rs:63:48: 66:10} {
4+
let mut _0: {async closure body@$DIR/async_closure_shims.rs:63:48: 66:10};
55

66
bb0: {
7-
_0 = {coroutine@$DIR/async_closure_shims.rs:62:48: 65:10 (#0)} { a: move _2, b: copy ((*_1).0: &i32) };
7+
_0 = {coroutine@$DIR/async_closure_shims.rs:63:48: 66:10 (#0)} { a: move _2, b: copy ((*_1).0: &i32) };
88
return;
99
}
1010
}

tests/mir-opt/async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.panic-unwind.mir

-10
This file was deleted.

tests/mir-opt/async_closure_shims.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
//@ edition:2021
22
// skip-filecheck
3-
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY
43

54
#![feature(async_closure, noop_waker, async_fn_traits)]
65
#![allow(unused)]
@@ -22,7 +21,7 @@ pub fn block_on<T>(fut: impl Future<Output = T>) -> T {
2221
}
2322
}
2423

25-
async fn call(f: &mut impl AsyncFn(i32)) {
24+
async fn call(f: &impl AsyncFn(i32)) {
2625
f(0).await;
2726
}
2827

@@ -43,18 +42,20 @@ async fn call_normal_mut<F: Future<Output = ()>>(f: &mut impl FnMut(i32) -> F) {
4342
}
4443

4544
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}.coroutine_closure_by_move.0.mir
46-
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.coroutine_by_move.0.mir
45+
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}-{closure#0}.built.after.mir
46+
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#0}-{closure#1}.built.after.mir
4747
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_ref.0.mir
4848
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}.coroutine_closure_by_move.0.mir
49-
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}-{closure#0}.coroutine_by_move.0.mir
49+
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}-{closure#0}.built.after.mir
50+
// EMIT_MIR async_closure_shims.main-{closure#0}-{closure#1}-{closure#1}.built.after.mir
5051
pub fn main() {
5152
block_on(async {
5253
let b = 2i32;
5354
let mut async_closure = async move |a: i32| {
5455
let a = &a;
5556
let b = &b;
5657
};
57-
call(&mut async_closure).await;
58+
call(&async_closure).await;
5859
call_mut(&mut async_closure).await;
5960
call_once(async_closure).await;
6061

0 commit comments

Comments
 (0)