Skip to content

Commit 47104a3

Browse files
committed
Allow call to get_body_with_borrowck_facts without -Z polonius
1 parent 4fd39dd commit 47104a3

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

compiler/rustc_borrowck/src/consumers.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@ pub use super::{
1414
};
1515

1616
/// 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.
1820
///
1921
/// Note:
2022
/// * This function will panic if the required body was already stolen. This
2123
/// can, for example, happen when requesting a body of a `const` function
2224
/// because they are evaluated during typechecking. The panic can be avoided
2325
/// by overriding the `mir_borrowck` query. You can find a complete example
2426
/// 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.
2727
///
2828
/// * Polonius is highly unstable, so expect regular changes in its signature or other details.
2929
pub fn get_body_with_borrowck_facts<'tcx>(

compiler/rustc_borrowck/src/lib.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ fn do_mir_borrowck<'a, 'tcx>(
154154

155155
debug!("do_mir_borrowck(def = {:?})", def);
156156

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-
162157
let tcx = infcx.tcx;
163158
let param_env = tcx.param_env(def.did);
164159
let id = tcx.hir().local_def_id_to_hir_id(def.did);
@@ -235,6 +230,8 @@ fn do_mir_borrowck<'a, 'tcx>(
235230
let borrow_set =
236231
Rc::new(BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &mdpe.move_data));
237232

233+
let use_polonius = return_body_with_facts || infcx.tcx.sess.opts.debugging_opts.polonius;
234+
238235
// Compute non-lexical lifetimes.
239236
let nll::NllOutput {
240237
regioncx,
@@ -254,6 +251,7 @@ fn do_mir_borrowck<'a, 'tcx>(
254251
&mdpe.move_data,
255252
&borrow_set,
256253
&upvars,
254+
use_polonius,
257255
);
258256

259257
// Dump MIR results into a file, if that is enabled. This let us

compiler/rustc_borrowck/src/nll.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
164164
move_data: &MoveData<'tcx>,
165165
borrow_set: &BorrowSet<'tcx>,
166166
upvars: &[Upvar<'tcx>],
167+
use_polonius: bool,
167168
) -> 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());
169171

170172
let universal_regions = Rc::new(universal_regions);
171173

@@ -281,7 +283,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
281283
all_facts.write_to_dir(dir_path, location_table).unwrap();
282284
}
283285

284-
if infcx.tcx.sess.opts.debugging_opts.polonius {
286+
if use_polonius {
285287
let algorithm =
286288
env::var("POLONIUS_ALGORITHM").unwrap_or_else(|_| String::from("Hybrid"));
287289
let algorithm = Algorithm::from_str(&algorithm).unwrap();

0 commit comments

Comments
 (0)