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: Split out counter increment sites from BCB node/edge counters #120564

Merged
merged 1 commit into from
Feb 7, 2024

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Feb 2, 2024

This makes it possible for two nodes/edges in the coverage graph to share the same counter, without causing the instrumentor to inject unwanted duplicate counter-increment statements.


@rustbot label +A-code-coverage

This makes it possible for two nodes/edges in the coverage graph to share the
same counter, without causing the instrumentor to inject unwanted duplicate
counter-increment statements.
@rustbot
Copy link
Collaborator

rustbot commented Feb 2, 2024

r? @estebank

(rustbot has picked a reviewer for you, use r? to override)

@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 Feb 2, 2024
@rustbot
Copy link
Collaborator

rustbot commented Feb 2, 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 Feb 2, 2024
@Zalathar
Copy link
Contributor Author

Zalathar commented Feb 2, 2024

For historical context, the original implementation of coverage didn't really distinguish between referring to a counter and incrementing that counter. The work done for rust-lang/compiler-team#645 ended up creating a clean separation between those two concepts in most of the coverage code, but the one remaining holdout was the code that is updated by this PR.

This is a necessary step towards allowing the instrumentor to be a bit smarter about how it assigns counters to nodes/edges in the coverage graph.

For example, future PRs might allow it to observe that the coverage expression c1 + (c0 - c1) is equivalent to just c0, and avoid creating the intermediate expressions. Without this PR, doing so would have the unwanted side-effect of emitting extra counter-increments for c0, which would give wildly incorrect coverage counts.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 6, 2024

The change lgtm. Is it possible to design a test that is changed by this PR? It seems like an important enough edge case to warrant ensuring the generated coverage statements don't change across future changes.

@oli-obk oli-obk assigned oli-obk and unassigned estebank Feb 6, 2024
@Zalathar
Copy link
Contributor Author

Zalathar commented Feb 6, 2024

By itself, this PR still inserts exactly the same counters in exactly the same places.

It's now legal for multiple nodes or edges to share the same counter, but the code that actually sets up the counters was historically written under the assumption that sharing was not allowed (and isn't substantially changed by this PR), so currently that sharing never actually happens.

(I've been experimenting with some follow-up changes that do take advantage of this PR, but they are more involved and need some more polish, so I haven't included them here.)

If a future change somehow causes counters to be inappropriately duplicated, or inserted in the wrong places, that should typically show up as incorrect line coverage counts in the .coverage snapshot files.

@oli-obk
Copy link
Contributor

oli-obk commented Feb 6, 2024

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Feb 6, 2024

📌 Commit 2e212b7 has been approved by oli-obk

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 Feb 6, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 6, 2024
coverage: Split out counter increment sites from BCB node/edge counters

This makes it possible for two nodes/edges in the coverage graph to share the same counter, without causing the instrumentor to inject unwanted duplicate counter-increment statements.

---

`@rustbot` label +A-code-coverage
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Feb 6, 2024
coverage: Split out counter increment sites from BCB node/edge counters

This makes it possible for two nodes/edges in the coverage graph to share the same counter, without causing the instrumentor to inject unwanted duplicate counter-increment statements.

---

``@rustbot`` label +A-code-coverage
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 6, 2024
…iaskrgr

Rollup of 9 pull requests

Successful merges:

 - rust-lang#120302 (various const interning cleanups)
 - rust-lang#120520 (Some cleanups around diagnostic levels.)
 - rust-lang#120521 (Make `NonZero` constructors generic.)
 - rust-lang#120527 (Switch OwnedStore handle count to AtomicU32)
 - rust-lang#120564 (coverage: Split out counter increment sites from BCB node/edge counters)
 - rust-lang#120575 (Simplify codegen diagnostic handling)
 - rust-lang#120597 (Suggest `[tail @ ..]` on `[..tail]` and `[...tail]` where `tail` is unresolved)
 - rust-lang#120609 (hir: Stop keeping prefixes for most of `use` list stems)
 - rust-lang#120633 (pattern_analysis: gather up place-relevant info)

r? `@ghost`
`@rustbot` modify labels: rollup
Nadrieril added a commit to Nadrieril/rust that referenced this pull request Feb 7, 2024
coverage: Split out counter increment sites from BCB node/edge counters

This makes it possible for two nodes/edges in the coverage graph to share the same counter, without causing the instrumentor to inject unwanted duplicate counter-increment statements.

---

```@rustbot``` label +A-code-coverage
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 7, 2024
Rollup of 13 pull requests

Successful merges:

 - rust-lang#110482 (Add armv8r-none-eabihf target for the Cortex-R52.)
 - rust-lang#119162 (Add unstable `-Z direct-access-external-data` cmdline flag for `rustc`)
 - rust-lang#120302 (various const interning cleanups)
 - rust-lang#120455 ( Add FileCheck annotations to MIR-opt SROA tests)
 - rust-lang#120470 (Mark "unused binding" suggestion as maybe incorrect)
 - rust-lang#120479 (Suggest turning `if let` into irrefutable `let` if appropriate)
 - rust-lang#120564 (coverage: Split out counter increment sites from BCB node/edge counters)
 - rust-lang#120633 (pattern_analysis: gather up place-relevant info)
 - rust-lang#120664 (Add parallel rustc ui tests)
 - rust-lang#120721 (fix `llvm_out` to use the correct LLVM root)
 - rust-lang#120726 (Don't use bashism in checktools.sh)
 - rust-lang#120733 (MirPass: make name more const)
 - rust-lang#120735 (Remove some `unchecked_claim_error_was_emitted` calls)

Failed merges:

 - rust-lang#120727 (exhaustiveness: Prefer "`0..MAX` not covered" to "`_` not covered")

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 7, 2024
Rollup of 13 pull requests

Successful merges:

 - rust-lang#110482 (Add armv8r-none-eabihf target for the Cortex-R52.)
 - rust-lang#119162 (Add unstable `-Z direct-access-external-data` cmdline flag for `rustc`)
 - rust-lang#120302 (various const interning cleanups)
 - rust-lang#120455 ( Add FileCheck annotations to MIR-opt SROA tests)
 - rust-lang#120470 (Mark "unused binding" suggestion as maybe incorrect)
 - rust-lang#120479 (Suggest turning `if let` into irrefutable `let` if appropriate)
 - rust-lang#120564 (coverage: Split out counter increment sites from BCB node/edge counters)
 - rust-lang#120633 (pattern_analysis: gather up place-relevant info)
 - rust-lang#120664 (Add parallel rustc ui tests)
 - rust-lang#120726 (Don't use bashism in checktools.sh)
 - rust-lang#120733 (MirPass: make name more const)
 - rust-lang#120735 (Remove some `unchecked_claim_error_was_emitted` calls)
 - rust-lang#120746 (Record coroutine kind in coroutine generics)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d62fd21 into rust-lang:master Feb 7, 2024
11 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Feb 7, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Feb 7, 2024
Rollup merge of rust-lang#120564 - Zalathar:increment-site, r=oli-obk

coverage: Split out counter increment sites from BCB node/edge counters

This makes it possible for two nodes/edges in the coverage graph to share the same counter, without causing the instrumentor to inject unwanted duplicate counter-increment statements.

---

````@rustbot```` label +A-code-coverage
@Zalathar Zalathar deleted the increment-site branch February 7, 2024 21:57
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. 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.

6 participants