@@ -15,6 +15,7 @@ use crate::mir::interpret::{
1515} ;
1616use crate :: mir:: visit:: Visitor ;
1717use crate :: mir:: * ;
18+ use crate :: ty:: CoroutineArgsExt ;
1819
1920const INDENT : & str = " " ;
2021/// Alignment for lining up comments following MIR statements
@@ -185,9 +186,6 @@ impl<'a, 'tcx> MirDumper<'a, 'tcx> {
185186 Some ( promoted) => write ! ( w, "::{promoted:?}`" ) ?,
186187 }
187188 writeln ! ( w, " {} {}" , self . disambiguator, self . pass_name) ?;
188- if let Some ( ref layout) = body. coroutine_layout_raw ( ) {
189- writeln ! ( w, "/* coroutine_layout = {layout:#?} */" ) ?;
190- }
191189 writeln ! ( w) ?;
192190 ( self . writer . extra_data ) ( PassWhere :: BeforeCFG , w) ?;
193191 write_user_type_annotations ( self . tcx ( ) , body, w) ?;
@@ -429,6 +427,31 @@ fn write_scope_tree(
429427 }
430428 }
431429
430+ // Coroutine debuginfo.
431+ if let Some ( layout) = body. coroutine_layout_raw ( ) {
432+ for ( field, name) in layout. field_names . iter_enumerated ( ) {
433+ if let Some ( name) = name
434+ && let source_info = layout. field_tys [ field] . source_info
435+ && source_info. scope == parent
436+ {
437+ let indented_debug_info =
438+ format ! ( "{0:1$}coroutine debug {2} => {3:?};" , INDENT , indent, name, field) ;
439+
440+ if options. include_extra_comments {
441+ writeln ! (
442+ w,
443+ "{0:1$} // in {2}" ,
444+ indented_debug_info,
445+ ALIGN ,
446+ comment( tcx, source_info) ,
447+ ) ?;
448+ } else {
449+ writeln ! ( w, "{indented_debug_info}" ) ?;
450+ }
451+ }
452+ }
453+ }
454+
432455 // Local variable types.
433456 for ( local, local_decl) in body. local_decls . iter_enumerated ( ) {
434457 if ( 1 ..body. arg_count + 1 ) . contains ( & local. index ( ) ) {
@@ -530,6 +553,50 @@ impl Debug for VarDebugInfo<'_> {
530553 }
531554}
532555
556+ fn write_coroutine_layout < ' tcx > (
557+ tcx : TyCtxt < ' tcx > ,
558+ layout : & CoroutineLayout < ' _ > ,
559+ w : & mut dyn io:: Write ,
560+ options : PrettyPrintMirOptions ,
561+ ) -> io:: Result < ( ) > {
562+ let CoroutineLayout {
563+ field_tys,
564+ field_names : _, // Dumped in scope tree with debug info.
565+ variant_fields,
566+ variant_source_info,
567+ storage_conflicts,
568+ } = layout;
569+
570+ writeln ! ( w, "{INDENT}coroutine layout {{" ) ?;
571+
572+ for ( field, CoroutineSavedTy { ty, source_info, ignore_for_traits } ) in
573+ field_tys. iter_enumerated ( )
574+ {
575+ let ignore_for_traits = if * ignore_for_traits { " (ignored for traits)" } else { "" } ;
576+ let indented_body = format ! ( "{INDENT}{INDENT}field {field:?}: {ty}{ignore_for_traits};" , ) ;
577+ if options. include_extra_comments {
578+ writeln ! ( w, "{0:ALIGN$} // in {1}" , indented_body, comment( tcx, * source_info) ) ?;
579+ } else {
580+ writeln ! ( w, "{}" , indented_body) ?;
581+ }
582+ }
583+
584+ writeln ! ( w, "{INDENT}{INDENT}variant_fields = {{" ) ?;
585+ for ( variant, fields) in variant_fields. iter_enumerated ( ) {
586+ let variant_name = ty:: CoroutineArgs :: variant_name ( variant) ;
587+ let header = format ! ( "{INDENT}{INDENT}{INDENT}{variant_name:9}({variant:?}): {fields:?}," ) ;
588+ if options. include_extra_comments {
589+ let source_info = variant_source_info[ variant] ;
590+ writeln ! ( w, "{0:ALIGN$} // in {1}" , header, comment( tcx, source_info) ) ?;
591+ } else {
592+ writeln ! ( w, "{}" , header) ?;
593+ }
594+ }
595+ writeln ! ( w, "{INDENT}{INDENT}}}" ) ?;
596+ writeln ! ( w, "{INDENT}{INDENT}storage_conflicts = {storage_conflicts:?}" ) ?;
597+ writeln ! ( w, "{INDENT}}}" )
598+ }
599+
533600/// Write out a human-readable textual representation of the MIR's `fn` type and the types of its
534601/// local variables (both user-defined bindings and compiler temporaries).
535602fn write_mir_intro < ' tcx > (
@@ -541,6 +608,10 @@ fn write_mir_intro<'tcx>(
541608 write_mir_sig ( tcx, body, w) ?;
542609 writeln ! ( w, "{{" ) ?;
543610
611+ if let Some ( ref layout) = body. coroutine_layout_raw ( ) {
612+ write_coroutine_layout ( tcx, layout, w, options) ?;
613+ }
614+
544615 // construct a scope tree and write it out
545616 let mut scope_tree: FxHashMap < SourceScope , Vec < SourceScope > > = Default :: default ( ) ;
546617 for ( index, scope_data) in body. source_scopes . iter_enumerated ( ) {
0 commit comments