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 ,
@@ -54,17 +53,17 @@ pub(super) fn trace<'mir, 'tcx>(
54
53
let local_use_map = & LocalUseMap :: build ( & relevant_live_locals, elements, body) ;
55
54
56
55
// When using `-Zpolonius=next`, compute the set of loans that can reach a given region.
57
- let num_loans = typeck. borrowck_context . borrow_set . len ( ) ;
58
- let mut inflowing_loans = SparseBitMatrix :: new ( num_loans) ;
59
56
if typeck. tcx ( ) . sess . opts . unstable_opts . polonius . is_next_enabled ( ) {
60
- let borrowck_context = & typeck. borrowck_context ;
57
+ let borrowck_context = & mut typeck. borrowck_context ;
58
+
61
59
let borrow_set = & borrowck_context. borrow_set ;
62
- let constraint_set = & borrowck_context . constraints . outlives_constraints ;
60
+ let mut live_loans = LiveLoans :: new ( borrow_set . len ( ) ) ;
63
61
64
62
let num_region_vars = typeck. infcx . num_region_vars ( ) ;
65
- let graph = constraint_set. graph ( num_region_vars) ;
63
+ let outlives_constraints = & borrowck_context. constraints . outlives_constraints ;
64
+ let graph = outlives_constraints. graph ( num_region_vars) ;
66
65
let region_graph =
67
- graph. region_graph ( constraint_set , borrowck_context. universal_regions . fr_static ) ;
66
+ graph. region_graph ( outlives_constraints , borrowck_context. universal_regions . fr_static ) ;
68
67
69
68
// Traverse each issuing region's constraints, and record the loan as flowing into the
70
69
// outlived region.
@@ -75,9 +74,13 @@ pub(super) fn trace<'mir, 'tcx>(
75
74
continue ;
76
75
}
77
76
78
- inflowing_loans. insert ( succ, loan) ;
77
+ live_loans . inflowing_loans . insert ( succ, loan) ;
79
78
}
80
79
}
80
+
81
+ // Store the inflowing loans in the liveness constraints: they will be used to compute live
82
+ // loans when liveness data is recorded there.
83
+ borrowck_context. constraints . liveness_constraints . loans = Some ( live_loans) ;
81
84
} ;
82
85
83
86
let cx = LivenessContext {
@@ -88,7 +91,6 @@ pub(super) fn trace<'mir, 'tcx>(
88
91
local_use_map,
89
92
move_data,
90
93
drop_data : FxIndexMap :: default ( ) ,
91
- inflowing_loans,
92
94
} ;
93
95
94
96
let mut results = LivenessResults :: new ( cx) ;
@@ -126,9 +128,6 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
126
128
/// Index indicating where each variable is assigned, used, or
127
129
/// dropped.
128
130
local_use_map : & ' me LocalUseMap ,
129
-
130
- /// Set of loans that flow into a given region, when using `-Zpolonius=next`.
131
- inflowing_loans : SparseBitMatrix < RegionVid , BorrowIndex > ,
132
131
}
133
132
134
133
struct DropData < ' tcx > {
@@ -519,14 +518,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
519
518
live_at : & IntervalSet < PointIndex > ,
520
519
) {
521
520
debug ! ( "add_use_live_facts_for(value={:?})" , value) ;
522
-
523
- Self :: make_all_regions_live (
524
- self . elements ,
525
- self . typeck ,
526
- value,
527
- live_at,
528
- & self . inflowing_loans ,
529
- ) ;
521
+ Self :: make_all_regions_live ( self . elements , self . typeck , value, live_at) ;
530
522
}
531
523
532
524
/// Some variable with type `live_ty` is "drop live" at `location`
@@ -577,14 +569,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
577
569
// All things in the `outlives` array may be touched by
578
570
// the destructor and must be live at this point.
579
571
for & kind in & drop_data. dropck_result . kinds {
580
- Self :: make_all_regions_live (
581
- self . elements ,
582
- self . typeck ,
583
- kind,
584
- live_at,
585
- & self . inflowing_loans ,
586
- ) ;
587
-
572
+ Self :: make_all_regions_live ( self . elements , self . typeck , kind, live_at) ;
588
573
polonius:: add_drop_of_var_derefs_origin ( self . typeck , dropped_local, & kind) ;
589
574
}
590
575
}
@@ -594,20 +579,13 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
594
579
typeck : & mut TypeChecker < ' _ , ' tcx > ,
595
580
value : impl TypeVisitable < TyCtxt < ' tcx > > ,
596
581
live_at : & IntervalSet < PointIndex > ,
597
- inflowing_loans : & SparseBitMatrix < RegionVid , BorrowIndex > ,
598
582
) {
599
583
debug ! ( "make_all_regions_live(value={:?})" , value) ;
600
584
debug ! (
601
585
"make_all_regions_live: live_at={}" ,
602
586
values:: location_set_str( elements, live_at. iter( ) ) ,
603
587
) ;
604
588
605
- // When using `-Zpolonius=next`, we want to record the loans that flow into this value's
606
- // regions as being live at the given `live_at` points: this will be used to compute the
607
- // location where a loan goes out of scope.
608
- let num_loans = typeck. borrowck_context . borrow_set . len ( ) ;
609
- let value_loans = & mut HybridBitSet :: new_empty ( num_loans) ;
610
-
611
589
value. visit_with ( & mut for_liveness:: FreeRegionsVisitor {
612
590
tcx : typeck. tcx ( ) ,
613
591
param_env : typeck. param_env ,
@@ -619,21 +597,8 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
619
597
. constraints
620
598
. liveness_constraints
621
599
. add_elements ( live_region_vid, live_at) ;
622
-
623
- // There can only be inflowing loans for this region when we are using
624
- // `-Zpolonius=next`.
625
- if let Some ( inflowing) = inflowing_loans. row ( live_region_vid) {
626
- value_loans. union ( inflowing) ;
627
- }
628
600
} ,
629
601
} ) ;
630
-
631
- // Record the loans reaching the value.
632
- if !value_loans. is_empty ( ) {
633
- for point in live_at. iter ( ) {
634
- typeck. borrowck_context . live_loans . union_row ( point, value_loans) ;
635
- }
636
- }
637
602
}
638
603
639
604
fn compute_drop_data (
0 commit comments