@@ -599,10 +599,11 @@ impl Map {
599599 tcx : TyCtxt < ' tcx > ,
600600 body : & Body < ' tcx > ,
601601 filter : impl FnMut ( Ty < ' tcx > ) -> bool ,
602+ place_limit : Option < usize > ,
602603 ) -> Self {
603604 let mut map = Self :: new ( ) ;
604605 let exclude = excluded_locals ( body) ;
605- map. register_with_filter ( tcx, body, filter, exclude) ;
606+ map. register_with_filter ( tcx, body, filter, exclude, place_limit ) ;
606607 debug ! ( "registered {} places ({} nodes in total)" , map. value_count, map. places. len( ) ) ;
607608 map
608609 }
@@ -614,12 +615,20 @@ impl Map {
614615 body : & Body < ' tcx > ,
615616 mut filter : impl FnMut ( Ty < ' tcx > ) -> bool ,
616617 exclude : BitSet < Local > ,
618+ place_limit : Option < usize > ,
617619 ) {
618620 // We use this vector as stack, pushing and popping projections.
619621 let mut projection = Vec :: new ( ) ;
620622 for ( local, decl) in body. local_decls . iter_enumerated ( ) {
621623 if !exclude. contains ( local) {
622- self . register_with_filter_rec ( tcx, local, & mut projection, decl. ty , & mut filter) ;
624+ self . register_with_filter_rec (
625+ tcx,
626+ local,
627+ & mut projection,
628+ decl. ty ,
629+ & mut filter,
630+ place_limit,
631+ ) ;
623632 }
624633 }
625634 }
@@ -634,7 +643,12 @@ impl Map {
634643 projection : & mut Vec < PlaceElem < ' tcx > > ,
635644 ty : Ty < ' tcx > ,
636645 filter : & mut impl FnMut ( Ty < ' tcx > ) -> bool ,
646+ place_limit : Option < usize > ,
637647 ) {
648+ if let Some ( place_limit) = place_limit && self . value_count >= place_limit {
649+ return
650+ }
651+
638652 // We know that the projection only contains trackable elements.
639653 let place = self . make_place ( local, projection) . unwrap ( ) ;
640654
@@ -672,13 +686,13 @@ impl Map {
672686 projection. push ( PlaceElem :: Downcast ( None , variant) ) ;
673687 let _ = self . make_place ( local, projection) ;
674688 projection. push ( PlaceElem :: Field ( field, ty) ) ;
675- self . register_with_filter_rec ( tcx, local, projection, ty, filter) ;
689+ self . register_with_filter_rec ( tcx, local, projection, ty, filter, place_limit ) ;
676690 projection. pop ( ) ;
677691 projection. pop ( ) ;
678692 return ;
679693 }
680694 projection. push ( PlaceElem :: Field ( field, ty) ) ;
681- self . register_with_filter_rec ( tcx, local, projection, ty, filter) ;
695+ self . register_with_filter_rec ( tcx, local, projection, ty, filter, place_limit ) ;
682696 projection. pop ( ) ;
683697 } ) ;
684698 }
0 commit comments