mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
introduce Polonius
enum for -Zpolonius
this allows to opt into using the legacy version or the in-tree prototype
This commit is contained in:
parent
2ffeb4636b
commit
4f7a27b225
@ -41,7 +41,8 @@ pub(crate) trait AllFactsExt {
|
||||
impl AllFactsExt for AllFacts {
|
||||
/// Return
|
||||
fn enabled(tcx: TyCtxt<'_>) -> bool {
|
||||
tcx.sess.opts.unstable_opts.nll_facts || tcx.sess.opts.unstable_opts.polonius
|
||||
tcx.sess.opts.unstable_opts.nll_facts
|
||||
|| tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled()
|
||||
}
|
||||
|
||||
fn write_to_dir(
|
||||
|
@ -169,10 +169,11 @@ pub(crate) fn compute_regions<'cx, 'tcx>(
|
||||
upvars: &[Upvar<'tcx>],
|
||||
consumer_options: Option<ConsumerOptions>,
|
||||
) -> NllOutput<'tcx> {
|
||||
let is_polonius_legacy_enabled = infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled();
|
||||
let polonius_input = consumer_options.map(|c| c.polonius_input()).unwrap_or_default()
|
||||
|| infcx.tcx.sess.opts.unstable_opts.polonius;
|
||||
|| is_polonius_legacy_enabled;
|
||||
let polonius_output = consumer_options.map(|c| c.polonius_output()).unwrap_or_default()
|
||||
|| infcx.tcx.sess.opts.unstable_opts.polonius;
|
||||
|| is_polonius_legacy_enabled;
|
||||
let mut all_facts =
|
||||
(polonius_input || AllFacts::enabled(infcx.tcx)).then_some(AllFacts::default());
|
||||
|
||||
|
@ -683,7 +683,7 @@ impl<'tcx> RegionInferenceContext<'tcx> {
|
||||
// In Polonius mode, the errors about missing universal region relations are in the output
|
||||
// and need to be emitted or propagated. Otherwise, we need to check whether the
|
||||
// constraints were too strong, and if so, emit or propagate those errors.
|
||||
if infcx.tcx.sess.opts.unstable_opts.polonius {
|
||||
if infcx.tcx.sess.opts.unstable_opts.polonius.is_legacy_enabled() {
|
||||
self.check_polonius_subset_errors(
|
||||
outlives_requirements.as_mut(),
|
||||
&mut errors_buffer,
|
||||
|
@ -9,6 +9,7 @@ use rustc_session::config::DebugInfo;
|
||||
use rustc_session::config::Input;
|
||||
use rustc_session::config::InstrumentXRay;
|
||||
use rustc_session::config::LinkSelfContained;
|
||||
use rustc_session::config::Polonius;
|
||||
use rustc_session::config::TraitSolver;
|
||||
use rustc_session::config::{build_configuration, build_session_options, to_crate_config};
|
||||
use rustc_session::config::{
|
||||
@ -814,7 +815,7 @@ fn test_unstable_options_tracking_hash() {
|
||||
tracked!(panic_abort_tests, true);
|
||||
tracked!(panic_in_drop, PanicStrategy::Abort);
|
||||
tracked!(plt, Some(true));
|
||||
tracked!(polonius, true);
|
||||
tracked!(polonius, Polonius::Legacy);
|
||||
tracked!(precise_enum_drop_elaboration, false);
|
||||
tracked!(print_fuel, Some("abc".to_string()));
|
||||
tracked!(profile, true);
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -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"),
|
||||
|
Loading…
Reference in New Issue
Block a user