Skip to content

Commit e0bb1c7

Browse files
committed
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.
1 parent c646b46 commit e0bb1c7

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

compiler/rustc_interface/src/tests.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ use rustc_session::config::{
1212
CollapseMacroDebuginfo, CoverageLevel, CoverageOptions, DebugInfo, DumpMonoStatsFormat,
1313
ErrorOutputType, ExternEntry, ExternLocation, Externs, FmtDebug, FunctionReturn,
1414
InliningThreshold, Input, InstrumentCoverage, InstrumentXRay, LinkSelfContained,
15-
LinkerPluginLto, LocationDetail, LtoCli, NextSolverConfig, OomStrategy, Options, OutFileName,
16-
OutputType, OutputTypes, PAuthKey, PacRet, Passes, PatchableFunctionEntry, Polonius,
17-
ProcMacroExecutionStrategy, Strip, SwitchWithOptPath, SymbolManglingVersion, WasiExecModel,
15+
LinkerPluginLto, LocationDetail, LtoCli, MirIncludeSpans, NextSolverConfig, OomStrategy,
16+
Options, OutFileName, OutputType, OutputTypes, PAuthKey, PacRet, Passes,
17+
PatchableFunctionEntry, Polonius, ProcMacroExecutionStrategy, Strip, SwitchWithOptPath,
18+
SymbolManglingVersion, WasiExecModel,
1819
};
1920
use rustc_session::lint::Level;
2021
use rustc_session::search_paths::SearchPath;
@@ -705,7 +706,7 @@ fn test_unstable_options_tracking_hash() {
705706
untracked!(ls, vec!["all".to_owned()]);
706707
untracked!(macro_backtrace, true);
707708
untracked!(meta_stats, true);
708-
untracked!(mir_include_spans, true);
709+
untracked!(mir_include_spans, MirIncludeSpans::On);
709710
untracked!(nll_facts, true);
710711
untracked!(no_analysis, true);
711712
untracked!(no_leak_check, true);

compiler/rustc_middle/src/mir/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ pub struct PrettyPrintMirOptions {
5454
impl PrettyPrintMirOptions {
5555
/// Create the default set of MIR pretty-printing options from the CLI flags.
5656
pub fn from_cli(tcx: TyCtxt<'_>) -> Self {
57-
Self { include_extra_comments: tcx.sess.opts.unstable_opts.mir_include_spans }
57+
Self { include_extra_comments: tcx.sess.opts.unstable_opts.mir_include_spans.is_enabled() }
5858
}
5959
}
6060

compiler/rustc_session/src/config.rs

+22
Original file line numberDiff line numberDiff line change
@@ -3369,3 +3369,25 @@ pub enum FunctionReturn {
33693369
/// Replace returns with jumps to thunk, without emitting the thunk.
33703370
ThunkExtern,
33713371
}
3372+
3373+
/// Whether extra span comments are included when dumping MIR, via the `-Z mir-include-spans` flag.
3374+
/// By default, only enabled in the NLL MIR dumps, and disabled in all other passes.
3375+
#[derive(Clone, Copy, Default, PartialEq, Debug)]
3376+
pub enum MirIncludeSpans {
3377+
Off,
3378+
On,
3379+
/// Default: include extra comments in NLL MIR dumps only. Can be ignored and considered as
3380+
/// `Off` in all other cases.
3381+
#[default]
3382+
Nll,
3383+
}
3384+
3385+
impl MirIncludeSpans {
3386+
/// Unless opting into extra comments for all passes, they can be considered disabled.
3387+
/// The cases where a distinction between on/off and a per-pass value can exist will be handled
3388+
/// in the passes themselves: i.e. the `Nll` value is considered off for all intents and
3389+
/// purposes, except for the NLL MIR dump pass.
3390+
pub fn is_enabled(self) -> bool {
3391+
self == MirIncludeSpans::On
3392+
}
3393+
}

compiler/rustc_session/src/options.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ mod desc {
445445
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`)";
446446
pub const parse_function_return: &str = "`keep` or `thunk-extern`";
447447
pub const parse_wasm_c_abi: &str = "`legacy` or `spec`";
448+
pub const parse_mir_include_spans: &str =
449+
"either a boolean (`yes`, `no`, `on`, `off`, etc), or `nll` (default: `nll`)";
448450
}
449451

450452
mod parse {
@@ -1488,6 +1490,17 @@ mod parse {
14881490
}
14891491
true
14901492
}
1493+
1494+
pub(crate) fn parse_mir_include_spans(slot: &mut MirIncludeSpans, v: Option<&str>) -> bool {
1495+
*slot = match v {
1496+
Some("on" | "yes" | "y" | "true") | None => MirIncludeSpans::On,
1497+
Some("off" | "no" | "n" | "false") => MirIncludeSpans::Off,
1498+
Some("nll") => MirIncludeSpans::Nll,
1499+
_ => return false,
1500+
};
1501+
1502+
true
1503+
}
14911504
}
14921505

14931506
options! {
@@ -1848,8 +1861,9 @@ options! {
18481861
specified passes to be enabled, overriding all other checks. In particular, this will \
18491862
enable unsound (known-buggy and hence usually disabled) passes without further warning! \
18501863
Passes that are not specified are enabled or disabled by other flags as usual."),
1851-
mir_include_spans: bool = (false, parse_bool, [UNTRACKED],
1852-
"use line numbers relative to the function in mir pretty printing"),
1864+
mir_include_spans: MirIncludeSpans = (MirIncludeSpans::default(), parse_mir_include_spans, [UNTRACKED],
1865+
"include extra comments in mir pretty printing, like line numbers and statement indices, \
1866+
details about types, etc. (boolean for all passes, 'nll' to enable in NLL MIR only, default: 'nll')"),
18531867
mir_keep_place_mention: bool = (false, parse_bool, [TRACKED],
18541868
"keep place mention MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \
18551869
(default: no)"),

0 commit comments

Comments
 (0)