diff --git a/compiler/rustc_mir_transform/src/coroutine.rs b/compiler/rustc_mir_transform/src/coroutine.rs index 08316aaed3b42..b1fc3dfe16bfa 100644 --- a/compiler/rustc_mir_transform/src/coroutine.rs +++ b/compiler/rustc_mir_transform/src/coroutine.rs @@ -68,7 +68,7 @@ use rustc_hir::lang_items::LangItem; use rustc_hir::{CoroutineDesugaring, CoroutineKind}; use rustc_index::bit_set::{BitMatrix, DenseBitSet, GrowableBitSet}; use rustc_index::{Idx, IndexVec}; -use rustc_middle::mir::visit::{MutVisitor, PlaceContext, Visitor}; +use rustc_middle::mir::visit::{MutVisitor, MutatingUseContext, PlaceContext, Visitor}; use rustc_middle::mir::*; use rustc_middle::ty::util::Discr; use rustc_middle::ty::{ @@ -111,6 +111,8 @@ impl<'tcx> MutVisitor<'tcx> for RenameLocalVisitor<'tcx> { fn visit_local(&mut self, local: &mut Local, _: PlaceContext, _: Location) { if *local == self.from { *local = self.to; + } else if *local == self.to { + *local = self.from; } } @@ -131,8 +133,8 @@ struct SelfArgVisitor<'tcx> { } impl<'tcx> SelfArgVisitor<'tcx> { - fn new(tcx: TyCtxt<'tcx>, elem: ProjectionElem>) -> Self { - Self { tcx, new_base: Place { local: SELF_ARG, projection: tcx.mk_place_elems(&[elem]) } } + fn new(tcx: TyCtxt<'tcx>, new_base: Place<'tcx>) -> Self { + Self { tcx, new_base } } } @@ -145,21 +147,20 @@ impl<'tcx> MutVisitor<'tcx> for SelfArgVisitor<'tcx> { assert_ne!(*local, SELF_ARG); } - fn visit_place(&mut self, place: &mut Place<'tcx>, context: PlaceContext, location: Location) { + fn visit_place(&mut self, place: &mut Place<'tcx>, _: PlaceContext, _: Location) { if place.local == SELF_ARG { replace_base(place, self.new_base, self.tcx); - } else { - self.visit_local(&mut place.local, context, location); + } - for elem in place.projection.iter() { - if let PlaceElem::Index(local) = elem { - assert_ne!(local, SELF_ARG); - } + for elem in place.projection.iter() { + if let PlaceElem::Index(local) = elem { + assert_ne!(local, SELF_ARG); } } } } +#[tracing::instrument(level = "trace", skip(tcx))] fn replace_base<'tcx>(place: &mut Place<'tcx>, new_base: Place<'tcx>, tcx: TyCtxt<'tcx>) { place.local = new_base.local; @@ -167,12 +168,14 @@ fn replace_base<'tcx>(place: &mut Place<'tcx>, new_base: Place<'tcx>, tcx: TyCtx new_projection.append(&mut place.projection.to_vec()); place.projection = tcx.mk_place_elems(&new_projection); + tracing::trace!(?place); } 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, @@ -205,8 +208,8 @@ struct TransformVisitor<'tcx> { // The set of locals that have no `StorageLive`/`StorageDead` annotations. always_live_locals: DenseBitSet, - // The original RETURN_PLACE local - old_ret_local: Local, + // New local we just create to hold the `CoroutineState` value. + new_ret_local: Local, old_yield_ty: Ty<'tcx>, @@ -271,6 +274,7 @@ impl<'tcx> TransformVisitor<'tcx> { // `core::ops::CoroutineState` only has single element tuple variants, // so we can just write to the downcasted first field and then set the // discriminant to the appropriate variant. + #[tracing::instrument(level = "trace", skip(self, statements))] fn make_state( &self, val: Operand<'tcx>, @@ -344,11 +348,12 @@ impl<'tcx> TransformVisitor<'tcx> { statements.push(Statement::new( source_info, - StatementKind::Assign(Box::new((Place::return_place(), rvalue))), + StatementKind::Assign(Box::new((self.new_ret_local.into(), rvalue))), )); } // Create a Place referencing a coroutine struct field + #[tracing::instrument(level = "trace", skip(self), ret)] fn make_field(&self, variant_index: VariantIdx, idx: FieldIdx, ty: Ty<'tcx>) -> Place<'tcx> { let self_place = Place::from(SELF_ARG); let base = self.tcx.mk_place_downcast_unnamed(self_place, variant_index); @@ -359,6 +364,7 @@ impl<'tcx> TransformVisitor<'tcx> { } // Create a statement which changes the discriminant + #[tracing::instrument(level = "trace", skip(self))] fn set_discr(&self, state_disc: VariantIdx, source_info: SourceInfo) -> Statement<'tcx> { let self_place = Place::from(SELF_ARG); Statement::new( @@ -371,6 +377,7 @@ impl<'tcx> TransformVisitor<'tcx> { } // Create a statement which reads the discriminant into a temporary + #[tracing::instrument(level = "trace", skip(self, body))] fn get_discr(&self, body: &mut Body<'tcx>) -> (Statement<'tcx>, Place<'tcx>) { let temp_decl = LocalDecl::new(self.discr_ty, body.span); let local_decls_len = body.local_decls.push(temp_decl); @@ -383,6 +390,27 @@ impl<'tcx> TransformVisitor<'tcx> { ); (assign, temp) } + + /// Allocates a new local and replaces all references of `local` with it. Returns the new local. + /// + /// `local` will be changed to a new local decl with type `ty`. + /// + /// Note that the new local will be uninitialized. It is the caller's responsibility to assign some + /// valid value to it before its first use. + #[tracing::instrument(level = "trace", skip(self, body))] + fn replace_local(&mut self, local: Local, new_local: Local, body: &mut Body<'tcx>) -> Local { + body.local_decls.swap(local, new_local); + + let mut visitor = RenameLocalVisitor { from: local, to: new_local, tcx: self.tcx }; + visitor.visit_body(body); + for suspension in &mut self.suspension_points { + let ctxt = PlaceContext::MutatingUse(MutatingUseContext::Yield); + let location = Location { block: START_BLOCK, statement_index: 0 }; + visitor.visit_place(&mut suspension.resume_arg, ctxt, location); + } + + new_local + } } impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> { @@ -390,22 +418,20 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> { self.tcx } - fn visit_local(&mut self, local: &mut Local, _: PlaceContext, _: Location) { + #[tracing::instrument(level = "trace", skip(self), ret)] + fn visit_local(&mut self, local: &mut Local, _: PlaceContext, _location: Location) { assert!(!self.remap.contains(*local)); } - fn visit_place( - &mut self, - place: &mut Place<'tcx>, - _context: PlaceContext, - _location: Location, - ) { + #[tracing::instrument(level = "trace", skip(self), ret)] + fn visit_place(&mut self, place: &mut Place<'tcx>, _: PlaceContext, _location: Location) { // Replace an Local in the remap with a coroutine struct access if let Some(&Some((ty, variant_index, idx))) = self.remap.get(place.local) { replace_base(place, self.make_field(variant_index, idx, ty), self.tcx); } } + #[tracing::instrument(level = "trace", skip(self, data), ret)] fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockData<'tcx>) { // Remove StorageLive and StorageDead statements for remapped locals for s in &mut data.statements { @@ -416,29 +442,35 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> { } } - let ret_val = match data.terminator().kind { + for (statement_index, statement) in data.statements.iter_mut().enumerate() { + let location = Location { block, statement_index }; + self.visit_statement(statement, location); + } + + let location = Location { block, statement_index: data.statements.len() }; + let mut terminator = data.terminator.take().unwrap(); + let source_info = terminator.source_info; + match terminator.kind { TerminatorKind::Return => { - Some((true, None, Operand::Move(Place::from(self.old_ret_local)), None)) + let mut v = Operand::Move(Place::return_place()); + self.visit_operand(&mut v, location); + // We must assign the value first in case it gets declared dead below + self.make_state(v, source_info, true, &mut data.statements); + // State for returned + let state = VariantIdx::new(CoroutineArgs::RETURNED); + data.statements.push(self.set_discr(state, source_info)); + terminator.kind = TerminatorKind::Return; } - TerminatorKind::Yield { ref value, resume, resume_arg, drop } => { - Some((false, Some((resume, resume_arg)), value.clone(), drop)) - } - _ => None, - }; - - if let Some((is_return, resume, v, drop)) = ret_val { - let source_info = data.terminator().source_info; - // We must assign the value first in case it gets declared dead below - self.make_state(v, source_info, is_return, &mut data.statements); - let state = if let Some((resume, mut resume_arg)) = resume { - // Yield - let state = CoroutineArgs::RESERVED_VARIANTS + self.suspension_points.len(); - + TerminatorKind::Yield { mut value, resume, mut resume_arg, drop } => { // The resume arg target location might itself be remapped if its base local is // live across a yield. - if let Some(&Some((ty, variant, idx))) = self.remap.get(resume_arg.local) { - replace_base(&mut resume_arg, self.make_field(variant, idx, ty), self.tcx); - } + self.visit_operand(&mut value, location); + let ctxt = PlaceContext::MutatingUse(MutatingUseContext::Yield); + self.visit_place(&mut resume_arg, ctxt, location); + // We must assign the value first in case it gets declared dead below + self.make_state(value.clone(), source_info, false, &mut data.statements); + // Yield + let state = CoroutineArgs::RESERVED_VARIANTS + self.suspension_points.len(); let storage_liveness: GrowableBitSet = self.storage_liveness[block].clone().unwrap().into(); @@ -453,7 +485,6 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> { .push(Statement::new(source_info, StatementKind::StorageDead(l))); } } - self.suspension_points.push(SuspensionPoint { state, resume, @@ -462,16 +493,13 @@ impl<'tcx> MutVisitor<'tcx> for TransformVisitor<'tcx> { storage_liveness, }); - VariantIdx::new(state) - } else { - // Return - VariantIdx::new(CoroutineArgs::RETURNED) // state for returned - }; - data.statements.push(self.set_discr(state, source_info)); - data.terminator_mut().kind = TerminatorKind::Return; - } - - self.super_basic_block_data(block, data); + let state = VariantIdx::new(state); + data.statements.push(self.set_discr(state, source_info)); + terminator.kind = TerminatorKind::Return; + } + _ => self.visit_terminator(&mut terminator, location), + }; + data.terminator = Some(terminator); } } @@ -484,20 +512,24 @@ fn make_aggregate_adt<'tcx>( Rvalue::Aggregate(Box::new(AggregateKind::Adt(def_id, variant_idx, args, None, None)), operands) } +#[tracing::instrument(level = "trace", skip(tcx, body))] fn make_coroutine_state_argument_indirect<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let coroutine_ty = body.local_decls.raw[1].ty; + let coroutine_ty = body.local_decls[SELF_ARG].ty; let ref_coroutine_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, coroutine_ty); // Replace the by value coroutine argument - body.local_decls.raw[1].ty = ref_coroutine_ty; + body.local_decls[SELF_ARG].ty = ref_coroutine_ty; // Add a deref to accesses of the coroutine state - SelfArgVisitor::new(tcx, ProjectionElem::Deref).visit_body(body); + SelfArgVisitor::new(tcx, tcx.mk_place_deref(SELF_ARG.into())).visit_body(body); } +#[tracing::instrument(level = "trace", skip(tcx, body))] fn make_coroutine_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { - let ref_coroutine_ty = body.local_decls.raw[1].ty; + let coroutine_ty = body.local_decls[SELF_ARG].ty; + + let ref_coroutine_ty = Ty::new_mut_ref(tcx, tcx.lifetimes.re_erased, coroutine_ty); let pin_did = tcx.require_lang_item(LangItem::Pin, body.span); let pin_adt_ref = tcx.adt_def(pin_did); @@ -505,32 +537,28 @@ fn make_coroutine_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body let pin_ref_coroutine_ty = Ty::new_adt(tcx, pin_adt_ref, args); // Replace the by ref coroutine argument - body.local_decls.raw[1].ty = pin_ref_coroutine_ty; + body.local_decls[SELF_ARG].ty = pin_ref_coroutine_ty; - // Add the Pin field access to accesses of the coroutine state - SelfArgVisitor::new(tcx, ProjectionElem::Field(FieldIdx::ZERO, ref_coroutine_ty)) - .visit_body(body); -} + let unpinned_local = body.local_decls.push(LocalDecl::new(ref_coroutine_ty, body.span)); -/// Allocates a new local and replaces all references of `local` with it. Returns the new local. -/// -/// `local` will be changed to a new local decl with type `ty`. -/// -/// Note that the new local will be uninitialized. It is the caller's responsibility to assign some -/// valid value to it before its first use. -fn replace_local<'tcx>( - local: Local, - ty: Ty<'tcx>, - body: &mut Body<'tcx>, - tcx: TyCtxt<'tcx>, -) -> Local { - let new_decl = LocalDecl::new(ty, body.span); - let new_local = body.local_decls.push(new_decl); - body.local_decls.swap(local, new_local); - - RenameLocalVisitor { from: local, to: new_local, tcx }.visit_body(body); + // Add the Pin field access to accesses of the coroutine state + SelfArgVisitor::new(tcx, tcx.mk_place_deref(unpinned_local.into())).visit_body(body); - new_local + let source_info = SourceInfo::outermost(body.span); + body.basic_blocks_mut()[START_BLOCK].statements.insert( + 0, + Statement::new( + source_info, + StatementKind::Assign(Box::new(( + unpinned_local.into(), + Rvalue::CopyForDeref(tcx.mk_place_field( + SELF_ARG.into(), + FieldIdx::ZERO, + ref_coroutine_ty, + )), + ))), + ), + ); } /// Transforms the `body` of the coroutine applying the following transforms: @@ -554,6 +582,7 @@ fn replace_local<'tcx>( /// The async lowering step and the type / lifetime inference / checking are /// still using the `ResumeTy` indirection for the time being, and that indirection /// is removed here. After this transform, the coroutine body only knows about `&mut Context<'_>`. +#[tracing::instrument(level = "trace", skip(tcx, body), ret)] fn transform_async_context<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) -> Ty<'tcx> { let context_mut_ref = Ty::new_task_context(tcx); @@ -607,6 +636,7 @@ fn eliminate_get_context_call<'tcx>(bb_data: &mut BasicBlockData<'tcx>) -> Local } #[cfg_attr(not(debug_assertions), allow(unused))] +#[tracing::instrument(level = "trace", skip(tcx, body), ret)] fn replace_resume_ty_local<'tcx>( tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, @@ -617,7 +647,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); @@ -671,6 +701,7 @@ struct LivenessInfo { /// case none exist, the local is considered to be always live. /// - a local has to be stored if it is either directly used after the /// the suspend point, or if it is live and has been previously borrowed. +#[tracing::instrument(level = "trace", skip(tcx, body))] fn locals_live_across_suspend_points<'tcx>( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, @@ -946,6 +977,7 @@ impl StorageConflictVisitor<'_, '_> { } } +#[tracing::instrument(level = "trace", skip(liveness, body))] fn compute_layout<'tcx>( liveness: LivenessInfo, body: &Body<'tcx>, @@ -1050,7 +1082,9 @@ fn compute_layout<'tcx>( variant_source_info, storage_conflicts, }; + debug!(?remap); debug!(?layout); + debug!(?storage_liveness); (remap, layout, storage_liveness) } @@ -1222,6 +1256,7 @@ fn generate_poison_block_and_redirect_unwinds_there<'tcx>( } } +#[tracing::instrument(level = "trace", skip(tcx, transform, body))] fn create_coroutine_resume_function<'tcx>( tcx: TyCtxt<'tcx>, transform: TransformVisitor<'tcx>, @@ -1275,8 +1310,6 @@ fn create_coroutine_resume_function<'tcx>( let default_block = insert_term_block(body, TerminatorKind::Unreachable); insert_switch(body, cases, &transform, default_block); - make_coroutine_state_argument_indirect(tcx, body); - match transform.coroutine_kind { CoroutineKind::Coroutine(_) | CoroutineKind::Desugared(CoroutineDesugaring::Async | CoroutineDesugaring::AsyncGen, _) => @@ -1285,22 +1318,14 @@ fn create_coroutine_resume_function<'tcx>( } // Iterator::next doesn't accept a pinned argument, // unlike for all other coroutine kinds. - CoroutineKind::Desugared(CoroutineDesugaring::Gen, _) => {} - } - - // 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); + CoroutineKind::Desugared(CoroutineDesugaring::Gen, _) => { + make_coroutine_state_argument_indirect(tcx, body); + } } } /// An operation that can be performed on a coroutine. -#[derive(PartialEq, Copy, Clone)] +#[derive(PartialEq, Copy, Clone, Debug)] enum Operation { Resume, Drop, @@ -1315,6 +1340,7 @@ impl Operation { } } +#[tracing::instrument(level = "trace", skip(transform, body))] fn create_cases<'tcx>( body: &mut Body<'tcx>, transform: &TransformVisitor<'tcx>, @@ -1446,6 +1472,8 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform { // This only applies to coroutines return; }; + tracing::trace!(def_id = ?body.source.def_id()); + let old_ret_ty = body.return_ty(); assert!(body.coroutine_drop().is_none() && body.coroutine_drop_async().is_none()); @@ -1492,10 +1520,6 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform { } }; - // We rename RETURN_PLACE which has type mir.return_ty to old_ret_local - // RETURN_PLACE then is a fresh unused local with type ret_ty. - let old_ret_local = replace_local(RETURN_PLACE, new_ret_ty, body, tcx); - // We need to insert clean drop for unresumed state and perform drop elaboration // (finally in open_drop_for_tuple) before async drop expansion. // Async drops, produced by this drop elaboration, will be expanded, @@ -1520,6 +1544,11 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform { cleanup_async_drops(body); } + // We rename RETURN_PLACE which has type mir.return_ty to new_ret_local + // RETURN_PLACE then is a fresh unused local with type ret_ty. + let new_ret_local = body.local_decls.push(LocalDecl::new(new_ret_ty, body.span)); + tracing::trace!(?new_ret_local); + let always_live_locals = always_storage_live_locals(body); let movable = coroutine_kind.movability() == hir::Movability::Movable; let liveness_info = @@ -1554,13 +1583,16 @@ impl<'tcx> crate::MirPass<'tcx> for StateTransform { storage_liveness, always_live_locals, suspension_points: Vec::new(), - old_ret_local, discr_ty, + new_ret_local, old_ret_ty, old_yield_ty, }; transform.visit_body(body); + // Swap the actual `RETURN_PLACE` and the provisional `new_ret_local`. + transform.replace_local(RETURN_PLACE, new_ret_local, body); + // MIR parameters are not explicitly assigned-to when entering the MIR body. // If we want to save their values inside the coroutine state, we need to do so explicitly. let source_info = SourceInfo::outermost(body.span); @@ -1645,6 +1677,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); } diff --git a/compiler/rustc_mir_transform/src/coroutine/drop.rs b/compiler/rustc_mir_transform/src/coroutine/drop.rs index fd2d8b2b0563e..862fed00e30e6 100644 --- a/compiler/rustc_mir_transform/src/coroutine/drop.rs +++ b/compiler/rustc_mir_transform/src/coroutine/drop.rs @@ -126,6 +126,7 @@ fn build_pin_fut<'tcx>( // Ready() => ready_block // Pending => yield_block //} +#[tracing::instrument(level = "trace", skip(tcx, body), ret)] fn build_poll_switch<'tcx>( tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, @@ -179,6 +180,7 @@ fn build_poll_switch<'tcx>( } // Gather blocks, reachable through 'drop' targets of Yield and Drop terminators (chained) +#[tracing::instrument(level = "trace", skip(body), ret)] fn gather_dropline_blocks<'tcx>(body: &mut Body<'tcx>) -> DenseBitSet { let mut dropline: DenseBitSet = DenseBitSet::new_empty(body.basic_blocks.len()); for (bb, data) in traversal::reverse_postorder(body) { @@ -249,6 +251,7 @@ pub(super) fn has_expandable_async_drops<'tcx>( } /// Expand Drop terminator for async drops into mainline poll-switch and dropline poll-switch +#[tracing::instrument(level = "trace", skip(tcx, body), ret)] pub(super) fn expand_async_drops<'tcx>( tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, @@ -259,6 +262,7 @@ pub(super) fn expand_async_drops<'tcx>( let dropline = gather_dropline_blocks(body); // Clean drop and async_fut fields if potentially async drop is not expanded (stays sync) let remove_asyncness = |block: &mut BasicBlockData<'tcx>| { + tracing::trace!("remove_asyncness"); if let TerminatorKind::Drop { place: _, target: _, @@ -273,6 +277,7 @@ pub(super) fn expand_async_drops<'tcx>( } }; for bb in START_BLOCK..body.basic_blocks.next_index() { + tracing::trace!(?bb); // Drops in unwind path (cleanup blocks) are not expanded to async drops, only sync drops in unwind path if body[bb].is_cleanup { remove_asyncness(&mut body[bb]); @@ -461,6 +466,7 @@ pub(super) fn expand_async_drops<'tcx>( } } +#[tracing::instrument(level = "trace", skip(tcx, body))] pub(super) fn elaborate_coroutine_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { use crate::elaborate_drop::{Unwind, elaborate_drop}; use crate::patch::MirPatch; @@ -519,6 +525,7 @@ pub(super) fn elaborate_coroutine_drops<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body elaborator.patch.apply(body); } +#[tracing::instrument(level = "trace", skip(tcx, body), ret)] pub(super) fn insert_clean_drop<'tcx>( tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>, @@ -550,6 +557,7 @@ pub(super) fn insert_clean_drop<'tcx>( .push(BasicBlockData::new(Some(Terminator { source_info, kind: term }), false)) } +#[tracing::instrument(level = "trace", skip(tcx, transform, body))] pub(super) fn create_coroutine_drop_shim<'tcx>( tcx: TyCtxt<'tcx>, transform: &TransformVisitor<'tcx>, @@ -621,6 +629,7 @@ pub(super) fn create_coroutine_drop_shim<'tcx>( } // Create async drop shim function to drop coroutine itself +#[tracing::instrument(level = "trace", skip(tcx, transform, body))] pub(super) fn create_coroutine_drop_shim_async<'tcx>( tcx: TyCtxt<'tcx>, transform: &TransformVisitor<'tcx>, @@ -676,12 +685,13 @@ pub(super) fn create_coroutine_drop_shim_async<'tcx>( let poll_enum = Ty::new_adt(tcx, poll_adt_ref, tcx.mk_args(&[tcx.types.unit.into()])); body.local_decls[RETURN_PLACE] = LocalDecl::with_source_info(poll_enum, source_info); - make_coroutine_state_argument_indirect(tcx, &mut body); - match transform.coroutine_kind { // Iterator::next doesn't accept a pinned argument, // unlike for all other coroutine kinds. - CoroutineKind::Desugared(CoroutineDesugaring::Gen, _) => {} + CoroutineKind::Desugared(CoroutineDesugaring::Gen, _) => { + make_coroutine_state_argument_indirect(tcx, &mut body); + } + _ => { make_coroutine_state_argument_pinned(tcx, &mut body); } diff --git a/compiler/rustc_mir_transform/src/dataflow_const_prop.rs b/compiler/rustc_mir_transform/src/dataflow_const_prop.rs index 5c984984d3cc3..0cb25bf1f8f65 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 @@ -241,9 +247,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 30e68a3f65058..98b2dcc0ba5e9 100644 --- a/compiler/rustc_mir_transform/src/gvn.rs +++ b/compiler/rustc_mir_transform/src/gvn.rs @@ -1697,14 +1697,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); } // Function calls and ASM may invalidate (nested) derefs. We must handle them carefully. // Currently, only preserving derefs for trivial terminators like SwitchInt and Goto. diff --git a/compiler/rustc_mir_transform/src/jump_threading.rs b/compiler/rustc_mir_transform/src/jump_threading.rs index f9e642e28ebd7..0aeb77121cc2d 100644 --- a/compiler/rustc_mir_transform/src/jump_threading.rs +++ b/compiler/rustc_mir_transform/src/jump_threading.rs @@ -612,9 +612,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. @@ -623,6 +623,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 9ff7e0b550030..eef2f2d1dd024 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -80,7 +80,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),* $(,)? } )?),+ $(,)?; )* ) => { $( @@ -179,12 +179,14 @@ declare_passes! { PreOptimizations, Final, MakeShim, - AfterUnreachableEnumBranching + AfterUnreachableEnumBranching, + PostStateTransform, }, SimplifyLocals { BeforeConstProp, AfterGVN, - Final + Final, + PostStateTransform, }; mod simplify_branches : SimplifyConstCondition { AfterConstProp, @@ -620,7 +622,6 @@ fn run_runtime_lowering_passes<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { // Otherwise it should run fairly late, but before optimizations begin. &add_retag::AddRetag, &elaborate_box_derefs::ElaborateBoxDerefs, - &coroutine::StateTransform, &Lint(known_panics_lint::KnownPanicsLint), ]; pm::run_passes_no_validate(tcx, body, passes, Some(MirPhase::Runtime(RuntimePhase::Initial))); @@ -725,6 +726,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 bca8ffb693b90..afb70a02c50e3 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -149,7 +149,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 18d09473c191e..0c679e1063055 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 75917d23883be..4399f4343d82c 100644 --- a/compiler/rustc_mir_transform/src/simplify.rs +++ b/compiler/rustc_mir_transform/src/simplify.rs @@ -55,6 +55,8 @@ pub(super) enum SimplifyCfg { Final, MakeShim, AfterUnreachableEnumBranching, + /// Extra run introduced by `StateTransform`. + PostStateTransform, } impl SimplifyCfg { @@ -70,6 +72,7 @@ impl SimplifyCfg { SimplifyCfg::AfterUnreachableEnumBranching => { "SimplifyCfg-after-unreachable-enum-branching" } + SimplifyCfg::PostStateTransform => "SimplifyCfg-post-StateTransform", } } } @@ -390,6 +393,8 @@ pub(super) enum SimplifyLocals { BeforeConstProp, AfterGVN, Final, + /// Extra run introduced by `StateTransform`. + PostStateTransform, } impl<'tcx> crate::MirPass<'tcx> for SimplifyLocals { @@ -398,6 +403,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 c8a9a88dc3fe3..3481b0447654d 100644 --- a/compiler/rustc_mir_transform/src/validate.rs +++ b/compiler/rustc_mir_transform/src/validate.rs @@ -450,7 +450,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); @@ -488,7 +488,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/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 050aac7c3ff05..5be61cbd492cd 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 @@ -2,7 +2,7 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> { debug _task_context => _2; - debug x => ((*(_1.0: &mut {async fn body of a()})).0: T); + debug x => ((*_20).0: T); let mut _0: std::task::Poll<()>; let _3: T; let mut _4: impl std::future::Future; @@ -10,89 +10,87 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) let mut _6: std::pin::Pin<&mut T>; let mut _7: &mut T; let mut _8: *mut T; - let mut _9: (); - let mut _10: std::task::Poll<()>; - let mut _11: &mut std::task::Context<'_>; - let mut _12: &mut impl std::future::Future; - let mut _13: std::pin::Pin<&mut impl std::future::Future>; - let mut _14: isize; - let mut _15: &mut std::task::Context<'_>; - let mut _16: &mut impl std::future::Future; - let mut _17: std::pin::Pin<&mut impl std::future::Future>; - let mut _18: isize; + let mut _9: std::task::Poll<()>; + let mut _10: &mut std::task::Context<'_>; + let mut _11: &mut impl std::future::Future; + let mut _12: std::pin::Pin<&mut impl std::future::Future>; + let mut _13: isize; + let mut _14: &mut std::task::Context<'_>; + let mut _15: &mut impl std::future::Future; + let mut _16: std::pin::Pin<&mut impl std::future::Future>; + let mut _17: isize; + let mut _18: (); let mut _19: u32; + let mut _20: &mut {async fn body of a()}; scope 1 { - debug x => (((*(_1.0: &mut {async fn body of a()})) as variant#4).0: T); + debug x => (((*_20) as variant#4).0: T); } bb0: { - _19 = discriminant((*(_1.0: &mut {async fn body of a()}))); - switchInt(move _19) -> [0: bb9, 3: bb12, 4: bb13, otherwise: bb14]; + _20 = deref_copy (_1.0: &mut {async fn body of a()}); + _19 = discriminant((*_20)); + switchInt(move _19) -> [0: bb8, 3: bb11, 4: bb12, otherwise: bb13]; } bb1: { nop; nop; - goto -> bb2; + _0 = Poll::<()>::Ready(const ()); + return; } bb2: { - _0 = Poll::<()>::Ready(const ()); + _0 = Poll::<()>::Pending; + discriminant((*_20)) = 4; return; } bb3: { - _0 = Poll::<()>::Pending; - discriminant((*(_1.0: &mut {async fn body of a()}))) = 4; - return; + StorageLive(_16); + _15 = &mut (((*_20) as variant#4).1: impl std::future::Future); + _16 = Pin::<&mut impl Future>::new_unchecked(move _15) -> [return: bb6, unwind unreachable]; } bb4: { - StorageLive(_17); - _16 = &mut (((*(_1.0: &mut {async fn body of a()})) as variant#4).1: impl std::future::Future); - _17 = Pin::<&mut impl Future>::new_unchecked(move _16) -> [return: bb7, unwind unreachable]; + unreachable; } bb5: { - unreachable; + StorageDead(_16); + _17 = discriminant(_9); + switchInt(move _17) -> [0: bb1, 1: bb2, otherwise: bb4]; } bb6: { - StorageDead(_17); - _18 = discriminant(_10); - switchInt(move _18) -> [0: bb1, 1: bb3, otherwise: bb5]; + _9 = as Future>::poll(move _16, move _14) -> [return: bb5, unwind unreachable]; } bb7: { - _10 = as Future>::poll(move _17, move _15) -> [return: bb6, unwind unreachable]; + _0 = Poll::<()>::Ready(const ()); + return; } bb8: { - _0 = Poll::<()>::Ready(const ()); - return; + goto -> bb10; } bb9: { - goto -> bb11; + goto -> bb7; } bb10: { - goto -> bb8; + drop(((*_20).0: T)) -> [return: bb9, unwind unreachable]; } bb11: { - drop(((*(_1.0: &mut {async fn body of a()})).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 796e95ff3d825..e4f35ea172ac5 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 @@ -2,7 +2,7 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> Poll<()> { debug _task_context => _2; - debug x => ((*(_1.0: &mut {async fn body of a()})).0: T); + debug x => ((*_20).0: T); let mut _0: std::task::Poll<()>; let _3: T; let mut _4: impl std::future::Future; @@ -10,112 +10,100 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) let mut _6: std::pin::Pin<&mut T>; let mut _7: &mut T; let mut _8: *mut T; - let mut _9: (); - let mut _10: std::task::Poll<()>; - let mut _11: &mut std::task::Context<'_>; - let mut _12: &mut impl std::future::Future; - let mut _13: std::pin::Pin<&mut impl std::future::Future>; - let mut _14: isize; - let mut _15: &mut std::task::Context<'_>; - let mut _16: &mut impl std::future::Future; - let mut _17: std::pin::Pin<&mut impl std::future::Future>; - let mut _18: isize; + let mut _9: std::task::Poll<()>; + let mut _10: &mut std::task::Context<'_>; + let mut _11: &mut impl std::future::Future; + let mut _12: std::pin::Pin<&mut impl std::future::Future>; + let mut _13: isize; + let mut _14: &mut std::task::Context<'_>; + let mut _15: &mut impl std::future::Future; + let mut _16: std::pin::Pin<&mut impl std::future::Future>; + let mut _17: isize; + let mut _18: (); let mut _19: u32; + let mut _20: &mut {async fn body of a()}; scope 1 { - debug x => (((*(_1.0: &mut {async fn body of a()})) as variant#4).0: T); + debug x => (((*_20) as variant#4).0: T); } bb0: { - _19 = discriminant((*(_1.0: &mut {async fn body of a()}))); - switchInt(move _19) -> [0: bb12, 2: bb18, 3: bb16, 4: bb17, otherwise: bb19]; + _20 = deref_copy (_1.0: &mut {async fn body of a()}); + _19 = discriminant((*_20)); + switchInt(move _19) -> [0: bb8, 2: bb15, 3: bb13, 4: bb14, otherwise: bb16]; } bb1: { nop; nop; - goto -> bb2; + _0 = Poll::<()>::Ready(const ()); + return; } bb2: { - _0 = Poll::<()>::Ready(const ()); + _0 = Poll::<()>::Pending; + discriminant((*_20)) = 4; return; } - bb3 (cleanup): { - nop; - nop; - goto -> bb5; + bb3: { + StorageLive(_16); + _15 = &mut (((*_20) as variant#4).1: impl std::future::Future); + _16 = Pin::<&mut impl Future>::new_unchecked(move _15) -> [return: bb6, unwind: bb12]; } - bb4 (cleanup): { - goto -> bb15; + bb4: { + unreachable; } - bb5 (cleanup): { - goto -> bb4; + bb5: { + StorageDead(_16); + _17 = discriminant(_9); + switchInt(move _17) -> [0: bb1, 1: bb2, otherwise: bb4]; } bb6: { - _0 = Poll::<()>::Pending; - discriminant((*(_1.0: &mut {async fn body of a()}))) = 4; - return; + _9 = as Future>::poll(move _16, move _14) -> [return: bb5, unwind: bb12]; } bb7: { - StorageLive(_17); - _16 = &mut (((*(_1.0: &mut {async fn body of a()})) as variant#4).1: impl std::future::Future); - _17 = Pin::<&mut impl Future>::new_unchecked(move _16) -> [return: bb10, unwind: bb15]; + _0 = Poll::<()>::Ready(const ()); + return; } bb8: { - unreachable; + goto -> bb11; } - bb9: { - StorageDead(_17); - _18 = discriminant(_10); - switchInt(move _18) -> [0: bb1, 1: bb6, otherwise: bb8]; + bb9 (cleanup): { + goto -> bb12; } bb10: { - _10 = as Future>::poll(move _17, move _15) -> [return: bb9, unwind: bb3]; + goto -> bb7; } bb11: { - _0 = Poll::<()>::Ready(const ()); - return; + drop(((*_20).0: T)) -> [return: bb10, unwind: bb9]; } - bb12: { - goto -> bb14; + bb12 (cleanup): { + discriminant((*_20)) = 2; + resume; } bb13: { - goto -> bb11; + goto -> bb3; } bb14: { - drop(((*(_1.0: &mut {async fn body of a()})).0: T)) -> [return: bb13, unwind: bb4]; + goto -> bb3; } - bb15 (cleanup): { - discriminant((*(_1.0: &mut {async fn body of a()}))) = 2; - resume; + bb15: { + assert(const false, "`async fn` resumed after panicking") -> [success: bb15, unwind continue]; } bb16: { - goto -> bb7; - } - - bb17: { - goto -> bb7; - } - - bb18: { - assert(const false, "`async fn` resumed after panicking") -> [success: bb18, unwind continue]; - } - - bb19: { _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 2e2876cb3fcf2..5ff9fc6a54a34 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 @@ -14,32 +14,54 @@ fn a::{closure#0}(_1: Pin<&mut {async fn body of a()}>, _2: &mut Context<'_>) -> let mut _0: std::task::Poll<()>; let mut _3: (); let mut _4: u32; + let mut _5: &mut {async fn body of a()}; bb0: { - _4 = discriminant((*(_1.0: &mut {async fn body of a()}))); - switchInt(move _4) -> [0: bb1, 1: bb4, otherwise: bb5]; + _5 = deref_copy (_1.0: &mut {async fn body of a()}); + _4 = discriminant((*_5)); + switchInt(move _4) -> [0: bb1, 1: bb9, otherwise: bb10]; } bb1: { _3 = const (); - goto -> bb3; + goto -> bb6; } bb2: { _0 = Poll::<()>::Ready(move _3); - discriminant((*(_1.0: &mut {async fn body of a()}))) = 1; + discriminant((*_5)) = 1; return; } 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 20fc4112ef288..0d69b1a474d9e 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 @@ -86,15 +86,16 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> let mut _36: (); let mut _37: (); let mut _38: u32; + let mut _39: &mut {async fn body of b()}; scope 1 { - debug __awaitee => (((*(_1.0: &mut {async fn body of b()})) as variant#3).0: {async fn body of a()}); + debug __awaitee => (((*_39) as variant#3).0: {async fn body of a()}); let _17: (); scope 2 { debug result => _17; } } scope 3 { - debug __awaitee => (((*(_1.0: &mut {async fn body of b()})) as variant#4).0: {async fn body of a()}); + debug __awaitee => (((*_39) as variant#4).0: {async fn body of a()}); let _33: (); scope 4 { debug result => _33; @@ -102,8 +103,9 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> } bb0: { - _38 = discriminant((*(_1.0: &mut {async fn body of b()}))); - switchInt(move _38) -> [0: bb1, 1: bb29, 3: bb27, 4: bb28, otherwise: bb8]; + _39 = deref_copy (_1.0: &mut {async fn body of b()}); + _38 = discriminant((*_39)); + switchInt(move _38) -> [0: bb1, 1: bb39, 3: bb37, 4: bb38, otherwise: bb40]; } bb1: { @@ -119,9 +121,8 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> bb3: { StorageDead(_5); - PlaceMention(_4); nop; - (((*(_1.0: &mut {async fn body of b()})) as variant#3).0: {async fn body of a()}) = move _4; + (((*_39) as variant#3).0: {async fn body of a()}) = move _4; goto -> bb4; } @@ -131,7 +132,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> StorageLive(_10); StorageLive(_11); StorageLive(_12); - _12 = &mut (((*(_1.0: &mut {async fn body of b()})) as variant#3).0: {async fn body of a()}); + _12 = &mut (((*_39) as variant#3).0: {async fn body of a()}); _11 = &mut (*_12); _10 = Pin::<&mut {async fn body of a()}>::new_unchecked(move _11) -> [return: bb5, unwind unreachable]; } @@ -155,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]; } @@ -178,7 +178,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> StorageDead(_4); StorageDead(_19); StorageDead(_20); - discriminant((*(_1.0: &mut {async fn body of b()}))) = 3; + discriminant((*_39)) = 3; return; } @@ -191,7 +191,7 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> StorageDead(_12); StorageDead(_9); StorageDead(_8); - drop((((*(_1.0: &mut {async fn body of b()})) as variant#3).0: {async fn body of a()})) -> [return: bb12, unwind unreachable]; + drop((((*_39) as variant#3).0: {async fn body of a()})) -> [return: bb12, unwind unreachable]; } bb11: { @@ -204,65 +204,59 @@ 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; - (((*(_1.0: &mut {async fn body of b()})) as variant#4).0: {async fn body of a()}) = move _21; - goto -> bb16; + (((*_39) as variant#4).0: {async fn body of a()}) = move _21; + goto -> bb15; } - bb16: { + bb15: { StorageLive(_24); StorageLive(_25); StorageLive(_26); StorageLive(_27); StorageLive(_28); - _28 = &mut (((*(_1.0: &mut {async fn body of b()})) as variant#4).0: {async fn body of a()}); + _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); @@ -275,11 +269,11 @@ fn b::{closure#0}(_1: Pin<&mut {async fn body of b()}>, _2: &mut Context<'_>) -> StorageDead(_21); StorageDead(_35); StorageDead(_36); - discriminant((*(_1.0: &mut {async fn body of b()}))) = 4; + discriminant((*_39)) = 4; return; } - bb21: { + bb20: { StorageLive(_33); _33 = copy ((_25 as Ready).0: ()); _37 = copy _33; @@ -288,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((((*(_1.0: &mut {async fn body of b()})) 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; + StorageDead(_21); + goto -> bb33; + } + + bb23: { + _0 = Poll::<()>::Ready(move _37); + discriminant((*_39)) = 1; + return; } bb24: { - StorageDead(_21); - goto -> bb26; + StorageDead(_36); + StorageDead(_35); + drop((((*_39) as variant#4).0: {async fn body of a()})) -> [return: bb25, unwind unreachable]; } bb25: { - _0 = Poll::<()>::Ready(move _37); - discriminant((*(_1.0: &mut {async fn body of b()}))) = 1; - return; + 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); @@ -328,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 d8fdb446135b3..6a7b69c19ea03 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 @@ -23,7 +23,7 @@ } */ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2: String) -> CoroutineState<(&str, String, &Location<'_>), ()> { - debug arg => (((*(_1.0: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18})) as variant#4).0: std::string::String); + debug arg => (((*_18) as variant#4).0: std::string::String); let mut _0: std::ops::CoroutineState<(&str, std::string::String, &std::panic::Location<'_>), ()>; let _3: std::string::String; let mut _4: (&str, std::string::String, &std::panic::Location<'_>); @@ -41,29 +41,20 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2 let mut _16: (); let mut _17: u32; let mut _18: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}; - let mut _19: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}; - let mut _20: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}; - let mut _21: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}; - let mut _22: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}; - let mut _23: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}; - let mut _24: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}; - let mut _25: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}; bb0: { _18 = deref_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: { - _19 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}); - (((*_19) as variant#4).0: std::string::String) = move _2; + (((*_18) as variant#4).0: std::string::String) = move _2; StorageLive(_3); StorageLive(_4); StorageLive(_5); StorageLive(_6); - _20 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}); - _6 = &(((*_20) as variant#4).0: std::string::String); + _6 = &(((*_18) as variant#4).0: std::string::String); _5 = ::clone(move _6) -> [return: bb2, unwind unreachable]; } @@ -76,29 +67,15 @@ 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); StorageDead(_4); - _21 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}); - discriminant((*_21)) = 3; + discriminant((*_18)) = 3; return; } - bb5: { - goto -> bb6; - } - - bb6: { - StorageDead(_4); - drop(_3) -> [return: bb7, unwind unreachable]; - } - - bb7: { + bb4: { StorageDead(_3); StorageLive(_8); StorageLive(_9); @@ -108,26 +85,21 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2 _10 = &(*_11); StorageLive(_12); StorageLive(_13); - _22 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}); - _13 = &(((*_22) as variant#4).0: std::string::String); - _12 = ::clone(move _13) -> [return: bb8, unwind unreachable]; + _13 = &(((*_18) as variant#4).0: std::string::String); + _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); @@ -135,65 +107,47 @@ fn main::{closure#0}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}>, _2 StorageDead(_9); StorageDead(_11); StorageDead(_15); - _23 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}); - discriminant((*_23)) = 4; + discriminant((*_18)) = 4; return; } - bb11: { - goto -> bb12; - } - - bb12: { - StorageDead(_9); - drop(_8) -> [return: bb13, unwind unreachable]; - } - - bb13: { + bb7: { StorageDead(_15); StorageDead(_11); StorageDead(_8); _16 = const (); - _24 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}); - drop((((*_24) 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); - _25 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:18:5: 18:18}); - discriminant((*_25)) = 1; + 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 dd17afad656b8..24cd27afc68e6 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 @@ -23,7 +23,7 @@ } */ fn main::{closure#1}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}>, _2: String) -> CoroutineState<(&str, String, &Location<'_>), ()> { - debug arg => (((*(_1.0: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18})) as variant#4).0: std::string::String); + debug arg => (((*_18) as variant#4).0: std::string::String); let mut _0: std::ops::CoroutineState<(&str, std::string::String, &std::panic::Location<'_>), ()>; let _3: std::string::String; let mut _4: (&str, std::string::String, &std::panic::Location<'_>); @@ -41,29 +41,20 @@ fn main::{closure#1}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}>, _2 let mut _16: (); let mut _17: u32; let mut _18: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}; - let mut _19: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}; - let mut _20: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}; - let mut _21: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}; - let mut _22: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}; - let mut _23: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}; - let mut _24: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}; - let mut _25: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}; bb0: { _18 = deref_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: { - _19 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}); - (((*_19) as variant#4).0: std::string::String) = move _2; + (((*_18) as variant#4).0: std::string::String) = move _2; StorageLive(_3); StorageLive(_4); StorageLive(_5); StorageLive(_6); - _20 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}); - _6 = &(((*_20) as variant#4).0: std::string::String); + _6 = &(((*_18) as variant#4).0: std::string::String); _5 = ::clone(move _6) -> [return: bb2, unwind unreachable]; } @@ -76,29 +67,15 @@ 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); StorageDead(_4); - _21 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}); - discriminant((*_21)) = 3; + discriminant((*_18)) = 3; return; } - bb5: { - goto -> bb6; - } - - bb6: { - StorageDead(_4); - drop(_3) -> [return: bb7, unwind unreachable]; - } - - bb7: { + bb4: { StorageDead(_3); StorageLive(_8); StorageLive(_9); @@ -108,26 +85,21 @@ fn main::{closure#1}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}>, _2 _10 = &(*_11); StorageLive(_12); StorageLive(_13); - _22 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}); - _13 = &(((*_22) as variant#4).0: std::string::String); - _12 = ::clone(move _13) -> [return: bb8, unwind unreachable]; + _13 = &(((*_18) as variant#4).0: std::string::String); + _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); @@ -135,65 +107,47 @@ fn main::{closure#1}(_1: Pin<&mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}>, _2 StorageDead(_9); StorageDead(_11); StorageDead(_15); - _23 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}); - discriminant((*_23)) = 4; + discriminant((*_18)) = 4; return; } - bb11: { - goto -> bb12; - } - - bb12: { - StorageDead(_9); - drop(_8) -> [return: bb13, unwind unreachable]; - } - - bb13: { + bb7: { StorageDead(_15); StorageDead(_11); StorageDead(_8); _16 = const (); - _24 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}); - drop((((*_24) 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); - _25 = deref_copy (_1.0: &mut {coroutine@$DIR/coroutine.rs:25:5: 25:18}); - discriminant((*_25)) = 1; + 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 9905cc3e00f99..9bec86cc291be 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,63 +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 _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 => (((*(_1.0: &mut {coroutine@$DIR/coroutine_tiny.rs:21:5: 21:13})) as variant#3).0: HasDrop); + debug _d => (((*_8) as variant#3).0: HasDrop); } bb0: { - _10 = discriminant((*(_1.0: &mut {coroutine@$DIR/coroutine_tiny.rs:21:5: 21:13}))); - switchInt(move _10) -> [0: bb1, 3: bb5, otherwise: bb6]; + _8 = deref_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; - (((*(_1.0: &mut {coroutine@$DIR/coroutine_tiny.rs:21:5: 21:13})) 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((*(_1.0: &mut {coroutine@$DIR/coroutine_tiny.rs:21:5: 21:13}))) = 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..6ee85c18a5e24 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,7 +40,8 @@ + _5 = const false; + StorageLive(_6); + StorageLive(_7); -+ _6 = copy (_2.0: &mut {coroutine@$DIR/inline_coroutine.rs:20:5: 20:8}); ++ StorageLive(_9); ++ _6 = deref_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..fcf140c32768c 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,7 +40,8 @@ + _5 = const false; + StorageLive(_6); + StorageLive(_7); -+ _6 = copy (_2.0: &mut {coroutine@$DIR/inline_coroutine.rs:20:5: 20:8}); ++ StorageLive(_9); ++ _6 = deref_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/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-abort.diff b/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-abort.diff index 2ae86e2eb8bbd..ff06ee9fce318 100644 --- a/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-abort.diff +++ b/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-abort.diff @@ -41,13 +41,6 @@ + let mut _30: (); + let mut _31: u32; + let mut _32: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _33: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _34: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _35: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _36: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _37: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _38: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _39: &mut {async fn body of ActionPermit<'_, T>::perform()}; + scope 7 { + let mut _15: std::future::Ready<()>; + scope 8 { @@ -57,14 +50,14 @@ + scope 12 (inlined Pin::<&mut std::future::Ready<()>>::new_unchecked) { + } + scope 13 (inlined as Future>::poll) { -+ let mut _41: (); -+ let mut _42: std::option::Option<()>; -+ let mut _43: &mut std::option::Option<()>; -+ let mut _44: &mut std::future::Ready<()>; -+ let mut _45: &mut std::pin::Pin<&mut std::future::Ready<()>>; ++ let mut _34: (); ++ let mut _35: std::option::Option<()>; ++ let mut _36: &mut std::option::Option<()>; ++ let mut _37: &mut std::future::Ready<()>; ++ let mut _38: &mut std::pin::Pin<&mut std::future::Ready<()>>; + scope 14 (inlined > as DerefMut>::deref_mut) { + scope 15 (inlined Pin::<&mut std::future::Ready<()>>::as_mut) { -+ let mut _46: &mut &mut std::future::Ready<()>; ++ let mut _39: &mut &mut std::future::Ready<()>; + scope 16 (inlined Pin::<&mut std::future::Ready<()>>::new_unchecked) { + } + scope 18 (inlined <&mut std::future::Ready<()> as DerefMut>::deref_mut) { @@ -74,22 +67,22 @@ + } + } + scope 19 (inlined Option::<()>::take) { -+ let mut _47: std::option::Option<()>; ++ let mut _40: std::option::Option<()>; + scope 20 (inlined std::mem::replace::>) { + scope 21 { + } + } + } + scope 22 (inlined #[track_caller] Option::<()>::expect) { -+ let mut _48: isize; -+ let mut _49: !; ++ let mut _41: isize; ++ let mut _42: !; + scope 23 { + } + } + } + } + scope 10 (inlined ready::<()>) { -+ let mut _40: std::option::Option<()>; ++ let mut _33: std::option::Option<()>; + } + scope 11 (inlined as IntoFuture>::into_future) { + } @@ -137,13 +130,6 @@ + StorageLive(_30); + StorageLive(_31); + StorageLive(_32); -+ StorageLive(_33); -+ StorageLive(_34); -+ StorageLive(_35); -+ StorageLive(_36); -+ StorageLive(_37); -+ StorageLive(_38); -+ StorageLive(_39); + _32 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); + _31 = discriminant((*_32)); + switchInt(move _31) -> [0: bb3, 1: bb10, 3: bb9, otherwise: bb5]; @@ -156,13 +142,6 @@ + } + + bb2: { -+ StorageDead(_39); -+ StorageDead(_38); -+ StorageDead(_37); -+ StorageDead(_36); -+ StorageDead(_35); -+ StorageDead(_34); -+ StorageDead(_33); + StorageDead(_32); + StorageDead(_31); + StorageDead(_30); @@ -183,22 +162,19 @@ } + bb3: { -+ _33 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ _34 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ (((*_33) as variant#3).0: ActionPermit<'_, T>) = move ((*_34).0: ActionPermit<'_, T>); ++ (((*_32) as variant#3).0: ActionPermit<'_, T>) = move ((*_32).0: ActionPermit<'_, T>); + StorageLive(_12); + StorageLive(_13); + StorageLive(_14); + _14 = (); -+ StorageLive(_40); -+ _40 = Option::<()>::Some(copy _14); -+ _13 = std::future::Ready::<()>(move _40); -+ StorageDead(_40); ++ StorageLive(_33); ++ _33 = Option::<()>::Some(copy _14); ++ _13 = std::future::Ready::<()>(move _33); ++ StorageDead(_33); + StorageDead(_14); + _12 = move _13; + StorageDead(_13); -+ _35 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ (((*_35) as variant#3).1: std::future::Ready<()>) = move _12; ++ (((*_32) as variant#3).1: std::future::Ready<()>) = move _12; + goto -> bb4; + } + @@ -210,8 +186,7 @@ + StorageLive(_19); + StorageLive(_20); + StorageLive(_21); -+ _36 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ _21 = &mut (((*_36) as variant#3).1: std::future::Ready<()>); ++ _21 = &mut (((*_32) as variant#3).1: std::future::Ready<()>); + _20 = &mut (*_21); + _19 = Pin::<&mut std::future::Ready<()>> { pointer: copy _20 }; + StorageDead(_20); @@ -222,27 +197,27 @@ + _23 = move _24; + _22 = &mut (*_23); + StorageDead(_24); -+ StorageLive(_44); -+ StorageLive(_45); -+ StorageLive(_49); -+ StorageLive(_41); ++ StorageLive(_37); ++ StorageLive(_38); + StorageLive(_42); -+ StorageLive(_43); -+ _45 = &mut _19; -+ StorageLive(_46); -+ _46 = &mut (_19.0: &mut std::future::Ready<()>); -+ _44 = copy (_19.0: &mut std::future::Ready<()>); -+ StorageDead(_46); -+ _43 = &mut ((*_44).0: std::option::Option<()>); -+ StorageLive(_47); -+ _47 = Option::<()>::None; -+ _42 = copy ((*_44).0: std::option::Option<()>); -+ ((*_44).0: std::option::Option<()>) = copy _47; -+ StorageDead(_47); -+ StorageDead(_43); -+ StorageLive(_48); -+ _48 = discriminant(_42); -+ switchInt(move _48) -> [0: bb11, 1: bb12, otherwise: bb5]; ++ StorageLive(_34); ++ StorageLive(_35); ++ StorageLive(_36); ++ _38 = &mut _19; ++ StorageLive(_39); ++ _39 = &mut (_19.0: &mut std::future::Ready<()>); ++ _37 = copy (_19.0: &mut std::future::Ready<()>); ++ StorageDead(_39); ++ _36 = &mut ((*_37).0: std::option::Option<()>); ++ StorageLive(_40); ++ _40 = Option::<()>::None; ++ _35 = copy ((*_37).0: std::option::Option<()>); ++ ((*_37).0: std::option::Option<()>) = copy _40; ++ StorageDead(_40); ++ StorageDead(_36); ++ StorageLive(_41); ++ _41 = discriminant(_35); ++ switchInt(move _41) -> [0: bb11, 1: bb12, otherwise: bb5]; } + + bb5: { @@ -262,8 +237,7 @@ + StorageDead(_12); + StorageDead(_28); + StorageDead(_29); -+ _37 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ discriminant((*_37)) = 3; ++ discriminant((*_32)) = 3; + goto -> bb2; + } + @@ -277,14 +251,12 @@ + StorageDead(_18); + StorageDead(_17); + StorageDead(_12); -+ _38 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ drop((((*_38) as variant#3).0: ActionPermit<'_, T>)) -> [return: bb8, unwind unreachable]; ++ drop((((*_32) as variant#3).0: ActionPermit<'_, T>)) -> [return: bb8, unwind unreachable]; + } + + bb8: { + _7 = Poll::<()>::Ready(move _30); -+ _39 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ discriminant((*_39)) = 1; ++ discriminant((*_32)) = 1; + goto -> bb2; + } + @@ -305,18 +277,18 @@ + } + + bb11: { -+ _49 = option::expect_failed(const "`Ready` polled after completion") -> unwind unreachable; ++ _42 = option::expect_failed(const "`Ready` polled after completion") -> unwind unreachable; + } + + bb12: { -+ _41 = move ((_42 as Some).0: ()); -+ StorageDead(_48); -+ StorageDead(_42); -+ _18 = Poll::<()>::Ready(move _41); ++ _34 = move ((_35 as Some).0: ()); + StorageDead(_41); -+ StorageDead(_49); -+ StorageDead(_45); -+ StorageDead(_44); ++ StorageDead(_35); ++ _18 = Poll::<()>::Ready(move _34); ++ StorageDead(_34); ++ StorageDead(_42); ++ StorageDead(_38); ++ StorageDead(_37); + StorageDead(_22); + StorageDead(_19); + _25 = discriminant(_18); diff --git a/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-unwind.diff b/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-unwind.diff index d7ae931aaae58..ff85fb106d32d 100644 --- a/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-unwind.diff +++ b/tests/mir-opt/inline_coroutine_body.run2-{closure#0}.Inline.panic-unwind.diff @@ -41,15 +41,6 @@ + let mut _30: (); + let mut _31: u32; + let mut _32: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _33: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _34: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _35: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _36: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _37: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _38: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _39: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _40: &mut {async fn body of ActionPermit<'_, T>::perform()}; -+ let mut _41: &mut {async fn body of ActionPermit<'_, T>::perform()}; + scope 7 { + let mut _15: std::future::Ready<()>; + scope 8 { @@ -59,14 +50,14 @@ + scope 12 (inlined Pin::<&mut std::future::Ready<()>>::new_unchecked) { + } + scope 13 (inlined as Future>::poll) { -+ let mut _43: (); -+ let mut _44: std::option::Option<()>; -+ let mut _45: &mut std::option::Option<()>; -+ let mut _46: &mut std::future::Ready<()>; -+ let mut _47: &mut std::pin::Pin<&mut std::future::Ready<()>>; ++ let mut _34: (); ++ let mut _35: std::option::Option<()>; ++ let mut _36: &mut std::option::Option<()>; ++ let mut _37: &mut std::future::Ready<()>; ++ let mut _38: &mut std::pin::Pin<&mut std::future::Ready<()>>; + scope 14 (inlined > as DerefMut>::deref_mut) { + scope 15 (inlined Pin::<&mut std::future::Ready<()>>::as_mut) { -+ let mut _48: &mut &mut std::future::Ready<()>; ++ let mut _39: &mut &mut std::future::Ready<()>; + scope 16 (inlined Pin::<&mut std::future::Ready<()>>::new_unchecked) { + } + scope 18 (inlined <&mut std::future::Ready<()> as DerefMut>::deref_mut) { @@ -76,22 +67,22 @@ + } + } + scope 19 (inlined Option::<()>::take) { -+ let mut _49: std::option::Option<()>; ++ let mut _40: std::option::Option<()>; + scope 20 (inlined std::mem::replace::>) { + scope 21 { + } + } + } + scope 22 (inlined #[track_caller] Option::<()>::expect) { -+ let mut _50: isize; -+ let mut _51: !; ++ let mut _41: isize; ++ let mut _42: !; + scope 23 { + } + } + } + } + scope 10 (inlined ready::<()>) { -+ let mut _42: std::option::Option<()>; ++ let mut _33: std::option::Option<()>; + } + scope 11 (inlined as IntoFuture>::into_future) { + } @@ -139,15 +130,6 @@ + StorageLive(_30); + StorageLive(_31); + StorageLive(_32); -+ StorageLive(_33); -+ StorageLive(_34); -+ StorageLive(_35); -+ StorageLive(_36); -+ StorageLive(_37); -+ StorageLive(_38); -+ StorageLive(_39); -+ StorageLive(_40); -+ StorageLive(_41); + _32 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); + _31 = discriminant((*_32)); + switchInt(move _31) -> [0: bb5, 1: bb15, 2: bb14, 3: bb13, otherwise: bb7]; @@ -168,15 +150,6 @@ + } + + bb4: { -+ StorageDead(_41); -+ StorageDead(_40); -+ StorageDead(_39); -+ StorageDead(_38); -+ StorageDead(_37); -+ StorageDead(_36); -+ StorageDead(_35); -+ StorageDead(_34); -+ StorageDead(_33); + StorageDead(_32); + StorageDead(_31); + StorageDead(_30); @@ -200,22 +173,19 @@ - StorageDead(_2); - return; + bb5: { -+ _33 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ _34 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ (((*_33) as variant#3).0: ActionPermit<'_, T>) = move ((*_34).0: ActionPermit<'_, T>); ++ (((*_32) as variant#3).0: ActionPermit<'_, T>) = move ((*_32).0: ActionPermit<'_, T>); + StorageLive(_12); + StorageLive(_13); + StorageLive(_14); + _14 = (); -+ StorageLive(_42); -+ _42 = Option::<()>::Some(copy _14); -+ _13 = std::future::Ready::<()>(move _42); -+ StorageDead(_42); ++ StorageLive(_33); ++ _33 = Option::<()>::Some(copy _14); ++ _13 = std::future::Ready::<()>(move _33); ++ StorageDead(_33); + StorageDead(_14); + _12 = move _13; + StorageDead(_13); -+ _35 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ (((*_35) as variant#3).1: std::future::Ready<()>) = move _12; ++ (((*_32) as variant#3).1: std::future::Ready<()>) = move _12; + goto -> bb6; } @@ -227,8 +197,7 @@ + StorageLive(_19); + StorageLive(_20); + StorageLive(_21); -+ _36 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ _21 = &mut (((*_36) as variant#3).1: std::future::Ready<()>); ++ _21 = &mut (((*_32) as variant#3).1: std::future::Ready<()>); + _20 = &mut (*_21); + _19 = Pin::<&mut std::future::Ready<()>> { pointer: copy _20 }; + StorageDead(_20); @@ -239,27 +208,27 @@ + _23 = move _24; + _22 = &mut (*_23); + StorageDead(_24); -+ StorageLive(_46); -+ StorageLive(_47); -+ StorageLive(_51); -+ StorageLive(_43); -+ StorageLive(_44); -+ StorageLive(_45); -+ _47 = &mut _19; -+ StorageLive(_48); -+ _48 = &mut (_19.0: &mut std::future::Ready<()>); -+ _46 = copy (_19.0: &mut std::future::Ready<()>); -+ StorageDead(_48); -+ _45 = &mut ((*_46).0: std::option::Option<()>); -+ StorageLive(_49); -+ _49 = Option::<()>::None; -+ _44 = copy ((*_46).0: std::option::Option<()>); -+ ((*_46).0: std::option::Option<()>) = copy _49; -+ StorageDead(_49); -+ StorageDead(_45); -+ StorageLive(_50); -+ _50 = discriminant(_44); -+ switchInt(move _50) -> [0: bb16, 1: bb17, otherwise: bb7]; ++ StorageLive(_37); ++ StorageLive(_38); ++ StorageLive(_42); ++ StorageLive(_34); ++ StorageLive(_35); ++ StorageLive(_36); ++ _38 = &mut _19; ++ StorageLive(_39); ++ _39 = &mut (_19.0: &mut std::future::Ready<()>); ++ _37 = copy (_19.0: &mut std::future::Ready<()>); ++ StorageDead(_39); ++ _36 = &mut ((*_37).0: std::option::Option<()>); ++ StorageLive(_40); ++ _40 = Option::<()>::None; ++ _35 = copy ((*_37).0: std::option::Option<()>); ++ ((*_37).0: std::option::Option<()>) = copy _40; ++ StorageDead(_40); ++ StorageDead(_36); ++ StorageLive(_41); ++ _41 = discriminant(_35); ++ switchInt(move _41) -> [0: bb16, 1: bb17, otherwise: bb7]; } - bb6 (cleanup): { @@ -281,8 +250,7 @@ + StorageDead(_12); + StorageDead(_28); + StorageDead(_29); -+ _37 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ discriminant((*_37)) = 3; ++ discriminant((*_32)) = 3; + goto -> bb4; + } + @@ -296,14 +264,12 @@ + StorageDead(_18); + StorageDead(_17); + StorageDead(_12); -+ _38 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ drop((((*_38) as variant#3).0: ActionPermit<'_, T>)) -> [return: bb10, unwind: bb12]; ++ drop((((*_32) as variant#3).0: ActionPermit<'_, T>)) -> [return: bb10, unwind: bb12]; + } + + bb10: { + _7 = Poll::<()>::Ready(move _30); -+ _39 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ discriminant((*_39)) = 1; ++ discriminant((*_32)) = 1; + goto -> bb4; + } + @@ -315,13 +281,11 @@ + StorageDead(_18); + StorageDead(_17); + StorageDead(_12); -+ _40 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ drop((((*_40) as variant#3).0: ActionPermit<'_, T>)) -> [return: bb12, unwind terminate(cleanup)]; ++ drop((((*_32) as variant#3).0: ActionPermit<'_, T>)) -> [return: bb12, unwind terminate(cleanup)]; + } + + bb12 (cleanup): { -+ _41 = deref_copy (_8.0: &mut {async fn body of ActionPermit<'_, T>::perform()}); -+ discriminant((*_41)) = 2; ++ discriminant((*_32)) = 2; + goto -> bb2; + } + @@ -346,18 +310,18 @@ + } + + bb16: { -+ _51 = option::expect_failed(const "`Ready` polled after completion") -> bb11; ++ _42 = option::expect_failed(const "`Ready` polled after completion") -> bb11; + } + + bb17: { -+ _43 = move ((_44 as Some).0: ()); -+ StorageDead(_50); -+ StorageDead(_44); -+ _18 = Poll::<()>::Ready(move _43); -+ StorageDead(_43); -+ StorageDead(_51); -+ StorageDead(_47); -+ StorageDead(_46); ++ _34 = move ((_35 as Some).0: ()); ++ StorageDead(_41); ++ StorageDead(_35); ++ _18 = Poll::<()>::Ready(move _34); ++ StorageDead(_34); ++ StorageDead(_42); ++ StorageDead(_38); ++ StorageDead(_37); + StorageDead(_22); + StorageDead(_19); + _25 = discriminant(_18); 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/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/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 diff --git a/tests/ui/rustc_public-ir-print/async-closure.stdout b/tests/ui/rustc_public-ir-print/async-closure.stdout index 5113dc5048b93..f5b5a26a06c6c 100644 --- a/tests/ui/rustc_public-ir-print/async-closure.stdout +++ b/tests/ui/rustc_public-ir-print/async-closure.stdout @@ -42,10 +42,8 @@ fn foo::{closure#0}::{closure#0}(_1: Pin<&mut {async closure body@$DIR/async-clo let mut _5: (); let mut _6: u32; let mut _7: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}; - let mut _8: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}; - let mut _9: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}; debug _task_context => _2; - debug y => (*((*(_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})).0: &i32)); + debug y => (*((*_7).0: &i32)); debug y => _3; bb0: { _7 = CopyForDeref((_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})); @@ -54,14 +52,12 @@ fn foo::{closure#0}::{closure#0}(_1: Pin<&mut {async closure body@$DIR/async-clo } bb1: { StorageLive(_3); - _8 = CopyForDeref((_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})); - _4 = CopyForDeref(((*_8).0: &i32)); + _4 = CopyForDeref(((*_7).0: &i32)); _3 = (*_4); _5 = (); StorageDead(_3); _0 = std::task::Poll::Ready(move _5); - _9 = CopyForDeref((_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})); - discriminant((*_9)) = 1; + discriminant((*_7)) = 1; return; } bb2: { @@ -78,10 +74,8 @@ fn foo::{closure#0}::{synthetic#0}(_1: Pin<&mut {async closure body@$DIR/async-c let mut _5: (); let mut _6: u32; let mut _7: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}; - let mut _8: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}; - let mut _9: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6}; debug _task_context => _2; - debug y => (*((*(_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})).0: &i32)); + debug y => (*((*_7).0: &i32)); debug y => _3; bb0: { _7 = CopyForDeref((_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})); @@ -90,14 +84,12 @@ fn foo::{closure#0}::{synthetic#0}(_1: Pin<&mut {async closure body@$DIR/async-c } bb1: { StorageLive(_3); - _8 = CopyForDeref((_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})); - _4 = CopyForDeref(((*_8).0: &i32)); + _4 = CopyForDeref(((*_7).0: &i32)); _3 = (*_4); _5 = (); StorageDead(_3); _0 = std::task::Poll::Ready(move _5); - _9 = CopyForDeref((_1.0: &mut {async closure body@$DIR/async-closure.rs:9:22: 11:6})); - discriminant((*_9)) = 1; + discriminant((*_7)) = 1; return; } bb2: {