@@ -62,6 +62,7 @@ use crate::session_diagnostics::VarNeedNotMut;
62
62
use self :: diagnostics:: { AccessKind , RegionName } ;
63
63
use self :: location:: LocationTable ;
64
64
use self :: prefixes:: PrefixSet ;
65
+ use consumers:: ConsumerOptions ;
65
66
use facts:: AllFacts ;
66
67
67
68
use self :: path_utils:: * ;
@@ -144,23 +145,23 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def: LocalDefId) -> &BorrowCheckResult<'_> {
144
145
tcx. infer_ctxt ( ) . with_opaque_type_inference ( DefiningAnchor :: Bind ( hir_owner. def_id ) ) . build ( ) ;
145
146
let input_body: & Body < ' _ > = & input_body. borrow ( ) ;
146
147
let promoted: & IndexSlice < _ , _ > = & promoted. borrow ( ) ;
147
- let opt_closure_req = do_mir_borrowck ( & infcx, input_body, promoted, false ) . 0 ;
148
+ let opt_closure_req = do_mir_borrowck ( & infcx, input_body, promoted, None ) . 0 ;
148
149
debug ! ( "mir_borrowck done" ) ;
149
150
150
151
tcx. arena . alloc ( opt_closure_req)
151
152
}
152
153
153
154
/// Perform the actual borrow checking.
154
155
///
155
- /// If `return_body_with_facts` is true, then return the body with non-erased
156
- /// region ids on which the borrow checking was performed together with Polonius
157
- /// facts .
156
+ /// Use `consumer_options: None` for the default behavior of returning
157
+ /// [`BorrowCheckResult`] only. Otherwise, return [`BodyWithBorrowckFacts`] according
158
+ /// to the given [`ConsumerOptions`] .
158
159
#[ instrument( skip( infcx, input_body, input_promoted) , fields( id=?input_body. source. def_id( ) ) , level = "debug" ) ]
159
160
fn do_mir_borrowck < ' tcx > (
160
161
infcx : & InferCtxt < ' tcx > ,
161
162
input_body : & Body < ' tcx > ,
162
163
input_promoted : & IndexSlice < Promoted , Body < ' tcx > > ,
163
- return_body_with_facts : bool ,
164
+ consumer_options : Option < ConsumerOptions > ,
164
165
) -> ( BorrowCheckResult < ' tcx > , Option < Box < BodyWithBorrowckFacts < ' tcx > > > ) {
165
166
let def = input_body. source . def_id ( ) . expect_local ( ) ;
166
167
debug ! ( ?def) ;
@@ -241,8 +242,6 @@ fn do_mir_borrowck<'tcx>(
241
242
let borrow_set =
242
243
Rc :: new ( BorrowSet :: build ( tcx, body, locals_are_invalidated_at_exit, & mdpe. move_data ) ) ;
243
244
244
- let use_polonius = return_body_with_facts || infcx. tcx . sess . opts . unstable_opts . polonius ;
245
-
246
245
// Compute non-lexical lifetimes.
247
246
let nll:: NllOutput {
248
247
regioncx,
@@ -262,7 +261,7 @@ fn do_mir_borrowck<'tcx>(
262
261
& mdpe. move_data ,
263
262
& borrow_set,
264
263
& upvars,
265
- use_polonius ,
264
+ consumer_options ,
266
265
) ;
267
266
268
267
// Dump MIR results into a file, if that is enabled. This let us
@@ -444,13 +443,15 @@ fn do_mir_borrowck<'tcx>(
444
443
tainted_by_errors,
445
444
} ;
446
445
447
- let body_with_facts = if return_body_with_facts {
448
- let output_facts = mbcx. polonius_output . expect ( "Polonius output was not computed" ) ;
446
+ let body_with_facts = if consumer_options . is_some ( ) {
447
+ let output_facts = mbcx. polonius_output ;
449
448
Some ( Box :: new ( BodyWithBorrowckFacts {
450
449
body : body_owned,
451
- input_facts : * polonius_input. expect ( "Polonius input facts were not generated" ) ,
450
+ borrow_set,
451
+ region_inference_context : regioncx,
452
+ location_table : polonius_input. as_ref ( ) . map ( |_| location_table_owned) ,
453
+ input_facts : polonius_input,
452
454
output_facts,
453
- location_table : location_table_owned,
454
455
} ) )
455
456
} else {
456
457
None
@@ -469,12 +470,20 @@ fn do_mir_borrowck<'tcx>(
469
470
pub struct BodyWithBorrowckFacts < ' tcx > {
470
471
/// A mir body that contains region identifiers.
471
472
pub body : Body < ' tcx > ,
472
- /// Polonius input facts.
473
- pub input_facts : AllFacts ,
474
- /// Polonius output facts.
475
- pub output_facts : Rc < self :: nll:: PoloniusOutput > ,
476
- /// The table that maps Polonius points to locations in the table.
477
- pub location_table : LocationTable ,
473
+ /// The set of borrows occurring in `body` with data about them.
474
+ pub borrow_set : Rc < BorrowSet < ' tcx > > ,
475
+ /// Context generated during borrowck, intended to be passed to
476
+ /// [`OutOfScopePrecomputer`](dataflow::OutOfScopePrecomputer).
477
+ pub region_inference_context : Rc < RegionInferenceContext < ' tcx > > ,
478
+ /// The table that maps Polonius points to locations in the table. Populated
479
+ /// when using [`ConsumerOptions::PoloniusInputFacts`] or above.
480
+ pub location_table : Option < LocationTable > ,
481
+ /// Polonius input facts. Populated when using
482
+ /// [`ConsumerOptions::PoloniusInputFacts`] or above.
483
+ pub input_facts : Option < Box < AllFacts > > ,
484
+ /// Polonius output facts. Populated when using
485
+ /// [`ConsumerOptions::PoloniusOutputFacts`] or above.
486
+ pub output_facts : Option < Rc < self :: nll:: PoloniusOutput > > ,
478
487
}
479
488
480
489
pub struct BorrowckInferCtxt < ' cx , ' tcx > {
0 commit comments