Draft of branch coverage support#118305
Conversation
|
@rustbot label +A-code-coverage |
|
@rustbot author |
tests/coverage/branch.coverage
Outdated
| LL| | if | ||
| LL| | ! | ||
| LL| 15| cond | ||
| ------------------ | ||
| | Branch (LL:9): [True: 10, False: 5] | ||
| ------------------ |
There was a problem hiding this comment.
Two problems here:
- The span doesn't include
!. - The true/false counts are reversed, since they're tracking
condinstead of!cond.
tests/coverage/branch.coverage
Outdated
| LL| | if | ||
| LL| 15| a | ||
| ------------------ | ||
| | Branch (LL:9): [True: 12, False: 3] | ||
| ------------------ | ||
| LL| | && | ||
| LL| 12| b | ||
| ------------------ | ||
| | Branch (LL:9): [True: 8, False: 4] | ||
| ------------------ |
There was a problem hiding this comment.
This all looks correct, which is nice.
tests/coverage/branch.coverage
Outdated
| LL| | if | ||
| LL| | let | ||
| LL| | true | ||
| LL| | = | ||
| LL| 15| cond |
There was a problem hiding this comment.
This currently doesn't get branch coverage at all. I'd like to fix that if possible, but for me it's a lower priority than getting the logical ops correct.
|
cc @Swatinem in case you're curious. The MIR building stuff will have to change once I figure out how to handle the logical ops better. |
|
☔ The latest upstream changes (presumably #118300) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Well, this definitely indicates a need to add macro-expanded spans to the list of things I need to figure out. The existing coverage code has some functions in |
|
I tried passing each of the branch spans through |
996fbe5 to
9000afd
Compare
|
Now that the So I'm thinking it might make sense for me to polish the current functionality into a review-ready state, so that people can start playing with branch coverage on nightly and start flushing out any lingering correctness issues. |
This comment has been minimized.
This comment has been minimized.
811cb89 to
934e104
Compare
|
I found a way to fix the mappings for We also need to propagate it through the |
|
Big rebase! I had to resolve some non-trivial merge conflicts, and I also changed the MIR builder code to be specific to branch coverage only, since currently there are no concrete plans to use it for recording non-branch coverage info (though this still remains a future possibility). |
|
☔ The latest upstream changes (presumably #121036) made this pull request unmergeable. Please resolve the merge conflicts. |
|
The main concern I have with this PR at the moment is that the way it handles (The current approach tries to keep track of the outermost enclosing My preferred approach would be to rearrange the MIR-building code in a way that naturally satisfies the needs of branch coverage (and beyond), without adversely affecting non-coverage builds. But that's going to require some care, because this code already has some important and subtle responsibilities. |
|
Updated for #121370 ( |
|
I've adjusted how I handle the issue of Instead of sneakily creating an extra block when inserting the block marker, I decided to just fix the issue at its source, by making the This adds one extra block to the lowering of |
|
I received some questions about this implementation, which I have answered in a Zulip thread: https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/Branch.20coverage.20questions |
8063c3f to
49b7641
Compare
|
☔ The latest upstream changes (presumably #121859) made this pull request unmergeable. Please resolve the merge conflicts. |
|
☔ The latest upstream changes (presumably #121998) made this pull request unmergeable. Please resolve the merge conflicts. |
|
☔ The latest upstream changes (presumably #122151) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Switched to a different mechanism for handling |
This will allow MIR building to check whether a function is eligible for coverage instrumentation, and avoid collecting branch coverage info if it is not.
|
Now that I've resolved my own concerns, I think it might be time to close this and open a new PR for actual review. |
EDIT: I've closed this and re-opened a non-draft version at #122322.
This is a work-in-progress snapshot of my implementation of branch coverage.
It works, and produces correct results in many cases. However, it sometimes produces confusing or incorrect results forifexpressions that contain the!/&&/||operators, since the THIR-to-MIR lowering of those is non-trivial.