@@ -3,6 +3,7 @@ use rustc_data_structures::fx::FxHashSet;
3
3
use rustc_middle:: mir:: visit:: { TyContext , Visitor } ;
4
4
use rustc_middle:: mir:: { Body , Local , Location , SourceInfo } ;
5
5
use rustc_middle:: span_bug;
6
+ use rustc_middle:: ty:: relate:: Relate ;
6
7
use rustc_middle:: ty:: visit:: TypeVisitable ;
7
8
use rustc_middle:: ty:: { GenericArgsRef , Region , RegionVid , Ty , TyCtxt } ;
8
9
use rustc_mir_dataflow:: ResultsCursor ;
@@ -13,6 +14,7 @@ use tracing::debug;
13
14
14
15
use super :: TypeChecker ;
15
16
use crate :: constraints:: OutlivesConstraintSet ;
17
+ use crate :: polonius:: PoloniusContext ;
16
18
use crate :: region_infer:: values:: LivenessValues ;
17
19
use crate :: universal_regions:: UniversalRegions ;
18
20
@@ -56,7 +58,13 @@ pub(super) fn generate<'a, 'tcx>(
56
58
57
59
// Mark regions that should be live where they appear within rvalues or within a call: like
58
60
// args, regions, and types.
59
- record_regular_live_regions ( typeck. tcx ( ) , & mut typeck. constraints . liveness_constraints , body) ;
61
+ record_regular_live_regions (
62
+ typeck. tcx ( ) ,
63
+ & mut typeck. constraints . liveness_constraints ,
64
+ & typeck. universal_regions ,
65
+ & mut typeck. polonius_context ,
66
+ body,
67
+ ) ;
60
68
}
61
69
62
70
// The purpose of `compute_relevant_live_locals` is to define the subset of `Local`
@@ -130,9 +138,12 @@ fn regions_that_outlive_free_regions<'tcx>(
130
138
fn record_regular_live_regions < ' tcx > (
131
139
tcx : TyCtxt < ' tcx > ,
132
140
liveness_constraints : & mut LivenessValues ,
141
+ universal_regions : & UniversalRegions < ' tcx > ,
142
+ polonius_context : & mut Option < PoloniusContext > ,
133
143
body : & Body < ' tcx > ,
134
144
) {
135
- let mut visitor = LiveVariablesVisitor { tcx, liveness_constraints } ;
145
+ let mut visitor =
146
+ LiveVariablesVisitor { tcx, liveness_constraints, universal_regions, polonius_context } ;
136
147
for ( bb, data) in body. basic_blocks . iter_enumerated ( ) {
137
148
visitor. visit_basic_block_data ( bb, data) ;
138
149
}
@@ -142,6 +153,8 @@ fn record_regular_live_regions<'tcx>(
142
153
struct LiveVariablesVisitor < ' a , ' tcx > {
143
154
tcx : TyCtxt < ' tcx > ,
144
155
liveness_constraints : & ' a mut LivenessValues ,
156
+ universal_regions : & ' a UniversalRegions < ' tcx > ,
157
+ polonius_context : & ' a mut Option < PoloniusContext > ,
145
158
}
146
159
147
160
impl < ' a , ' tcx > Visitor < ' tcx > for LiveVariablesVisitor < ' a , ' tcx > {
@@ -184,12 +197,17 @@ impl<'a, 'tcx> LiveVariablesVisitor<'a, 'tcx> {
184
197
/// all regions appearing in the type of `value` must be live at `location`.
185
198
fn record_regions_live_at < T > ( & mut self , value : T , location : Location )
186
199
where
187
- T : TypeVisitable < TyCtxt < ' tcx > > ,
200
+ T : TypeVisitable < TyCtxt < ' tcx > > + Relate < TyCtxt < ' tcx > > ,
188
201
{
189
202
debug ! ( "record_regions_live_at(value={:?}, location={:?})" , value, location) ;
190
203
self . tcx . for_each_free_region ( & value, |live_region| {
191
204
let live_region_vid = live_region. as_var ( ) ;
192
205
self . liveness_constraints . add_location ( live_region_vid, location) ;
193
206
} ) ;
207
+
208
+ // When using `-Zpolonius=next`, we record the variance of each live region.
209
+ if let Some ( polonius_context) = self . polonius_context {
210
+ polonius_context. record_live_region_variance ( self . tcx , self . universal_regions , value) ;
211
+ }
194
212
}
195
213
}
0 commit comments