11
11
use borrow_check:: borrow_set:: BorrowSet ;
12
12
use borrow_check:: location:: { LocationIndex , LocationTable } ;
13
13
use borrow_check:: nll:: facts:: AllFactsExt ;
14
+ use dataflow:: indexes:: BorrowIndex ;
14
15
use dataflow:: move_paths:: MoveData ;
15
16
use dataflow:: FlowAtLocation ;
16
17
use dataflow:: MaybeInitializedPlaces ;
17
- use dataflow:: indexes:: BorrowIndex ;
18
18
use rustc:: hir:: def_id:: DefId ;
19
19
use rustc:: infer:: InferCtxt ;
20
20
use rustc:: mir:: { ClosureOutlivesSubject , ClosureRegionRequirements , Mir } ;
@@ -23,25 +23,25 @@ use rustc::util::nodemap::FxHashMap;
23
23
use std:: collections:: BTreeSet ;
24
24
use std:: fmt:: Debug ;
25
25
use std:: io;
26
- use std:: rc:: Rc ;
27
26
use std:: path:: PathBuf ;
27
+ use std:: rc:: Rc ;
28
28
use transform:: MirSource ;
29
29
use util:: liveness:: { LivenessResults , LocalSet } ;
30
30
31
31
use self :: mir_util:: PassWhere ;
32
+ use polonius_engine:: { Algorithm , Output } ;
32
33
use util as mir_util;
33
34
use util:: pretty:: { self , ALIGN } ;
34
- use polonius_engine:: { Algorithm , Output } ;
35
35
36
36
mod constraint_generation;
37
37
pub mod explain_borrow;
38
38
mod facts;
39
+ mod invalidation;
39
40
crate mod region_infer;
40
41
mod renumber;
41
42
mod subtype_constraint_generation;
42
43
crate mod type_check;
43
44
mod universal_regions;
44
- mod invalidation;
45
45
46
46
use self :: facts:: AllFacts ;
47
47
use self :: region_infer:: RegionInferenceContext ;
@@ -119,8 +119,7 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
119
119
// Create the region inference context, taking ownership of the region inference
120
120
// data that was contained in `infcx`.
121
121
let var_origins = infcx. take_region_var_origins ( ) ;
122
- let mut regioncx =
123
- RegionInferenceContext :: new ( var_origins, universal_regions, mir) ;
122
+ let mut regioncx = RegionInferenceContext :: new ( var_origins, universal_regions, mir) ;
124
123
125
124
// Generate various constraints.
126
125
subtype_constraint_generation:: generate (
@@ -144,22 +143,27 @@ pub(in borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(
144
143
location_table,
145
144
& mir,
146
145
def_id,
147
- borrow_set
146
+ borrow_set,
148
147
) ;
149
148
150
149
// Dump facts if requested.
151
150
let polonius_output = all_facts. and_then ( |all_facts| {
152
- if infcx. tcx . sess . opts . debugging_opts . nll_facts {
153
- let def_path = infcx. tcx . hir . def_path ( def_id) ;
154
- let dir_path = PathBuf :: from ( "nll-facts" ) . join ( def_path. to_filename_friendly_no_crate ( ) ) ;
155
- all_facts. write_to_dir ( dir_path, location_table) . unwrap ( ) ;
156
- }
157
-
158
- if infcx. tcx . sess . opts . debugging_opts . polonius {
159
- Some ( Rc :: new ( Output :: compute ( & all_facts, Algorithm :: DatafrogOpt , false ) ) )
160
- } else {
161
- None
162
- }
151
+ if infcx. tcx . sess . opts . debugging_opts . nll_facts {
152
+ let def_path = infcx. tcx . hir . def_path ( def_id) ;
153
+ let dir_path =
154
+ PathBuf :: from ( "nll-facts" ) . join ( def_path. to_filename_friendly_no_crate ( ) ) ;
155
+ all_facts. write_to_dir ( dir_path, location_table) . unwrap ( ) ;
156
+ }
157
+
158
+ if infcx. tcx . sess . opts . debugging_opts . polonius {
159
+ Some ( Rc :: new ( Output :: compute (
160
+ & all_facts,
161
+ Algorithm :: DatafrogOpt ,
162
+ false ,
163
+ ) ) )
164
+ } else {
165
+ None
166
+ }
163
167
} ) ;
164
168
165
169
// Solve the region constraints.
@@ -195,7 +199,8 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
195
199
return ;
196
200
}
197
201
198
- let regular_liveness_per_location: FxHashMap < _ , _ > = mir. basic_blocks ( )
202
+ let regular_liveness_per_location: FxHashMap < _ , _ > = mir
203
+ . basic_blocks ( )
199
204
. indices ( )
200
205
. flat_map ( |bb| {
201
206
let mut results = vec ! [ ] ;
@@ -208,7 +213,8 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
208
213
} )
209
214
. collect ( ) ;
210
215
211
- let drop_liveness_per_location: FxHashMap < _ , _ > = mir. basic_blocks ( )
216
+ let drop_liveness_per_location: FxHashMap < _ , _ > = mir
217
+ . basic_blocks ( )
212
218
. indices ( )
213
219
. flat_map ( |bb| {
214
220
let mut results = vec ! [ ] ;
@@ -221,47 +227,55 @@ fn dump_mir_results<'a, 'gcx, 'tcx>(
221
227
} )
222
228
. collect ( ) ;
223
229
224
- mir_util:: dump_mir ( infcx. tcx , None , "nll" , & 0 , source, mir, |pass_where, out| {
225
- match pass_where {
226
- // Before the CFG, dump out the values for each region variable.
227
- PassWhere :: BeforeCFG => {
228
- regioncx. dump_mir ( out) ?;
229
-
230
- if let Some ( closure_region_requirements) = closure_region_requirements {
231
- writeln ! ( out, "|" ) ?;
232
- writeln ! ( out, "| Free Region Constraints" ) ?;
233
- for_each_region_constraint ( closure_region_requirements, & mut |msg| {
234
- writeln ! ( out, "| {}" , msg)
235
- } ) ?;
230
+ mir_util:: dump_mir (
231
+ infcx. tcx ,
232
+ None ,
233
+ "nll" ,
234
+ & 0 ,
235
+ source,
236
+ mir,
237
+ |pass_where, out| {
238
+ match pass_where {
239
+ // Before the CFG, dump out the values for each region variable.
240
+ PassWhere :: BeforeCFG => {
241
+ regioncx. dump_mir ( out) ?;
242
+
243
+ if let Some ( closure_region_requirements) = closure_region_requirements {
244
+ writeln ! ( out, "|" ) ?;
245
+ writeln ! ( out, "| Free Region Constraints" ) ?;
246
+ for_each_region_constraint ( closure_region_requirements, & mut |msg| {
247
+ writeln ! ( out, "| {}" , msg)
248
+ } ) ?;
249
+ }
236
250
}
237
- }
238
251
239
- // Before each basic block, dump out the values
240
- // that are live on entry to the basic block.
241
- PassWhere :: BeforeBlock ( bb) => {
242
- let s = live_variable_set ( & liveness. regular . ins [ bb] , & liveness. drop . ins [ bb] ) ;
243
- writeln ! ( out, " | Live variables on entry to {:?}: {}" , bb, s) ?;
244
- }
252
+ // Before each basic block, dump out the values
253
+ // that are live on entry to the basic block.
254
+ PassWhere :: BeforeBlock ( bb) => {
255
+ let s = live_variable_set ( & liveness. regular . ins [ bb] , & liveness. drop . ins [ bb] ) ;
256
+ writeln ! ( out, " | Live variables on entry to {:?}: {}" , bb, s) ?;
257
+ }
245
258
246
- PassWhere :: BeforeLocation ( location) => {
247
- let s = live_variable_set (
248
- & regular_liveness_per_location[ & location] ,
249
- & drop_liveness_per_location[ & location] ,
250
- ) ;
251
- writeln ! (
252
- out,
253
- "{:ALIGN$} | Live variables on entry to {:?}: {}" ,
254
- "" ,
255
- location,
256
- s,
257
- ALIGN = ALIGN
258
- ) ?;
259
- }
259
+ PassWhere :: BeforeLocation ( location) => {
260
+ let s = live_variable_set (
261
+ & regular_liveness_per_location[ & location] ,
262
+ & drop_liveness_per_location[ & location] ,
263
+ ) ;
264
+ writeln ! (
265
+ out,
266
+ "{:ALIGN$} | Live variables on entry to {:?}: {}" ,
267
+ "" ,
268
+ location,
269
+ s,
270
+ ALIGN = ALIGN
271
+ ) ?;
272
+ }
260
273
261
- PassWhere :: AfterLocation ( _) | PassWhere :: AfterCFG => { }
262
- }
263
- Ok ( ( ) )
264
- } ) ;
274
+ PassWhere :: AfterLocation ( _) | PassWhere :: AfterCFG => { }
275
+ }
276
+ Ok ( ( ) )
277
+ } ,
278
+ ) ;
265
279
266
280
// Also dump the inference graph constraints as a graphviz file.
267
281
let _: io:: Result < ( ) > = do catch {
@@ -292,7 +306,8 @@ fn dump_annotation<'a, 'gcx, 'tcx>(
292
306
// better.
293
307
294
308
if let Some ( closure_region_requirements) = closure_region_requirements {
295
- let mut err = tcx. sess
309
+ let mut err = tcx
310
+ . sess
296
311
. diagnostic ( )
297
312
. span_note_diag ( mir. span , "External requirements" ) ;
298
313
@@ -312,7 +327,8 @@ fn dump_annotation<'a, 'gcx, 'tcx>(
312
327
313
328
err. emit ( ) ;
314
329
} else {
315
- let mut err = tcx. sess
330
+ let mut err = tcx
331
+ . sess
316
332
. diagnostic ( )
317
333
. span_note_diag ( mir. span , "No external requirements" ) ;
318
334
regioncx. annotate ( & mut err) ;
@@ -331,8 +347,7 @@ fn for_each_region_constraint(
331
347
} ;
332
348
with_msg ( & format ! (
333
349
"where {:?}: {:?}" ,
334
- subject,
335
- req. outlived_free_region,
350
+ subject, req. outlived_free_region,
336
351
) ) ?;
337
352
}
338
353
Ok ( ( ) )
0 commit comments