The value of -Cinstrument-coverage= doesn't need to be Option

Not using this flag is identical to passing `-Cinstrument-coverage=off`, so
there's no need to distinguish between `None` and `Some(Off)`.
This commit is contained in:
Zalathar 2023-10-25 14:36:13 +11:00
parent 278eaf509d
commit 9f5fc0283c
3 changed files with 15 additions and 17 deletions

View File

@ -612,7 +612,7 @@ macro_rules! tracked {
tracked!(force_frame_pointers, Some(false)); tracked!(force_frame_pointers, Some(false));
tracked!(force_unwind_tables, Some(true)); tracked!(force_unwind_tables, Some(true));
tracked!(inline_threshold, Some(0xf007ba11)); tracked!(inline_threshold, Some(0xf007ba11));
tracked!(instrument_coverage, Some(InstrumentCoverage::All)); tracked!(instrument_coverage, InstrumentCoverage::All);
tracked!(link_dead_code, Some(true)); tracked!(link_dead_code, Some(true));
tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto); tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto);
tracked!(llvm_args, vec![String::from("1"), String::from("2")]); tracked!(llvm_args, vec![String::from("1"), String::from("2")]);

View File

@ -2743,13 +2743,11 @@ pub fn build_session_options(
// This is what prevents them from being used on stable compilers. // This is what prevents them from being used on stable compilers.
match cg.instrument_coverage { match cg.instrument_coverage {
// Stable values: // Stable values:
Some(InstrumentCoverage::All | InstrumentCoverage::Off) | None => {} InstrumentCoverage::All | InstrumentCoverage::Off => {}
// Unstable values: // Unstable values:
Some( InstrumentCoverage::Branch
InstrumentCoverage::Branch | InstrumentCoverage::ExceptUnusedFunctions
| InstrumentCoverage::ExceptUnusedFunctions | InstrumentCoverage::ExceptUnusedGenerics => {
| InstrumentCoverage::ExceptUnusedGenerics,
) => {
if !unstable_opts.unstable_options { if !unstable_opts.unstable_options {
handler.early_error( handler.early_error(
"`-C instrument-coverage=branch` and `-C instrument-coverage=except-*` \ "`-C instrument-coverage=branch` and `-C instrument-coverage=except-*` \
@ -2759,7 +2757,7 @@ pub fn build_session_options(
} }
} }
if cg.instrument_coverage.is_some() && cg.instrument_coverage != Some(InstrumentCoverage::Off) { if cg.instrument_coverage != InstrumentCoverage::Off {
if cg.profile_generate.enabled() || cg.profile_use.is_some() { if cg.profile_generate.enabled() || cg.profile_use.is_some() {
handler.early_error( handler.early_error(
"option `-C instrument-coverage` is not compatible with either `-C profile-use` \ "option `-C instrument-coverage` is not compatible with either `-C profile-use` \

View File

@ -294,7 +294,7 @@ impl CodegenOptions {
// JUSTIFICATION: defn of the suggested wrapper fn // JUSTIFICATION: defn of the suggested wrapper fn
#[allow(rustc::bad_opt_access)] #[allow(rustc::bad_opt_access)]
pub fn instrument_coverage(&self) -> InstrumentCoverage { pub fn instrument_coverage(&self) -> InstrumentCoverage {
self.instrument_coverage.unwrap_or(InstrumentCoverage::Off) self.instrument_coverage
} }
} }
@ -913,23 +913,23 @@ pub(crate) fn parse_dump_mono_stats(slot: &mut DumpMonoStatsFormat, v: Option<&s
} }
pub(crate) fn parse_instrument_coverage( pub(crate) fn parse_instrument_coverage(
slot: &mut Option<InstrumentCoverage>, slot: &mut InstrumentCoverage,
v: Option<&str>, v: Option<&str>,
) -> bool { ) -> bool {
if v.is_some() { if v.is_some() {
let mut bool_arg = None; let mut bool_arg = false;
if parse_opt_bool(&mut bool_arg, v) { if parse_bool(&mut bool_arg, v) {
*slot = bool_arg.unwrap().then_some(InstrumentCoverage::All); *slot = if bool_arg { InstrumentCoverage::All } else { InstrumentCoverage::Off };
return true; return true;
} }
} }
let Some(v) = v else { let Some(v) = v else {
*slot = Some(InstrumentCoverage::All); *slot = InstrumentCoverage::All;
return true; return true;
}; };
*slot = Some(match v { *slot = match v {
"all" => InstrumentCoverage::All, "all" => InstrumentCoverage::All,
"branch" => InstrumentCoverage::Branch, "branch" => InstrumentCoverage::Branch,
"except-unused-generics" | "except_unused_generics" => { "except-unused-generics" | "except_unused_generics" => {
@ -940,7 +940,7 @@ pub(crate) fn parse_instrument_coverage(
} }
"off" | "no" | "n" | "false" | "0" => InstrumentCoverage::Off, "off" | "no" | "n" | "false" | "0" => InstrumentCoverage::Off,
_ => return false, _ => return false,
}); };
true true
} }
@ -1352,7 +1352,7 @@ pub(crate) fn parse_dump_solver_proof_tree(
inline_threshold: Option<u32> = (None, parse_opt_number, [TRACKED], inline_threshold: Option<u32> = (None, parse_opt_number, [TRACKED],
"set the threshold for inlining a function"), "set the threshold for inlining a function"),
#[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")] #[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")]
instrument_coverage: Option<InstrumentCoverage> = (None, parse_instrument_coverage, [TRACKED], instrument_coverage: InstrumentCoverage = (InstrumentCoverage::Off, parse_instrument_coverage, [TRACKED],
"instrument the generated code to support LLVM source-based code coverage \ "instrument the generated code to support LLVM source-based code coverage \
reports (note, the compiler build config must include `profiler = true`); \ reports (note, the compiler build config must include `profiler = true`); \
implies `-C symbol-mangling-version=v0`. Optional values are: implies `-C symbol-mangling-version=v0`. Optional values are: