@@ -303,10 +303,10 @@ pub fn mono_reachable_as_bitset<'a, 'tcx>(
303
303
body : & ' a Body < ' tcx > ,
304
304
tcx : TyCtxt < ' tcx > ,
305
305
instance : Instance < ' tcx > ,
306
- ) -> BitSet < BasicBlock > {
306
+ ) -> ( BitSet < BasicBlock > , BitSet < Local > ) {
307
307
let mut iter = mono_reachable ( body, tcx, instance) ;
308
308
while let Some ( _) = iter. next ( ) { }
309
- iter. visited
309
+ ( iter. visited , iter . locals )
310
310
}
311
311
312
312
pub struct MonoReachable < ' a , ' tcx > {
@@ -318,6 +318,23 @@ pub struct MonoReachable<'a, 'tcx> {
318
318
// store ours in a BitSet and thus save allocations because BitSet has a small size
319
319
// optimization.
320
320
worklist : BitSet < BasicBlock > ,
321
+ locals : BitSet < Local > ,
322
+ }
323
+
324
+ struct UsedLocals < ' a > {
325
+ locals : & ' a mut BitSet < Local > ,
326
+ }
327
+
328
+ use crate :: mir:: visit:: Visitor ;
329
+ impl < ' a , ' tcx > Visitor < ' tcx > for UsedLocals < ' a > {
330
+ fn visit_local (
331
+ & mut self ,
332
+ local : Local ,
333
+ _ctx : crate :: mir:: visit:: PlaceContext ,
334
+ _location : Location ,
335
+ ) {
336
+ self . locals . insert ( local) ;
337
+ }
321
338
}
322
339
323
340
impl < ' a , ' tcx > MonoReachable < ' a , ' tcx > {
@@ -334,6 +351,7 @@ impl<'a, 'tcx> MonoReachable<'a, 'tcx> {
334
351
instance,
335
352
visited : BitSet :: new_empty ( body. basic_blocks . len ( ) ) ,
336
353
worklist,
354
+ locals : BitSet :: new_empty ( body. local_decls . len ( ) ) ,
337
355
}
338
356
}
339
357
@@ -357,6 +375,7 @@ impl<'a, 'tcx> Iterator for MonoReachable<'a, 'tcx> {
357
375
}
358
376
359
377
let data = & self . body [ idx] ;
378
+ UsedLocals { locals : & mut self . locals } . visit_basic_block_data ( idx, data) ;
360
379
361
380
if let Some ( ( bits, targets) ) =
362
381
Body :: try_const_mono_switchint ( self . tcx , self . instance , data)
0 commit comments