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: Arrange span extraction/refinement as a series of passes #126535

Merged
merged 5 commits into from
Jun 17, 2024

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Jun 16, 2024

The old code for extracting/refining coverage spans from MIR has been dismantled and split up into several passes (e.g. see #126294), but because this was done incrementally, the resulting code is disorganised.

This PR addresses that by moving the main control-flow into a single function (coverage::spans::extract_refined_covspans) that more clearly shows the process as a series of separate steps, most delegated to helper functions in the same file.

This should make it easier to understand and modify the refinement process. It also means that submodule from_mir is now only concerned with the details of extracting relevant spans from the various kinds of MIR statement/terminator.

There should be no change to the resulting coverage maps, as demonstrated by the lack of changes to tests.

@rustbot
Copy link
Collaborator

rustbot commented Jun 16, 2024

r? @nnethercote

rustbot has assigned @nnethercote.
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 Jun 16, 2024
@rustbot
Copy link
Collaborator

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

Zalathar commented Jun 16, 2024

Notes for review:

The first patch renames several variables to be more consistent overall, to get that out of the way before moving code around.

We then move big chunks of code from spans::from_mir into spans, using git diff --color-moved to confirm that there are no unintended changes/additions/removals.

The remaining patches then perform other smaller rearrangements, once again using git diff --color-moved to check that the rearranged code hasn't been unintentionally modified.


This PR looks complicated at a glance, but fundamentally isn't doing very much beyond moving code around.

// - Put those spans in a corresponding bucket, truncated to the start of the hole.
// - If one of those spans also extends after the hole, put the rest of it
// in a "fragments" vector that is processed by the next hole.
let mut buckets = (0..holes.len()).map(|_| vec![]).collect::<Vec<_>>();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Side note: I though about using inline const to change this to:

    let mut buckets = vec![(const { vec![] }); holes.len()];

But currently there are false warnings (#126457) that make this annoying, and the old code is perfectly fine, so I left it as-is.

@nnethercote
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 17, 2024

📌 Commit 2d3e6c8 has been approved by nnethercote

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 Jun 17, 2024
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 17, 2024
Rollup of 8 pull requests

Successful merges:

 - rust-lang#125258 (Resolve elided lifetimes in assoc const to static if no other lifetimes are in scope)
 - rust-lang#126250 (docs(change): Don't mention a Cargo 2024 edition change for 1.79)
 - rust-lang#126288 (doc: Added commas where needed)
 - rust-lang#126346 (export std::os::fd module on HermitOS)
 - rust-lang#126468 (div_euclid, rem_euclid: clarify/extend documentation)
 - rust-lang#126531 (Add codegen test for `Request::provide_*`)
 - rust-lang#126535 (coverage: Arrange span extraction/refinement as a series of passes)
 - rust-lang#126538 (coverage: Several small improvements to graph code)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit d9af579 into rust-lang:master Jun 17, 2024
6 checks passed
@rustbot rustbot added this to the 1.81.0 milestone Jun 17, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 17, 2024
Rollup merge of rust-lang#126535 - Zalathar:covspans, r=nnethercote

coverage: Arrange span extraction/refinement as a series of passes

The old code for extracting/refining coverage spans from MIR has been dismantled and split up into several passes (e.g. see rust-lang#126294), but because this was done incrementally, the resulting code is disorganised.

This PR addresses that by moving the main control-flow into a single function (`coverage::spans::extract_refined_covspans`) that more clearly shows the process as a series of separate steps, most delegated to helper functions in the same file.

This should make it easier to understand and modify the refinement process. It also means that submodule `from_mir` is now only concerned with the details of extracting relevant spans from the various kinds of MIR statement/terminator.

There should be no change to the resulting coverage maps, as demonstrated by the lack of changes to tests.
@Zalathar Zalathar deleted the covspans branch June 17, 2024 06:40
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