Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

coverage: Re-enable UnreachablePropagation for coverage builds #122860

Merged
merged 4 commits into from Mar 27, 2024

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Mar 22, 2024

This is a sequence of 3 related changes:

  • Clean up the existing code that scans for unused functions
  • Detect functions that were instrumented for coverage, but have had all their coverage statements removed by later MIR transforms (e.g. UnreachablePropagation)
  • Re-enable UnreachablePropagation in coverage builds

Because we now detect functions that have lost their coverage statements, and treat them as unused, we don't need to worry about UnreachablePropagation removing all of those statements. This is demonstrated by tests/coverage/unreachable.rs.

Fixes #116171.

@rustbot
Copy link
Collaborator

rustbot commented Mar 22, 2024

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 22, 2024
@rustbot
Copy link
Collaborator

rustbot commented Mar 22, 2024

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbot rustbot added the A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) label Mar 22, 2024
@Zalathar

This comment was marked as resolved.

@petrochenkov
Copy link
Contributor

Blocked on #122542.
@rustbot blocked

@rustbot rustbot added S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 22, 2024
@Zalathar
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-blocked Status: Marked as blocked ❌ on something else such as an RFC or other implementation work. labels Mar 23, 2024
@cjgillot cjgillot self-assigned this Mar 24, 2024
@petrochenkov petrochenkov removed their assignment Mar 25, 2024
})
.filter({
// We only need one arbitrary instance per definition.
let mut seen = FxHashSet::default();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to create an inner scope for this. A function-level binding is good enough, it's moved into the closure anyway.

@@ -354,78 +346,94 @@ fn add_unused_functions(cx: &CodegenCx<'_, '_>) {
assert!(cx.codegen_unit.is_code_coverage_dead_code_cgu());

let tcx = cx.tcx;
let usage = prepare_usage_sets(tcx);

let is_unused_fn = |def_id: &&LocalDefId| -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closure should take by value, and let the caller dereference.

@cjgillot
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Mar 26, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 26, 2024
coverage: Re-enable `UnreachablePropagation` for coverage builds

This is a sequence of 3 related changes:
- Clean up the existing code that scans for unused functions
- Detect functions that were instrumented for coverage, but have had all their coverage statements removed by later MIR transforms (e.g. `UnreachablePropagation`)
- Re-enable `UnreachablePropagation` in coverage builds

Because we now detect functions that have lost their coverage statements, and treat them as unused, we don't need to worry about `UnreachablePropagation` removing all of those statements. This is demonstrated by `tests/coverage/unreachable.rs`.

Fixes rust-lang#116171.
@bors
Copy link
Contributor

bors commented Mar 26, 2024

⌛ Trying commit 72db933 with merge fff1443...

If a function was instrumented for coverage, but all of its coverage statements
have been removed by later MIR transforms, it should be treated as "unused"
even if the compiler generates an unreachable stub for it.
@Zalathar
Copy link
Contributor Author

Addressed feedback (diff).

I think I still prefer the way it was, but 🤷‍♂️.

@Zalathar
Copy link
Contributor Author

I'm not 100% sure, but I don't think we have any benchmarks that actually enable coverage.

@cjgillot
Copy link
Contributor

Thanks.
@bors r+

@bors
Copy link
Contributor

bors commented Mar 26, 2024

📌 Commit 1cca252 has been approved by cjgillot

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 26, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 27, 2024
…llaumeGomez

Rollup of 6 pull requests

Successful merges:

 - rust-lang#121843 (Implement `-L KIND=`@RUSTC_BUILTIN/...`)`
 - rust-lang#122860 (coverage: Re-enable `UnreachablePropagation` for coverage builds)
 - rust-lang#123021 (Make `TyCtxt::coroutine_layout` take coroutine's kind parameter)
 - rust-lang#123024 (CFI: Enable KCFI testing of run-pass tests)
 - rust-lang#123083 (lib: fix some unnecessary_cast clippy lint)
 - rust-lang#123116 (rustdoc: Swap fields and variant documentations)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 8a7f285 into rust-lang:master Mar 27, 2024
11 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Mar 27, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 27, 2024
Rollup merge of rust-lang#122860 - Zalathar:unused, r=cjgillot

coverage: Re-enable `UnreachablePropagation` for coverage builds

This is a sequence of 3 related changes:
- Clean up the existing code that scans for unused functions
- Detect functions that were instrumented for coverage, but have had all their coverage statements removed by later MIR transforms (e.g. `UnreachablePropagation`)
- Re-enable `UnreachablePropagation` in coverage builds

Because we now detect functions that have lost their coverage statements, and treat them as unused, we don't need to worry about `UnreachablePropagation` removing all of those statements. This is demonstrated by `tests/coverage/unreachable.rs`.

Fixes rust-lang#116171.
@Zalathar Zalathar deleted the unused branch March 27, 2024 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. S-waiting-on-perf Status: Waiting on a perf run to be completed. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make coverage robust against MIR optimizations removing all counter-increment statements
6 participants