diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index 2ccd8178e667b..5c3cceedf3bac 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -174,6 +174,7 @@ const SELF_ARG: Local = Local::from_u32(1); const CTX_ARG: Local = Local::from_u32(2); /// A `yield` point in the coroutine. +#[derive(Debug)] struct SuspensionPoint<'tcx> { /// State discriminant used when suspending or resuming at this point. state: usize, @@ -651,7 +652,7 @@ fn replace_resume_ty_local<'tcx>( // We have to replace the `ResumeTy` that is used for type and borrow checking // with `&mut Context<'_>` in MIR. #[cfg(debug_assertions)] - { + if local_ty != context_mut_ref { if let ty::Adt(resume_ty_adt, _) = local_ty.kind() { let expected_adt = tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, body.span)); assert_eq!(*resume_ty_adt, expected_adt); @@ -1326,16 +1327,6 @@ fn create_coroutine_resume_function<'tcx>( make_coroutine_state_argument_indirect(tcx, body); } } - - // Make sure we remove dead blocks to remove - // unrelated code from the drop part of the function - simplify::remove_dead_blocks(body); - - pm::run_passes_no_validate(tcx, body, &[&abort_unwinding_calls::AbortUnwindingCalls], None); - - if let Some(dumper) = MirDumper::new(tcx, "coroutine_resume", body) { - dumper.dump_mir(body); - } } /// An operation that can be performed on a coroutine. @@ -1691,6 +1682,21 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform { // Create the Coroutine::resume / Future::poll function create_coroutine_resume_function(tcx, transform, body, can_return, can_unwind); + if let Some(dumper) = MirDumper::new(tcx, "coroutine_resume", body) { + dumper.dump_mir(body); + } + + pm::run_passes_no_validate( + tcx, + body, + &[ + &crate::abort_unwinding_calls::AbortUnwindingCalls, + &crate::simplify::SimplifyCfg::PostStateTransform, + &crate::simplify::SimplifyLocals::PostStateTransform, + ], + None, + ); + // Run derefer to fix Derefs that are not in the first place deref_finder(tcx, body, false); } diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 8bcda77f4bc32..f0208608098b8 100644 --- a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs +++ b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs @@ -46,6 +46,12 @@ impl<'tcx> crate::MirPass<'tcx> for DataflowConstProp { return; } + // Avoid computing layout inside coroutines, since their `optimized_mir` is used for layout + // computation, which can create a cycle. + if body.coroutine.is_some() { + return; + } + // We want to have a somewhat linear runtime w.r.t. the number of statements/terminators. // Let's call this number `n`. Dataflow analysis has `O(h*n)` transfer function // applications, where `h` is the height of the lattice. Because the height of our lattice @@ -237,9 +243,8 @@ impl<'a, 'tcx> ConstAnalysis<'a, 'tcx> { TerminatorKind::Drop { place, .. } => { state.flood_with(place.as_ref(), &self.map, FlatSet::::BOTTOM); } - TerminatorKind::Yield { .. } => { - // They would have an effect, but are not allowed in this phase. - bug!("encountered disallowed terminator"); + TerminatorKind::Yield { resume_arg, .. } => { + state.flood_with(resume_arg.as_ref(), &self.map, FlatSet::::BOTTOM); } TerminatorKind::SwitchInt { discr, targets } => { return self.handle_switch_int(discr, targets, state); diff --git a/compiler/rustc_mir_transform/src/gvn.rs b/compiler/rustc_mir_transform/src/gvn.rs index 8eae80e235ccd..bb0c16c3508d2 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -1912,14 +1912,18 @@ impl<'tcx> MutVisitor<'tcx> for VnState<'_, '_, 'tcx> { } fn visit_terminator(&mut self, terminator: &mut Terminator<'tcx>, location: Location) { - if let Terminator { kind: TerminatorKind::Call { destination, .. }, .. } = terminator { - if let Some(local) = destination.as_local() - && self.ssa.is_ssa(local) - { - let ty = self.local_decls[local].ty; - let opaque = self.new_opaque(ty); - self.assign(local, opaque); - } + let destination = match terminator.kind { + TerminatorKind::Call { destination, .. } => Some(destination), + TerminatorKind::Yield { resume_arg, .. } => Some(resume_arg), + _ => None, + }; + if let Some(destination) = destination + && let Some(local) = destination.as_local() + && self.ssa.is_ssa(local) + { + let ty = self.local_decls[local].ty; + let opaque = self.new_opaque(ty); + self.assign(local, opaque); } // Terminators that can write to memory may invalidate (nested) derefs. if terminator.kind.can_write_to_memory() { diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index 492f5ca82a07e..068a45fa29825 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -610,9 +610,9 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> { | TerminatorKind::Unreachable | TerminatorKind::CoroutineDrop => bug!("{term:?} has no terminators"), // Disallowed during optimizations. - TerminatorKind::FalseEdge { .. } - | TerminatorKind::FalseUnwind { .. } - | TerminatorKind::Yield { .. } => bug!("{term:?} invalid"), + TerminatorKind::FalseEdge { .. } | TerminatorKind::FalseUnwind { .. } => { + bug!("{term:?} invalid") + } // Cannot reason about inline asm. TerminatorKind::InlineAsm { .. } => return, // `SwitchInt` is handled specially. @@ -621,6 +621,7 @@ impl<'a, 'tcx> TOFinder<'a, 'tcx> { TerminatorKind::Goto { .. } => None, // Flood the overwritten place, and progress through. TerminatorKind::Drop { place: destination, .. } + | TerminatorKind::Yield { resume_arg: destination, .. } | TerminatorKind::Call { destination, .. } => Some(destination), // Ignore, as this can be a no-op at codegen time. TerminatorKind::Assert { .. } => None, diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 4625b20fd8900..dd15cd084bacc 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -81,7 +81,7 @@ mod ssa; macro_rules! declare_passes { ( $( - $vis:vis mod $mod_name:ident : $($pass_name:ident $( { $($ident:ident),* } )?),+ $(,)?; + $vis:vis mod $mod_name:ident : $($pass_name:ident $( { $($ident:ident),* $(,)? } )?),+ $(,)?; )* ) => { $( @@ -181,12 +181,14 @@ declare_passes! { PreOptimizations, Final, MakeShim, - AfterUnreachableEnumBranching + AfterUnreachableEnumBranching, + PostStateTransform, }, SimplifyLocals { BeforeConstProp, AfterGVN, - Final + Final, + PostStateTransform, }; mod simplify_branches : SimplifyConstCondition { AfterInstSimplify, @@ -627,7 +629,6 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { &add_retag::AddRetag, &erase_deref_temps::EraseDerefTemps, &elaborate_box_derefs::ElaborateBoxDerefs, - &coroutine::StateTransform, &Lint(known_panics_lint::KnownPanicsLint), ]; pm::run_passes_no_validate(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::Initial))); @@ -742,6 +743,7 @@ pub(crate) fn run_optimization_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<' &simplify::SimplifyLocals::Final, &multiple_return_terminators::MultipleReturnTerminators, &large_enums::EnumSizeOpt { discrepancy: 128 }, + &coroutine::StateTransform, // Some cleanup necessary at least for LLVM and potentially other codegen backends. &add_call_guards::CriticalCallEdges, // Cleanup for human readability, off by default. diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 85e340c0a02ab..37ac90f088132 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -150,7 +150,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceKind<'tcx>) -> Body< tcx, &mut body, &[ - &mentioned_items::MentionedItems, &abort_unwinding_calls::AbortUnwindingCalls, &add_call_guards::CriticalCallEdges, ], diff --git a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs index a0f1260cd986d..f4bcb4d3bcd06 100644 --- a/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs +++ b/compiler/rustc_mir_transform/src/shim/async_destructor_ctor.rs @@ -216,6 +216,7 @@ fn build_adrop_for_coroutine_shim<'tcx>( body.source.instance = instance; body.phase = MirPhase::Runtime(RuntimePhase::Initial); body.var_debug_info.clear(); + body.mentioned_items = None; let pin_adt_ref = tcx.adt_def(tcx.require_lang_item(LangItem::Pin, span)); let args = tcx.mk_args(&[proxy_ref.into()]); let pin_proxy_ref = Ty::new_adt(tcx, pin_adt_ref, args); diff --git a/compiler/rustc_mir_transform/src/simplify.rs b/compiler/rustc_mir_transform/src/simplify.rs index da31600e8324c..1efa1784d2f1c 100644 --- a/compiler/rustc_mir_transform/src/simplify.rs +++ b/compiler/rustc_mir_transform/src/simplify.rs @@ -57,6 +57,8 @@ pub(super) enum SimplifyCfg { Final, MakeShim, AfterUnreachableEnumBranching, + /// Extra run introduced by `StateTransform`. + PostStateTransform, } impl SimplifyCfg { @@ -72,6 +74,7 @@ impl SimplifyCfg { SimplifyCfg::AfterUnreachableEnumBranching => { "SimplifyCfg-after-unreachable-enum-branching" } + SimplifyCfg::PostStateTransform => "SimplifyCfg-post-StateTransform", } } } @@ -416,6 +419,8 @@ pub(super) enum SimplifyLocals { BeforeConstProp, AfterGVN, Final, + /// Extra run introduced by `StateTransform`. + PostStateTransform, } impl<'tcx> crate::MirPass<'tcx> for SimplifyLocals { @@ -424,6 +429,7 @@ impl<'tcx> crate::MirPass<'tcx> for SimplifyLocals { SimplifyLocals::BeforeConstProp => "SimplifyLocals-before-const-prop", SimplifyLocals::AfterGVN => "SimplifyLocals-after-value-numbering", SimplifyLocals::Final => "SimplifyLocals-final", + SimplifyLocals::PostStateTransform => "SimplifyLocals-post-StateTransform", } } diff --git a/compiler/rustc_mir_transform/src/validate.rs b/compiler/rustc_mir_transform/src/validate.rs index 5a9018a62c574..bde2794481544 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -451,7 +451,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> { if self.body.coroutine.is_none() { self.fail(location, "`Yield` cannot appear outside coroutine bodies"); } - if self.body.phase >= MirPhase::Runtime(RuntimePhase::Initial) { + if self.body.phase >= MirPhase::Runtime(RuntimePhase::Optimized) { self.fail(location, "`Yield` should have been replaced by coroutine lowering"); } self.check_edge(location, *resume, EdgeKind::Normal); @@ -489,7 +489,7 @@ impl<'a, 'tcx> Visitor<'tcx> for CfgChecker<'a, 'tcx> { if self.body.coroutine.is_none() { self.fail(location, "`CoroutineDrop` cannot appear outside coroutine bodies"); } - if self.body.phase >= MirPhase::Runtime(RuntimePhase::Initial) { + if self.body.phase >= MirPhase::Runtime(RuntimePhase::Optimized) { self.fail( location, "`CoroutineDrop` should have been replaced by coroutine lowering", diff --git a/tests/crashes/140303.rs b/tests/crashes/140303.rs deleted file mode 100644 index 43a20b5e58ed4..0000000000000 --- a/tests/crashes/140303.rs +++ /dev/null @@ -1,22 +0,0 @@ -//@ known-bug: #140303 -//@compile-flags: -Zvalidate-mir -use std::future::Future; -async fn a() -> impl Sized { - b(c) -} -async fn c(); // kaboom -fn b(e: d) -> impl Sized -where - d: f, -{ - || -> ::h { panic!() } -} -trait f { - type h; -} -impl f for d -where - d: Fn() -> g, - g: Future, -{ -} diff --git a/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir b/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir index 435c1532895ca..0e7aa6167f462 100644 --- a/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir +++ b/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-abort.mir @@ -29,72 +29,68 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) bb0: { _20 = copy (_1.0: &mut {async fn body of a()}); _19 = discriminant((*_20)); - switchInt(move _19) -> [0: bb9, 3: bb12, 4: bb13, otherwise: bb14]; + switchInt(move _19) -> [0: bb8, 3: bb11, 4: bb12, otherwise: bb13]; } bb1: { nop; nop; - goto -> bb2; - } - - bb2: { _0 = Poll::<()>::Ready(const ()); return; } - bb3: { + bb2: { _0 = Poll::<()>::Pending; discriminant((*_20)) = 4; return; } - bb4: { + bb3: { StorageLive(_16); _15 = &mut (((*_20) as variant#4).1: impl std::future::Future); - _16 = Pin::<&mut impl Future>::new_unchecked(move _15) -> [return: bb7, unwind unreachable]; + _16 = Pin::<&mut impl Future>::new_unchecked(move _15) -> [return: bb6, unwind unreachable]; } - bb5: { + bb4: { unreachable; } - bb6: { + bb5: { StorageDead(_16); _17 = discriminant(_9); - switchInt(move _17) -> [0: bb1, 1: bb3, otherwise: bb5]; + switchInt(move _17) -> [0: bb1, 1: bb2, otherwise: bb4]; } - bb7: { - _9 = as Future>::poll(move _16, move _14) -> [return: bb6, unwind unreachable]; + bb6: { + _9 = as Future>::poll(move _16, move _14) -> [return: bb5, unwind unreachable]; } - bb8: { + bb7: { _0 = Poll::<()>::Ready(const ()); return; } + bb8: { + goto -> bb10; + } + bb9: { - goto -> bb11; + goto -> bb7; } bb10: { - goto -> bb8; + drop(((*_20).0: T)) -> [return: bb9, unwind unreachable]; } bb11: { - drop(((*_20).0: T)) -> [return: bb10, unwind unreachable]; + goto -> bb3; } bb12: { - goto -> bb4; + goto -> bb3; } bb13: { - goto -> bb4; - } - - bb14: { _0 = Poll::<()>::Ready(const ()); return; } diff --git a/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir b/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir index 1dc1d08136290..82f2091d4a1a8 100644 --- a/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir +++ b/tests/mir-opt/async_drop_live_dead.a-{closure#0}.coroutine_drop_async.0.panic-unwind.mir @@ -29,95 +29,81 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) bb0: { _20 = copy (_1.0: &mut {async fn body of a()}); _19 = discriminant((*_20)); - switchInt(move _19) -> [0: bb12, 2: bb18, 3: bb16, 4: bb17, otherwise: bb19]; + switchInt(move _19) -> [0: bb8, 2: bb15, 3: bb13, 4: bb14, otherwise: bb16]; } bb1: { nop; nop; - goto -> bb2; - } - - bb2: { _0 = Poll::<()>::Ready(const ()); return; } - bb3 (cleanup): { - nop; - nop; - goto -> bb5; - } - - bb4 (cleanup): { - goto -> bb15; - } - - bb5 (cleanup): { - goto -> bb4; - } - - bb6: { + bb2: { _0 = Poll::<()>::Pending; discriminant((*_20)) = 4; return; } - bb7: { + bb3: { StorageLive(_16); _15 = &mut (((*_20) as variant#4).1: impl std::future::Future); - _16 = Pin::<&mut impl Future>::new_unchecked(move _15) -> [return: bb10, unwind: bb15]; + _16 = Pin::<&mut impl Future>::new_unchecked(move _15) -> [return: bb6, unwind: bb12]; } - bb8: { + bb4: { unreachable; } - bb9: { + bb5: { StorageDead(_16); _17 = discriminant(_9); - switchInt(move _17) -> [0: bb1, 1: bb6, otherwise: bb8]; + switchInt(move _17) -> [0: bb1, 1: bb2, otherwise: bb4]; } - bb10: { - _9 = as Future>::poll(move _16, move _14) -> [return: bb9, unwind: bb3]; + bb6: { + _9 = as Future>::poll(move _16, move _14) -> [return: bb5, unwind: bb12]; } - bb11: { + bb7: { _0 = Poll::<()>::Ready(const ()); return; } - bb12: { - goto -> bb14; + bb8: { + goto -> bb11; } - bb13: { - goto -> bb11; + bb9 (cleanup): { + goto -> bb12; } - bb14: { - drop(((*_20).0: T)) -> [return: bb13, unwind: bb4]; + bb10: { + goto -> bb7; } - bb15 (cleanup): { + bb11: { + drop(((*_20).0: T)) -> [return: bb10, unwind: bb9]; + } + + bb12 (cleanup): { discriminant((*_20)) = 2; resume; } - bb16: { - goto -> bb7; + bb13: { + goto -> bb3; } - bb17: { - goto -> bb7; + bb14: { + goto -> bb3; } - bb18: { - assert(const false, "`async fn` resumed after panicking") -> [success: bb18, unwind continue]; + bb15: { + assert(const false, "`async fn` resumed after panicking") -> [success: bb15, unwind continue]; } - bb19: { + bb16: { _0 = Poll::<()>::Ready(const ()); return; } diff --git a/tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir b/tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir index 6cad5b105d3e3..f2be506e36885 100644 --- a/tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir +++ b/tests/mir-opt/building/async_await.a-{closure#0}.coroutine_resume.0.mir @@ -19,12 +19,12 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> bb0: { _5 = copy (_1.0: &mut {async fn body of a()}); _4 = discriminant((*_5)); - switchInt(move _4) -> [0: bb1, 1: bb4, otherwise: bb5]; + switchInt(move _4) -> [0: bb1, 1: bb9, otherwise: bb10]; } bb1: { _3 = const (); - goto -> bb3; + goto -> bb6; } bb2: { @@ -34,14 +34,34 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> } bb3: { - goto -> bb2; + return; } bb4: { - assert(const false, "`async fn` resumed after completion") -> [success: bb4, unwind unreachable]; + goto -> bb8; + } + + bb5 (cleanup): { + unreachable; + } + + bb6: { + goto -> bb2; + } + + bb7 (cleanup): { + resume; + } + + bb8: { + goto -> bb3; + } + + bb9: { + assert(const false, "`async fn` resumed after completion") -> [success: bb9, unwind continue]; } - bb5: { + bb10: { unreachable; } } diff --git a/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir b/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir index 96ee37185db16..775371863fbe2 100644 --- a/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir +++ b/tests/mir-opt/building/async_await.b-{closure#0}.coroutine_resume.0.mir @@ -105,7 +105,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> bb0: { _39 = copy (_1.0: &mut {async fn body of b()}); _38 = discriminant((*_39)); - switchInt(move _38) -> [0: bb1, 1: bb29, 3: bb27, 4: bb28, otherwise: bb8]; + switchInt(move _38) -> [0: bb1, 1: bb39, 3: bb37, 4: bb38, otherwise: bb40]; } bb1: { @@ -121,7 +121,6 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> bb3: { StorageDead(_5); - PlaceMention(_4); nop; (((*_39) as variant#3).0: {async fn body of a()}) = move _4; goto -> bb4; @@ -157,7 +156,6 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> bb7: { StorageDead(_13); StorageDead(_10); - PlaceMention(_9); _16 = discriminant(_9); switchInt(move _16) -> [0: bb10, 1: bb9, otherwise: bb8]; } @@ -206,30 +204,25 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> bb12: { nop; - goto -> bb13; - } - - bb13: { StorageDead(_4); StorageDead(_3); StorageLive(_21); StorageLive(_22); - _22 = a() -> [return: bb14, unwind unreachable]; + _22 = a() -> [return: bb13, unwind unreachable]; } - bb14: { - _21 = <{async fn body of a()} as IntoFuture>::into_future(move _22) -> [return: bb15, unwind unreachable]; + bb13: { + _21 = <{async fn body of a()} as IntoFuture>::into_future(move _22) -> [return: bb14, unwind unreachable]; } - bb15: { + bb14: { StorageDead(_22); - PlaceMention(_21); nop; (((*_39) as variant#4).0: {async fn body of a()}) = move _21; - goto -> bb16; + goto -> bb15; } - bb16: { + bb15: { StorageLive(_24); StorageLive(_25); StorageLive(_26); @@ -237,34 +230,33 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> StorageLive(_28); _28 = &mut (((*_39) as variant#4).0: {async fn body of a()}); _27 = &mut (*_28); - _26 = Pin::<&mut {async fn body of a()}>::new_unchecked(move _27) -> [return: bb17, unwind unreachable]; + _26 = Pin::<&mut {async fn body of a()}>::new_unchecked(move _27) -> [return: bb16, unwind unreachable]; } - bb17: { + bb16: { StorageDead(_27); StorageLive(_29); StorageLive(_30); StorageLive(_31); _31 = copy _2; _30 = move _31; - goto -> bb18; + goto -> bb17; } - bb18: { + bb17: { _29 = &mut (*_30); StorageDead(_31); - _25 = <{async fn body of a()} as Future>::poll(move _26, move _29) -> [return: bb19, unwind unreachable]; + _25 = <{async fn body of a()} as Future>::poll(move _26, move _29) -> [return: bb18, unwind unreachable]; } - bb19: { + bb18: { StorageDead(_29); StorageDead(_26); - PlaceMention(_25); _32 = discriminant(_25); - switchInt(move _32) -> [0: bb21, 1: bb20, otherwise: bb8]; + switchInt(move _32) -> [0: bb20, 1: bb19, otherwise: bb8]; } - bb20: { + bb19: { _24 = const (); StorageDead(_30); StorageDead(_28); @@ -281,7 +273,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> return; } - bb21: { + bb20: { StorageLive(_33); _33 = copy ((_25 as Ready).0: ()); _37 = copy _33; @@ -290,38 +282,91 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> StorageDead(_28); StorageDead(_25); StorageDead(_24); - drop((((*_39) as variant#4).0: {async fn body of a()})) -> [return: bb23, unwind unreachable]; + drop((((*_39) as variant#4).0: {async fn body of a()})) -> [return: bb22, unwind unreachable]; } - bb22: { + bb21: { StorageDead(_36); _2 = move _35; StorageDead(_35); _7 = const (); - goto -> bb16; + goto -> bb15; } - bb23: { + bb22: { nop; - goto -> bb24; - } - - bb24: { StorageDead(_21); - goto -> bb26; + goto -> bb33; } - bb25: { + bb23: { _0 = Poll::<()>::Ready(move _37); discriminant((*_39)) = 1; return; } + bb24: { + StorageDead(_36); + StorageDead(_35); + drop((((*_39) as variant#4).0: {async fn body of a()})) -> [return: bb25, unwind unreachable]; + } + + bb25: { + nop; + StorageDead(_21); + goto -> bb28; + } + bb26: { - goto -> bb25; + StorageDead(_20); + StorageDead(_19); + drop((((*_39) as variant#3).0: {async fn body of a()})) -> [return: bb27, unwind unreachable]; } bb27: { + nop; + StorageDead(_4); + StorageDead(_3); + goto -> bb28; + } + + bb28: { + goto -> bb34; + } + + bb29: { + coroutine_drop; + } + + bb30: { + return; + } + + bb31: { + goto -> bb36; + } + + bb32 (cleanup): { + unreachable; + } + + bb33: { + goto -> bb23; + } + + bb34: { + goto -> bb29; + } + + bb35 (cleanup): { + resume; + } + + bb36: { + goto -> bb30; + } + + bb37: { StorageLive(_3); StorageLive(_4); StorageLive(_19); @@ -330,15 +375,19 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> goto -> bb11; } - bb28: { + bb38: { StorageLive(_21); StorageLive(_35); StorageLive(_36); _35 = move _2; - goto -> bb22; + goto -> bb21; } - bb29: { - assert(const false, "`async fn` resumed after completion") -> [success: bb29, unwind unreachable]; + bb39: { + assert(const false, "`async fn` resumed after completion") -> [success: bb39, unwind continue]; + } + + bb40: { + unreachable; } } diff --git a/tests/mir-opt/building/coroutine.main-{closure#0}.StateTransform.after.mir b/tests/mir-opt/building/coroutine.main-{closure#0}.StateTransform.after.mir index b61215dc28cb4..f5005bb872d28 100644 --- a/tests/mir-opt/building/coroutine.main-{closure#0}.StateTransform.after.mir +++ b/tests/mir-opt/building/coroutine.main-{closure#0}.StateTransform.after.mir @@ -45,7 +45,7 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2 bb0: { _18 = copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}); _17 = discriminant((*_18)); - switchInt(move _17) -> [0: bb1, 1: bb19, 3: bb17, 4: bb18, otherwise: bb20]; + switchInt(move _17) -> [0: bb1, 1: bb11, 3: bb9, 4: bb10, otherwise: bb12]; } bb1: { @@ -67,10 +67,6 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2 bb3: { _4 = (const "first", move _5, move _7); StorageDead(_7); - goto -> bb4; - } - - bb4: { StorageDead(_5); _0 = CoroutineState::<(&str, String, &Location<'_>), ()>::Yielded(move _4); StorageDead(_3); @@ -79,16 +75,7 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2 return; } - bb5: { - goto -> bb6; - } - - bb6: { - StorageDead(_4); - drop(_3) -> [return: bb7, unwind unreachable]; - } - - bb7: { + bb4: { StorageDead(_3); StorageLive(_8); StorageLive(_9); @@ -99,24 +86,20 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2 StorageLive(_12); StorageLive(_13); _13 = &(((*_18) as variant#4).0: std::string::String); - _12 = ::clone(move _13) -> [return: bb8, unwind unreachable]; + _12 = ::clone(move _13) -> [return: bb5, unwind unreachable]; } - bb8: { + bb5: { StorageDead(_13); StorageLive(_14); StorageLive(_15); - _15 = Location::<'_>::caller() -> [return: bb9, unwind unreachable]; + _15 = Location::<'_>::caller() -> [return: bb6, unwind unreachable]; } - bb9: { + bb6: { _14 = &(*_15); _9 = (move _10, move _12, move _14); StorageDead(_14); - goto -> bb10; - } - - bb10: { StorageDead(_12); StorageDead(_10); _0 = CoroutineState::<(&str, String, &Location<'_>), ()>::Yielded(move _9); @@ -128,58 +111,43 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2 return; } - bb11: { - goto -> bb12; - } - - bb12: { - StorageDead(_9); - drop(_8) -> [return: bb13, unwind unreachable]; - } - - bb13: { + bb7: { StorageDead(_15); StorageDead(_11); StorageDead(_8); _16 = const (); - drop((((*_18) as variant#4).0: std::string::String)) -> [return: bb14, unwind unreachable]; - } - - bb14: { - goto -> bb16; + drop((((*_18) as variant#4).0: std::string::String)) -> [return: bb8, unwind unreachable]; } - bb15: { + bb8: { _0 = CoroutineState::<(&str, String, &Location<'_>), ()>::Complete(move _16); discriminant((*_18)) = 1; return; } - bb16: { - goto -> bb15; - } - - bb17: { + bb9: { StorageLive(_3); StorageLive(_4); _3 = move _2; - goto -> bb5; + StorageDead(_4); + drop(_3) -> [return: bb4, unwind unreachable]; } - bb18: { + bb10: { StorageLive(_8); StorageLive(_9); StorageLive(_11); StorageLive(_15); _8 = move _2; - goto -> bb11; + StorageDead(_9); + drop(_8) -> [return: bb7, unwind unreachable]; } - bb19: { - assert(const false, "coroutine resumed after completion") -> [success: bb19, unwind unreachable]; + bb11: { + assert(const false, "coroutine resumed after completion") -> [success: bb11, unwind unreachable]; } - bb20: { + bb12: { unreachable; } } diff --git a/tests/mir-opt/building/coroutine.main-{closure#1}.StateTransform.after.mir b/tests/mir-opt/building/coroutine.main-{closure#1}.StateTransform.after.mir index aac028a9e6c0e..50dff91275b80 100644 --- a/tests/mir-opt/building/coroutine.main-{closure#1}.StateTransform.after.mir +++ b/tests/mir-opt/building/coroutine.main-{closure#1}.StateTransform.after.mir @@ -45,7 +45,7 @@ fn main::{closure#1}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}>, _2 bb0: { _18 = copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}); _17 = discriminant((*_18)); - switchInt(move _17) -> [0: bb1, 1: bb19, 3: bb17, 4: bb18, otherwise: bb20]; + switchInt(move _17) -> [0: bb1, 1: bb11, 3: bb9, 4: bb10, otherwise: bb12]; } bb1: { @@ -67,10 +67,6 @@ fn main::{closure#1}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}>, _2 bb3: { _4 = (const "first", move _5, move _7); StorageDead(_7); - goto -> bb4; - } - - bb4: { StorageDead(_5); _0 = CoroutineState::<(&str, String, &Location<'_>), ()>::Yielded(move _4); StorageDead(_3); @@ -79,16 +75,7 @@ fn main::{closure#1}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}>, _2 return; } - bb5: { - goto -> bb6; - } - - bb6: { - StorageDead(_4); - drop(_3) -> [return: bb7, unwind unreachable]; - } - - bb7: { + bb4: { StorageDead(_3); StorageLive(_8); StorageLive(_9); @@ -99,24 +86,20 @@ fn main::{closure#1}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}>, _2 StorageLive(_12); StorageLive(_13); _13 = &(((*_18) as variant#4).0: std::string::String); - _12 = ::clone(move _13) -> [return: bb8, unwind unreachable]; + _12 = ::clone(move _13) -> [return: bb5, unwind unreachable]; } - bb8: { + bb5: { StorageDead(_13); StorageLive(_14); StorageLive(_15); - _15 = Location::<'_>::caller() -> [return: bb9, unwind unreachable]; + _15 = Location::<'_>::caller() -> [return: bb6, unwind unreachable]; } - bb9: { + bb6: { _14 = &(*_15); _9 = (move _10, move _12, move _14); StorageDead(_14); - goto -> bb10; - } - - bb10: { StorageDead(_12); StorageDead(_10); _0 = CoroutineState::<(&str, String, &Location<'_>), ()>::Yielded(move _9); @@ -128,58 +111,43 @@ fn main::{closure#1}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}>, _2 return; } - bb11: { - goto -> bb12; - } - - bb12: { - StorageDead(_9); - drop(_8) -> [return: bb13, unwind unreachable]; - } - - bb13: { + bb7: { StorageDead(_15); StorageDead(_11); StorageDead(_8); _16 = const (); - drop((((*_18) as variant#4).0: std::string::String)) -> [return: bb14, unwind unreachable]; - } - - bb14: { - goto -> bb16; + drop((((*_18) as variant#4).0: std::string::String)) -> [return: bb8, unwind unreachable]; } - bb15: { + bb8: { _0 = CoroutineState::<(&str, String, &Location<'_>), ()>::Complete(move _16); discriminant((*_18)) = 1; return; } - bb16: { - goto -> bb15; - } - - bb17: { + bb9: { StorageLive(_3); StorageLive(_4); _3 = move _2; - goto -> bb5; + StorageDead(_4); + drop(_3) -> [return: bb4, unwind unreachable]; } - bb18: { + bb10: { StorageLive(_8); StorageLive(_9); StorageLive(_11); StorageLive(_15); _8 = move _2; - goto -> bb11; + StorageDead(_9); + drop(_8) -> [return: bb7, unwind unreachable]; } - bb19: { - assert(const false, "coroutine resumed after completion") -> [success: bb19, unwind unreachable]; + bb11: { + assert(const false, "coroutine resumed after completion") -> [success: bb11, unwind unreachable]; } - bb20: { + bb12: { unreachable; } } diff --git a/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-abort.mir b/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-abort.mir index 33fbca7f77ed1..8d947ab30abad 100644 --- a/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-abort.mir +++ b/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-abort.mir @@ -6,19 +6,17 @@ fn main::{closure#0}(_1: *mut {coroutine@$DIR/coroutine_drop_cleanup.rs:12:5: 12 let _3: std::string::String; let _4: (); let mut _5: (); - let mut _6: (); - let mut _7: u32; + let mut _6: u32; scope 1 { debug _s => (((*_1) as variant#3).0: std::string::String); } bb0: { - _7 = discriminant((*_1)); - switchInt(move _7) -> [0: bb5, 3: bb8, otherwise: bb9]; + _6 = discriminant((*_1)); + switchInt(move _6) -> [0: bb5, 3: bb8, otherwise: bb9]; } bb1: { - StorageDead(_5); StorageDead(_4); drop((((*_1) as variant#3).0: std::string::String)) -> [return: bb2, unwind unreachable]; } @@ -50,7 +48,6 @@ fn main::{closure#0}(_1: *mut {coroutine@$DIR/coroutine_drop_cleanup.rs:12:5: 12 bb8: { StorageLive(_4); - StorageLive(_5); goto -> bb1; } diff --git a/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-unwind.mir b/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-unwind.mir index 69e7219af9ff8..52a8747e00ebf 100644 --- a/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-unwind.mir +++ b/tests/mir-opt/coroutine_drop_cleanup.main-{closure#0}.coroutine_drop.0.panic-unwind.mir @@ -6,19 +6,17 @@ fn main::{closure#0}(_1: *mut {coroutine@$DIR/coroutine_drop_cleanup.rs:12:5: 12 let _3: std::string::String; let _4: (); let mut _5: (); - let mut _6: (); - let mut _7: u32; + let mut _6: u32; scope 1 { debug _s => (((*_1) as variant#3).0: std::string::String); } bb0: { - _7 = discriminant((*_1)); - switchInt(move _7) -> [0: bb7, 3: bb10, otherwise: bb11]; + _6 = discriminant((*_1)); + switchInt(move _6) -> [0: bb7, 3: bb10, otherwise: bb11]; } bb1: { - StorageDead(_5); StorageDead(_4); drop((((*_1) as variant#3).0: std::string::String)) -> [return: bb2, unwind: bb5]; } @@ -59,7 +57,6 @@ fn main::{closure#0}(_1: *mut {coroutine@$DIR/coroutine_drop_cleanup.rs:12:5: 12 bb10: { StorageLive(_4); - StorageLive(_5); goto -> bb1; } diff --git a/tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-abort.mir b/tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-abort.mir index 4731aed335d9f..1f389761317f6 100644 --- a/tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-abort.mir +++ b/tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-abort.mir @@ -6,11 +6,9 @@ yields () let mut _0: (); let _3: Foo; let _5: (); - let mut _6: (); - let _7: (); - let mut _8: Foo; - let _9: (); - let mut _10: Bar; + let _6: (); + let mut _7: Foo; + let _8: (); scope 1 { debug a => _3; let _4: Bar; @@ -22,62 +20,48 @@ yields () bb0: { StorageLive(_3); _3 = Foo(const 5_i32); - StorageLive(_4); _4 = Bar(const 6_i32); StorageLive(_5); - StorageLive(_6); - _6 = (); - _5 = yield(move _6) -> [resume: bb1, drop: bb6]; + _5 = yield(const ()) -> [resume: bb1, drop: bb5]; } bb1: { - StorageDead(_6); StorageDead(_5); + StorageLive(_6); StorageLive(_7); - StorageLive(_8); - _8 = move _3; - _7 = take::(move _8) -> [return: bb2, unwind unreachable]; + _7 = move _3; + _6 = take::(move _7) -> [return: bb2, unwind unreachable]; } bb2: { - StorageDead(_8); StorageDead(_7); - StorageLive(_9); - StorageLive(_10); - _10 = move _4; - _9 = take::(move _10) -> [return: bb3, unwind unreachable]; + StorageDead(_6); + StorageLive(_8); + _8 = take::(move _4) -> [return: bb3, unwind unreachable]; } bb3: { - StorageDead(_10); - StorageDead(_9); + StorageDead(_8); _0 = const (); - StorageDead(_4); - goto -> bb4; - } - - bb4: { StorageDead(_3); - drop(_1) -> [return: bb5, unwind unreachable]; + drop(_1) -> [return: bb4, unwind unreachable]; } - bb5: { + bb4: { return; } - bb6: { - StorageDead(_6); + bb5: { StorageDead(_5); - StorageDead(_4); - drop(_3) -> [return: bb7, unwind unreachable]; + drop(_3) -> [return: bb6, unwind unreachable]; } - bb7: { + bb6: { StorageDead(_3); - drop(_1) -> [return: bb8, unwind unreachable]; + drop(_1) -> [return: bb7, unwind unreachable]; } - bb8: { + bb7: { coroutine_drop; } } diff --git a/tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir b/tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir index 14e1782b86016..a77a9c9a96341 100644 --- a/tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir +++ b/tests/mir-opt/coroutine_storage_dead_unwind.main-{closure#0}.StateTransform.before.panic-unwind.mir @@ -6,11 +6,9 @@ yields () let mut _0: (); let _3: Foo; let _5: (); - let mut _6: (); - let _7: (); - let mut _8: Foo; - let _9: (); - let mut _10: Bar; + let _6: (); + let mut _7: Foo; + let _8: (); scope 1 { debug a => _3; let _4: Bar; @@ -22,97 +20,73 @@ yields () bb0: { StorageLive(_3); _3 = Foo(const 5_i32); - StorageLive(_4); _4 = Bar(const 6_i32); StorageLive(_5); - StorageLive(_6); - _6 = (); - _5 = yield(move _6) -> [resume: bb1, drop: bb6]; + _5 = yield(const ()) -> [resume: bb1, drop: bb5]; } bb1: { - StorageDead(_6); StorageDead(_5); + StorageLive(_6); StorageLive(_7); - StorageLive(_8); - _8 = move _3; - _7 = take::(move _8) -> [return: bb2, unwind: bb10]; + _7 = move _3; + _6 = take::(move _7) -> [return: bb2, unwind: bb9]; } bb2: { - StorageDead(_8); StorageDead(_7); - StorageLive(_9); - StorageLive(_10); - _10 = move _4; - _9 = take::(move _10) -> [return: bb3, unwind: bb9]; + StorageDead(_6); + StorageLive(_8); + _8 = take::(move _4) -> [return: bb3, unwind: bb8]; } bb3: { - StorageDead(_10); - StorageDead(_9); + StorageDead(_8); _0 = const (); - StorageDead(_4); - goto -> bb4; - } - - bb4: { StorageDead(_3); - drop(_1) -> [return: bb5, unwind: bb14]; + drop(_1) -> [return: bb4, unwind continue]; } - bb5: { + bb4: { return; } - bb6: { - StorageDead(_6); + bb5: { StorageDead(_5); - StorageDead(_4); - drop(_3) -> [return: bb7, unwind: bb15]; + drop(_3) -> [return: bb6, unwind: bb12]; } - bb7: { + bb6: { StorageDead(_3); - drop(_1) -> [return: bb8, unwind: bb14]; + drop(_1) -> [return: bb7, unwind continue]; } - bb8: { + bb7: { coroutine_drop; } - bb9 (cleanup): { - StorageDead(_10); - StorageDead(_9); - goto -> bb12; - } - - bb10 (cleanup): { - goto -> bb11; - } - - bb11 (cleanup): { + bb8 (cleanup): { StorageDead(_8); - StorageDead(_7); - goto -> bb12; + goto -> bb10; } - bb12 (cleanup): { - StorageDead(_4); - goto -> bb13; + bb9 (cleanup): { + StorageDead(_7); + StorageDead(_6); + goto -> bb10; } - bb13 (cleanup): { + bb10 (cleanup): { StorageDead(_3); - drop(_1) -> [return: bb14, unwind terminate(cleanup)]; + drop(_1) -> [return: bb11, unwind terminate(cleanup)]; } - bb14 (cleanup): { + bb11 (cleanup): { resume; } - bb15 (cleanup): { + bb12 (cleanup): { StorageDead(_3); - drop(_1) -> [return: bb14, unwind terminate(cleanup)]; + drop(_1) -> [return: bb11, unwind terminate(cleanup)]; } } diff --git a/tests/mir-opt/coroutine_tiny.main-{closure#0}.coroutine_resume.0.mir b/tests/mir-opt/coroutine_tiny.main-{closure#0}.coroutine_resume.0.mir index 222c7144ef07d..71425740581c2 100644 --- a/tests/mir-opt/coroutine_tiny.main-{closure#0}.coroutine_resume.0.mir +++ b/tests/mir-opt/coroutine_tiny.main-{closure#0}.coroutine_resume.0.mir @@ -25,65 +25,91 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine_tiny.rs:21:5: 21:13} debug _x => _2; let mut _0: std::ops::CoroutineState<(), ()>; let _3: HasDrop; - let mut _4: !; - let mut _5: (); - let _6: u8; - let mut _7: (); - let _8: (); - let mut _9: (); - let mut _10: u32; - let mut _11: &mut {coroutine@$DIR/coroutine_tiny.rs:21:5: 21:13}; + let _4: u8; + let _5: (); + let mut _6: (); + let mut _7: u32; + let mut _8: &mut {coroutine@$DIR/coroutine_tiny.rs:21:5: 21:13}; scope 1 { - debug _d => (((*_11) as variant#3).0: HasDrop); + debug _d => (((*_8) as variant#3).0: HasDrop); } bb0: { - _11 = copy (_1.0: &mut {coroutine@$DIR/coroutine_tiny.rs:21:5: 21:13}); - _10 = discriminant((*_11)); - switchInt(move _10) -> [0: bb1, 3: bb5, otherwise: bb6]; + _8 = copy (_1.0: &mut {coroutine@$DIR/coroutine_tiny.rs:21:5: 21:13}); + _7 = discriminant((*_8)); + switchInt(move _7) -> [0: bb1, 3: bb14, otherwise: bb15]; } bb1: { nop; - (((*_11) as variant#3).0: HasDrop) = HasDrop; - StorageLive(_4); + (((*_8) as variant#3).0: HasDrop) = const HasDrop; goto -> bb2; } bb2: { - StorageLive(_6); - StorageLive(_7); - _7 = (); - _0 = CoroutineState::<(), ()>::Yielded(move _7); + StorageLive(_4); + _0 = CoroutineState::<(), ()>::Yielded(const ()); StorageDead(_4); - StorageDead(_6); - StorageDead(_7); - discriminant((*_11)) = 3; + discriminant((*_8)) = 3; return; } bb3: { - StorageDead(_7); - StorageDead(_6); - StorageLive(_8); - _8 = callee() -> [return: bb4, unwind unreachable]; + StorageDead(_4); + StorageLive(_5); + _5 = callee() -> [return: bb4, unwind unreachable]; } bb4: { - StorageDead(_8); - _5 = const (); + StorageDead(_5); goto -> bb2; } bb5: { + StorageDead(_4); + drop((((*_8) as variant#3).0: HasDrop)) -> [return: bb6, unwind unreachable]; + } + + bb6: { + nop; + goto -> bb11; + } + + bb7: { + coroutine_drop; + } + + bb8: { + return; + } + + bb9: { + goto -> bb13; + } + + bb10 (cleanup): { + unreachable; + } + + bb11: { + goto -> bb7; + } + + bb12 (cleanup): { + resume; + } + + bb13: { + goto -> bb8; + } + + bb14: { StorageLive(_4); - StorageLive(_6); - StorageLive(_7); - _6 = move _2; + _4 = move _2; goto -> bb3; } - bb6: { + bb15: { unreachable; } } diff --git a/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff index 151580da19e09..571bcc31e222d 100644 --- a/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff +++ b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-abort.diff @@ -23,6 +23,7 @@ + let mut _6: &mut {coroutine@$DIR/inline_coroutine.rs:20:5: 20:8}; + let mut _7: u32; + let mut _8: i32; ++ let mut _9: bool; + } bb0: { @@ -39,6 +40,7 @@ + _5 = const false; + StorageLive(_6); + StorageLive(_7); ++ StorageLive(_9); + _6 = copy (_2.0: &mut {coroutine@$DIR/inline_coroutine.rs:20:5: 20:8}); + _7 = discriminant((*_6)); + switchInt(move _7) -> [0: bb3, 1: bb7, 3: bb8, otherwise: bb9]; @@ -56,6 +58,7 @@ bb2: { - StorageDead(_3); - _1 = <{coroutine@$DIR/inline_coroutine.rs:20:5: 20:8} as Coroutine>::resume(move _2, const false) -> [return: bb3, unwind unreachable]; ++ StorageDead(_9); + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); @@ -97,8 +100,9 @@ + + bb8: { + StorageLive(_8); ++ _9 = move _5; + StorageDead(_8); -+ _1 = CoroutineState::::Complete(copy _5); ++ _1 = CoroutineState::::Complete(move _9); + discriminant((*_6)) = 1; + goto -> bb2; + } diff --git a/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff index 6196fc0d0c6bf..33751862f7c92 100644 --- a/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline/inline_coroutine.main.Inline.panic-unwind.diff @@ -23,6 +23,7 @@ + let mut _6: &mut {coroutine@$DIR/inline_coroutine.rs:20:5: 20:8}; + let mut _7: u32; + let mut _8: i32; ++ let mut _9: bool; + } bb0: { @@ -39,6 +40,7 @@ + _5 = const false; + StorageLive(_6); + StorageLive(_7); ++ StorageLive(_9); + _6 = copy (_2.0: &mut {coroutine@$DIR/inline_coroutine.rs:20:5: 20:8}); + _7 = discriminant((*_6)); + switchInt(move _7) -> [0: bb5, 1: bb9, 3: bb10, otherwise: bb11]; @@ -72,6 +74,7 @@ - _0 = const (); - StorageDead(_1); - return; ++ StorageDead(_9); + StorageDead(_7); + StorageDead(_6); + StorageDead(_5); @@ -111,8 +114,9 @@ + + bb10: { + StorageLive(_8); ++ _9 = move _5; + StorageDead(_8); -+ _1 = CoroutineState::::Complete(copy _5); ++ _1 = CoroutineState::::Complete(move _9); + discriminant((*_6)) = 1; + goto -> bb4; + } diff --git a/tests/ui/async-await/future-sizes/async-awaiting-fut.rs b/tests/ui/async-await/future-sizes/async-awaiting-fut.rs index 7113f591630d1..550496be8c100 100644 --- a/tests/ui/async-await/future-sizes/async-awaiting-fut.rs +++ b/tests/ui/async-await/future-sizes/async-awaiting-fut.rs @@ -5,7 +5,7 @@ //@ edition:2021 //@ build-pass //@ ignore-pass -//@ only-x86_64 +//@ only-64bit async fn wait() {} diff --git a/tests/ui/async-await/future-sizes/async-awaiting-fut.stdout b/tests/ui/async-await/future-sizes/async-awaiting-fut.stdout index b30c15bcbe6ed..a1056edd9c914 100644 --- a/tests/ui/async-await/future-sizes/async-awaiting-fut.stdout +++ b/tests/ui/async-await/future-sizes/async-awaiting-fut.stdout @@ -1,35 +1,32 @@ -print-type-size type: `{async fn body of test()}`: 3078 bytes, alignment: 1 bytes +print-type-size type: `{async fn body of test()}`: 3079 bytes, alignment: 1 bytes print-type-size discriminant: 1 bytes print-type-size variant `Unresumed`: 0 bytes -print-type-size variant `Suspend0`: 3077 bytes -print-type-size local `.__awaitee`: 3077 bytes, type: {async fn body of calls_fut<{async fn body of big_fut()}>()} +print-type-size variant `Suspend0`: 3078 bytes +print-type-size local `.__awaitee`: 3078 bytes, type: {async fn body of calls_fut<{async fn body of big_fut()}>()} print-type-size variant `Returned`: 0 bytes print-type-size variant `Panicked`: 0 bytes -print-type-size type: `std::mem::ManuallyDrop<{async fn body of calls_fut<{async fn body of big_fut()}>()}>`: 3077 bytes, alignment: 1 bytes -print-type-size field `.value`: 3077 bytes -print-type-size type: `std::mem::MaybeUninit<{async fn body of calls_fut<{async fn body of big_fut()}>()}>`: 3077 bytes, alignment: 1 bytes -print-type-size variant `MaybeUninit`: 3077 bytes +print-type-size type: `std::mem::ManuallyDrop<{async fn body of calls_fut<{async fn body of big_fut()}>()}>`: 3078 bytes, alignment: 1 bytes +print-type-size field `.value`: 3078 bytes +print-type-size type: `std::mem::MaybeUninit<{async fn body of calls_fut<{async fn body of big_fut()}>()}>`: 3078 bytes, alignment: 1 bytes +print-type-size variant `MaybeUninit`: 3078 bytes print-type-size field `.uninit`: 0 bytes -print-type-size field `.value`: 3077 bytes -print-type-size type: `{async fn body of calls_fut<{async fn body of big_fut()}>()}`: 3077 bytes, alignment: 1 bytes +print-type-size field `.value`: 3078 bytes +print-type-size type: `{async fn body of calls_fut<{async fn body of big_fut()}>()}`: 3078 bytes, alignment: 1 bytes print-type-size discriminant: 1 bytes print-type-size variant `Unresumed`: 1025 bytes print-type-size upvar `.fut`: 1025 bytes -print-type-size variant `Suspend0`: 2052 bytes +print-type-size variant `Suspend0`: 3077 bytes print-type-size upvar `.fut`: 1025 bytes print-type-size local `.fut`: 1025 bytes -print-type-size local `..coroutine_field4`: 1 bytes, type: bool print-type-size local `.__awaitee`: 1 bytes, type: {async fn body of wait()} -print-type-size variant `Suspend1`: 3076 bytes +print-type-size padding: 1025 bytes +print-type-size local `..coroutine_field3`: 1 bytes, alignment: 1 bytes, type: bool +print-type-size variant `Suspend1`: 3077 bytes print-type-size upvar `.fut`: 1025 bytes print-type-size padding: 1025 bytes -print-type-size local `..coroutine_field4`: 1 bytes, alignment: 1 bytes, type: bool +print-type-size local `.__awaitee`: 1 bytes, alignment: 1 bytes, type: {async fn body of wait()} print-type-size local `.__awaitee`: 1025 bytes, type: {async fn body of big_fut()} -print-type-size variant `Suspend2`: 2052 bytes -print-type-size upvar `.fut`: 1025 bytes -print-type-size local `.fut`: 1025 bytes -print-type-size local `..coroutine_field4`: 1 bytes, type: bool -print-type-size local `.__awaitee`: 1 bytes, type: {async fn body of wait()} +print-type-size local `..coroutine_field3`: 1 bytes, type: bool print-type-size variant `Returned`: 1025 bytes print-type-size upvar `.fut`: 1025 bytes print-type-size variant `Panicked`: 1025 bytes @@ -68,6 +65,8 @@ print-type-size type: `std::panic::AssertUnwindSafe`: 16 bytes, alignment: 8 bytes print-type-size field `.pointer`: 16 bytes +print-type-size type: `std::future::ResumeTy`: 8 bytes, alignment: 8 bytes +print-type-size field `.0`: 8 bytes print-type-size type: `std::pin::Pin<&mut {async fn body of big_fut()}>`: 8 bytes, alignment: 8 bytes print-type-size field `.pointer`: 8 bytes print-type-size type: `std::pin::Pin<&mut {async fn body of calls_fut<{async fn body of big_fut()}>()}>`: 8 bytes, alignment: 8 bytes @@ -81,6 +80,8 @@ print-type-size field `._vtable_ptr`: 8 bytes print-type-size field `._phantom`: 0 bytes print-type-size type: `std::ptr::NonNull`: 8 bytes, alignment: 8 bytes print-type-size field `.pointer`: 8 bytes +print-type-size type: `std::ptr::NonNull>`: 8 bytes, alignment: 8 bytes +print-type-size field `.pointer`: 8 bytes print-type-size type: `std::mem::ManuallyDrop`: 1 bytes, alignment: 1 bytes print-type-size field `.value`: 1 bytes print-type-size type: `std::mem::ManuallyDrop<{async fn body of wait()}>`: 1 bytes, alignment: 1 bytes diff --git a/tests/ui/async-await/future-sizes/large-arg.rs b/tests/ui/async-await/future-sizes/large-arg.rs index b05a2b7191512..1ec7a8d50cb38 100644 --- a/tests/ui/async-await/future-sizes/large-arg.rs +++ b/tests/ui/async-await/future-sizes/large-arg.rs @@ -5,7 +5,7 @@ //@ edition: 2021 //@ build-pass //@ ignore-pass -//@ only-x86_64 +//@ only-64bit pub async fn test() { let _ = a([0u8; 1024]).await; diff --git a/tests/ui/async-await/future-sizes/large-arg.stdout b/tests/ui/async-await/future-sizes/large-arg.stdout index e00420d1493f4..b6051da95ca42 100644 --- a/tests/ui/async-await/future-sizes/large-arg.stdout +++ b/tests/ui/async-await/future-sizes/large-arg.stdout @@ -78,6 +78,8 @@ print-type-size type: `std::panic::AssertUnwindSafe`: 16 bytes, alignment: 8 bytes print-type-size field `.pointer`: 16 bytes +print-type-size type: `std::future::ResumeTy`: 8 bytes, alignment: 8 bytes +print-type-size field `.0`: 8 bytes print-type-size type: `std::pin::Pin<&mut {async fn body of a<[u8; 1024]>()}>`: 8 bytes, alignment: 8 bytes print-type-size field `.pointer`: 8 bytes print-type-size type: `std::pin::Pin<&mut {async fn body of b<[u8; 1024]>()}>`: 8 bytes, alignment: 8 bytes @@ -91,6 +93,8 @@ print-type-size field `._vtable_ptr`: 8 bytes print-type-size field `._phantom`: 0 bytes print-type-size type: `std::ptr::NonNull`: 8 bytes, alignment: 8 bytes print-type-size field `.pointer`: 8 bytes +print-type-size type: `std::ptr::NonNull>`: 8 bytes, alignment: 8 bytes +print-type-size field `.pointer`: 8 bytes print-type-size type: `std::task::Poll<()>`: 1 bytes, alignment: 1 bytes print-type-size discriminant: 1 bytes print-type-size variant `Ready`: 0 bytes diff --git a/tests/ui/coroutine/size-moved-locals.rs b/tests/ui/coroutine/size-moved-locals.rs index 0f800de84544d..30ff74534c3c3 100644 --- a/tests/ui/coroutine/size-moved-locals.rs +++ b/tests/ui/coroutine/size-moved-locals.rs @@ -76,5 +76,5 @@ fn main() { assert_eq!(1025, std::mem::size_of_val(&move_before_yield())); assert_eq!(1026, std::mem::size_of_val(&move_before_yield_with_noop())); assert_eq!(2051, std::mem::size_of_val(&overlap_move_points())); - assert_eq!(1026, std::mem::size_of_val(&overlap_x_and_y())); + assert_eq!(2050, std::mem::size_of_val(&overlap_x_and_y())); } diff --git a/tests/ui/print_type_sizes/async.rs b/tests/ui/print_type_sizes/async.rs index b6ec88426345b..8e670ba5df4a4 100644 --- a/tests/ui/print_type_sizes/async.rs +++ b/tests/ui/print_type_sizes/async.rs @@ -5,7 +5,7 @@ //@ edition:2021 //@ build-pass //@ ignore-pass -//@ only-x86_64 +//@ only-64bit #![allow(dropping_copy_types)] diff --git a/tests/ui/print_type_sizes/async.stdout b/tests/ui/print_type_sizes/async.stdout index d3d6b6471c6ef..0499531158844 100644 --- a/tests/ui/print_type_sizes/async.stdout +++ b/tests/ui/print_type_sizes/async.stdout @@ -36,6 +36,8 @@ print-type-size type: `std::panic::AssertUnwindSafe`: 16 bytes, alignment: 8 bytes print-type-size field `.pointer`: 16 bytes +print-type-size type: `std::future::ResumeTy`: 8 bytes, alignment: 8 bytes +print-type-size field `.0`: 8 bytes print-type-size type: `std::pin::Pin<&mut {async fn body of test()}>`: 8 bytes, alignment: 8 bytes print-type-size field `.pointer`: 8 bytes print-type-size type: `std::pin::Pin<&mut {async fn body of wait()}>`: 8 bytes, alignment: 8 bytes @@ -45,6 +47,8 @@ print-type-size field `._vtable_ptr`: 8 bytes print-type-size field `._phantom`: 0 bytes print-type-size type: `std::ptr::NonNull`: 8 bytes, alignment: 8 bytes print-type-size field `.pointer`: 8 bytes +print-type-size type: `std::ptr::NonNull>`: 8 bytes, alignment: 8 bytes +print-type-size field `.pointer`: 8 bytes print-type-size type: `std::mem::ManuallyDrop<{async fn body of wait()}>`: 1 bytes, alignment: 1 bytes print-type-size field `.value`: 1 bytes print-type-size type: `std::mem::MaybeUninit<{async fn body of wait()}>`: 1 bytes, alignment: 1 bytes diff --git a/tests/ui/print_type_sizes/coroutine_discr_placement.stdout b/tests/ui/print_type_sizes/coroutine_discr_placement.stdout index 4ce1ce46f6e82..30a9df6f20948 100644 --- a/tests/ui/print_type_sizes/coroutine_discr_placement.stdout +++ b/tests/ui/print_type_sizes/coroutine_discr_placement.stdout @@ -1,17 +1,7 @@ -print-type-size type: `{coroutine@$DIR/coroutine_discr_placement.rs:13:5: 13:7}`: 8 bytes, alignment: 4 bytes +print-type-size type: `{coroutine@$DIR/coroutine_discr_placement.rs:13:5: 13:7}`: 1 bytes, alignment: 1 bytes print-type-size discriminant: 1 bytes print-type-size variant `Unresumed`: 0 bytes -print-type-size variant `Suspend0`: 7 bytes -print-type-size padding: 3 bytes -print-type-size local `.w`: 4 bytes, alignment: 4 bytes -print-type-size variant `Suspend1`: 7 bytes -print-type-size padding: 3 bytes -print-type-size local `.z`: 4 bytes, alignment: 4 bytes +print-type-size variant `Suspend0`: 0 bytes +print-type-size variant `Suspend1`: 0 bytes print-type-size variant `Returned`: 0 bytes print-type-size variant `Panicked`: 0 bytes -print-type-size type: `std::mem::ManuallyDrop`: 4 bytes, alignment: 4 bytes -print-type-size field `.value`: 4 bytes -print-type-size type: `std::mem::MaybeUninit`: 4 bytes, alignment: 4 bytes -print-type-size variant `MaybeUninit`: 4 bytes -print-type-size field `.uninit`: 0 bytes -print-type-size field `.value`: 4 bytes