Skip to content

Commit 4f7a27b

Browse files
committed
introduce Polonius enum for -Zpolonius
this allows to opt into using the legacy version or the in-tree prototype
1 parent 2ffeb46 commit 4f7a27b

File tree

6 files changed

+54
-6
lines changed

6 files changed

+54
-6
lines changed

compiler/rustc_borrowck/src/facts.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ pub(crate) trait AllFactsExt {
4141
impl AllFactsExt for AllFacts {
4242
/// Return
4343
fn enabled(tcx: TyCtxt<'_>) -> bool {
44-
tcx.sess.opts.unstable_opts.nll_facts || tcx.sess.opts.unstable_opts.polonius
44+
tcx.sess.opts.unstable_opts.nll_facts
45+
|| tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled()
4546
}
4647

4748
fn write_to_dir(

compiler/rustc_borrowck/src/nll.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
169169
upvars: &[Upvar<'tcx>],
170170
consumer_options: Option<ConsumerOptions>,
171171
) -> NllOutput<'tcx> {
172+
let is_polonius_legacy_enabled = infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled();
172173
let polonius_input = consumer_options.map(|c| c.polonius_input()).unwrap_or_default()
173-
|| infcx.tcx.sess.opts.unstable_opts.polonius;
174+
|| is_polonius_legacy_enabled;
174175
let polonius_output = consumer_options.map(|c| c.polonius_output()).unwrap_or_default()
175-
|| infcx.tcx.sess.opts.unstable_opts.polonius;
176+
|| is_polonius_legacy_enabled;
176177
let mut all_facts =
177178
(polonius_input || AllFacts::enabled(infcx.tcx)).then_some(AllFacts::default());
178179

compiler/rustc_borrowck/src/region_infer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
683683
// In Polonius mode, the errors about missing universal region relations are in the output
684684
// and need to be emitted or propagated. Otherwise, we need to check whether the
685685
// constraints were too strong, and if so, emit or propagate those errors.
686-
if infcx.tcx.sess.opts.unstable_opts.polonius {
686+
if infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled() {
687687
self.check_polonius_subset_errors(
688688
outlives_requirements.as_mut(),
689689
&mut errors_buffer,

compiler/rustc_interface/src/tests.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use rustc_session::config::DebugInfo;
99
use rustc_session::config::Input;
1010
use rustc_session::config::InstrumentXRay;
1111
use rustc_session::config::LinkSelfContained;
12+
use rustc_session::config::Polonius;
1213
use rustc_session::config::TraitSolver;
1314
use rustc_session::config::{build_configuration, build_session_options, to_crate_config};
1415
use rustc_session::config::{
@@ -814,7 +815,7 @@ fn test_unstable_options_tracking_hash() {
814815
tracked!(panic_abort_tests, true);
815816
tracked!(panic_in_drop, PanicStrategy::Abort);
816817
tracked!(plt, Some(true));
817-
tracked!(polonius, true);
818+
tracked!(polonius, Polonius::Legacy);
818819
tracked!(precise_enum_drop_elaboration, false);
819820
tracked!(print_fuel, Some("abc".to_string()));
820821
tracked!(profile, true);

compiler/rustc_session/src/config.rs

+29
Original file line numberDiff line numberDiff line change
@@ -3166,6 +3166,7 @@ impl PpMode {
31663166
/// we have an opt-in scheme here, so one is hopefully forced to think about
31673167
/// how the hash should be calculated when adding a new command-line argument.
31683168
pub(crate) mod dep_tracking {
3169+
use super::Polonius;
31693170
use super::{
31703171
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, DebugInfoCompression,
31713172
ErrorOutputType, InstrumentCoverage, InstrumentXRay, LdImpl, LinkerPluginLto,
@@ -3276,6 +3277,7 @@ pub(crate) mod dep_tracking {
32763277
OomStrategy,
32773278
LanguageIdentifier,
32783279
TraitSolver,
3280+
Polonius,
32793281
);
32803282

32813283
impl<T1, T2> DepTrackingHash for (T1, T2)
@@ -3414,3 +3416,30 @@ impl DumpMonoStatsFormat {
34143416
}
34153417
}
34163418
}
3419+
3420+
/// `-Zpolonius` values, enabling the borrow checker polonius analysis, and which version: legacy,
3421+
/// or future prototype.
3422+
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
3423+
pub enum Polonius {
3424+
/// The default value: disabled.
3425+
Off,
3426+
3427+
/// Legacy version, using datalog and the `polonius-engine` crate. Historical value for `-Zpolonius`.
3428+
Legacy,
3429+
3430+
/// In-tree experimentation
3431+
Next,
3432+
}
3433+
3434+
impl Default for Polonius {
3435+
fn default() -> Self {
3436+
Polonius::Off
3437+
}
3438+
}
3439+
3440+
impl Polonius {
3441+
/// Returns whether the legacy version of polonius is enabled
3442+
pub fn is_legacy_enabled(&self) -> bool {
3443+
matches!(self, Polonius::Legacy)
3444+
}
3445+
}

compiler/rustc_session/src/options.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,7 @@ mod desc {
415415
pub const parse_gcc_ld: &str = "one of: no value, `lld`";
416416
pub const parse_link_self_contained: &str = "one of: `y`, `yes`, `on`, `n`, `no`, `off`, or a list of enabled (`+` prefix) and disabled (`-` prefix) \
417417
components: `crto`, `libc`, `unwind`, `linker`, `sanitizers`, `mingw`";
418+
pub const parse_polonius: &str = "either no value or `legacy` (the default), or `next`";
418419
pub const parse_stack_protector: &str =
419420
"one of (`none` (default), `basic`, `strong`, or `all`)";
420421
pub const parse_branch_protection: &str =
@@ -472,6 +473,21 @@ mod parse {
472473
}
473474
}
474475

476+
/// Parses whether polonius is enabled, and if so, which version.
477+
pub(crate) fn parse_polonius(slot: &mut Polonius, v: Option<&str>) -> bool {
478+
match v {
479+
Some("legacy") | None => {
480+
*slot = Polonius::Legacy;
481+
true
482+
}
483+
Some("next") => {
484+
*slot = Polonius::Next;
485+
true
486+
}
487+
_ => false,
488+
}
489+
}
490+
475491
/// Use this for any string option that has a static default.
476492
pub(crate) fn parse_string(slot: &mut String, v: Option<&str>) -> bool {
477493
match v {
@@ -1669,7 +1685,7 @@ options! {
16691685
"whether to use the PLT when calling into shared libraries;
16701686
only has effect for PIC code on systems with ELF binaries
16711687
(default: PLT is disabled if full relro is enabled on x86_64)"),
1672-
polonius: bool = (false, parse_bool, [TRACKED],
1688+
polonius: Polonius = (Polonius::default(), parse_polonius, [TRACKED],
16731689
"enable polonius-based borrow-checker (default: no)"),
16741690
polymorphize: bool = (false, parse_bool, [TRACKED],
16751691
"perform polymorphization analysis"),

0 commit comments

Comments
 (0)