11use rustc_data_structures:: fx:: { FxIndexMap , FxIndexSet } ;
22use rustc_data_structures:: graph:: WithSuccessors ;
3- use rustc_index:: bit_set:: { HybridBitSet , SparseBitMatrix } ;
3+ use rustc_index:: bit_set:: HybridBitSet ;
44use rustc_index:: interval:: IntervalSet ;
55use rustc_infer:: infer:: canonical:: QueryRegionConstraints ;
66use rustc_infer:: infer:: outlives:: for_liveness;
77use rustc_middle:: mir:: { BasicBlock , Body , ConstraintCategory , Local , Location } ;
88use rustc_middle:: traits:: query:: DropckOutlivesResult ;
9- use rustc_middle:: ty:: { RegionVid , Ty , TyCtxt , TypeVisitable , TypeVisitableExt } ;
9+ use rustc_middle:: ty:: { Ty , TyCtxt , TypeVisitable , TypeVisitableExt } ;
1010use rustc_span:: DUMMY_SP ;
1111use rustc_trait_selection:: traits:: query:: type_op:: outlives:: DropckOutlives ;
1212use rustc_trait_selection:: traits:: query:: type_op:: { TypeOp , TypeOpOutput } ;
@@ -16,9 +16,8 @@ use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
1616use rustc_mir_dataflow:: move_paths:: { HasMoveData , MoveData , MovePathIndex } ;
1717use rustc_mir_dataflow:: ResultsCursor ;
1818
19- use crate :: dataflow:: BorrowIndex ;
2019use crate :: {
21- region_infer:: values:: { self , PointIndex , RegionValueElements } ,
20+ region_infer:: values:: { self , LiveLoans , PointIndex , RegionValueElements } ,
2221 type_check:: liveness:: local_use_map:: LocalUseMap ,
2322 type_check:: liveness:: polonius,
2423 type_check:: NormalizeLocation ,
@@ -54,17 +53,17 @@ pub(super) fn trace<'mir, 'tcx>(
5453 let local_use_map = & LocalUseMap :: build ( & relevant_live_locals, elements, body) ;
5554
5655 // 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) ;
5956 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+
6159 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 ( ) ) ;
6361
6462 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) ;
6665 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 ) ;
6867
6968 // Traverse each issuing region's constraints, and record the loan as flowing into the
7069 // outlived region.
@@ -75,9 +74,13 @@ pub(super) fn trace<'mir, 'tcx>(
7574 continue ;
7675 }
7776
78- inflowing_loans. insert ( succ, loan) ;
77+ live_loans . inflowing_loans . insert ( succ, loan) ;
7978 }
8079 }
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) ;
8184 } ;
8285
8386 let cx = LivenessContext {
@@ -88,7 +91,6 @@ pub(super) fn trace<'mir, 'tcx>(
8891 local_use_map,
8992 move_data,
9093 drop_data : FxIndexMap :: default ( ) ,
91- inflowing_loans,
9294 } ;
9395
9496 let mut results = LivenessResults :: new ( cx) ;
@@ -126,9 +128,6 @@ struct LivenessContext<'me, 'typeck, 'flow, 'tcx> {
126128 /// Index indicating where each variable is assigned, used, or
127129 /// dropped.
128130 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 > ,
132131}
133132
134133struct DropData < ' tcx > {
@@ -519,14 +518,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
519518 live_at : & IntervalSet < PointIndex > ,
520519 ) {
521520 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) ;
530522 }
531523
532524 /// Some variable with type `live_ty` is "drop live" at `location`
@@ -577,14 +569,7 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
577569 // All things in the `outlives` array may be touched by
578570 // the destructor and must be live at this point.
579571 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) ;
588573 polonius:: add_drop_of_var_derefs_origin ( self . typeck , dropped_local, & kind) ;
589574 }
590575 }
@@ -594,20 +579,13 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
594579 typeck : & mut TypeChecker < ' _ , ' tcx > ,
595580 value : impl TypeVisitable < TyCtxt < ' tcx > > ,
596581 live_at : & IntervalSet < PointIndex > ,
597- inflowing_loans : & SparseBitMatrix < RegionVid , BorrowIndex > ,
598582 ) {
599583 debug ! ( "make_all_regions_live(value={:?})" , value) ;
600584 debug ! (
601585 "make_all_regions_live: live_at={}" ,
602586 values:: location_set_str( elements, live_at. iter( ) ) ,
603587 ) ;
604588
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-
611589 value. visit_with ( & mut for_liveness:: FreeRegionsVisitor {
612590 tcx : typeck. tcx ( ) ,
613591 param_env : typeck. param_env ,
@@ -619,21 +597,8 @@ impl<'tcx> LivenessContext<'_, '_, '_, 'tcx> {
619597 . constraints
620598 . liveness_constraints
621599 . 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- }
628600 } ,
629601 } ) ;
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- }
637602 }
638603
639604 fn compute_drop_data (
0 commit comments