8
8
// option. This file may not be copied, modified, or distributed
9
9
// except according to those terms.
10
10
11
- use super :: free_regions :: FreeRegions ;
11
+ use super :: universal_regions :: UniversalRegions ;
12
12
use rustc:: infer:: InferCtxt ;
13
13
use rustc:: infer:: RegionVariableOrigin ;
14
14
use rustc:: infer:: NLLRegionVariableOrigin ;
@@ -33,8 +33,8 @@ pub struct RegionInferenceContext<'tcx> {
33
33
34
34
/// The liveness constraints added to each region. For most
35
35
/// regions, these start out empty and steadily grow, though for
36
- /// each free region R they start out containing the entire CFG
37
- /// and `end(R)`.
36
+ /// each universally quantified region R they start out containing
37
+ /// the entire CFG and `end(R)`.
38
38
///
39
39
/// In this `BitMatrix` representation, the rows are the region
40
40
/// variables and the columns are the free regions and MIR locations.
@@ -52,7 +52,10 @@ pub struct RegionInferenceContext<'tcx> {
52
52
/// the free regions.)
53
53
point_indices : BTreeMap < Location , usize > ,
54
54
55
- num_free_regions : usize ,
55
+ /// Number of universally quantified regions. This is used to
56
+ /// determine the meaning of the bits in `inferred_values` and
57
+ /// friends.
58
+ num_universal_regions : usize ,
56
59
57
60
free_region_map : & ' tcx FreeRegionMap < ' tcx > ,
58
61
}
@@ -92,10 +95,14 @@ impl<'tcx> RegionInferenceContext<'tcx> {
92
95
/// Creates a new region inference context with a total of
93
96
/// `num_region_variables` valid inference variables; the first N
94
97
/// of those will be constant regions representing the free
95
- /// regions defined in `free_regions`.
96
- pub fn new ( var_origins : VarOrigins , free_regions : & FreeRegions < ' tcx > , mir : & Mir < ' tcx > ) -> Self {
98
+ /// regions defined in `universal_regions`.
99
+ pub fn new (
100
+ var_origins : VarOrigins ,
101
+ universal_regions : & UniversalRegions < ' tcx > ,
102
+ mir : & Mir < ' tcx > ,
103
+ ) -> Self {
97
104
let num_region_variables = var_origins. len ( ) ;
98
- let num_free_regions = free_regions . indices . len ( ) ;
105
+ let num_universal_regions = universal_regions . indices . len ( ) ;
99
106
100
107
let mut num_points = 0 ;
101
108
let mut point_indices = BTreeMap :: new ( ) ;
@@ -106,7 +113,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
106
113
block,
107
114
statement_index,
108
115
} ;
109
- point_indices. insert ( location, num_free_regions + num_points) ;
116
+ point_indices. insert ( location, num_universal_regions + num_points) ;
110
117
num_points += 1 ;
111
118
}
112
119
}
@@ -121,25 +128,26 @@ impl<'tcx> RegionInferenceContext<'tcx> {
121
128
definitions,
122
129
liveness_constraints : BitMatrix :: new (
123
130
num_region_variables,
124
- num_free_regions + num_points,
131
+ num_universal_regions + num_points,
125
132
) ,
126
133
inferred_values : None ,
127
134
constraints : Vec :: new ( ) ,
128
135
point_indices,
129
- num_free_regions ,
130
- free_region_map : free_regions . free_region_map ,
136
+ num_universal_regions ,
137
+ free_region_map : universal_regions . free_region_map ,
131
138
} ;
132
139
133
- result. init_free_regions ( free_regions ) ;
140
+ result. init_universal_regions ( universal_regions ) ;
134
141
135
142
result
136
143
}
137
144
138
- /// Initializes the region variables for each free region
139
- /// (lifetime parameter). The first N variables always correspond
140
- /// to the free regions appearing in the function signature (both
141
- /// named and anonymous) and where clauses. This function iterates
142
- /// over those regions and initializes them with minimum values.
145
+ /// Initializes the region variables for each universally
146
+ /// quantified region (lifetime parameter). The first N variables
147
+ /// always correspond to the regions appearing in the function
148
+ /// signature (both named and anonymous) and where clauses. This
149
+ /// function iterates over those regions and initializes them with
150
+ /// minimum values.
143
151
///
144
152
/// For example:
145
153
///
@@ -154,13 +162,13 @@ impl<'tcx> RegionInferenceContext<'tcx> {
154
162
/// and (b) any free regions that it outlives, which in this case
155
163
/// is just itself. R1 (`'b`) in contrast also outlives `'a` and
156
164
/// hence contains R0 and R1.
157
- fn init_free_regions ( & mut self , free_regions : & FreeRegions < ' tcx > ) {
158
- let FreeRegions {
165
+ fn init_universal_regions ( & mut self , universal_regions : & UniversalRegions < ' tcx > ) {
166
+ let UniversalRegions {
159
167
indices,
160
168
free_region_map : _,
161
- } = free_regions ;
169
+ } = universal_regions ;
162
170
163
- // For each free region X:
171
+ // For each universally quantified region X:
164
172
for ( free_region, & variable) in indices {
165
173
// These should be free-region variables.
166
174
assert ! ( match self . definitions[ variable] . origin {
@@ -218,7 +226,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
218
226
& self ,
219
227
matrix : & BitMatrix ,
220
228
r : RegionVid ,
221
- s : RegionVid
229
+ s : RegionVid ,
222
230
) -> bool {
223
231
matrix. contains ( r. index ( ) , s. index ( ) )
224
232
}
@@ -240,7 +248,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
240
248
}
241
249
}
242
250
243
- for fr in ( 0 .. self . num_free_regions ) . map ( RegionVid :: new) {
251
+ for fr in ( 0 .. self . num_universal_regions ) . map ( RegionVid :: new) {
244
252
if self . region_contains_region_in_matrix ( inferred_values, r, fr) {
245
253
result. push_str ( & format ! ( "{}{:?}" , sep, fr) ) ;
246
254
sep = ", " ;
@@ -287,9 +295,9 @@ impl<'tcx> RegionInferenceContext<'tcx> {
287
295
// Find the minimal regions that can solve the constraints. This is infallible.
288
296
self . propagate_constraints ( mir) ;
289
297
290
- // Now, see whether any of the constraints were too strong. In particular,
291
- // we want to check for a case where a free region exceeded its bounds.
292
- // Consider:
298
+ // Now, see whether any of the constraints were too strong. In
299
+ // particular, we want to check for a case where a universally
300
+ // quantified region exceeded its bounds. Consider:
293
301
//
294
302
// fn foo<'a, 'b>(x: &'a u32) -> &'b u32 { x }
295
303
//
@@ -300,7 +308,8 @@ impl<'tcx> RegionInferenceContext<'tcx> {
300
308
// have no evidence that `'b` outlives `'a`, so we want to report
301
309
// an error.
302
310
303
- // The free regions are always found in a prefix of the full list.
311
+ // The universal regions are always found in a prefix of the
312
+ // full list.
304
313
let free_region_definitions = self . definitions
305
314
. iter_enumerated ( )
306
315
. take_while ( |( _, fr_definition) | fr_definition. name . is_some ( ) ) ;
@@ -322,7 +331,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
322
331
323
332
// Find every region `o` such that `fr: o`
324
333
// (because `fr` includes `end(o)`).
325
- for outlived_fr in fr_value. take_while ( |& i| i < self . num_free_regions ) {
334
+ for outlived_fr in fr_value. take_while ( |& i| i < self . num_universal_regions ) {
326
335
// `fr` includes `end(fr)`, that's not especially
327
336
// interesting.
328
337
if fr. index ( ) == outlived_fr {
@@ -451,11 +460,11 @@ impl<'tcx> RegionInferenceContext<'tcx> {
451
460
// If we reach the END point in the graph, then copy
452
461
// over any skolemized end points in the `from_region`
453
462
// and make sure they are included in the `to_region`.
454
- let free_region_indices = inferred_values
463
+ let universal_region_indices = inferred_values
455
464
. iter ( from_region. index ( ) )
456
- . take_while ( |& i| i < self . num_free_regions )
465
+ . take_while ( |& i| i < self . num_universal_regions )
457
466
. collect :: < Vec < _ > > ( ) ;
458
- for fr in & free_region_indices {
467
+ for fr in & universal_region_indices {
459
468
changed |= inferred_values. add ( to_region. index ( ) , * fr) ;
460
469
}
461
470
} else {
@@ -523,7 +532,7 @@ impl<'tcx> RegionDefinition<'tcx> {
523
532
fn new ( origin : RegionVariableOrigin ) -> Self {
524
533
// Create a new region definition. Note that, for free
525
534
// regions, these fields get updated later in
526
- // `init_free_regions `.
535
+ // `init_universal_regions `.
527
536
Self { origin, name : None }
528
537
}
529
538
}
0 commit comments