@@ -11,9 +11,9 @@ use super::MoveDataParamEnv;
11
11
12
12
use crate :: util:: elaborate_drops:: DropFlagState ;
13
13
14
- use super :: generic:: GenKill ;
14
+ use super :: generic:: { AnalysisDomain , GenKill , GenKillAnalysis } ;
15
15
use super :: move_paths:: { HasMoveData , InitIndex , InitKind , MoveData , MovePathIndex } ;
16
- use super :: { BitDenotation , BottomValue , GenKillSet } ;
16
+ use super :: { BottomValue , GenKillSet } ;
17
17
18
18
use super :: drop_flag_effects_for_function_entry;
19
19
use super :: drop_flag_effects_for_location;
@@ -217,6 +217,7 @@ impl<'a, 'tcx> HasMoveData<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> {
217
217
/// }
218
218
/// ```
219
219
pub struct EverInitializedPlaces < ' a , ' tcx > {
220
+ #[ allow( dead_code) ]
220
221
tcx : TyCtxt < ' tcx > ,
221
222
body : & ' a Body < ' tcx > ,
222
223
mdpe : & ' a MoveDataParamEnv < ' tcx > ,
@@ -249,7 +250,7 @@ impl<'a, 'tcx> MaybeInitializedPlaces<'a, 'tcx> {
249
250
250
251
impl < ' a , ' tcx > MaybeUninitializedPlaces < ' a , ' tcx > {
251
252
fn update_bits (
252
- trans : & mut GenKillSet < MovePathIndex > ,
253
+ trans : & mut impl GenKill < MovePathIndex > ,
253
254
path : MovePathIndex ,
254
255
state : DropFlagState ,
255
256
) {
@@ -262,7 +263,7 @@ impl<'a, 'tcx> MaybeUninitializedPlaces<'a, 'tcx> {
262
263
263
264
impl < ' a , ' tcx > DefinitelyInitializedPlaces < ' a , ' tcx > {
264
265
fn update_bits (
265
- trans : & mut GenKillSet < MovePathIndex > ,
266
+ trans : & mut impl GenKill < MovePathIndex > ,
266
267
path : MovePathIndex ,
267
268
state : DropFlagState ,
268
269
) {
@@ -273,7 +274,7 @@ impl<'a, 'tcx> DefinitelyInitializedPlaces<'a, 'tcx> {
273
274
}
274
275
}
275
276
276
- impl < ' tcx > super :: generic :: AnalysisDomain < ' tcx > for MaybeInitializedPlaces < ' _ , ' tcx > {
277
+ impl < ' tcx > AnalysisDomain < ' tcx > for MaybeInitializedPlaces < ' _ , ' tcx > {
277
278
type Idx = MovePathIndex ;
278
279
279
280
const NAME : & ' static str = "maybe_init" ;
@@ -294,7 +295,7 @@ impl<'tcx> super::generic::AnalysisDomain<'tcx> for MaybeInitializedPlaces<'_, '
294
295
}
295
296
}
296
297
297
- impl < ' tcx > super :: generic :: GenKillAnalysis < ' tcx > for MaybeInitializedPlaces < ' _ , ' tcx > {
298
+ impl < ' tcx > GenKillAnalysis < ' tcx > for MaybeInitializedPlaces < ' _ , ' tcx > {
298
299
fn statement_effect (
299
300
& self ,
300
301
trans : & mut impl GenKill < Self :: Idx > ,
@@ -339,44 +340,61 @@ impl<'tcx> super::generic::GenKillAnalysis<'tcx> for MaybeInitializedPlaces<'_,
339
340
}
340
341
}
341
342
342
- impl < ' a , ' tcx > BitDenotation < ' tcx > for MaybeUninitializedPlaces < ' a , ' tcx > {
343
+ impl < ' tcx > AnalysisDomain < ' tcx > for MaybeUninitializedPlaces < ' _ , ' tcx > {
343
344
type Idx = MovePathIndex ;
344
- fn name ( ) -> & ' static str {
345
- "maybe_uninit"
346
- }
347
- fn bits_per_block ( & self ) -> usize {
345
+
346
+ const NAME : & ' static str = "maybe_uninit" ;
347
+
348
+ fn bits_per_block ( & self , _ : & mir :: Body < ' tcx > ) -> usize {
348
349
self . move_data ( ) . move_paths . len ( )
349
350
}
350
351
351
352
// sets on_entry bits for Arg places
352
- fn start_block_effect ( & self , entry_set : & mut BitSet < MovePathIndex > ) {
353
+ fn initialize_start_block ( & self , body : & mir :: Body < ' tcx > , state : & mut BitSet < Self :: Idx > ) {
353
354
// set all bits to 1 (uninit) before gathering counterevidence
354
- assert ! ( self . bits_per_block( ) == entry_set . domain_size( ) ) ;
355
- entry_set . insert_all ( ) ;
355
+ assert ! ( self . bits_per_block( body ) == state . domain_size( ) ) ;
356
+ state . insert_all ( ) ;
356
357
357
358
drop_flag_effects_for_function_entry ( self . tcx , self . body , self . mdpe , |path, s| {
358
359
assert ! ( s == DropFlagState :: Present ) ;
359
- entry_set . remove ( path) ;
360
+ state . remove ( path) ;
360
361
} ) ;
361
362
}
362
363
363
- fn statement_effect ( & self , trans : & mut GenKillSet < Self :: Idx > , location : Location ) {
364
+ fn pretty_print_idx ( & self , w : & mut impl std:: io:: Write , mpi : Self :: Idx ) -> std:: io:: Result < ( ) > {
365
+ write ! ( w, "{:?}" , self . move_data( ) . move_paths[ mpi] )
366
+ }
367
+ }
368
+
369
+ impl < ' tcx > GenKillAnalysis < ' tcx > for MaybeUninitializedPlaces < ' _ , ' tcx > {
370
+ fn statement_effect (
371
+ & self ,
372
+ trans : & mut impl GenKill < Self :: Idx > ,
373
+ _statement : & mir:: Statement < ' tcx > ,
374
+ location : Location ,
375
+ ) {
364
376
drop_flag_effects_for_location ( self . tcx , self . body , self . mdpe , location, |path, s| {
365
377
Self :: update_bits ( trans, path, s)
366
378
} )
367
379
}
368
380
369
- fn terminator_effect ( & self , trans : & mut GenKillSet < Self :: Idx > , location : Location ) {
381
+ fn terminator_effect (
382
+ & self ,
383
+ trans : & mut impl GenKill < Self :: Idx > ,
384
+ _terminator : & mir:: Terminator < ' tcx > ,
385
+ location : Location ,
386
+ ) {
370
387
drop_flag_effects_for_location ( self . tcx , self . body , self . mdpe , location, |path, s| {
371
388
Self :: update_bits ( trans, path, s)
372
389
} )
373
390
}
374
391
375
- fn propagate_call_return (
392
+ fn call_return_effect (
376
393
& self ,
377
- in_out : & mut BitSet < MovePathIndex > ,
378
- _call_bb : mir:: BasicBlock ,
379
- _dest_bb : mir:: BasicBlock ,
394
+ trans : & mut impl GenKill < Self :: Idx > ,
395
+ _block : mir:: BasicBlock ,
396
+ _func : & mir:: Operand < ' tcx > ,
397
+ _args : & [ mir:: Operand < ' tcx > ] ,
380
398
dest_place : & mir:: Place < ' tcx > ,
381
399
) {
382
400
// when a call returns successfully, that means we need to set
@@ -387,48 +405,65 @@ impl<'a, 'tcx> BitDenotation<'tcx> for MaybeUninitializedPlaces<'a, 'tcx> {
387
405
self . move_data ( ) ,
388
406
self . move_data ( ) . rev_lookup . find ( dest_place. as_ref ( ) ) ,
389
407
|mpi| {
390
- in_out . remove ( mpi) ;
408
+ trans . kill ( mpi) ;
391
409
} ,
392
410
) ;
393
411
}
394
412
}
395
413
396
- impl < ' a , ' tcx > BitDenotation < ' tcx > for DefinitelyInitializedPlaces < ' a , ' tcx > {
414
+ impl < ' a , ' tcx > AnalysisDomain < ' tcx > for DefinitelyInitializedPlaces < ' a , ' tcx > {
397
415
type Idx = MovePathIndex ;
398
- fn name ( ) -> & ' static str {
399
- "definite_init"
400
- }
401
- fn bits_per_block ( & self ) -> usize {
416
+
417
+ const NAME : & ' static str = "definite_init" ;
418
+
419
+ fn bits_per_block ( & self , _ : & mir :: Body < ' tcx > ) -> usize {
402
420
self . move_data ( ) . move_paths . len ( )
403
421
}
404
422
405
423
// sets on_entry bits for Arg places
406
- fn start_block_effect ( & self , entry_set : & mut BitSet < MovePathIndex > ) {
407
- entry_set . clear ( ) ;
424
+ fn initialize_start_block ( & self , _ : & mir :: Body < ' tcx > , state : & mut BitSet < Self :: Idx > ) {
425
+ state . clear ( ) ;
408
426
409
427
drop_flag_effects_for_function_entry ( self . tcx , self . body , self . mdpe , |path, s| {
410
428
assert ! ( s == DropFlagState :: Present ) ;
411
- entry_set . insert ( path) ;
429
+ state . insert ( path) ;
412
430
} ) ;
413
431
}
414
432
415
- fn statement_effect ( & self , trans : & mut GenKillSet < Self :: Idx > , location : Location ) {
433
+ fn pretty_print_idx ( & self , w : & mut impl std:: io:: Write , mpi : Self :: Idx ) -> std:: io:: Result < ( ) > {
434
+ write ! ( w, "{:?}" , self . move_data( ) . move_paths[ mpi] )
435
+ }
436
+ }
437
+
438
+ impl < ' tcx > GenKillAnalysis < ' tcx > for DefinitelyInitializedPlaces < ' _ , ' tcx > {
439
+ fn statement_effect (
440
+ & self ,
441
+ trans : & mut impl GenKill < Self :: Idx > ,
442
+ _statement : & mir:: Statement < ' tcx > ,
443
+ location : Location ,
444
+ ) {
416
445
drop_flag_effects_for_location ( self . tcx , self . body , self . mdpe , location, |path, s| {
417
446
Self :: update_bits ( trans, path, s)
418
447
} )
419
448
}
420
449
421
- fn terminator_effect ( & self , trans : & mut GenKillSet < Self :: Idx > , location : Location ) {
450
+ fn terminator_effect (
451
+ & self ,
452
+ trans : & mut impl GenKill < Self :: Idx > ,
453
+ _terminator : & mir:: Terminator < ' tcx > ,
454
+ location : Location ,
455
+ ) {
422
456
drop_flag_effects_for_location ( self . tcx , self . body , self . mdpe , location, |path, s| {
423
457
Self :: update_bits ( trans, path, s)
424
458
} )
425
459
}
426
460
427
- fn propagate_call_return (
461
+ fn call_return_effect (
428
462
& self ,
429
- in_out : & mut BitSet < MovePathIndex > ,
430
- _call_bb : mir:: BasicBlock ,
431
- _dest_bb : mir:: BasicBlock ,
463
+ trans : & mut impl GenKill < Self :: Idx > ,
464
+ _block : mir:: BasicBlock ,
465
+ _func : & mir:: Operand < ' tcx > ,
466
+ _args : & [ mir:: Operand < ' tcx > ] ,
432
467
dest_place : & mir:: Place < ' tcx > ,
433
468
) {
434
469
// when a call returns successfully, that means we need to set
@@ -439,30 +474,36 @@ impl<'a, 'tcx> BitDenotation<'tcx> for DefinitelyInitializedPlaces<'a, 'tcx> {
439
474
self . move_data ( ) ,
440
475
self . move_data ( ) . rev_lookup . find ( dest_place. as_ref ( ) ) ,
441
476
|mpi| {
442
- in_out . insert ( mpi) ;
477
+ trans . gen ( mpi) ;
443
478
} ,
444
479
) ;
445
480
}
446
481
}
447
482
448
- impl < ' a , ' tcx > BitDenotation < ' tcx > for EverInitializedPlaces < ' a , ' tcx > {
483
+ impl < ' tcx > AnalysisDomain < ' tcx > for EverInitializedPlaces < ' _ , ' tcx > {
449
484
type Idx = InitIndex ;
450
- fn name ( ) -> & ' static str {
451
- "ever_init"
452
- }
453
- fn bits_per_block ( & self ) -> usize {
485
+
486
+ const NAME : & ' static str = "ever_init" ;
487
+
488
+ fn bits_per_block ( & self , _ : & mir :: Body < ' tcx > ) -> usize {
454
489
self . move_data ( ) . inits . len ( )
455
490
}
456
491
457
- fn start_block_effect ( & self , entry_set : & mut BitSet < InitIndex > ) {
458
- for arg_init in 0 ..self . body . arg_count {
459
- entry_set . insert ( InitIndex :: new ( arg_init) ) ;
492
+ fn initialize_start_block ( & self , body : & mir :: Body < ' tcx > , state : & mut BitSet < Self :: Idx > ) {
493
+ for arg_init in 0 ..body. arg_count {
494
+ state . insert ( InitIndex :: new ( arg_init) ) ;
460
495
}
461
496
}
497
+ }
462
498
463
- fn statement_effect ( & self , trans : & mut GenKillSet < Self :: Idx > , location : Location ) {
464
- let ( _, body, move_data) = ( self . tcx , self . body , self . move_data ( ) ) ;
465
- let stmt = & body[ location. block ] . statements [ location. statement_index ] ;
499
+ impl < ' tcx > GenKillAnalysis < ' tcx > for EverInitializedPlaces < ' _ , ' tcx > {
500
+ fn statement_effect (
501
+ & self ,
502
+ trans : & mut impl GenKill < Self :: Idx > ,
503
+ stmt : & mir:: Statement < ' tcx > ,
504
+ location : Location ,
505
+ ) {
506
+ let move_data = self . move_data ( ) ;
466
507
let init_path_map = & move_data. init_path_map ;
467
508
let init_loc_map = & move_data. init_loc_map ;
468
509
let rev_lookup = & move_data. rev_lookup ;
@@ -471,7 +512,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for EverInitializedPlaces<'a, 'tcx> {
471
512
"statement {:?} at loc {:?} initializes move_indexes {:?}" ,
472
513
stmt, location, & init_loc_map[ location]
473
514
) ;
474
- trans. gen_all ( & init_loc_map[ location] ) ;
515
+ trans. gen_all ( init_loc_map[ location] . iter ( ) . copied ( ) ) ;
475
516
476
517
match stmt. kind {
477
518
mir:: StatementKind :: StorageDead ( local) => {
@@ -482,13 +523,18 @@ impl<'a, 'tcx> BitDenotation<'tcx> for EverInitializedPlaces<'a, 'tcx> {
482
523
"stmt {:?} at loc {:?} clears the ever initialized status of {:?}" ,
483
524
stmt, location, & init_path_map[ move_path_index]
484
525
) ;
485
- trans. kill_all ( & init_path_map[ move_path_index] ) ;
526
+ trans. kill_all ( init_path_map[ move_path_index] . iter ( ) . copied ( ) ) ;
486
527
}
487
528
_ => { }
488
529
}
489
530
}
490
531
491
- fn terminator_effect ( & self , trans : & mut GenKillSet < Self :: Idx > , location : Location ) {
532
+ fn terminator_effect (
533
+ & self ,
534
+ trans : & mut impl GenKill < Self :: Idx > ,
535
+ _terminator : & mir:: Terminator < ' tcx > ,
536
+ location : Location ,
537
+ ) {
492
538
let ( body, move_data) = ( self . body , self . move_data ( ) ) ;
493
539
let term = body[ location. block ] . terminator ( ) ;
494
540
let init_loc_map = & move_data. init_loc_map ;
@@ -497,28 +543,29 @@ impl<'a, 'tcx> BitDenotation<'tcx> for EverInitializedPlaces<'a, 'tcx> {
497
543
term, location, & init_loc_map[ location]
498
544
) ;
499
545
trans. gen_all (
500
- init_loc_map[ location] . iter ( ) . filter ( |init_index| {
501
- move_data. inits [ * * init_index] . kind != InitKind :: NonPanicPathOnly
502
- } ) ,
546
+ init_loc_map[ location]
547
+ . iter ( )
548
+ . filter ( |init_index| {
549
+ move_data. inits [ * * init_index] . kind != InitKind :: NonPanicPathOnly
550
+ } )
551
+ . copied ( ) ,
503
552
) ;
504
553
}
505
554
506
- fn propagate_call_return (
555
+ fn call_return_effect (
507
556
& self ,
508
- in_out : & mut BitSet < InitIndex > ,
509
- call_bb : mir:: BasicBlock ,
510
- _dest_bb : mir:: BasicBlock ,
557
+ trans : & mut impl GenKill < Self :: Idx > ,
558
+ block : mir:: BasicBlock ,
559
+ _func : & mir:: Operand < ' tcx > ,
560
+ _args : & [ mir:: Operand < ' tcx > ] ,
511
561
_dest_place : & mir:: Place < ' tcx > ,
512
562
) {
513
563
let move_data = self . move_data ( ) ;
514
- let bits_per_block = self . bits_per_block ( ) ;
515
564
let init_loc_map = & move_data. init_loc_map ;
516
565
517
- let call_loc =
518
- Location { block : call_bb, statement_index : self . body [ call_bb] . statements . len ( ) } ;
566
+ let call_loc = self . body . terminator_loc ( block) ;
519
567
for init_index in & init_loc_map[ call_loc] {
520
- assert ! ( init_index. index( ) < bits_per_block) ;
521
- in_out. insert ( * init_index) ;
568
+ trans. gen ( * init_index) ;
522
569
}
523
570
}
524
571
}
0 commit comments