Skip to content

Commit dbd6be3

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

File tree

6 files changed

+56
-9
lines changed

6 files changed

+56
-9
lines changed

compiler/rustc_borrowck/src/facts.rs

Lines changed: 2 additions & 1 deletion
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

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

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 1 deletion
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::{
@@ -815,7 +816,7 @@ fn test_unstable_options_tracking_hash() {
815816
tracked!(panic_abort_tests, true);
816817
tracked!(panic_in_drop, PanicStrategy::Abort);
817818
tracked!(plt, Some(true));
818-
tracked!(polonius, true);
819+
tracked!(polonius, Polonius::Legacy);
819820
tracked!(precise_enum_drop_elaboration, false);
820821
tracked!(print_fuel, Some("abc".to_string()));
821822
tracked!(profile, true);

compiler/rustc_session/src/config.rs

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3121,9 +3121,9 @@ pub(crate) mod dep_tracking {
31213121
use super::{
31223122
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, ErrorOutputType,
31233123
InstrumentCoverage, InstrumentXRay, LdImpl, LinkerPluginLto, LocationDetail, LtoCli,
3124-
OomStrategy, OptLevel, OutFileName, OutputType, OutputTypes, Passes, ResolveDocLinks,
3125-
SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath, SymbolManglingVersion,
3126-
TraitSolver, TrimmedDefPaths,
3124+
OomStrategy, OptLevel, OutFileName, OutputType, OutputTypes, Passes, Polonius,
3125+
ResolveDocLinks, SourceFileHashAlgorithm, SplitDwarfKind, SwitchWithOptPath,
3126+
SymbolManglingVersion, TraitSolver, TrimmedDefPaths,
31273127
};
31283128
use crate::lint;
31293129
use crate::options::WasiExecModel;
@@ -3227,6 +3227,7 @@ pub(crate) mod dep_tracking {
32273227
OomStrategy,
32283228
LanguageIdentifier,
32293229
TraitSolver,
3230+
Polonius,
32303231
);
32313232

32323233
impl<T1, T2> DepTrackingHash for (T1, T2)
@@ -3365,3 +3366,30 @@ impl DumpMonoStatsFormat {
33653366
}
33663367
}
33673368
}
3369+
3370+
/// `-Zpolonius` values, enabling the borrow checker polonius analysis, and which version: legacy,
3371+
/// or future prototype.
3372+
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
3373+
pub enum Polonius {
3374+
/// The default value: disabled.
3375+
Off,
3376+
3377+
/// Legacy version, using datalog and the `polonius-engine` crate. Historical value for `-Zpolonius`.
3378+
Legacy,
3379+
3380+
/// In-tree experimentation
3381+
Next,
3382+
}
3383+
3384+
impl Default for Polonius {
3385+
fn default() -> Self {
3386+
Polonius::Off
3387+
}
3388+
}
3389+
3390+
impl Polonius {
3391+
/// Returns whether the legacy version of polonius is enabled
3392+
pub fn is_legacy_enabled(&self) -> bool {
3393+
matches!(self, Polonius::Legacy)
3394+
}
3395+
}

compiler/rustc_session/src/options.rs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ mod desc {
413413
pub const parse_gcc_ld: &str = "one of: no value, `lld`";
414414
pub const parse_link_self_contained: &str = "one of: `y`, `yes`, `on`, `n`, `no`, `off`, or a list of enabled (`+` prefix) and disabled (`-` prefix) \
415415
components: `crto`, `libc`, `unwind`, `linker`, `sanitizers`, `mingw`";
416+
pub const parse_polonius: &str = "either no value or `legacy` (the default), or `next`";
416417
pub const parse_stack_protector: &str =
417418
"one of (`none` (default), `basic`, `strong`, or `all`)";
418419
pub const parse_branch_protection: &str =
@@ -470,6 +471,21 @@ mod parse {
470471
}
471472
}
472473

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

0 commit comments

Comments
 (0)