about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRémy Rakic <remy.rakic+github@gmail.com>2024-08-28 21:13:56 +0000
committerRémy Rakic <remy.rakic+github@gmail.com>2024-08-30 07:14:19 +0000
commite0bb1c72912bc5712e937a5f8ed3e80147554b7e (patch)
tree9b1cb7f9a93a21fcdc03864924a09f4429af4db2
parentc646b46b5299a58e7a0d475f0972f460d46cf68a (diff)
downloadrust-e0bb1c72912bc5712e937a5f8ed3e80147554b7e.tar.gz
rust-e0bb1c72912bc5712e937a5f8ed3e80147554b7e.zip
make `-Z mir-include-spans` a dedicated enum
We want to allow setting this on the CLI, override it only in MIR
passes, and disable it altogether in mir-opt tests.

The default value is "only for NLL MIR dumps", which is considered off
for all intents and purposes, except for `rustc_borrowck` when an NLL
MIR dump is requested.
-rw-r--r--compiler/rustc_interface/src/tests.rs9
-rw-r--r--compiler/rustc_middle/src/mir/pretty.rs2
-rw-r--r--compiler/rustc_session/src/config.rs22
-rw-r--r--compiler/rustc_session/src/options.rs18
4 files changed, 44 insertions, 7 deletions
diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs
index 844d8ef02e0..42fed98df01 100644
--- a/compiler/rustc_interface/src/tests.rs
+++ b/compiler/rustc_interface/src/tests.rs
@@ -12,9 +12,10 @@ use rustc_session::config::{
     CollapseMacroDebuginfo, CoverageLevel, CoverageOptions, DebugInfo, DumpMonoStatsFormat,
     ErrorOutputType, ExternEntry, ExternLocation, Externs, FmtDebug, FunctionReturn,
     InliningThreshold, Input, InstrumentCoverage, InstrumentXRay, LinkSelfContained,
-    LinkerPluginLto, LocationDetail, LtoCli, NextSolverConfig, OomStrategy, Options, OutFileName,
-    OutputType, OutputTypes, PAuthKey, PacRet, Passes, PatchableFunctionEntry, Polonius,
-    ProcMacroExecutionStrategy, Strip, SwitchWithOptPath, SymbolManglingVersion, WasiExecModel,
+    LinkerPluginLto, LocationDetail, LtoCli, MirIncludeSpans, NextSolverConfig, OomStrategy,
+    Options, OutFileName, OutputType, OutputTypes, PAuthKey, PacRet, Passes,
+    PatchableFunctionEntry, Polonius, ProcMacroExecutionStrategy, Strip, SwitchWithOptPath,
+    SymbolManglingVersion, WasiExecModel,
 };
 use rustc_session::lint::Level;
 use rustc_session::search_paths::SearchPath;
@@ -705,7 +706,7 @@ fn test_unstable_options_tracking_hash() {
     untracked!(ls, vec!["all".to_owned()]);
     untracked!(macro_backtrace, true);
     untracked!(meta_stats, true);
-    untracked!(mir_include_spans, true);
+    untracked!(mir_include_spans, MirIncludeSpans::On);
     untracked!(nll_facts, true);
     untracked!(no_analysis, true);
     untracked!(no_leak_check, true);
diff --git a/compiler/rustc_middle/src/mir/pretty.rs b/compiler/rustc_middle/src/mir/pretty.rs
index d296a3b7b60..9906be60e3e 100644
--- a/compiler/rustc_middle/src/mir/pretty.rs
+++ b/compiler/rustc_middle/src/mir/pretty.rs
@@ -54,7 +54,7 @@ pub struct PrettyPrintMirOptions {
 impl PrettyPrintMirOptions {
     /// Create the default set of MIR pretty-printing options from the CLI flags.
     pub fn from_cli(tcx: TyCtxt<'_>) -> Self {
-        Self { include_extra_comments: tcx.sess.opts.unstable_opts.mir_include_spans }
+        Self { include_extra_comments: tcx.sess.opts.unstable_opts.mir_include_spans.is_enabled() }
     }
 }
 
diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs
index fbdb3cb1534..945bab6887e 100644
--- a/compiler/rustc_session/src/config.rs
+++ b/compiler/rustc_session/src/config.rs
@@ -3369,3 +3369,25 @@ pub enum FunctionReturn {
     /// Replace returns with jumps to thunk, without emitting the thunk.
     ThunkExtern,
 }
+
+/// Whether extra span comments are included when dumping MIR, via the `-Z mir-include-spans` flag.
+/// By default, only enabled in the NLL MIR dumps, and disabled in all other passes.
+#[derive(Clone, Copy, Default, PartialEq, Debug)]
+pub enum MirIncludeSpans {
+    Off,
+    On,
+    /// Default: include extra comments in NLL MIR dumps only. Can be ignored and considered as
+    /// `Off` in all other cases.
+    #[default]
+    Nll,
+}
+
+impl MirIncludeSpans {
+    /// Unless opting into extra comments for all passes, they can be considered disabled.
+    /// The cases where a distinction between on/off and a per-pass value can exist will be handled
+    /// in the passes themselves: i.e. the `Nll` value is considered off for all intents and
+    /// purposes, except for the NLL MIR dump pass.
+    pub fn is_enabled(self) -> bool {
+        self == MirIncludeSpans::On
+    }
+}
diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs
index 4492ad09357..37077901e0c 100644
--- a/compiler/rustc_session/src/options.rs
+++ b/compiler/rustc_session/src/options.rs
@@ -445,6 +445,8 @@ mod desc {
     pub const parse_llvm_module_flag: &str = "<key>:<type>:<value>:<behavior>. Type must currently be `u32`. Behavior should be one of (`error`, `warning`, `require`, `override`, `append`, `appendunique`, `max`, `min`)";
     pub const parse_function_return: &str = "`keep` or `thunk-extern`";
     pub const parse_wasm_c_abi: &str = "`legacy` or `spec`";
+    pub const parse_mir_include_spans: &str =
+        "either a boolean (`yes`, `no`, `on`, `off`, etc), or `nll` (default: `nll`)";
 }
 
 mod parse {
@@ -1488,6 +1490,17 @@ mod parse {
         }
         true
     }
+
+    pub(crate) fn parse_mir_include_spans(slot: &mut MirIncludeSpans, v: Option<&str>) -> bool {
+        *slot = match v {
+            Some("on" | "yes" | "y" | "true") | None => MirIncludeSpans::On,
+            Some("off" | "no" | "n" | "false") => MirIncludeSpans::Off,
+            Some("nll") => MirIncludeSpans::Nll,
+            _ => return false,
+        };
+
+        true
+    }
 }
 
 options! {
@@ -1848,8 +1861,9 @@ options! {
         specified passes to be enabled, overriding all other checks. In particular, this will \
         enable unsound (known-buggy and hence usually disabled) passes without further warning! \
         Passes that are not specified are enabled or disabled by other flags as usual."),
-    mir_include_spans: bool = (false, parse_bool, [UNTRACKED],
-        "use line numbers relative to the function in mir pretty printing"),
+    mir_include_spans: MirIncludeSpans = (MirIncludeSpans::default(), parse_mir_include_spans, [UNTRACKED],
+        "include extra comments in mir pretty printing, like line numbers and statement indices, \
+         details about types, etc. (boolean for all passes, 'nll' to enable in NLL MIR only, default: 'nll')"),
     mir_keep_place_mention: bool = (false, parse_bool, [TRACKED],
         "keep place mention MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
         (default: no)"),