@@ -25,7 +25,9 @@ use rustc_hir as hir;
25
25
use rustc_hir:: def_id:: LocalDefId ;
26
26
use rustc_index:: bit_set:: ChunkedBitSet ;
27
27
use rustc_index:: vec:: IndexVec ;
28
- use rustc_infer:: infer:: { DefiningAnchor , InferCtxt , NllRegionVariableOrigin , TyCtxtInferExt } ;
28
+ use rustc_infer:: infer:: {
29
+ DefiningAnchor , InferCtxt , NllRegionVariableOrigin , RegionVariableOrigin , TyCtxtInferExt ,
30
+ } ;
29
31
use rustc_middle:: mir:: {
30
32
traversal, Body , ClearCrossCrate , Local , Location , Mutability , NonDivergingIntrinsic , Operand ,
31
33
Place , PlaceElem , PlaceRef , VarDebugInfoContents ,
@@ -95,6 +97,7 @@ use nll::{PoloniusOutput, ToRegionVid};
95
97
use place_ext:: PlaceExt ;
96
98
use places_conflict:: { places_conflict, PlaceConflictBias } ;
97
99
use region_infer:: RegionInferenceContext ;
100
+ use renumber:: RegionCtxt ;
98
101
99
102
// FIXME(eddyb) perhaps move this somewhere more centrally.
100
103
#[ derive( Debug ) ]
@@ -168,10 +171,10 @@ fn do_mir_borrowck<'tcx>(
168
171
return_body_with_facts : bool ,
169
172
) -> ( BorrowCheckResult < ' tcx > , Option < Box < BodyWithBorrowckFacts < ' tcx > > > ) {
170
173
let def = input_body. source . with_opt_param ( ) . as_local ( ) . unwrap ( ) ;
171
-
172
174
debug ! ( ?def) ;
173
175
174
176
let tcx = infcx. tcx ;
177
+ let infcx = BorrowckInferCtxt :: new ( infcx) ;
175
178
let param_env = tcx. param_env ( def. did ) ;
176
179
177
180
let mut local_names = IndexVec :: from_elem ( None , & input_body. local_decls ) ;
@@ -219,7 +222,7 @@ fn do_mir_borrowck<'tcx>(
219
222
let mut body_owned = input_body. clone ( ) ;
220
223
let mut promoted = input_promoted. clone ( ) ;
221
224
let free_regions =
222
- nll:: replace_regions_in_mir ( infcx, param_env, & mut body_owned, & mut promoted) ;
225
+ nll:: replace_regions_in_mir ( & infcx, param_env, & mut body_owned, & mut promoted) ;
223
226
let body = & body_owned; // no further changes
224
227
225
228
let location_table_owned = LocationTable :: new ( body) ;
@@ -257,7 +260,7 @@ fn do_mir_borrowck<'tcx>(
257
260
opt_closure_req,
258
261
nll_errors,
259
262
} = nll:: compute_regions (
260
- infcx,
263
+ & infcx,
261
264
free_regions,
262
265
body,
263
266
& promoted,
@@ -272,12 +275,12 @@ fn do_mir_borrowck<'tcx>(
272
275
273
276
// Dump MIR results into a file, if that is enabled. This let us
274
277
// write unit-tests, as well as helping with debugging.
275
- nll:: dump_mir_results ( infcx, & body, & regioncx, & opt_closure_req) ;
278
+ nll:: dump_mir_results ( & infcx, & body, & regioncx, & opt_closure_req) ;
276
279
277
280
// We also have a `#[rustc_regions]` annotation that causes us to dump
278
281
// information.
279
282
nll:: dump_annotation (
280
- infcx,
283
+ & infcx,
281
284
& body,
282
285
& regioncx,
283
286
& opt_closure_req,
@@ -321,7 +324,7 @@ fn do_mir_borrowck<'tcx>(
321
324
322
325
if let Err ( ( move_data, move_errors) ) = move_data_results {
323
326
let mut promoted_mbcx = MirBorrowckCtxt {
324
- infcx,
327
+ infcx : & infcx ,
325
328
param_env,
326
329
body : promoted_body,
327
330
move_data : & move_data,
@@ -350,7 +353,7 @@ fn do_mir_borrowck<'tcx>(
350
353
}
351
354
352
355
let mut mbcx = MirBorrowckCtxt {
353
- infcx,
356
+ infcx : & infcx ,
354
357
param_env,
355
358
body,
356
359
move_data : & mdpe. move_data ,
@@ -482,22 +485,81 @@ pub struct BodyWithBorrowckFacts<'tcx> {
482
485
pub location_table : LocationTable ,
483
486
}
484
487
485
- struct BorrowckInferCtxt < ' cx , ' tcx > {
488
+ pub struct BorrowckInferCtxt < ' cx , ' tcx > {
486
489
pub ( crate ) infcx : & ' cx InferCtxt < ' tcx > ,
487
490
488
491
#[ cfg( debug_assertions) ]
489
- pub ( crate ) _reg_var_to_origin : RefCell < FxHashMap < ty:: Region < ' tcx > , NllRegionVariableOrigin > > ,
492
+ pub ( crate ) reg_var_to_origin : RefCell < FxHashMap < ty:: RegionVid , RegionCtxt > > ,
490
493
}
491
494
492
495
impl < ' cx , ' tcx > BorrowckInferCtxt < ' cx , ' tcx > {
493
496
#[ cfg( not( debug_assertions) ) ]
494
- pub ( crate ) fn _new ( infcx : & ' cx InferCtxt < ' tcx > ) -> Self {
497
+ pub ( crate ) fn new ( infcx : & ' cx InferCtxt < ' tcx > ) -> Self {
495
498
BorrowckInferCtxt { infcx }
496
499
}
497
500
498
501
#[ cfg( debug_assertions) ]
499
- pub ( crate ) fn _new ( infcx : & ' cx InferCtxt < ' tcx > ) -> Self {
500
- BorrowckInferCtxt { infcx, _reg_var_to_origin : RefCell :: new ( Default :: default ( ) ) }
502
+ pub ( crate ) fn new ( infcx : & ' cx InferCtxt < ' tcx > ) -> Self {
503
+ BorrowckInferCtxt { infcx, reg_var_to_origin : RefCell :: new ( Default :: default ( ) ) }
504
+ }
505
+
506
+ #[ cfg( not( debug_assertions) ) ]
507
+ pub ( crate ) fn next_region_var ( & self , origin : RegionVariableOrigin ) -> ty:: Region < ' tcx > {
508
+ self . infcx . next_region_var ( origin)
509
+ }
510
+
511
+ #[ cfg( debug_assertions) ]
512
+ pub ( crate ) fn next_region_var (
513
+ & self ,
514
+ origin : RegionVariableOrigin ,
515
+ ctxt : RegionCtxt ,
516
+ ) -> ty:: Region < ' tcx > {
517
+ let next_region = self . infcx . next_region_var ( origin) ;
518
+ let vid = next_region
519
+ . try_get_var ( )
520
+ . unwrap_or_else ( || bug ! ( "expected RegionKind::RegionVar on {:?}" , next_region) ) ;
521
+
522
+ debug ! ( "inserting vid {:?} with origin {:?} into var_to_origin" , vid, origin) ;
523
+ let mut var_to_origin = self . reg_var_to_origin . borrow_mut ( ) ;
524
+ let prev = var_to_origin. insert ( vid, ctxt) ;
525
+ debug ! ( "var_to_origin after insertion: {:?}" , var_to_origin) ;
526
+
527
+ // This only makes sense if not called in a canonicalization context. If this
528
+ // ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
529
+ // or modify how we track nll region vars for that map.
530
+ assert ! ( matches!( prev, None ) ) ;
531
+
532
+ next_region
533
+ }
534
+
535
+ #[ cfg( not( debug_assertions) ) ]
536
+ pub ( crate ) fn next_nll_region_var ( & self , origin : NllRegionVariableOrigin ) -> ty:: Region < ' tcx > {
537
+ self . infcx . next_nll_region_var ( origin)
538
+ }
539
+
540
+ #[ cfg( debug_assertions) ]
541
+ #[ instrument( skip( self ) , level = "debug" ) ]
542
+ pub ( crate ) fn next_nll_region_var (
543
+ & self ,
544
+ origin : NllRegionVariableOrigin ,
545
+ ctxt : RegionCtxt ,
546
+ ) -> ty:: Region < ' tcx > {
547
+ let next_region = self . infcx . next_nll_region_var ( origin. clone ( ) ) ;
548
+ let vid = next_region
549
+ . try_get_var ( )
550
+ . unwrap_or_else ( || bug ! ( "expected RegionKind::RegionVar on {:?}" , next_region) ) ;
551
+
552
+ debug ! ( "inserting vid {:?} with origin {:?} into var_to_origin" , vid, origin) ;
553
+ let mut var_to_origin = self . reg_var_to_origin . borrow_mut ( ) ;
554
+ let prev = var_to_origin. insert ( vid, ctxt) ;
555
+ debug ! ( "var_to_origin after insertion: {:?}" , var_to_origin) ;
556
+
557
+ // This only makes sense if not called in a canonicalization context. If this
558
+ // ever changes we either want to get rid of `BorrowckInferContext::reg_var_to_origin`
559
+ // or modify how we track nll region vars for that map.
560
+ assert ! ( matches!( prev, None ) ) ;
561
+
562
+ next_region
501
563
}
502
564
}
503
565
@@ -510,7 +572,7 @@ impl<'cx, 'tcx> Deref for BorrowckInferCtxt<'cx, 'tcx> {
510
572
}
511
573
512
574
struct MirBorrowckCtxt < ' cx , ' tcx > {
513
- infcx : & ' cx InferCtxt < ' tcx > ,
575
+ infcx : & ' cx BorrowckInferCtxt < ' cx , ' tcx > ,
514
576
param_env : ParamEnv < ' tcx > ,
515
577
body : & ' cx Body < ' tcx > ,
516
578
move_data : & ' cx MoveData < ' tcx > ,
0 commit comments