-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Reland - Report coverage 0
of dead blocks
#85385
Reland - Report coverage 0
of dead blocks
#85385
Conversation
@tmandry - I ran several experiments, trying different things, and tested compiling and coverage report generation on Fuchsia tests that were not working under the reverted PR. I did identify the original problem and corrected for it. |
converted to draft because I found a new case with the same ICE caused by the reverted PR; so this is still not 100% fixed. |
f3eabbd
to
e28f3a3
Compare
As alluded to in my previous comment, I managed to trigger the same assertion failure that forced us to revert the previous PR for dead block coverage (though much more rare): thread 'rustc' panicked at 'No counters provided the source_hash for used function: Instance { def: Item(WithOptConstParam { did: DefId(0:1199 ~ ffx_emulator[8787]::types::__mock_MockFuchsiaPaths_FuchsiaPaths::__get_image_path::{impl#2}::matches), const_param_did: None }), substs: [] }', compiler/rustc_codegen_ssa/src/coverageinfo/map.rs:156:9 Initially, just to capture the stack trace and see where the problem was coming from, I added an assert to query stack during panic: The stack trace (not shown here) showed that the problem occurs during the So I replaced the assert with a simple check, and if the result of dropping the dead blocks removes all |
@wesleywiser - I think Tyler is out for a few days. No rust really, but if you are willing to review this one, it should be ready to land. FYI, I've been validating the edge cases that failed before no longer fail by compiling all of Fuchsia OS ( |
@richkadel I'd be happy to take a look later today! |
@wesleywiser @tmandry - Thanks for your initial reviews. Please let me know what I need to do to get your approval. I can't simplify the logic any further. I could remove the I can add more comments in the code, if that would help? Thanks, |
I've been thinking about this, and my concern is that we need to assert that other passes never remove counters to catch bugs, but I don't see a reason why it would always be true. For example, Instead of creating unreachable counters at the time they're removed, is there some bookkeeping we can do to notice those counters are indeed unreachable at codegen time? If we could then the logic could be self-contained and everything would just "fall out" of the final MIR, regardless of the passes that run on it. I realize this might require a pre-pass over the MIR at codegen time, but it could be a linear scan of all statements in all blocks (since we would have already simplified it), and I think that would be preferable. |
Some of this is probably obvious, but to summarize, once the I think that any "bookkeeping" would have to be an additional data structure in the Also, keep in mind this would only be relevant when blocks are removed due to const evaluation, and that's exceptionally rare. So the additional data structure and the added lookup logic during codegen seems to outweigh the benefit. So let's go back to your initial concern:
OK, I can see that argument. It gives me a different idea. Let me see if I can change this to just simply be an opt-in kind of approach that leaves almost everything as it was before, and only implement the special handling (to save unreachable code regions) when simplifying after specific actions like (maybe only) const eval. This sounds too obvious to me now, so I wonder if I already tried this and his a roadblock, but I'll give it another shot. |
Is this any better? Much less changed. |
cb0082c
to
74b8e38
Compare
I just thought of a better way that addresses your concern, and overall should be more reliable, I believe. I will want to test it by compiling everything against fuchsia kitchen sink again. |
I think I'd be fine with another data structure on the mir body, for what it's worth. |
74b8e38
to
702c8df
Compare
No need for that. In fact, what I just committed is even better than what I had planned to do. I found the root cause of the problems that plagued the So I removed the stuff you were concerned with, and cleaned up some unneeded checks, now that the And as a bonus, I also was able to add a new test that I confirmed caused the same kind of malformed coverage issues, without the fixes I just made. That makes me much more comfortable that we should be able to catch similar issues or compiler regressions early. This is once again ready for review. |
FYI, I think Tyler is OOO this week, but I think you should be able to confirm that this revised PR addresses both your concerns and Tyler's concerns, and if so, maybe you would be willing to approve this? The new version of the PR removes the somewhat controversial directive for how to handle dropped coverage (Assert, Allow, or Save), and now makes the right choice atomically, in an efficient way. And it finally includes a new test that confirms the new logic addresses the edge case that was giving me problems! I was able to finally deduce the improved approach by trying many different approaches, experimentally, until I not only had a solution that fully compiles and generates correct coverage on a very large codebase of complex Rust (including many third party crates), but in doing so, also finally revealed the root cause of prior failures (edge case with some generator implementations). From this, I was able to generate a new test ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! I like this a lot more than the previous approach 🙂
702c8df
to
65d3e60
Compare
Fixes: rust-lang#84018 With `-Z instrument-coverage`, coverage reporting of dead blocks (for example, blocks dropped because a conditional branch is dropped, based on const evaluation) is now supported. Note, this PR relands an earlier, reverted PR that failed when compiling generators. The prior issues with generators has been resolved and a new test was added to prevent future regressions. Check out the resulting changes to test coverage of dead blocks in the test coverage reports in this PR.
⌛ Testing commit f4f76e6 with merge 82407804c56e80a6bff84821f015c59e527e7171... |
💔 Test failed - checks-actions |
I don't see any error messages? Possible spurious infra failure on:
|
@wesleywiser - I think we just need a "retry" (reason: spurious), unless you see something I don't. Thanks! |
@bors retry |
…erage, r=wesleywiser Reland - Report coverage `0` of dead blocks Fixes: rust-lang#84018 With `-Z instrument-coverage`, coverage reporting of dead blocks (for example, blocks dropped because a conditional branch is dropped, based on const evaluation) is now supported. Note, this PR relands an earlier, reverted PR that failed when compiling generators. The prior issues with generators has been resolved and a new test was added to prevent future regressions. Check out the resulting changes to test coverage of dead blocks in the test coverage reports in this PR. r? `@tmandry` fyi: `@wesleywiser`
⌛ Testing commit f4f76e6 with merge 555e88f95f60af84045bdcf8127a1a3df688675f... |
💔 Test failed - checks-actions |
@wesleywiser - Any idea what's going on here? Is this PR just unlucky? (2 spurious failures in 2 attempts?) I can't see any details on the failure, and the changes should not have any Mac-specific impact AFAICT. Do we need to "try" instead of "retry" (I'm not sure if there's a difference, but wondering if the failure yesterday left some bad state that "retry" may be using)? Confused. |
I think the macOS builders are just pretty flaky. I ran into the same thing in another PR today.
@bors retry |
Oh, yes, sorry... I meant to say, "does it need a fresh Anyway, hopefully this time it will work. Thank you! |
☀️ Test successful - checks-actions |
Fixes: #84018
With
-Z instrument-coverage
, coverage reporting of dead blocks(for example, blocks dropped because a conditional branch is dropped,
based on const evaluation) is now supported.
Note, this PR relands an earlier, reverted PR that failed when compiling
generators. The prior issues with generators has been resolved and a new
test was added to prevent future regressions.
Check out the resulting changes to test coverage of dead blocks in the
test coverage reports in this PR.
r? @tmandry
fyi: @wesleywiser