@@ -15,9 +15,8 @@ use rustc_hir::intravisit::FnKind;
1515use rustc_hir:: { def_id, Body , FnDecl , HirId } ;
1616use rustc_index:: bit_set:: { BitSet , HybridBitSet } ;
1717use 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 ;
2120use rustc_session:: { declare_lint_pass, declare_tool_lint} ;
2221use rustc_span:: source_map:: { BytePos , Span } ;
2322use std:: convert:: TryFrom ;
@@ -83,16 +82,10 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for RedundantClone {
8382 let mir = cx. tcx . optimized_mir ( def_id) ;
8483 let mir_read_only = mir. unwrap_read_only ( ) ;
8584
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) ;
9689 let mut possible_borrower = {
9790 let mut vis = PossibleBorrowerVisitor :: new ( cx, mir) ;
9891 vis. visit_body ( mir_read_only) ;
@@ -377,55 +370,53 @@ impl<'tcx> mir::visit::Visitor<'tcx> for LocalUseVisitor {
377370
378371/// Determines liveness of each local purely based on `StorageLive`/`Dead`.
379372#[ 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 ;
389374
390- impl < ' a , ' tcx > BitDenotation < ' tcx > for MaybeStorageLive < ' a , ' tcx > {
375+ impl < ' tcx > AnalysisDomain < ' tcx > for MaybeStorageLive {
391376 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 ( )
397381 }
398382
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) ;
402386 }
403387 }
388+ }
404389
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 ) {
408392 match stmt. kind {
409393 mir:: StatementKind :: StorageLive ( l) => trans. gen ( l) ,
410394 mir:: StatementKind :: StorageDead ( l) => trans. kill ( l) ,
411395 _ => ( ) ,
412396 }
413397 }
414398
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+ }
416406
417- fn propagate_call_return (
407+ fn call_return_effect (
418408 & 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 > ,
423414 ) {
424415 // Nothing to do when a call returns successfully
425416 }
426417}
427418
428- impl < ' a , ' tcx > BottomValue for MaybeStorageLive < ' a , ' tcx > {
419+ impl BottomValue for MaybeStorageLive {
429420 /// bottom = dead
430421 const BOTTOM_VALUE : bool = false ;
431422}
@@ -451,8 +442,8 @@ impl<'a, 'tcx> PossibleBorrowerVisitor<'a, 'tcx> {
451442 fn into_map (
452443 self ,
453444 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 > {
456447 let mut map = FxHashMap :: default ( ) ;
457448 for row in ( 1 ..self . body . local_decls . len ( ) ) . map ( mir:: Local :: from_usize) {
458449 if is_copy ( cx, self . body . local_decls [ row] . ty ) {
@@ -475,9 +466,9 @@ impl<'a, 'tcx> PossibleBorrowerVisitor<'a, 'tcx> {
475466 }
476467
477468 let bs = BitSet :: new_empty ( self . body . local_decls . len ( ) ) ;
478- PossibleBorrower {
469+ PossibleBorrowerMap {
479470 map,
480- maybe_live : DataflowResultsCursor :: new ( maybe_live , self . body ) ,
471+ maybe_live,
481472 bitset : ( bs. clone ( ) , bs) ,
482473 }
483474 }
@@ -557,18 +548,18 @@ fn rvalue_locals(rvalue: &mir::Rvalue<'_>, mut visit: impl FnMut(mir::Local)) {
557548}
558549
559550/// Result of `PossibleBorrowerVisitor`.
560- struct PossibleBorrower < ' a , ' tcx > {
551+ struct PossibleBorrowerMap < ' a , ' tcx > {
561552 /// Mapping `Local -> its possible borrowers`
562553 map : FxHashMap < mir:: Local , HybridBitSet < mir:: Local > > ,
563- maybe_live : DataflowResultsCursor < ' a , ' tcx , MaybeStorageLive < ' a , ' tcx > > ,
554+ maybe_live : ResultsCursor < ' a , ' tcx , MaybeStorageLive > ,
564555 // Caches to avoid allocation of `BitSet` on every query
565556 bitset : ( BitSet < mir:: Local > , BitSet < mir:: Local > ) ,
566557}
567558
568- impl PossibleBorrower < ' _ , ' _ > {
559+ impl PossibleBorrowerMap < ' _ , ' _ > {
569560 /// Returns true if the set of borrowers of `borrowed` living at `at` matches with `borrowers`.
570561 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) ;
572563
573564 self . bitset . 0 . clear ( ) ;
574565 let maybe_live = & mut self . maybe_live ;
0 commit comments