@@ -646,14 +646,11 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
646646
647647 fn dump_alloc_helper < Tag , Extra > (
648648 & self ,
649- allocs_seen : & mut FxHashSet < AllocId > ,
650649 allocs_to_print : & mut VecDeque < AllocId > ,
651650 alloc : & Allocation < Tag , Extra > ,
652651 ) {
653652 for & ( _, target_id) in alloc. relocations ( ) . values ( ) {
654- if allocs_seen. insert ( target_id) {
655- allocs_to_print. push_back ( target_id) ;
656- }
653+ allocs_to_print. push_back ( target_id) ;
657654 }
658655 crate :: util:: pretty:: write_allocation ( self . tcx . tcx , alloc, & mut std:: io:: stderr ( ) , "" )
659656 . unwrap ( ) ;
@@ -666,9 +663,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
666663 allocs. sort ( ) ;
667664 allocs. dedup ( ) ;
668665 let mut allocs_to_print = VecDeque :: from ( allocs) ;
669- let mut allocs_seen = FxHashSet :: default ( ) ;
666+ // `allocs_printed` contains all allocations that we have already printed.
667+ let mut allocs_printed = FxHashSet :: default ( ) ;
670668
671669 while let Some ( id) = allocs_to_print. pop_front ( ) {
670+ if !allocs_printed. insert ( id) {
671+ // Already printed, so skip this.
672+ continue ;
673+ }
672674 eprint ! ( "Alloc {:<5}: " , id) ;
673675 fn msg < Tag , Extra > ( alloc : & Allocation < Tag , Extra > , extra : & str ) {
674676 eprintln ! (
@@ -688,14 +690,14 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
688690 MemoryKind :: CallerLocation => msg ( alloc, " (caller_location)" ) ,
689691 MemoryKind :: Machine ( m) => msg ( alloc, & format ! ( " ({:?})" , m) ) ,
690692 } ;
691- self . dump_alloc_helper ( & mut allocs_seen , & mut allocs_to_print, alloc) ;
693+ self . dump_alloc_helper ( & mut allocs_to_print, alloc) ;
692694 }
693695 Err ( ( ) ) => {
694696 // global alloc?
695697 match self . tcx . alloc_map . lock ( ) . get ( id) {
696698 Some ( GlobalAlloc :: Memory ( alloc) ) => {
697699 msg ( alloc, " (immutable)" ) ;
698- self . dump_alloc_helper ( & mut allocs_seen , & mut allocs_to_print, alloc) ;
700+ self . dump_alloc_helper ( & mut allocs_to_print, alloc) ;
699701 }
700702 Some ( GlobalAlloc :: Function ( func) ) => {
701703 eprintln ! ( "{}" , func) ;
@@ -722,8 +724,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
722724 } ) ;
723725 while let Some ( id) = todo. pop ( ) {
724726 if reachable. insert ( id) {
727+ // This is a new allocation, add its relocations to `todo`.
725728 if let Some ( ( _, alloc) ) = self . alloc_map . get ( id) {
726- // This is a new allocation, add its relocations to `todo`.
727729 todo. extend ( alloc. relocations ( ) . values ( ) . map ( |& ( _, target_id) | target_id) ) ;
728730 }
729731 }
0 commit comments