1
1
use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
2
2
use rustc_data_structures:: graph:: WithSuccessors ;
3
- use rustc_index:: bit_set:: { HybridBitSet , SparseBitMatrix } ;
3
+ use rustc_index:: bit_set:: HybridBitSet ;
4
4
use rustc_index:: interval:: IntervalSet ;
5
5
use rustc_infer:: infer:: canonical:: QueryRegionConstraints ;
6
6
use rustc_infer:: infer:: outlives:: for_liveness;
7
7
use rustc_middle:: mir:: { BasicBlock , Body , ConstraintCategory , Local , Location } ;
8
8
use rustc_middle:: traits:: query:: DropckOutlivesResult ;
9
- use rustc_middle:: ty:: { RegionVid , Ty , TyCtxt , TypeVisitable , TypeVisitableExt } ;
9
+ use rustc_middle:: ty:: { Ty , TyCtxt , TypeVisitable , TypeVisitableExt } ;
10
10
use rustc_span:: DUMMY_SP ;
11
11
use rustc_trait_selection:: traits:: query:: type_op:: outlives:: DropckOutlives ;
12
12
use rustc_trait_selection:: traits:: query:: type_op:: { TypeOp , TypeOpOutput } ;
@@ -16,9 +16,8 @@ use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
16
16
use rustc_mir_dataflow:: move_paths:: { HasMoveData , MoveData , MovePathIndex } ;
17
17
use rustc_mir_dataflow:: ResultsCursor ;
18
18
19
- use crate :: dataflow:: BorrowIndex ;
20
19
use crate :: {
21
- region_infer:: values:: { self , PointIndex , RegionValueElements } ,
20
+ region_infer:: values:: { self , LiveLoans , PointIndex , RegionValueElements } ,
22
21
type_check:: liveness:: local_use_map:: LocalUseMap ,
23
22
type_check:: liveness:: polonius,
24
23
type_check:: NormalizeLocation ,
@@ -52,15 +51,12 @@ pub(super) fn trace<'mir, 'tcx>(
52
51
let local_use_map = & LocalUseMap :: build ( & relevant_live_locals, elements, body) ;
53
52
54
53
// When using `-Zpolonius=next`, compute the set of loans that can reach a given region.
55
- let num_loans = typeck. borrowck_context . borrow_set . len ( ) ;
56
- let mut inflowing_loans = SparseBitMatrix :: new ( num_loans) ;
57
54
if typeck. tcx ( ) . sess . opts . unstable_opts . polonius . is_next_enabled ( ) {
58
- let borrowck_context = & typeck. borrowck_context ;
55
+ let borrowck_context = & mut typeck. borrowck_context ;
59
56
let borrow_set = & borrowck_context. borrow_set ;
57
+ let mut live_loans = LiveLoans :: new ( borrow_set. len ( ) ) ;
60
58
let outlives_constraints = & borrowck_context. constraints . outlives_constraints ;
61
-
62
- let num_region_vars = typeck. infcx . num_region_vars ( ) ;
63
- let graph = outlives_constraints. graph ( num_region_vars) ;
59
+ let graph = outlives_constraints. graph ( typeck. infcx . num_region_vars ( ) ) ;
64
60
let region_graph =
65
61
graph. region_graph ( outlives_constraints, borrowck_context. universal_regions . fr_static ) ;
66
62
@@ -73,9 +69,13 @@ pub(super) fn trace<'mir, 'tcx>(
73
69
continue ;
74
70
}
75
71
76
- inflowing_loans. insert ( succ, loan) ;
72
+ live_loans . inflowing_loans . insert ( succ, loan) ;
77
73
}
78
74
}
75
+
76
+ // Store the inflowing loans in the liveness constraints: they will be used to compute live
77
+ // loans when liveness data is recorded there.
78
+ borrowck_context. constraints . liveness_constraints . loans = Some ( live_loans) ;
79
79
} ;
80
80
81
81
let cx = LivenessContext {
@@ -86,7 +86,6 @@ pub(super) fn trace<'mir, 'tcx>(
86
86
local_use_map,
87
87
move_data,
88
88
drop_data : FxIndexMap :: default ( ) ,
89
- inflowing_loans,
90
89
} ;
91
90
92
91
let mut results = LivenessResults :: new ( cx) ;
@@ -124,9 +123,6 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
124
123
/// Index indicating where each variable is assigned, used, or
125
124
/// dropped.
126
125
local_use_map : & ' me LocalUseMap ,
127
-
128
- /// Set of loans that flow into a given region, when using `-Zpolonius=next`.
129
- inflowing_loans : SparseBitMatrix < RegionVid , BorrowIndex > ,
130
126
}
131
127
132
128
struct DropData < ' tcx > {
@@ -517,14 +513,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
517
513
live_at : & IntervalSet < PointIndex > ,
518
514
) {
519
515
debug ! ( "add_use_live_facts_for(value={:?})" , value) ;
520
-
521
- Self :: make_all_regions_live (
522
- self . elements ,
523
- self . typeck ,
524
- value,
525
- live_at,
526
- & self . inflowing_loans ,
527
- ) ;
516
+ Self :: make_all_regions_live ( self . elements , self . typeck , value, live_at) ;
528
517
}
529
518
530
519
/// Some variable with type `live_ty` is "drop live" at `location`
@@ -575,14 +564,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
575
564
// All things in the `outlives` array may be touched by
576
565
// the destructor and must be live at this point.
577
566
for & kind in & drop_data. dropck_result . kinds {
578
- Self :: make_all_regions_live (
579
- self . elements ,
580
- self . typeck ,
581
- kind,
582
- live_at,
583
- & self . inflowing_loans ,
584
- ) ;
585
-
567
+ Self :: make_all_regions_live ( self . elements , self . typeck , kind, live_at) ;
586
568
polonius:: add_drop_of_var_derefs_origin ( self . typeck , dropped_local, & kind) ;
587
569
}
588
570
}
@@ -592,20 +574,13 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
592
574
typeck : & mut TypeChecker < ' _ , ' tcx > ,
593
575
value : impl TypeVisitable < TyCtxt < ' tcx > > ,
594
576
live_at : & IntervalSet < PointIndex > ,
595
- inflowing_loans : & SparseBitMatrix < RegionVid , BorrowIndex > ,
596
577
) {
597
578
debug ! ( "make_all_regions_live(value={:?})" , value) ;
598
579
debug ! (
599
580
"make_all_regions_live: live_at={}" ,
600
581
values:: pretty_print_points( elements, live_at. iter( ) ) ,
601
582
) ;
602
583
603
- // When using `-Zpolonius=next`, we want to record the loans that flow into this value's
604
- // regions as being live at the given `live_at` points: this will be used to compute the
605
- // location where a loan goes out of scope.
606
- let num_loans = typeck. borrowck_context . borrow_set . len ( ) ;
607
- let value_loans = & mut HybridBitSet :: new_empty ( num_loans) ;
608
-
609
584
value. visit_with ( & mut for_liveness:: FreeRegionsVisitor {
610
585
tcx : typeck. tcx ( ) ,
611
586
param_env : typeck. param_env ,
@@ -617,21 +592,8 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
617
592
. constraints
618
593
. liveness_constraints
619
594
. add_points ( live_region_vid, live_at) ;
620
-
621
- // There can only be inflowing loans for this region when we are using
622
- // `-Zpolonius=next`.
623
- if let Some ( inflowing) = inflowing_loans. row ( live_region_vid) {
624
- value_loans. union ( inflowing) ;
625
- }
626
595
} ,
627
596
} ) ;
628
-
629
- // Record the loans reaching the value.
630
- if !value_loans. is_empty ( ) {
631
- for point in live_at. iter ( ) {
632
- typeck. borrowck_context . live_loans . union_row ( point, value_loans) ;
633
- }
634
- }
635
597
}
636
598
637
599
fn compute_drop_data (
0 commit comments