@@ -15,9 +15,8 @@ use rustc_hir::intravisit::FnKind;
15
15
use rustc_hir:: { def_id, Body , FnDecl , HirId } ;
16
16
use rustc_index:: bit_set:: { BitSet , HybridBitSet } ;
17
17
use rustc_lint:: { LateContext , LateLintPass } ;
18
- use rustc_mir:: dataflow:: {
19
- do_dataflow, BitDenotation , BottomValue , DataflowResults , DataflowResultsCursor , DebugFormatted , GenKillSet ,
20
- } ;
18
+ use rustc_mir:: dataflow:: generic:: { Analysis , AnalysisDomain , GenKill , GenKillAnalysis , ResultsCursor } ;
19
+ use rustc_mir:: dataflow:: BottomValue ;
21
20
use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
22
21
use rustc_span:: source_map:: { BytePos , Span } ;
23
22
use std:: convert:: TryFrom ;
@@ -83,16 +82,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
83
82
let mir = cx. tcx . optimized_mir ( def_id) ;
84
83
let mir_read_only = mir. unwrap_read_only ( ) ;
85
84
86
- let dead_unwinds = BitSet :: new_empty ( mir. basic_blocks ( ) . len ( ) ) ;
87
- let maybe_storage_live_result = do_dataflow (
88
- cx. tcx ,
89
- mir,
90
- def_id,
91
- & [ ] ,
92
- & dead_unwinds,
93
- MaybeStorageLive :: new ( mir) ,
94
- |bd, p| DebugFormatted :: new ( & bd. body . local_decls [ p] ) ,
95
- ) ;
85
+ let maybe_storage_live_result = MaybeStorageLive
86
+ . into_engine ( cx. tcx , mir, def_id)
87
+ . iterate_to_fixpoint ( )
88
+ . into_results_cursor ( mir) ;
96
89
let mut possible_borrower = {
97
90
let mut vis = PossibleBorrowerVisitor :: new ( cx, mir) ;
98
91
vis. visit_body ( mir_read_only) ;
@@ -377,55 +370,53 @@ impl<'tcx> mir::visit::Visitor<'tcx> for LocalUseVisitor {
377
370
378
371
/// Determines liveness of each local purely based on `StorageLive`/`Dead`.
379
372
#[ derive( Copy , Clone ) ]
380
- struct MaybeStorageLive < ' a , ' tcx > {
381
- body : & ' a mir:: Body < ' tcx > ,
382
- }
383
-
384
- impl < ' a , ' tcx > MaybeStorageLive < ' a , ' tcx > {
385
- fn new ( body : & ' a mir:: Body < ' tcx > ) -> Self {
386
- MaybeStorageLive { body }
387
- }
388
- }
373
+ struct MaybeStorageLive ;
389
374
390
- impl < ' a , ' tcx > BitDenotation < ' tcx > for MaybeStorageLive < ' a , ' tcx > {
375
+ impl < ' tcx > AnalysisDomain < ' tcx > for MaybeStorageLive {
391
376
type Idx = mir:: Local ;
392
- fn name ( ) -> & ' static str {
393
- "maybe_storage_live"
394
- }
395
- fn bits_per_block ( & self ) -> usize {
396
- self . body . local_decls . len ( )
377
+ const NAME : & ' static str = "maybe_storage_live" ;
378
+
379
+ fn bits_per_block ( & self , body : & mir:: Body < ' tcx > ) -> usize {
380
+ body. local_decls . len ( )
397
381
}
398
382
399
- fn start_block_effect ( & self , on_entry : & mut BitSet < mir :: Local > ) {
400
- for arg in self . body . args_iter ( ) {
401
- on_entry . insert ( arg) ;
383
+ fn initialize_start_block ( & self , body : & mir :: Body < ' tcx > , state : & mut BitSet < Self :: Idx > ) {
384
+ for arg in body. args_iter ( ) {
385
+ state . insert ( arg) ;
402
386
}
403
387
}
388
+ }
404
389
405
- fn statement_effect ( & self , trans : & mut GenKillSet < mir:: Local > , loc : mir:: Location ) {
406
- let stmt = & self . body [ loc. block ] . statements [ loc. statement_index ] ;
407
-
390
+ impl < ' tcx > GenKillAnalysis < ' tcx > for MaybeStorageLive {
391
+ fn statement_effect ( & self , trans : & mut impl GenKill < Self :: Idx > , stmt : & mir:: Statement < ' tcx > , _: mir:: Location ) {
408
392
match stmt. kind {
409
393
mir:: StatementKind :: StorageLive ( l) => trans. gen ( l) ,
410
394
mir:: StatementKind :: StorageDead ( l) => trans. kill ( l) ,
411
395
_ => ( ) ,
412
396
}
413
397
}
414
398
415
- fn terminator_effect ( & self , _trans : & mut GenKillSet < mir:: Local > , _loc : mir:: Location ) { }
399
+ fn terminator_effect (
400
+ & self ,
401
+ _trans : & mut impl GenKill < Self :: Idx > ,
402
+ _terminator : & mir:: Terminator < ' tcx > ,
403
+ _loc : mir:: Location ,
404
+ ) {
405
+ }
416
406
417
- fn propagate_call_return (
407
+ fn call_return_effect (
418
408
& self ,
419
- _in_out : & mut BitSet < mir:: Local > ,
420
- _call_bb : mir:: BasicBlock ,
421
- _dest_bb : mir:: BasicBlock ,
422
- _dest_place : & mir:: Place < ' tcx > ,
409
+ _in_out : & mut impl GenKill < Self :: Idx > ,
410
+ _block : mir:: BasicBlock ,
411
+ _func : & mir:: Operand < ' tcx > ,
412
+ _args : & [ mir:: Operand < ' tcx > ] ,
413
+ _return_place : & mir:: Place < ' tcx > ,
423
414
) {
424
415
// Nothing to do when a call returns successfully
425
416
}
426
417
}
427
418
428
- impl < ' a , ' tcx > BottomValue for MaybeStorageLive < ' a , ' tcx > {
419
+ impl BottomValue for MaybeStorageLive {
429
420
/// bottom = dead
430
421
const BOTTOM_VALUE : bool = false ;
431
422
}
@@ -451,8 +442,8 @@ impl<'a, 'tcx> PossibleBorrowerVisitor<'a, 'tcx> {
451
442
fn into_map (
452
443
self ,
453
444
cx : & LateContext < ' a , ' tcx > ,
454
- maybe_live : DataflowResults < ' tcx , MaybeStorageLive < ' a , ' tcx > > ,
455
- ) -> PossibleBorrower < ' a , ' tcx > {
445
+ maybe_live : ResultsCursor < ' tcx , ' tcx , MaybeStorageLive > ,
446
+ ) -> PossibleBorrowerMap < ' a , ' tcx > {
456
447
let mut map = FxHashMap :: default ( ) ;
457
448
for row in ( 1 ..self . body . local_decls . len ( ) ) . map ( mir:: Local :: from_usize) {
458
449
if is_copy ( cx, self . body . local_decls [ row] . ty ) {
@@ -475,9 +466,9 @@ impl<'a, 'tcx> PossibleBorrowerVisitor<'a, 'tcx> {
475
466
}
476
467
477
468
let bs = BitSet :: new_empty ( self . body . local_decls . len ( ) ) ;
478
- PossibleBorrower {
469
+ PossibleBorrowerMap {
479
470
map,
480
- maybe_live : DataflowResultsCursor :: new ( maybe_live , self . body ) ,
471
+ maybe_live,
481
472
bitset : ( bs. clone ( ) , bs) ,
482
473
}
483
474
}
@@ -557,18 +548,18 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) {
557
548
}
558
549
559
550
/// Result of `PossibleBorrowerVisitor`.
560
- struct PossibleBorrower < ' a , ' tcx > {
551
+ struct PossibleBorrowerMap < ' a , ' tcx > {
561
552
/// Mapping `Local -> its possible borrowers`
562
553
map : FxHashMap < mir:: Local , HybridBitSet < mir:: Local > > ,
563
- maybe_live : DataflowResultsCursor < ' a , ' tcx , MaybeStorageLive < ' a , ' tcx > > ,
554
+ maybe_live : ResultsCursor < ' a , ' tcx , MaybeStorageLive > ,
564
555
// Caches to avoid allocation of `BitSet` on every query
565
556
bitset : ( BitSet < mir:: Local > , BitSet < mir:: Local > ) ,
566
557
}
567
558
568
- impl PossibleBorrower < ' _ , ' _ > {
559
+ impl PossibleBorrowerMap < ' _ , ' _ > {
569
560
/// Returns true if the set of borrowers of `borrowed` living at `at` matches with `borrowers`.
570
561
fn only_borrowers ( & mut self , borrowers : & [ mir:: Local ] , borrowed : mir:: Local , at : mir:: Location ) -> bool {
571
- self . maybe_live . seek ( at) ;
562
+ self . maybe_live . seek_after ( at) ;
572
563
573
564
self . bitset . 0 . clear ( ) ;
574
565
let maybe_live = & mut self . maybe_live ;
0 commit comments