Skip to content

Commit 1f544ce

Browse files
committed
coverage: Remove all unstable values of -Cinstrument-coverage
1 parent 4a0cc88 commit 1f544ce

File tree

14 files changed

+26
-118
lines changed

14 files changed

+26
-118
lines changed

Diff for: compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -355,21 +355,20 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
355355

356356
let tcx = cx.tcx;
357357

358-
let ignore_unused_generics = tcx.sess.instrument_coverage_except_unused_generics();
359-
360358
let eligible_def_ids = tcx.mir_keys(()).iter().filter_map(|local_def_id| {
361359
let def_id = local_def_id.to_def_id();
362360
let kind = tcx.def_kind(def_id);
363361
// `mir_keys` will give us `DefId`s for all kinds of things, not
364362
// just "functions", like consts, statics, etc. Filter those out.
365-
// If `ignore_unused_generics` was specified, filter out any
366-
// generic functions from consideration as well.
367363
if !matches!(kind, DefKind::Fn | DefKind::AssocFn | DefKind::Closure) {
368364
return None;
369365
}
370-
if ignore_unused_generics && tcx.generics_of(def_id).requires_monomorphization(tcx) {
371-
return None;
372-
}
366+
367+
// FIXME(79651): Consider trying to filter out dummy instantiations of
368+
// unused generic functions from library crates, because they can produce
369+
// "unused instantiation" in coverage reports even when they are actually
370+
// used by some downstream crate in the same binary.
371+
373372
Some(local_def_id.to_def_id())
374373
});
375374

Diff for: compiler/rustc_monomorphize/src/partitioning.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,7 @@ where
175175
}
176176

177177
// Mark one CGU for dead code, if necessary.
178-
let instrument_dead_code =
179-
tcx.sess.instrument_coverage() && !tcx.sess.instrument_coverage_except_unused_functions();
180-
if instrument_dead_code {
178+
if tcx.sess.instrument_coverage() {
181179
mark_code_coverage_dead_code_cgu(&mut codegen_units);
182180
}
183181

Diff for: compiler/rustc_session/src/config.rs

+1-37
Original file line numberDiff line numberDiff line change
@@ -134,31 +134,13 @@ pub enum LtoCli {
134134
/// and higher). Nevertheless, there are many variables, depending on options
135135
/// selected, code structure, and enabled attributes. If errors are encountered,
136136
/// either while compiling or when generating `llvm-cov show` reports, consider
137-
/// lowering the optimization level, including or excluding `-C link-dead-code`,
138-
/// or using `-Zunstable-options -C instrument-coverage=except-unused-functions`
139-
/// or `-Zunstable-options -C instrument-coverage=except-unused-generics`.
140-
///
141-
/// Note that `ExceptUnusedFunctions` means: When `mapgen.rs` generates the
142-
/// coverage map, it will not attempt to generate synthetic functions for unused
143-
/// (and not code-generated) functions (whether they are generic or not). As a
144-
/// result, non-codegenned functions will not be included in the coverage map,
145-
/// and will not appear, as covered or uncovered, in coverage reports.
146-
///
147-
/// `ExceptUnusedGenerics` will add synthetic functions to the coverage map,
148-
/// unless the function has type parameters.
137+
/// lowering the optimization level, or including/excluding `-C link-dead-code`.
149138
#[derive(Clone, Copy, PartialEq, Hash, Debug)]
150139
pub enum InstrumentCoverage {
151140
/// `-C instrument-coverage=no` (or `off`, `false` etc.)
152141
No,
153142
/// `-C instrument-coverage` or `-C instrument-coverage=yes`
154143
Yes,
155-
/// Additionally, instrument branches and output branch coverage.
156-
/// `-Zunstable-options -C instrument-coverage=branch`
157-
Branch,
158-
/// `-Zunstable-options -C instrument-coverage=except-unused-generics`
159-
ExceptUnusedGenerics,
160-
/// `-Zunstable-options -C instrument-coverage=except-unused-functions`
161-
ExceptUnusedFunctions,
162144
}
163145

164146
/// Settings for `-Z instrument-xray` flag.
@@ -2718,24 +2700,6 @@ pub fn build_session_options(early_dcx: &mut EarlyDiagCtxt, matches: &getopts::M
27182700
}
27192701
}
27202702

2721-
// Check for unstable values of `-C instrument-coverage`.
2722-
// This is what prevents them from being used on stable compilers.
2723-
match cg.instrument_coverage {
2724-
// Stable values:
2725-
InstrumentCoverage::Yes | InstrumentCoverage::No => {}
2726-
// Unstable values:
2727-
InstrumentCoverage::Branch
2728-
| InstrumentCoverage::ExceptUnusedFunctions
2729-
| InstrumentCoverage::ExceptUnusedGenerics => {
2730-
if !unstable_opts.unstable_options {
2731-
early_dcx.early_fatal(
2732-
"`-C instrument-coverage=branch` and `-C instrument-coverage=except-*` \
2733-
require `-Z unstable-options`",
2734-
);
2735-
}
2736-
}
2737-
}
2738-
27392703
if cg.instrument_coverage != InstrumentCoverage::No {
27402704
if cg.profile_generate.enabled() || cg.profile_use.is_some() {
27412705
early_dcx.early_fatal(

Diff for: compiler/rustc_session/src/options.rs

+6-16
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ mod desc {
395395
pub const parse_linker_flavor: &str = ::rustc_target::spec::LinkerFlavorCli::one_of();
396396
pub const parse_optimization_fuel: &str = "crate=integer";
397397
pub const parse_dump_mono_stats: &str = "`markdown` (default) or `json`";
398-
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`";
398+
pub const parse_instrument_coverage: &str = parse_bool;
399399
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`";
400400
pub const parse_unpretty: &str = "`string` or `string=string`";
401401
pub const parse_treat_err_as_bug: &str = "either no value or a non-negative number";
@@ -928,15 +928,10 @@ mod parse {
928928
return true;
929929
};
930930

931+
// Parse values that have historically been accepted by stable compilers,
932+
// even though they're currently just aliases for boolean values.
931933
*slot = match v {
932934
"all" => InstrumentCoverage::Yes,
933-
"branch" => InstrumentCoverage::Branch,
934-
"except-unused-generics" | "except_unused_generics" => {
935-
InstrumentCoverage::ExceptUnusedGenerics
936-
}
937-
"except-unused-functions" | "except_unused_functions" => {
938-
InstrumentCoverage::ExceptUnusedFunctions
939-
}
940935
"0" => InstrumentCoverage::No,
941936
_ => return false,
942937
};
@@ -1445,14 +1440,9 @@ options! {
14451440
"set the threshold for inlining a function"),
14461441
#[rustc_lint_opt_deny_field_access("use `Session::instrument_coverage` instead of this field")]
14471442
instrument_coverage: InstrumentCoverage = (InstrumentCoverage::No, parse_instrument_coverage, [TRACKED],
1448-
"instrument the generated code to support LLVM source-based code coverage \
1449-
reports (note, the compiler build config must include `profiler = true`); \
1450-
implies `-C symbol-mangling-version=v0`. Optional values are:
1451-
`=no` `=n` `=off` `=false` (default)
1452-
`=yes` `=y` `=on` `=true` (implicit value)
1453-
`=branch` (unstable)
1454-
`=except-unused-generics` (unstable)
1455-
`=except-unused-functions` (unstable)"),
1443+
"instrument the generated code to support LLVM source-based code coverage reports \
1444+
(note, the compiler build config must include `profiler = true`); \
1445+
implies `-C symbol-mangling-version=v0`"),
14561446
link_arg: (/* redirected to link_args */) = ((), parse_string_push, [UNTRACKED],
14571447
"a single extra argument to append to the linker invocation (can be used several times)"),
14581448
link_args: Vec<String> = (Vec::new(), parse_list, [UNTRACKED],

Diff for: compiler/rustc_session/src/session.rs

-12
Original file line numberDiff line numberDiff line change
@@ -352,18 +352,6 @@ impl Session {
352352
self.opts.cg.instrument_coverage() != InstrumentCoverage::No
353353
}
354354

355-
pub fn instrument_coverage_branch(&self) -> bool {
356-
self.opts.cg.instrument_coverage() == InstrumentCoverage::Branch
357-
}
358-
359-
pub fn instrument_coverage_except_unused_generics(&self) -> bool {
360-
self.opts.cg.instrument_coverage() == InstrumentCoverage::ExceptUnusedGenerics
361-
}
362-
363-
pub fn instrument_coverage_except_unused_functions(&self) -> bool {
364-
self.opts.cg.instrument_coverage() == InstrumentCoverage::ExceptUnusedFunctions
365-
}
366-
367355
pub fn is_sanitizer_cfi_enabled(&self) -> bool {
368356
self.opts.unstable_opts.sanitizer.contains(SanitizerSet::CFI)
369357
}

Diff for: src/doc/rustc/src/instrument-coverage.md

-9
Original file line numberDiff line numberDiff line change
@@ -346,15 +346,6 @@ $ llvm-cov report \
346346
more fine-grained coverage options are added.
347347
Using this value is currently not recommended.
348348

349-
### Unstable values
350-
351-
- `-Z unstable-options -C instrument-coverage=branch`:
352-
Placeholder for potential branch coverage support in the future.
353-
- `-Z unstable-options -C instrument-coverage=except-unused-generics`:
354-
Instrument all functions except unused generics.
355-
- `-Z unstable-options -C instrument-coverage=except-unused-functions`:
356-
Instrument only used (called) functions and instantiated generic functions.
357-
358349
## Other references
359350

360351
Rust's implementation and workflow for source-based code coverage is based on the same library and tools used to implement [source-based code coverage in Clang]. (This document is partially based on the Clang guide.)

Diff for: tests/coverage/auxiliary/used_crate.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,8 @@ fn use_this_lib_crate() {
7676
// ```
7777
//
7878
// The notice is triggered because the function is unused by the library itself,
79-
// and when the library is compiled, a synthetic function is generated, so
80-
// unused function coverage can be reported. Coverage can be skipped for unused
81-
// generic functions with:
82-
//
83-
// ```shell
84-
// $ `rustc -Zunstable-options -C instrument-coverage=except-unused-generics ...`
85-
// ```
79+
// so when the library is compiled, an "unused" set of mappings for that function
80+
// is included in the library's coverage metadata.
8681
//
8782
// Even though this function is used by `uses_crate.rs` (and
8883
// counted), with substitutions for `T`, those instantiations are only generated
@@ -98,6 +93,6 @@ fn use_this_lib_crate() {
9893
// another binary that never used this generic function, then it would be valid
9994
// to show the unused generic, with unknown substitution (`_`).
10095
//
101-
// The alternative is to exclude all generics from being included in the "unused
102-
// functions" list, which would then omit coverage results for
103-
// `unused_generic_function<T>()`, below.
96+
// The alternative would be to exclude all generics from being included in the
97+
// "unused functions" list, which would then omit coverage results for
98+
// `unused_generic_function<T>()`.

Diff for: tests/coverage/uses_crate.coverage

+5-10
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,8 @@ $DIR/auxiliary/used_crate.rs:
124124
LL| |// ```
125125
LL| |//
126126
LL| |// The notice is triggered because the function is unused by the library itself,
127-
LL| |// and when the library is compiled, a synthetic function is generated, so
128-
LL| |// unused function coverage can be reported. Coverage can be skipped for unused
129-
LL| |// generic functions with:
130-
LL| |//
131-
LL| |// ```shell
132-
LL| |// $ `rustc -Zunstable-options -C instrument-coverage=except-unused-generics ...`
133-
LL| |// ```
127+
LL| |// so when the library is compiled, an "unused" set of mappings for that function
128+
LL| |// is included in the library's coverage metadata.
134129
LL| |//
135130
LL| |// Even though this function is used by `uses_crate.rs` (and
136131
LL| |// counted), with substitutions for `T`, those instantiations are only generated
@@ -146,9 +141,9 @@ $DIR/auxiliary/used_crate.rs:
146141
LL| |// another binary that never used this generic function, then it would be valid
147142
LL| |// to show the unused generic, with unknown substitution (`_`).
148143
LL| |//
149-
LL| |// The alternative is to exclude all generics from being included in the "unused
150-
LL| |// functions" list, which would then omit coverage results for
151-
LL| |// `unused_generic_function<T>()`, below.
144+
LL| |// The alternative would be to exclude all generics from being included in the
145+
LL| |// "unused functions" list, which would then omit coverage results for
146+
LL| |// `unused_generic_function<T>()`.
152147

153148
$DIR/uses_crate.rs:
154149
LL| |// This test was failing on Linux for a while due to #110393 somehow making

Diff for: tests/ui/instrument-coverage/bad-value.bad.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
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
1+
error: incorrect value `bad-value` for codegen option `instrument-coverage` - one of: `y`, `yes`, `on`, `true`, `n`, `no`, `off` or `false` was expected
22

Diff for: tests/ui/instrument-coverage/bad-value.blank.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
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
1+
error: incorrect value `` for codegen option `instrument-coverage` - one of: `y`, `yes`, `on`, `true`, `n`, `no`, `off` or `false` was expected
22

Diff for: tests/ui/instrument-coverage/unstable.branch.stderr

-2
This file was deleted.

Diff for: tests/ui/instrument-coverage/unstable.except-unused-functions.stderr

-2
This file was deleted.

Diff for: tests/ui/instrument-coverage/unstable.except-unused-generics.stderr

-2
This file was deleted.

Diff for: tests/ui/instrument-coverage/unstable.rs

-6
This file was deleted.

0 commit comments

Comments
 (0)