1
Fork 0

introduce Polonius enum for -Zpolonius

this allows to opt into using the legacy version or the in-tree
prototype
This commit is contained in:
Rémy Rakic 2023-06-30 11:55:38 +00:00
parent 2ffeb4636b
commit 4f7a27b225
6 changed files with 54 additions and 6 deletions

View file

@ -3166,6 +3166,7 @@ impl PpMode {
/// we have an opt-in scheme here, so one is hopefully forced to think about
/// how the hash should be calculated when adding a new command-line argument.
pub(crate) mod dep_tracking {
use super::Polonius;
use super::{
BranchProtection, CFGuard, CFProtection, CrateType, DebugInfo, DebugInfoCompression,
ErrorOutputType, InstrumentCoverage, InstrumentXRay, LdImpl, LinkerPluginLto,
@ -3276,6 +3277,7 @@ pub(crate) mod dep_tracking {
OomStrategy,
LanguageIdentifier,
TraitSolver,
Polonius,
);
impl<T1, T2> DepTrackingHash for (T1, T2)
@ -3414,3 +3416,30 @@ impl DumpMonoStatsFormat {
}
}
}
/// `-Zpolonius` values, enabling the borrow checker polonius analysis, and which version: legacy,
/// or future prototype.
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
pub enum Polonius {
/// The default value: disabled.
Off,
/// Legacy version, using datalog and the `polonius-engine` crate. Historical value for `-Zpolonius`.
Legacy,
/// In-tree experimentation
Next,
}
impl Default for Polonius {
fn default() -> Self {
Polonius::Off
}
}
impl Polonius {
/// Returns whether the legacy version of polonius is enabled
pub fn is_legacy_enabled(&self) -> bool {
matches!(self, Polonius::Legacy)
}
}

View file

@ -415,6 +415,7 @@ mod desc {
pub const parse_gcc_ld: &str = "one of: no value, `lld`";
pub const parse_link_self_contained: &str = "one of: `y`, `yes`, `on`, `n`, `no`, `off`, or a list of enabled (`+` prefix) and disabled (`-` prefix) \
components: `crto`, `libc`, `unwind`, `linker`, `sanitizers`, `mingw`";
pub const parse_polonius: &str = "either no value or `legacy` (the default), or `next`";
pub const parse_stack_protector: &str =
"one of (`none` (default), `basic`, `strong`, or `all`)";
pub const parse_branch_protection: &str =
@ -472,6 +473,21 @@ mod parse {
}
}
/// Parses whether polonius is enabled, and if so, which version.
pub(crate) fn parse_polonius(slot: &mut Polonius, v: Option<&str>) -> bool {
match v {
Some("legacy") | None => {
*slot = Polonius::Legacy;
true
}
Some("next") => {
*slot = Polonius::Next;
true
}
_ => false,
}
}
/// Use this for any string option that has a static default.
pub(crate) fn parse_string(slot: &mut String, v: Option<&str>) -> bool {
match v {
@ -1669,7 +1685,7 @@ options! {
"whether to use the PLT when calling into shared libraries;
only has effect for PIC code on systems with ELF binaries
(default: PLT is disabled if full relro is enabled on x86_64)"),
polonius: bool = (false, parse_bool, [TRACKED],
polonius: Polonius = (Polonius::default(), parse_polonius, [TRACKED],
"enable polonius-based borrow-checker (default: no)"),
polymorphize: bool = (false, parse_bool, [TRACKED],
"perform polymorphization analysis"),