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: Clarify loop-edge detection and graph traversal #116654

Merged
merged 6 commits into from
Oct 12, 2023

Conversation

Zalathar
Copy link
Contributor

This is a collection of improvements to two semi-related pieces of code:

  • The code in counters that detects which graph edges don't exit a loop, and would therefore be good candidates to have their coverage computed as an expression rather than having a physical counter.
  • The code in graph that traverses the coverage BCB graph in a particular order, and tracks loops and loop edges along the way (which is relevant to the above).

I was originally only planning to make the graph changes, but there was going to be a lot of indentation churn in counters anyway, and once I started looking I noticed a lot of opportunities for simplification.


@rustbot label +A-code-coverage

This is the only BCB that `TraverseCoverageGraphWithLoops::next` works with, so
calling it `next_bcb` just makes the code less clear.
The previous code was storing the worklist in a vector, and then selectively
adding items to the start or end of the vector. That's a perfect use-case for a
double-ended queue.

This change also reveals that the existing code was a bit confused about which
end of the worklist is the front or back. For now, items are always removed
from the front of the queue (instead of the back), and code that adds items to
the queue has been flipped, to preserve the existing behaviour.
Having to keep passing in a graph reference was a holdover from when the graph
was partly mutated during traversal. As of rust-lang#114354 that is no longer necessary,
so we can simplify the traversal code by storing a graph reference as a field
in `TraverseCoverageGraphWithLoops`.
As long as we store the loop header BCB, we can look up its incoming loop
backedges as needed.
@rustbot
Copy link
Collaborator

rustbot commented Oct 12, 2023

r? @oli-obk

(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 Oct 12, 2023
@Zalathar
Copy link
Contributor Author

While replacing the traversal worklists with a VecDeque, I noticed that the existing code was very confused about whether it was adding new items to the front or back of the worklist. Because items were being popped from the back of the worklist, pushing an item to the back of the vector gave it a high priority, and inserting at the front of the vector gave it a low priority. This contradicted the comments and debug messages in the surrounding code.

Trying to “fix” that ended up breaking a number of unit tests, and also churned several coverage-map tests. For now I've left the existing behaviour intact, because it's unclear whether the change would be better or worse, and figuring that out is beyond the scope of these cleanups.

(I did change things so that items are now popped from the front of the worklist. To preserve existing behaviour, I swapped around around the code that adds new items to the front/back.)

@rustbot rustbot added the A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) label Oct 12, 2023
@rustbot
Copy link
Collaborator

rustbot commented Oct 12, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@oli-obk
Copy link
Contributor

oli-obk commented Oct 12, 2023

@bors r+

@bors
Copy link
Contributor

bors commented Oct 12, 2023

📌 Commit d99ab97 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 Oct 12, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Oct 12, 2023
…iaskrgr

Rollup of 5 pull requests

Successful merges:

 - rust-lang#116593 (Add unstable book page for the no-jump-tables codegen option)
 - rust-lang#116625 (`rustc_hir_pretty` cleanups)
 - rust-lang#116642 (Handle several `#[diagnostic::on_unimplemented]` attributes correctly)
 - rust-lang#116654 (coverage: Clarify loop-edge detection and graph traversal)
 - rust-lang#116669 (Fix mips platform support entries.)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 4832811 into rust-lang:master Oct 12, 2023
11 checks passed
@rustbot rustbot added this to the 1.75.0 milestone Oct 12, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 12, 2023
Rollup merge of rust-lang#116654 - Zalathar:reloop-traversal, r=oli-obk

coverage: Clarify loop-edge detection and graph traversal

This is a collection of improvements to two semi-related pieces of code:

- The code in `counters` that detects which graph edges don't exit a loop, and would therefore be good candidates to have their coverage computed as an expression rather than having a physical counter.
- The code in `graph` that traverses the coverage BCB graph in a particular order, and tracks loops and loop edges along the way (which is relevant to the above).

I was originally only planning to make the `graph` changes, but there was going to be a lot of indentation churn in `counters` anyway, and once I started looking I noticed a lot of opportunities for simplification.

---

`@rustbot` label +A-code-coverage
@Zalathar Zalathar deleted the reloop-traversal branch October 12, 2023 22:44
bors-ferrocene bot added a commit to ferrocene/ferrocene that referenced this pull request Oct 13, 2023
50: Automated pull from upstream `master` r=Dajamante a=github-actions[bot]


This PR pulls the following changes from the upstream repository:

* rust-lang/rust#116619
* rust-lang/rust#115964
* rust-lang/rust#116391
* rust-lang/rust#116510
* rust-lang/rust#116671
  * rust-lang/rust#116669
  * rust-lang/rust#116654
  * rust-lang/rust#116642
  * rust-lang/rust#116625
  * rust-lang/rust#116593
* rust-lang/rust#116649
* rust-lang/rust#116600
* rust-lang/rust#116628



Co-authored-by: Nadrieril <[email protected]>
Co-authored-by: Scott McMurray <[email protected]>
Co-authored-by: bjorn3 <[email protected]>
Co-authored-by: Nicholas Nethercote <[email protected]>
Co-authored-by: Trevor Gross <[email protected]>
Co-authored-by: Georg Semmler <[email protected]>
Co-authored-by: Guillaume Gomez <[email protected]>
Co-authored-by: Gurinder Singh <[email protected]>
Co-authored-by: bors <[email protected]>
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.

4 participants