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 coverage expressions based on sums #117651

Merged
merged 8 commits into from Nov 26, 2023

Conversation

Zalathar
Copy link
Contributor

@Zalathar Zalathar commented Nov 7, 2023

This is a combination of some interlinked changes to the code that creates coverage counters/expressions for nodes and edges in the coverage graph:

  • Some preparatory cleanups in MakeBcbCounters::make_branch_counters
  • Use BcbCounter (instead of CovTerm) when building coverage expressions
    • This makes it easier to introduce a fold for building sums
  • Simplify the creation of coverage expressions based on sums, by having Iterator::fold do much of the work
  • Get rid of the awkward BcbBranch enum, and replace it with graph edges represented as (from_bcb, to_bcb)
    • This further simplifies the body of the fold

@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. A-code-coverage Area: Source-based code coverage (-Cinstrument-coverage) labels Nov 7, 2023
@cjgillot cjgillot self-assigned this Nov 8, 2023
@Zalathar Zalathar force-pushed the fold-sums branch 3 times, most recently from e138d9a to 959517f Compare November 8, 2023 05:47
@Zalathar Zalathar marked this pull request as ready for review November 8, 2023 05:48
@rustbot
Copy link
Collaborator

rustbot commented Nov 8, 2023

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

/// no benefit in having a separate counter for its in-edge, because it
/// would have the same value as the node's own counter.
///
/// FIXME: That assumption might not be true for [`TerminatorKind::Yield`]?
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that this concern is equally true of the old code and the new code.

It's just a corner-case that came to mind while writing up these docs.

@Zalathar Zalathar force-pushed the fold-sums branch 2 times, most recently from 2017d54 to b38fb70 Compare November 12, 2023 11:51
@Zalathar Zalathar force-pushed the fold-sums branch 5 times, most recently from f0decb2 to c41a60c Compare November 19, 2023 01:13
Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

r=me with one nit

/// FIXME: That assumption might not be true for [`TerminatorKind::Yield`]?
#[inline(always)]
pub(super) fn bcb_has_multiple_in_edges(&self, bcb: BasicCoverageBlock) -> bool {
self.predecessors[bcb].len() > 1
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be a special case for the entry bcb?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added an extra patch with some assertions/comments explaining why we don't have to worry about the special case of bcb0.

@cjgillot cjgillot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 19, 2023
@Zalathar Zalathar force-pushed the fold-sums branch 3 times, most recently from 4f3ac74 to a5e574a Compare November 20, 2023 00:42
@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-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 20, 2023
@bors
Copy link
Contributor

bors commented Nov 22, 2023

☔ The latest upstream changes (presumably #118143) made this pull request unmergeable. Please resolve the merge conflicts.

@Zalathar Zalathar force-pushed the fold-sums branch 3 times, most recently from 4d2be8e to c1bbb0d Compare November 23, 2023 00:05
@Zalathar
Copy link
Contributor Author

(I've been rebasing because I have other work that builds on top of this branch, but I haven't been making further changes.)

This lets us avoid creating two copies of the node's branch list.
Now that this code path unconditionally calls `make_branch_counters`, we might
as well make that method responsible for creating the node's counter as well,
since it needs the resulting term anyway.
This means that we no longer have to manage the distinction between
`BcbCounter` and `CovTerm` when preparing expressions.
In some cases we need to prepare a coverage expression that is the sum of an
arbitrary number of other terms. This patch simplifies the code paths that
build those sums.

This causes some churn in the mappings, because the previous code was building
its sums in a somewhat idiosyncratic order.
This was previously a helper method in `MakeBcbCounters`, but putting it in the
graph lets us call it from `BcbBranch`, and gives us a more fine-grained
borrow.
`BcbBranch` represented an out-edge of a coverage graph node, but would
silently refer to a node instead in cases where that node only had one in-edge.

Instead we now refer to a graph edge as a `(from_bcb, to_bcb)` pair, or
sometimes as just one of those nodes when the other node is implied by the
surrounding context. The case of sole in-edges is handled by special code added
directly to `get_or_make_edge_counter_operand`.
This explains why we don't have to worry about bcb0 having multiple in-edges.
@cjgillot
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Nov 25, 2023

📌 Commit 3163bc8 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 Nov 25, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 25, 2023
…mpiler-errors

Rollup of 7 pull requests

Successful merges:

 - rust-lang#117651 (coverage: Simplify building coverage expressions based on sums)
 - rust-lang#117968 (Stabilize `ptr::addr_eq`)
 - rust-lang#118158 (Reduce fluent boilerplate)
 - rust-lang#118201 (Miscellaneous `ObligationCauseCode` cleanups)
 - rust-lang#118288 (Use `is_{some,ok}_and` more in the compiler)
 - rust-lang#118289 (`is_{some,ok}_and` for rustdoc)
 - rust-lang#118290 (Don't ICE when encountering placeholders in implied bounds computation)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 26, 2023
…mpiler-errors

Rollup of 7 pull requests

Successful merges:

 - rust-lang#117651 (coverage: Simplify building coverage expressions based on sums)
 - rust-lang#117968 (Stabilize `ptr::addr_eq`)
 - rust-lang#118158 (Reduce fluent boilerplate)
 - rust-lang#118201 (Miscellaneous `ObligationCauseCode` cleanups)
 - rust-lang#118288 (Use `is_{some,ok}_and` more in the compiler)
 - rust-lang#118289 (`is_{some,ok}_and` for rustdoc)
 - rust-lang#118290 (Don't ICE when encountering placeholders in implied bounds computation)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit fd1a263 into rust-lang:master Nov 26, 2023
11 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Nov 26, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 26, 2023
Rollup merge of rust-lang#117651 - Zalathar:fold-sums, r=cjgillot

coverage: Simplify building coverage expressions based on sums

This is a combination of some interlinked changes to the code that creates coverage counters/expressions for nodes and edges in the coverage graph:

- Some preparatory cleanups in `MakeBcbCounters::make_branch_counters`
- Use `BcbCounter` (instead of `CovTerm`) when building coverage expressions
  - This makes it easier to introduce a fold for building sums
- Simplify the creation of coverage expressions based on sums, by having `Iterator::fold` do much of the work
- Get rid of the awkward `BcbBranch` enum, and replace it with graph edges represented as `(from_bcb, to_bcb)`
  - This further simplifies the body of the fold
@Zalathar Zalathar deleted the fold-sums branch November 26, 2023 05:58
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.

None yet

5 participants