From 4fd39dd8a6f20bb919b30a56022c16e235cf7d5a Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Wed, 15 Sep 2021 11:41:37 -0700 Subject: [PATCH 1/2] Make rustc_mir_dataflow::framework::graphviz and rustc_mir_transform::MirPass public --- compiler/rustc_mir_dataflow/src/lib.rs | 4 ++-- compiler/rustc_mir_transform/src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_mir_dataflow/src/lib.rs b/compiler/rustc_mir_dataflow/src/lib.rs index bfae09b7760a0..72c4e27cbeabf 100644 --- a/compiler/rustc_mir_dataflow/src/lib.rs +++ b/compiler/rustc_mir_dataflow/src/lib.rs @@ -28,8 +28,8 @@ pub use self::drop_flag_effects::{ on_lookup_result_bits, }; pub use self::framework::{ - fmt, lattice, visit_results, Analysis, AnalysisDomain, Backward, Direction, Engine, Forward, - GenKill, GenKillAnalysis, JoinSemiLattice, Results, ResultsCursor, ResultsRefCursor, + fmt, graphviz, lattice, visit_results, Analysis, AnalysisDomain, Backward, Direction, Engine, + Forward, GenKill, GenKillAnalysis, JoinSemiLattice, Results, ResultsCursor, ResultsRefCursor, ResultsVisitable, ResultsVisitor, }; diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index 90d7cbee976d0..bfd0de85438d1 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -76,7 +76,7 @@ mod unreachable_prop; use rustc_const_eval::transform::check_consts; use rustc_const_eval::transform::promote_consts; use rustc_const_eval::transform::validate; -use rustc_const_eval::transform::MirPass; +pub use rustc_const_eval::transform::MirPass; use rustc_mir_dataflow::rustc_peek; pub fn provide(providers: &mut Providers) { From 47104a34a67444a086fd38c82e005f316f7f567a Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Wed, 15 Sep 2021 11:45:31 -0700 Subject: [PATCH 2/2] Allow call to get_body_with_borrowck_facts without -Z polonius --- compiler/rustc_borrowck/src/consumers.rs | 6 +++--- compiler/rustc_borrowck/src/lib.rs | 8 +++----- compiler/rustc_borrowck/src/nll.rs | 6 ++++-- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/compiler/rustc_borrowck/src/consumers.rs b/compiler/rustc_borrowck/src/consumers.rs index f6e4e3888418f..4333038a6f936 100644 --- a/compiler/rustc_borrowck/src/consumers.rs +++ b/compiler/rustc_borrowck/src/consumers.rs @@ -14,7 +14,9 @@ pub use super::{ }; /// 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: /// * 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 /// 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/`. -/// * 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. pub fn get_body_with_borrowck_facts<'tcx>( diff --git a/compiler/rustc_borrowck/src/lib.rs b/compiler/rustc_borrowck/src/lib.rs index 4e4b8a953cd12..b3b7d7e02ccef 100644 --- a/compiler/rustc_borrowck/src/lib.rs +++ b/compiler/rustc_borrowck/src/lib.rs @@ -154,11 +154,6 @@ fn do_mir_borrowck<'a, 'tcx>( 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 param_env = tcx.param_env(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 = 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. let nll::NllOutput { regioncx, @@ -254,6 +251,7 @@ fn do_mir_borrowck<'a, 'tcx>( &mdpe.move_data, &borrow_set, &upvars, + use_polonius, ); // Dump MIR results into a file, if that is enabled. This let us diff --git a/compiler/rustc_borrowck/src/nll.rs b/compiler/rustc_borrowck/src/nll.rs index 8b2c0362261ca..477b049b07596 100644 --- a/compiler/rustc_borrowck/src/nll.rs +++ b/compiler/rustc_borrowck/src/nll.rs @@ -164,8 +164,10 @@ pub(crate) fn compute_regions<'cx, 'tcx>( move_data: &MoveData<'tcx>, borrow_set: &BorrowSet<'tcx>, upvars: &[Upvar<'tcx>], + use_polonius: bool, ) -> 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); @@ -281,7 +283,7 @@ pub(crate) fn compute_regions<'cx, 'tcx>( all_facts.write_to_dir(dir_path, location_table).unwrap(); } - if infcx.tcx.sess.opts.debugging_opts.polonius { + if use_polonius { let algorithm = env::var("POLONIUS_ALGORITHM").unwrap_or_else(|_| String::from("Hybrid")); let algorithm = Algorithm::from_str(&algorithm).unwrap();