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: Simplify building the coverage graph with CoverageSuccessors #119508

Merged
merged 5 commits into from
Jan 15, 2024

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Jan 2, 2024

This is a collection of simplifications to the code that builds the basic coverage block graph, which is a simplified view of the MIR control-flow graph that ignores panics and merges straight-line sequences of blocks into a single BCB node.

The biggest change is to how we determine the coverage-relevant successors of a block. Previously we would call Terminator::successors and apply some ad-hoc postprocessing, but with this PR we instead have our own match on the terminator kind that produces a coverage-specific enum CoverageSuccessors. That enum also includes information about whether a block has exactly one successor that it can be chained into as part of a single BCB.

@rustbot
Copy link
Collaborator

rustbot commented Jan 2, 2024

r? @compiler-errors

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

rustbot commented Jan 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 Jan 2, 2024
@Zalathar Zalathar changed the title coverage: Simplify building the coverage graph with Successors coverage: Simplify building the coverage graph with CoverageSuccessors Jan 2, 2024
@Zalathar Zalathar force-pushed the graph branch 2 times, most recently from e52cac3 to 1eef281 Compare January 2, 2024 07:29
@Zalathar
Copy link
Contributor Author

Zalathar commented Jan 13, 2024

Hmm, I was writing up some more comments on the (incidental) switch to boxed slices, and it occurred to me that split_off(0) doesn't quite work the way I thought it did.

That kind of undermines one of my reasons for using boxed slices, since doing so is less “free” than I had assumed.

@Zalathar
Copy link
Contributor Author

I've pushed an update that removes the boxed slice changes, and also stops using split_off(0) entirely (diff).

I've also filed #119913 to note my surprise at this behaviour of split_off(0).

Filtering out unreachable successors is only needed by the main graph traversal
loop, so we can move the filtering step into that loop instead, eliminating the
need to pass the MIR body into `bcb_filtered_successors`.
The old loop had two separate places where it would flush the acumulated list
of straight-line blocks into a new BCB. One occurred at the start of the loop
body when the current block couldn't be chained into, and the other occurred at
the end of the loop body when the current block couldn't be chained from.

The latter check can be hoisted to the start of the loop body by making it
examine the previous block (which has added itself to the list) instead of the
current block. With that done, we can combine the two separate flushes into one
flush with two possible trigger conditions.
This also switches from `split_off(0)` to `std::mem::take` when emptying the
accumulated list of blocks, because `split_off(0)` handles capacity in a way
that is unintuitive when used in a loop.
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 14, 2024

📌 Commit 5eae945 has been approved by compiler-errors

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 Jan 14, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 15, 2024
coverage: Simplify building the coverage graph with `CoverageSuccessors`

This is a collection of simplifications to the code that builds the *basic coverage block* graph, which is a simplified view of the MIR control-flow graph that ignores panics and merges straight-line sequences of blocks into a single BCB node.

The biggest change is to how we determine the coverage-relevant successors of a block. Previously we would call `Terminator::successors` and apply some ad-hoc postprocessing, but with this PR we instead have our own `match` on the terminator kind that produces a coverage-specific enum `CoverageSuccessors`. That enum also includes information about whether a block has exactly one successor that it can be chained into as part of a single BCB.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 15, 2024
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#119508 (coverage: Simplify building the coverage graph with `CoverageSuccessors`)
 - rust-lang#119818 (Silence some follow-up errors [3/x])
 - rust-lang#119870 (std: Doc blocking behavior of LazyLock)
 - rust-lang#119963 (Fix `allow_internal_unstable` for `(min_)specialization`)
 - rust-lang#119968 (Remove unused/unnecessary features)
 - rust-lang#119971 (Use `zip_eq` to enforce that things being zipped have equal sizes)
 - rust-lang#119974 (Minor `trimmed_def_paths` improvements)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors
Copy link
Contributor

bors commented Jan 15, 2024

⌛ Testing commit 5eae945 with merge 73252d5...

@bors
Copy link
Contributor

bors commented Jan 15, 2024

☀️ Test successful - checks-actions
Approved by: compiler-errors
Pushing 73252d5 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Jan 15, 2024
@bors bors merged commit 73252d5 into rust-lang:master Jan 15, 2024
12 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 15, 2024
@Zalathar Zalathar deleted the graph branch January 15, 2024 09:08
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (73252d5): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.3% [0.3%, 0.3%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-1.0% [-1.0%, -1.0%] 1
All ❌✅ (primary) - - 0

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 666.737s -> 669.714s (0.45%)
Artifact size: 308.19 MiB -> 308.18 MiB (-0.00%)

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) merged-by-bors This PR was explicitly merged by bors. 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