File tree 3 files changed +10
-10
lines changed
compiler/rustc_borrowck/src
3 files changed +10
-10
lines changed Original file line number Diff line number Diff line change @@ -14,16 +14,16 @@ pub use super::{
14
14
} ;
15
15
16
16
/// This function computes Polonius facts for the given body. It makes a copy of
17
- /// the body because it needs to regenerate the region identifiers.
17
+ /// the body because it needs to regenerate the region identifiers. This function
18
+ /// should never be invoked during a typical compilation session due to performance
19
+ /// issues with Polonius.
18
20
///
19
21
/// Note:
20
22
/// * This function will panic if the required body was already stolen. This
21
23
/// can, for example, happen when requesting a body of a `const` function
22
24
/// because they are evaluated during typechecking. The panic can be avoided
23
25
/// by overriding the `mir_borrowck` query. You can find a complete example
24
26
/// that shows how to do this at `src/test/run-make/obtain-borrowck/`.
25
- /// * This function will also panic if computation of Polonius facts
26
- /// (`-Zpolonius` flag) is not enabled.
27
27
///
28
28
/// * Polonius is highly unstable, so expect regular changes in its signature or other details.
29
29
pub fn get_body_with_borrowck_facts < ' tcx > (
Original file line number Diff line number Diff line change @@ -154,11 +154,6 @@ fn do_mir_borrowck<'a, 'tcx>(
154
154
155
155
debug ! ( "do_mir_borrowck(def = {:?})" , def) ;
156
156
157
- assert ! (
158
- !return_body_with_facts || infcx. tcx. sess. opts. debugging_opts. polonius,
159
- "borrowck facts can be requested only when Polonius is enabled"
160
- ) ;
161
-
162
157
let tcx = infcx. tcx ;
163
158
let param_env = tcx. param_env ( def. did ) ;
164
159
let id = tcx. hir ( ) . local_def_id_to_hir_id ( def. did ) ;
@@ -235,6 +230,8 @@ fn do_mir_borrowck<'a, 'tcx>(
235
230
let borrow_set =
236
231
Rc :: new ( BorrowSet :: build ( tcx, body, locals_are_invalidated_at_exit, & mdpe. move_data ) ) ;
237
232
233
+ let use_polonius = return_body_with_facts || infcx. tcx . sess . opts . debugging_opts . polonius ;
234
+
238
235
// Compute non-lexical lifetimes.
239
236
let nll:: NllOutput {
240
237
regioncx,
@@ -254,6 +251,7 @@ fn do_mir_borrowck<'a, 'tcx>(
254
251
& mdpe. move_data ,
255
252
& borrow_set,
256
253
& upvars,
254
+ use_polonius,
257
255
) ;
258
256
259
257
// Dump MIR results into a file, if that is enabled. This let us
Original file line number Diff line number Diff line change @@ -164,8 +164,10 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
164
164
move_data : & MoveData < ' tcx > ,
165
165
borrow_set : & BorrowSet < ' tcx > ,
166
166
upvars : & [ Upvar < ' tcx > ] ,
167
+ use_polonius : bool ,
167
168
) -> NllOutput < ' tcx > {
168
- let mut all_facts = AllFacts :: enabled ( infcx. tcx ) . then_some ( AllFacts :: default ( ) ) ;
169
+ let mut all_facts =
170
+ ( use_polonius || AllFacts :: enabled ( infcx. tcx ) ) . then_some ( AllFacts :: default ( ) ) ;
169
171
170
172
let universal_regions = Rc :: new ( universal_regions) ;
171
173
@@ -281,7 +283,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
281
283
all_facts. write_to_dir ( dir_path, location_table) . unwrap ( ) ;
282
284
}
283
285
284
- if infcx . tcx . sess . opts . debugging_opts . polonius {
286
+ if use_polonius {
285
287
let algorithm =
286
288
env:: var ( "POLONIUS_ALGORITHM" ) . unwrap_or_else ( |_| String :: from ( "Hybrid" ) ) ;
287
289
let algorithm = Algorithm :: from_str ( & algorithm) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments