11use super :: {
22 for_each_consumable, record_consumed_borrow:: ConsumedAndBorrowedPlaces , DropRangesBuilder ,
3- HirIdIndex , NodeInfo , PostOrderId ,
3+ NodeInfo , PostOrderId , TrackedValue , TrackedValueIndex ,
44} ;
55use hir:: {
66 intravisit:: { self , NestedVisitorMap , Visitor } ,
7- Body , Expr , ExprKind , Guard , HirId , HirIdMap ,
7+ Body , Expr , ExprKind , Guard , HirId ,
88} ;
9+ use rustc_data_structures:: fx:: FxHashMap ;
910use rustc_hir as hir;
1011use rustc_index:: vec:: IndexVec ;
1112use rustc_middle:: {
@@ -61,20 +62,20 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
6162 ) -> Self {
6263 debug ! ( "consumed_places: {:?}" , places. consumed) ;
6364 let drop_ranges = DropRangesBuilder :: new (
64- places. consumed . iter ( ) . flat_map ( |( _, places) | places. iter ( ) . copied ( ) ) ,
65+ places. consumed . iter ( ) . flat_map ( |( _, places) | places. iter ( ) . cloned ( ) ) ,
6566 hir,
6667 num_exprs,
6768 ) ;
6869 Self { hir, places, drop_ranges, expr_index : PostOrderId :: from_u32 ( 0 ) , typeck_results, tcx }
6970 }
7071
71- fn record_drop ( & mut self , hir_id : HirId ) {
72- if self . places . borrowed . contains ( & hir_id ) {
73- debug ! ( "not marking {:?} as dropped because it is borrowed at some point" , hir_id ) ;
72+ fn record_drop ( & mut self , value : TrackedValue ) {
73+ if self . places . borrowed . contains ( & value ) {
74+ debug ! ( "not marking {:?} as dropped because it is borrowed at some point" , value ) ;
7475 } else {
75- debug ! ( "marking {:?} as dropped at {:?}" , hir_id , self . expr_index) ;
76+ debug ! ( "marking {:?} as dropped at {:?}" , value , self . expr_index) ;
7677 let count = self . expr_index ;
77- self . drop_ranges . drop_at ( hir_id , count) ;
78+ self . drop_ranges . drop_at ( value , count) ;
7879 }
7980 }
8081
@@ -88,7 +89,9 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
8889 . get ( & expr. hir_id )
8990 . map_or ( vec ! [ ] , |places| places. iter ( ) . cloned ( ) . collect ( ) ) ;
9091 for place in places {
91- for_each_consumable ( place, self . hir . find ( place) , |hir_id| self . record_drop ( hir_id) ) ;
92+ for_each_consumable ( place, self . hir . find ( place. hir_id ( ) ) , |value| {
93+ self . record_drop ( value)
94+ } ) ;
9295 }
9396 }
9497
@@ -100,7 +103,7 @@ impl<'a, 'tcx> DropRangeVisitor<'a, 'tcx> {
100103 {
101104 let location = self . expr_index ;
102105 debug ! ( "reinitializing {:?} at {:?}" , hir_id, location) ;
103- self . drop_ranges . reinit_at ( * hir_id, location) ;
106+ self . drop_ranges . reinit_at ( TrackedValue :: Variable ( * hir_id) , location) ;
104107 } else {
105108 debug ! ( "reinitializing {:?} is not supported" , expr) ;
106109 }
@@ -264,36 +267,40 @@ impl<'a, 'tcx> Visitor<'tcx> for DropRangeVisitor<'a, 'tcx> {
264267}
265268
266269impl DropRangesBuilder {
267- fn new ( hir_ids : impl Iterator < Item = HirId > , hir : Map < ' _ > , num_exprs : usize ) -> Self {
268- let mut hir_id_map = HirIdMap :: < HirIdIndex > :: default ( ) ;
270+ fn new (
271+ tracked_values : impl Iterator < Item = TrackedValue > ,
272+ hir : Map < ' _ > ,
273+ num_exprs : usize ,
274+ ) -> Self {
275+ let mut tracked_value_map = FxHashMap :: < _ , TrackedValueIndex > :: default ( ) ;
269276 let mut next = <_ >:: from ( 0u32 ) ;
270- for hir_id in hir_ids {
271- for_each_consumable ( hir_id , hir. find ( hir_id) , |hir_id | {
272- if !hir_id_map . contains_key ( & hir_id ) {
273- hir_id_map . insert ( hir_id , next) ;
274- next = < _ > :: from ( next. index ( ) + 1 ) ;
277+ for value in tracked_values {
278+ for_each_consumable ( value , hir. find ( value . hir_id ( ) ) , |value | {
279+ if !tracked_value_map . contains_key ( & value ) {
280+ tracked_value_map . insert ( value , next) ;
281+ next = next + 1 ;
275282 }
276283 } ) ;
277284 }
278- debug ! ( "hir_id_map: {:?}" , hir_id_map ) ;
279- let num_values = hir_id_map . len ( ) ;
285+ debug ! ( "hir_id_map: {:?}" , tracked_value_map ) ;
286+ let num_values = tracked_value_map . len ( ) ;
280287 Self {
281- hir_id_map ,
288+ tracked_value_map ,
282289 nodes : IndexVec :: from_fn_n ( |_| NodeInfo :: new ( num_values) , num_exprs + 1 ) ,
283290 deferred_edges : <_ >:: default ( ) ,
284291 post_order_map : <_ >:: default ( ) ,
285292 }
286293 }
287294
288- fn hidx ( & self , hir_id : HirId ) -> HirIdIndex {
289- * self . hir_id_map . get ( & hir_id ) . unwrap ( )
295+ fn tracked_value_index ( & self , tracked_value : TrackedValue ) -> TrackedValueIndex {
296+ * self . tracked_value_map . get ( & tracked_value ) . unwrap ( )
290297 }
291298
292299 /// Adds an entry in the mapping from HirIds to PostOrderIds
293300 ///
294301 /// Needed so that `add_control_edge_hir_id` can work.
295- fn add_node_mapping ( & mut self , hir_id : HirId , post_order_id : PostOrderId ) {
296- self . post_order_map . insert ( hir_id , post_order_id) ;
302+ fn add_node_mapping ( & mut self , node_hir_id : HirId , post_order_id : PostOrderId ) {
303+ self . post_order_map . insert ( node_hir_id , post_order_id) ;
297304 }
298305
299306 /// Like add_control_edge, but uses a hir_id as the target.
@@ -304,13 +311,13 @@ impl DropRangesBuilder {
304311 self . deferred_edges . push ( ( from, to) ) ;
305312 }
306313
307- fn drop_at ( & mut self , value : HirId , location : PostOrderId ) {
308- let value = self . hidx ( value) ;
314+ fn drop_at ( & mut self , value : TrackedValue , location : PostOrderId ) {
315+ let value = self . tracked_value_index ( value) ;
309316 self . node_mut ( location. into ( ) ) . drops . push ( value) ;
310317 }
311318
312- fn reinit_at ( & mut self , value : HirId , location : PostOrderId ) {
313- let value = match self . hir_id_map . get ( & value) {
319+ fn reinit_at ( & mut self , value : TrackedValue , location : PostOrderId ) {
320+ let value = match self . tracked_value_map . get ( & value) {
314321 Some ( value) => * value,
315322 // If there's no value, this is never consumed and therefore is never dropped. We can
316323 // ignore this.
0 commit comments