Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6bfe236

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 92da216 commit 6bfe236

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

‎compiler/rustc_interface/src/tests.rs‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ use rustc_session::config::{
1212
CollapseMacroDebuginfo, CoverageLevel, CoverageOptions, DebugInfo, DumpMonoStatsFormat,
1313
ErrorOutputType, ExternEntry, ExternLocation, Externs, FunctionReturn, InliningThreshold,
1414
Input, InstrumentCoverage, InstrumentXRay, LinkSelfContained, LinkerPluginLto, LocationDetail,
15-
LtoCli, NextSolverConfig, OomStrategy, Options, OutFileName, OutputType,OutputTypes,PAuthKey,
16-
PacRet,Passes,PatchableFunctionEntry,Polonius,ProcMacroExecutionStrategy,Strip,
17-
SwitchWithOptPath, SymbolManglingVersion, WasiExecModel,
15+
LtoCli, MirIncludeSpans,NextSolverConfig, OomStrategy, Options, OutFileName, OutputType,
16+
OutputTypes,PAuthKey,PacRet,Passes,PatchableFunctionEntry,Polonius,
17+
ProcMacroExecutionStrategy,Strip,SwitchWithOptPath, SymbolManglingVersion, WasiExecModel,
1818
};
1919
use rustc_session::lint::Level;
2020
use rustc_session::search_paths::SearchPath;
@@ -705,7 +705,7 @@ fn test_unstable_options_tracking_hash() {
705705
untracked!(ls, vec!["all".to_owned()]);
706706
untracked!(macro_backtrace, true);
707707
untracked!(meta_stats, true);
708-
untracked!(mir_include_spans, true);
708+
untracked!(mir_include_spans, MirIncludeSpans::On);
709709
untracked!(nll_facts, true);
710710
untracked!(no_analysis, true);
711711
untracked!(no_leak_check, true);

‎compiler/rustc_middle/src/mir/pretty.rs‎

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3348,3 +3348,25 @@ pub enum FunctionReturn {
33483348
/// Replace returns with jumps to thunk, without emitting the thunk.
33493349
ThunkExtern,
33503350
}
3351+
3352+
/// Whether extra span comments are included when dumping MIR, via the `-Z mir-include-spans` flag.
3353+
/// By default, only enabled in the NLL MIR dumps, and disabled in all other passes.
3354+
#[derive(Clone, Copy, Default, PartialEq, Debug)]
3355+
pub enum MirIncludeSpans {
3356+
Off,
3357+
On,
3358+
/// Default: include extra comments in NLL MIR dumps only. Can be ignored and considered as
3359+
/// `Off` in all other cases.
3360+
#[default]
3361+
Nll,
3362+
}
3363+
3364+
impl MirIncludeSpans {
3365+
/// Unless opting into extra comments for all passes, they can be considered disabled.
3366+
/// The cases where a distinction between on/off and a per-pass value can exist will be handled
3367+
/// in the passes themselves: i.e. the `Nll` value is considered off for all intents and
3368+
/// purposes, except for the NLL MIR dump pass.
3369+
pub fn is_enabled(self) -> bool {
3370+
self == MirIncludeSpans::On
3371+
}
3372+
}

‎compiler/rustc_session/src/options.rs‎

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

449451
mod parse {
@@ -1477,6 +1479,17 @@ mod parse {
14771479
}
14781480
true
14791481
}
1482+
1483+
pub(crate) fn parse_mir_include_spans(slot: &mut MirIncludeSpans, v: Option<&str>) -> bool {
1484+
*slot = match v {
1485+
Some("on" | "yes" | "y" | "true") | None => MirIncludeSpans::On,
1486+
Some("off" | "no" | "n" | "false") => MirIncludeSpans::Off,
1487+
Some("nll") => MirIncludeSpans::Nll,
1488+
_ => return false,
1489+
};
1490+
1491+
true
1492+
}
14801493
}
14811494

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /