1
Fork 0

Allow call to get_body_with_borrowck_facts without -Z polonius

This commit is contained in:
Will Crichton 2021-09-15 11:45:31 -07:00
parent 4fd39dd8a6
commit 47104a34a6
3 changed files with 10 additions and 10 deletions

View file

@ -14,7 +14,9 @@ pub use super::{
}; };
/// This function computes Polonius facts for the given body. It makes a copy of /// This function computes Polonius facts for the given body. It makes a copy of
/// the body because it needs to regenerate the region identifiers. /// the body because it needs to regenerate the region identifiers. This function
/// should never be invoked during a typical compilation session due to performance
/// issues with Polonius.
/// ///
/// Note: /// Note:
/// * This function will panic if the required body was already stolen. This /// * This function will panic if the required body was already stolen. This
@ -22,8 +24,6 @@ pub use super::{
/// because they are evaluated during typechecking. The panic can be avoided /// because they are evaluated during typechecking. The panic can be avoided
/// by overriding the `mir_borrowck` query. You can find a complete example /// by overriding the `mir_borrowck` query. You can find a complete example
/// that shows how to do this at `src/test/run-make/obtain-borrowck/`. /// that shows how to do this at `src/test/run-make/obtain-borrowck/`.
/// * This function will also panic if computation of Polonius facts
/// (`-Zpolonius` flag) is not enabled.
/// ///
/// * Polonius is highly unstable, so expect regular changes in its signature or other details. /// * Polonius is highly unstable, so expect regular changes in its signature or other details.
pub fn get_body_with_borrowck_facts<'tcx>( pub fn get_body_with_borrowck_facts<'tcx>(

View file

@ -154,11 +154,6 @@ fn do_mir_borrowck<'a, 'tcx>(
debug!("do_mir_borrowck(def = {:?})", def); debug!("do_mir_borrowck(def = {:?})", def);
assert!(
!return_body_with_facts || infcx.tcx.sess.opts.debugging_opts.polonius,
"borrowck facts can be requested only when Polonius is enabled"
);
let tcx = infcx.tcx; let tcx = infcx.tcx;
let param_env = tcx.param_env(def.did); let param_env = tcx.param_env(def.did);
let id = tcx.hir().local_def_id_to_hir_id(def.did); let id = tcx.hir().local_def_id_to_hir_id(def.did);
@ -235,6 +230,8 @@ fn do_mir_borrowck<'a, 'tcx>(
let borrow_set = let borrow_set =
Rc::new(BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &mdpe.move_data)); Rc::new(BorrowSet::build(tcx, body, locals_are_invalidated_at_exit, &mdpe.move_data));
let use_polonius = return_body_with_facts || infcx.tcx.sess.opts.debugging_opts.polonius;
// Compute non-lexical lifetimes. // Compute non-lexical lifetimes.
let nll::NllOutput { let nll::NllOutput {
regioncx, regioncx,
@ -254,6 +251,7 @@ fn do_mir_borrowck<'a, 'tcx>(
&mdpe.move_data, &mdpe.move_data,
&borrow_set, &borrow_set,
&upvars, &upvars,
use_polonius,
); );
// Dump MIR results into a file, if that is enabled. This let us // Dump MIR results into a file, if that is enabled. This let us

View file

@ -164,8 +164,10 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
move_data: &MoveData<'tcx>, move_data: &MoveData<'tcx>,
borrow_set: &BorrowSet<'tcx>, borrow_set: &BorrowSet<'tcx>,
upvars: &[Upvar<'tcx>], upvars: &[Upvar<'tcx>],
use_polonius: bool,
) -> NllOutput<'tcx> { ) -> NllOutput<'tcx> {
let mut all_facts = AllFacts::enabled(infcx.tcx).then_some(AllFacts::default()); let mut all_facts =
(use_polonius || AllFacts::enabled(infcx.tcx)).then_some(AllFacts::default());
let universal_regions = Rc::new(universal_regions); let universal_regions = Rc::new(universal_regions);
@ -281,7 +283,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
all_facts.write_to_dir(dir_path, location_table).unwrap(); all_facts.write_to_dir(dir_path, location_table).unwrap();
} }
if infcx.tcx.sess.opts.debugging_opts.polonius { if use_polonius {
let algorithm = let algorithm =
env::var("POLONIUS_ALGORITHM").unwrap_or_else(|_| String::from("Hybrid")); env::var("POLONIUS_ALGORITHM").unwrap_or_else(|_| String::from("Hybrid"));
let algorithm = Algorithm::from_str(&algorithm).unwrap(); let algorithm = Algorithm::from_str(&algorithm).unwrap();