diff --git a/compiler/rustc_interface/src/tests.rs b/compiler/rustc_interface/src/tests.rs index 5e1fc248b80..4f15d1c1d3a 100644 --- a/compiler/rustc_interface/src/tests.rs +++ b/compiler/rustc_interface/src/tests.rs @@ -590,7 +590,7 @@ fn test_codegen_options_tracking_hash() { tracked!(force_frame_pointers, Some(false)); tracked!(force_unwind_tables, Some(true)); tracked!(inline_threshold, Some(0xf007ba11)); - tracked!(instrument_coverage, InstrumentCoverage::All); + tracked!(instrument_coverage, InstrumentCoverage::Yes); tracked!(link_dead_code, Some(true)); tracked!(linker_plugin_lto, LinkerPluginLto::LinkerPluginAuto); tracked!(llvm_args, vec![String::from("1"), String::from("2")]); diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index dadbcff6f68..10243ec3a34 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -146,8 +146,10 @@ pub enum LtoCli { /// unless the function has type parameters. #[derive(Clone, Copy, PartialEq, Hash, Debug)] pub enum InstrumentCoverage { - /// Default `-C instrument-coverage` or `-C instrument-coverage=statement` - All, + /// `-C instrument-coverage=no` (or `off`, `false` etc.) + No, + /// `-C instrument-coverage` or `-C instrument-coverage=yes` + Yes, /// Additionally, instrument branches and output branch coverage. /// `-Zunstable-options -C instrument-coverage=branch` Branch, @@ -155,8 +157,6 @@ pub enum InstrumentCoverage { ExceptUnusedGenerics, /// `-Zunstable-options -C instrument-coverage=except-unused-functions` ExceptUnusedFunctions, - /// `-C instrument-coverage=off` (or `no`, etc.) - Off, } /// Settings for `-Z instrument-xray` flag. @@ -2722,7 +2722,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M // This is what prevents them from being used on stable compilers. match cg.instrument_coverage { // Stable values: - InstrumentCoverage::All | InstrumentCoverage::Off => {} + InstrumentCoverage::Yes | InstrumentCoverage::No => {} // Unstable values: InstrumentCoverage::Branch | InstrumentCoverage::ExceptUnusedFunctions @@ -2736,7 +2736,7 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M } } - if cg.instrument_coverage != InstrumentCoverage::Off { + if cg.instrument_coverage != InstrumentCoverage::No { if cg.profile_generate.enabled() || cg.profile_use.is_some() { early_dcx.early_fatal( "option `-C instrument-coverage` is not compatible with either `-C profile-use` \ diff --git a/compiler/rustc_session/src/options.rs b/compiler/rustc_session/src/options.rs index 55e1556cdf8..139bc8059d9 100644 --- a/compiler/rustc_session/src/options.rs +++ b/compiler/rustc_session/src/options.rs @@ -394,8 +394,7 @@ mod desc { pub const parse_linker_flavor: &str = ::rustc_target::spec::LinkerFlavorCli::one_of(); pub const parse_optimization_fuel: &str = "crate=integer"; pub const parse_dump_mono_stats: &str = "`markdown` (default) or `json`"; - pub const parse_instrument_coverage: &str = - "`all` (default), `branch`, `except-unused-generics`, `except-unused-functions`, or `off`"; + pub const parse_instrument_coverage: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc) or (unstable) one of `branch`, `except-unused-generics`, `except-unused-functions`"; pub const parse_instrument_xray: &str = "either a boolean (`yes`, `no`, `on`, `off`, etc), or a comma separated list of settings: `always` or `never` (mutually exclusive), `ignore-loops`, `instruction-threshold=N`, `skip-entry`, `skip-exit`"; pub const parse_unpretty: &str = "`string` or `string=string`"; pub const parse_treat_err_as_bug: &str = "either no value or a non-negative number"; @@ -918,18 +917,18 @@ mod parse { if v.is_some() { let mut bool_arg = false; if parse_bool(&mut bool_arg, v) { - *slot = if bool_arg { InstrumentCoverage::All } else { InstrumentCoverage::Off }; + *slot = if bool_arg { InstrumentCoverage::Yes } else { InstrumentCoverage::No }; return true; } } let Some(v) = v else { - *slot = InstrumentCoverage::All; + *slot = InstrumentCoverage::Yes; return true; }; *slot = match v { - "all" => InstrumentCoverage::All, + "all" => InstrumentCoverage::Yes, "branch" => InstrumentCoverage::Branch, "except-unused-generics" | "except_unused_generics" => { InstrumentCoverage::ExceptUnusedGenerics @@ -937,7 +936,7 @@ mod parse { "except-unused-functions" | "except_unused_functions" => { InstrumentCoverage::ExceptUnusedFunctions } - "off" | "no" | "n" | "false" | "0" => InstrumentCoverage::Off, + "0" => InstrumentCoverage::No, _ => return false, }; true @@ -1444,15 +1443,15 @@ options! { inline_threshold: Option = (None, parse_opt_number, [TRACKED], "set the threshold for inlining a function"), #[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")] - instrument_coverage: InstrumentCoverage = (InstrumentCoverage::Off, parse_instrument_coverage, [TRACKED], + instrument_coverage: InstrumentCoverage = (InstrumentCoverage::No, parse_instrument_coverage, [TRACKED], "instrument the generated code to support LLVM source-based code coverage \ reports (note, the compiler build config must include `profiler = true`); \ implies `-C symbol-mangling-version=v0`. Optional values are: - `=all` (implicit value) - `=branch` - `=except-unused-generics` - `=except-unused-functions` - `=off` (default)"), + `=no` `=n` `=off` `=false` (default) + `=yes` `=y` `=on` `=true` (implicit value) + `=branch` (unstable) + `=except-unused-generics` (unstable) + `=except-unused-functions` (unstable)"), link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED], "a single extra argument to append to the linker invocation (can be used several times)"), link_args: Vec = (Vec::new(), parse_list, [UNTRACKED], diff --git a/compiler/rustc_session/src/session.rs b/compiler/rustc_session/src/session.rs index 4f4d8fabb72..71235f5b171 100644 --- a/compiler/rustc_session/src/session.rs +++ b/compiler/rustc_session/src/session.rs @@ -352,7 +352,7 @@ impl Session { } pub fn instrument_coverage(&self) -> bool { - self.opts.cg.instrument_coverage() != InstrumentCoverage::Off + self.opts.cg.instrument_coverage() != InstrumentCoverage::No } pub fn instrument_coverage_branch(&self) -> bool { diff --git a/src/doc/rustc/src/instrument-coverage.md b/src/doc/rustc/src/instrument-coverage.md index 5b766318331..2f93252eddc 100644 --- a/src/doc/rustc/src/instrument-coverage.md +++ b/src/doc/rustc/src/instrument-coverage.md @@ -331,10 +331,29 @@ $ llvm-cov report \ ## `-C instrument-coverage=` -- `-C instrument-coverage=all`: Instrument all functions, including unused functions and unused generics. (This is the same as `-C instrument-coverage`, with no value.) -- `-C instrument-coverage=off`: Do not instrument any functions. (This is the same as simply not including the `-C instrument-coverage` option.) -- `-Zunstable-options -C instrument-coverage=except-unused-generics`: Instrument all functions except unused generics. -- `-Zunstable-options -C instrument-coverage=except-unused-functions`: Instrument only used (called) functions and instantiated generic functions. +- `-C instrument-coverage=no` (or `n`/`off`/`false`): + Don't enable coverage instrumentation. No functions will be instrumented for coverage. + - This is the same as not using the `-C instrument-coverage` flag at all. +- `-C instrument-coverage=yes` (or `y`/`on`/`true`): + Enable coverage instrumentation with the default behaviour. + Currently this instruments all functions, including unused functions and unused generics. + - This is the same as `-C instrument-coverage` with no value. + +### Other values + +- `-C instrument-coverage=all`: + Currently an alias for `yes`, but may behave differently in the future if + more fine-grained coverage options are added. + Using this value is currently not recommended. + +### Unstable values + +- `-Z unstable-options -C instrument-coverage=branch`: + Placeholder for potential branch coverage support in the future. +- `-Z unstable-options -C instrument-coverage=except-unused-generics`: + Instrument all functions except unused generics. +- `-Z unstable-options -C instrument-coverage=except-unused-functions`: + Instrument only used (called) functions and instantiated generic functions. ## Other references diff --git a/tests/ui/instrument-coverage/bad-value.bad.stderr b/tests/ui/instrument-coverage/bad-value.bad.stderr index b867d169dae..0411a1f98a3 100644 --- a/tests/ui/instrument-coverage/bad-value.bad.stderr +++ b/tests/ui/instrument-coverage/bad-value.bad.stderr @@ -1,2 +1,2 @@ -error: incorrect value `bad-value` for codegen option `instrument-coverage` - `all` (default), `branch`, `except-unused-generics`, `except-unused-functions`, or `off` was expected +error: incorrect value `bad-value` for codegen option `instrument-coverage` - either a boolean (`yes`, `no`, `on`, `off`, etc) or (unstable) one of `branch`, `except-unused-generics`, `except-unused-functions` was expected diff --git a/tests/ui/instrument-coverage/bad-value.blank.stderr b/tests/ui/instrument-coverage/bad-value.blank.stderr index e7122fb61cd..b3a8e7cf947 100644 --- a/tests/ui/instrument-coverage/bad-value.blank.stderr +++ b/tests/ui/instrument-coverage/bad-value.blank.stderr @@ -1,2 +1,2 @@ -error: incorrect value `` for codegen option `instrument-coverage` - `all` (default), `branch`, `except-unused-generics`, `except-unused-functions`, or `off` was expected +error: incorrect value `` for codegen option `instrument-coverage` - either a boolean (`yes`, `no`, `on`, `off`, etc) or (unstable) one of `branch`, `except-unused-generics`, `except-unused-functions` was expected