8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
+ use borrow_check:: location:: LocationTable ;
11
12
use borrow_check:: nll:: constraints:: ConstraintCategory ;
12
13
use borrow_check:: nll:: region_infer:: values:: { self , PointIndex , RegionValueElements } ;
13
14
use borrow_check:: nll:: type_check:: liveness:: liveness_map:: { LiveVar , NllLivenessMap } ;
@@ -49,6 +50,7 @@ pub(super) fn trace(
49
50
flow_inits : & mut FlowAtLocation < MaybeInitializedPlaces < ' _ , ' gcx , ' tcx > > ,
50
51
move_data : & MoveData < ' tcx > ,
51
52
liveness_map : & NllLivenessMap ,
53
+ location_table : & LocationTable ,
52
54
) {
53
55
debug ! ( "trace()" ) ;
54
56
@@ -67,6 +69,7 @@ pub(super) fn trace(
67
69
move_data,
68
70
liveness_map,
69
71
drop_data : FxHashMap :: default ( ) ,
72
+ location_table,
70
73
} ;
71
74
72
75
LivenessResults :: new ( cx) . compute_for_all_locals ( ) ;
@@ -105,6 +108,9 @@ where
105
108
106
109
/// Map tracking which variables need liveness computation.
107
110
liveness_map : & ' me NllLivenessMap ,
111
+
112
+ /// Maps between a MIR Location and a LocationIndex
113
+ location_table : & ' me LocationTable ,
108
114
}
109
115
110
116
struct DropData < ' tcx > {
@@ -453,7 +459,13 @@ impl LivenessContext<'_, '_, '_, '_, 'tcx> {
453
459
) {
454
460
debug ! ( "add_use_live_facts_for(value={:?})" , value) ;
455
461
456
- Self :: make_all_regions_live ( self . elements , & mut self . typeck , value, live_at)
462
+ Self :: make_all_regions_live (
463
+ self . elements ,
464
+ & mut self . typeck ,
465
+ value,
466
+ live_at,
467
+ self . location_table ,
468
+ )
457
469
}
458
470
459
471
/// Some variable with type `live_ty` is "drop live" at `location`
@@ -505,7 +517,13 @@ impl LivenessContext<'_, '_, '_, '_, 'tcx> {
505
517
// All things in the `outlives` array may be touched by
506
518
// the destructor and must be live at this point.
507
519
for & kind in & drop_data. dropck_result . kinds {
508
- Self :: make_all_regions_live ( self . elements , & mut self . typeck , kind, live_at) ;
520
+ Self :: make_all_regions_live (
521
+ self . elements ,
522
+ & mut self . typeck ,
523
+ kind,
524
+ live_at,
525
+ self . location_table ,
526
+ ) ;
509
527
}
510
528
}
511
529
@@ -514,6 +532,7 @@ impl LivenessContext<'_, '_, '_, '_, 'tcx> {
514
532
typeck : & mut TypeChecker < ' _ , ' _ , ' tcx > ,
515
533
value : impl TypeFoldable < ' tcx > ,
516
534
live_at : & HybridBitSet < PointIndex > ,
535
+ location_table : & LocationTable ,
517
536
) {
518
537
debug ! ( "make_all_regions_live(value={:?})" , value) ;
519
538
debug ! (
@@ -532,8 +551,12 @@ impl LivenessContext<'_, '_, '_, '_, 'tcx> {
532
551
. liveness_constraints
533
552
. add_elements ( live_region_vid, live_at) ;
534
553
535
- if let Some ( _) = borrowck_context. all_facts {
536
- bug ! ( "polonius liveness facts not implemented yet" )
554
+ if let Some ( facts) = borrowck_context. all_facts {
555
+ for point in live_at. iter ( ) {
556
+ let loc = elements. to_location ( point) ;
557
+ facts. region_live_at . push ( ( live_region_vid, location_table. start_index ( loc) ) ) ;
558
+ facts. region_live_at . push ( ( live_region_vid, location_table. mid_index ( loc) ) ) ;
559
+ }
537
560
}
538
561
} ) ;
539
562
}
0 commit comments