@@ -13,7 +13,7 @@ use super::MoveDataParamEnv;
1313use crate :: util:: elaborate_drops:: DropFlagState ;
1414
1515use super :: move_paths:: { HasMoveData , InitIndex , InitKind , MoveData , MovePathIndex } ;
16- use super :: { AnalysisDomain , BottomValue , GenKill , GenKillAnalysis } ;
16+ use super :: { lattice , AnalysisDomain , GenKill , GenKillAnalysis } ;
1717
1818use super :: drop_flag_effects_for_function_entry;
1919use super :: drop_flag_effects_for_location;
@@ -290,27 +290,25 @@ impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
290290}
291291
292292impl < ' tcx > AnalysisDomain < ' tcx > for MaybeInitializedPlaces < ' _ , ' tcx > {
293- type Idx = MovePathIndex ;
294-
293+ type Domain = BitSet < MovePathIndex > ;
295294 const NAME : & ' static str = "maybe_init" ;
296295
297- fn bits_per_block ( & self , _: & mir:: Body < ' tcx > ) -> usize {
298- self . move_data ( ) . move_paths . len ( )
296+ fn bottom_value ( & self , _: & mir:: Body < ' tcx > ) -> Self :: Domain {
297+ // bottom = uninitialized
298+ BitSet :: new_empty ( self . move_data ( ) . move_paths . len ( ) )
299299 }
300300
301- fn initialize_start_block ( & self , _: & mir:: Body < ' tcx > , state : & mut BitSet < Self :: Idx > ) {
301+ fn initialize_start_block ( & self , _: & mir:: Body < ' tcx > , state : & mut Self :: Domain ) {
302302 drop_flag_effects_for_function_entry ( self . tcx , self . body , self . mdpe , |path, s| {
303303 assert ! ( s == DropFlagState :: Present ) ;
304304 state. insert ( path) ;
305305 } ) ;
306306 }
307-
308- fn pretty_print_idx ( & self , w : & mut impl std:: io:: Write , mpi : Self :: Idx ) -> std:: io:: Result < ( ) > {
309- write ! ( w, "{}" , self . move_data( ) . move_paths[ mpi] )
310- }
311307}
312308
313309impl < ' tcx > GenKillAnalysis < ' tcx > for MaybeInitializedPlaces < ' _ , ' tcx > {
310+ type Idx = MovePathIndex ;
311+
314312 fn statement_effect (
315313 & self ,
316314 trans : & mut impl GenKill < Self :: Idx > ,
@@ -376,32 +374,30 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
376374}
377375
378376impl < ' tcx > AnalysisDomain < ' tcx > for MaybeUninitializedPlaces < ' _ , ' tcx > {
379- type Idx = MovePathIndex ;
377+ type Domain = BitSet < MovePathIndex > ;
380378
381379 const NAME : & ' static str = "maybe_uninit" ;
382380
383- fn bits_per_block ( & self , _: & mir:: Body < ' tcx > ) -> usize {
384- self . move_data ( ) . move_paths . len ( )
381+ fn bottom_value ( & self , _: & mir:: Body < ' tcx > ) -> Self :: Domain {
382+ // bottom = initialized (start_block_effect counters this at outset)
383+ BitSet :: new_empty ( self . move_data ( ) . move_paths . len ( ) )
385384 }
386385
387386 // sets on_entry bits for Arg places
388- fn initialize_start_block ( & self , body : & mir:: Body < ' tcx > , state : & mut BitSet < Self :: Idx > ) {
387+ fn initialize_start_block ( & self , _ : & mir:: Body < ' tcx > , state : & mut Self :: Domain ) {
389388 // set all bits to 1 (uninit) before gathering counterevidence
390- assert ! ( self . bits_per_block( body) == state. domain_size( ) ) ;
391389 state. insert_all ( ) ;
392390
393391 drop_flag_effects_for_function_entry ( self . tcx , self . body , self . mdpe , |path, s| {
394392 assert ! ( s == DropFlagState :: Present ) ;
395393 state. remove ( path) ;
396394 } ) ;
397395 }
398-
399- fn pretty_print_idx ( & self , w : & mut impl std:: io:: Write , mpi : Self :: Idx ) -> std:: io:: Result < ( ) > {
400- write ! ( w, "{}" , self . move_data( ) . move_paths[ mpi] )
401- }
402396}
403397
404398impl < ' tcx > GenKillAnalysis < ' tcx > for MaybeUninitializedPlaces < ' _ , ' tcx > {
399+ type Idx = MovePathIndex ;
400+
405401 fn statement_effect (
406402 & self ,
407403 trans : & mut impl GenKill < Self :: Idx > ,
@@ -471,30 +467,30 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
471467}
472468
473469impl < ' a , ' tcx > AnalysisDomain < ' tcx > for DefinitelyInitializedPlaces < ' a , ' tcx > {
474- type Idx = MovePathIndex ;
470+ /// Use set intersection as the join operator.
471+ type Domain = lattice:: Dual < BitSet < MovePathIndex > > ;
475472
476473 const NAME : & ' static str = "definite_init" ;
477474
478- fn bits_per_block ( & self , _: & mir:: Body < ' tcx > ) -> usize {
479- self . move_data ( ) . move_paths . len ( )
475+ fn bottom_value ( & self , _: & mir:: Body < ' tcx > ) -> Self :: Domain {
476+ // bottom = initialized (start_block_effect counters this at outset)
477+ lattice:: Dual ( BitSet :: new_filled ( self . move_data ( ) . move_paths . len ( ) ) )
480478 }
481479
482480 // sets on_entry bits for Arg places
483- fn initialize_start_block ( & self , _: & mir:: Body < ' tcx > , state : & mut BitSet < Self :: Idx > ) {
484- state. clear ( ) ;
481+ fn initialize_start_block ( & self , _: & mir:: Body < ' tcx > , state : & mut Self :: Domain ) {
482+ state. 0 . clear ( ) ;
485483
486484 drop_flag_effects_for_function_entry ( self . tcx , self . body , self . mdpe , |path, s| {
487485 assert ! ( s == DropFlagState :: Present ) ;
488- state. insert ( path) ;
486+ state. 0 . insert ( path) ;
489487 } ) ;
490488 }
491-
492- fn pretty_print_idx ( & self , w : & mut impl std:: io:: Write , mpi : Self :: Idx ) -> std:: io:: Result < ( ) > {
493- write ! ( w, "{}" , self . move_data( ) . move_paths[ mpi] )
494- }
495489}
496490
497491impl < ' tcx > GenKillAnalysis < ' tcx > for DefinitelyInitializedPlaces < ' _ , ' tcx > {
492+ type Idx = MovePathIndex ;
493+
498494 fn statement_effect (
499495 & self ,
500496 trans : & mut impl GenKill < Self :: Idx > ,
@@ -540,22 +536,25 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
540536}
541537
542538impl < ' tcx > AnalysisDomain < ' tcx > for EverInitializedPlaces < ' _ , ' tcx > {
543- type Idx = InitIndex ;
539+ type Domain = BitSet < InitIndex > ;
544540
545541 const NAME : & ' static str = "ever_init" ;
546542
547- fn bits_per_block ( & self , _: & mir:: Body < ' tcx > ) -> usize {
548- self . move_data ( ) . inits . len ( )
543+ fn bottom_value ( & self , _: & mir:: Body < ' tcx > ) -> Self :: Domain {
544+ // bottom = no initialized variables by default
545+ BitSet :: new_empty ( self . move_data ( ) . inits . len ( ) )
549546 }
550547
551- fn initialize_start_block ( & self , body : & mir:: Body < ' tcx > , state : & mut BitSet < Self :: Idx > ) {
548+ fn initialize_start_block ( & self , body : & mir:: Body < ' tcx > , state : & mut Self :: Domain ) {
552549 for arg_init in 0 ..body. arg_count {
553550 state. insert ( InitIndex :: new ( arg_init) ) ;
554551 }
555552 }
556553}
557554
558555impl < ' tcx > GenKillAnalysis < ' tcx > for EverInitializedPlaces < ' _ , ' tcx > {
556+ type Idx = InitIndex ;
557+
559558 fn statement_effect (
560559 & self ,
561560 trans : & mut impl GenKill < Self :: Idx > ,
@@ -625,23 +624,3 @@ impl<'tcx> GenKillAnalysis<'tcx> for EverInitializedPlaces<'_, 'tcx> {
625624 }
626625 }
627626}
628-
629- impl < ' a , ' tcx > BottomValue for MaybeInitializedPlaces < ' a , ' tcx > {
630- /// bottom = uninitialized
631- const BOTTOM_VALUE : bool = false ;
632- }
633-
634- impl < ' a , ' tcx > BottomValue for MaybeUninitializedPlaces < ' a , ' tcx > {
635- /// bottom = initialized (start_block_effect counters this at outset)
636- const BOTTOM_VALUE : bool = false ;
637- }
638-
639- impl < ' a , ' tcx > BottomValue for DefinitelyInitializedPlaces < ' a , ' tcx > {
640- /// bottom = initialized (start_block_effect counters this at outset)
641- const BOTTOM_VALUE : bool = true ;
642- }
643-
644- impl < ' a , ' tcx > BottomValue for EverInitializedPlaces < ' a , ' tcx > {
645- /// bottom = no initialized variables by default
646- const BOTTOM_VALUE : bool = false ;
647- }
0 commit comments