@@ -13,7 +13,7 @@ use super::MoveDataParamEnv;
13
13
use crate :: util:: elaborate_drops:: DropFlagState ;
14
14
15
15
use super :: move_paths:: { HasMoveData , InitIndex , InitKind , MoveData , MovePathIndex } ;
16
- use super :: { AnalysisDomain , BottomValue , GenKill , GenKillAnalysis } ;
16
+ use super :: { lattice , AnalysisDomain , GenKill , GenKillAnalysis } ;
17
17
18
18
use super :: drop_flag_effects_for_function_entry;
19
19
use super :: drop_flag_effects_for_location;
@@ -290,27 +290,25 @@ impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
290
290
}
291
291
292
292
impl < ' tcx > AnalysisDomain < ' tcx > for MaybeInitializedPlaces < ' _ , ' tcx > {
293
- type Idx = MovePathIndex ;
294
-
293
+ type Domain = BitSet < MovePathIndex > ;
295
294
const NAME : & ' static str = "maybe_init" ;
296
295
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 ( ) )
299
299
}
300
300
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 ) {
302
302
drop_flag_effects_for_function_entry ( self . tcx , self . body , self . mdpe , |path, s| {
303
303
assert ! ( s == DropFlagState :: Present ) ;
304
304
state. insert ( path) ;
305
305
} ) ;
306
306
}
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
- }
311
307
}
312
308
313
309
impl < ' tcx > GenKillAnalysis < ' tcx > for MaybeInitializedPlaces < ' _ , ' tcx > {
310
+ type Idx = MovePathIndex ;
311
+
314
312
fn statement_effect (
315
313
& self ,
316
314
trans : & mut impl GenKill < Self :: Idx > ,
@@ -376,32 +374,30 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_, 'tcx> {
376
374
}
377
375
378
376
impl < ' tcx > AnalysisDomain < ' tcx > for MaybeUninitializedPlaces < ' _ , ' tcx > {
379
- type Idx = MovePathIndex ;
377
+ type Domain = BitSet < MovePathIndex > ;
380
378
381
379
const NAME : & ' static str = "maybe_uninit" ;
382
380
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 ( ) )
385
384
}
386
385
387
386
// 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 ) {
389
388
// set all bits to 1 (uninit) before gathering counterevidence
390
- assert ! ( self . bits_per_block( body) == state. domain_size( ) ) ;
391
389
state. insert_all ( ) ;
392
390
393
391
drop_flag_effects_for_function_entry ( self . tcx , self . body , self . mdpe , |path, s| {
394
392
assert ! ( s == DropFlagState :: Present ) ;
395
393
state. remove ( path) ;
396
394
} ) ;
397
395
}
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
- }
402
396
}
403
397
404
398
impl < ' tcx > GenKillAnalysis < ' tcx > for MaybeUninitializedPlaces < ' _ , ' tcx > {
399
+ type Idx = MovePathIndex ;
400
+
405
401
fn statement_effect (
406
402
& self ,
407
403
trans : & mut impl GenKill < Self :: Idx > ,
@@ -471,30 +467,30 @@ impl<'tcx> GenKillAnalysis<'tcx> for MaybeUninitializedPlaces<'_, 'tcx> {
471
467
}
472
468
473
469
impl < ' 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 > > ;
475
472
476
473
const NAME : & ' static str = "definite_init" ;
477
474
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 ( ) ) )
480
478
}
481
479
482
480
// 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 ( ) ;
485
483
486
484
drop_flag_effects_for_function_entry ( self . tcx , self . body , self . mdpe , |path, s| {
487
485
assert ! ( s == DropFlagState :: Present ) ;
488
- state. insert ( path) ;
486
+ state. 0 . insert ( path) ;
489
487
} ) ;
490
488
}
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
- }
495
489
}
496
490
497
491
impl < ' tcx > GenKillAnalysis < ' tcx > for DefinitelyInitializedPlaces < ' _ , ' tcx > {
492
+ type Idx = MovePathIndex ;
493
+
498
494
fn statement_effect (
499
495
& self ,
500
496
trans : & mut impl GenKill < Self :: Idx > ,
@@ -540,22 +536,25 @@ impl<'tcx> GenKillAnalysis<'tcx> for DefinitelyInitializedPlaces<'_, 'tcx> {
540
536
}
541
537
542
538
impl < ' tcx > AnalysisDomain < ' tcx > for EverInitializedPlaces < ' _ , ' tcx > {
543
- type Idx = InitIndex ;
539
+ type Domain = BitSet < InitIndex > ;
544
540
545
541
const NAME : & ' static str = "ever_init" ;
546
542
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 ( ) )
549
546
}
550
547
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 ) {
552
549
for arg_init in 0 ..body. arg_count {
553
550
state. insert ( InitIndex :: new ( arg_init) ) ;
554
551
}
555
552
}
556
553
}
557
554
558
555
impl < ' tcx > GenKillAnalysis < ' tcx > for EverInitializedPlaces < ' _ , ' tcx > {
556
+ type Idx = InitIndex ;
557
+
559
558
fn statement_effect (
560
559
& self ,
561
560
trans : & mut impl GenKill < Self :: Idx > ,
@@ -625,23 +624,3 @@ impl<'tcx> GenKillAnalysis<'tcx> for EverInitializedPlaces<'_, 'tcx> {
625
624
}
626
625
}
627
626
}
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