-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Fixes reported bugs in Rust Coverage #79958
Fixes reported bugs in Rust Coverage #79958
Conversation
Fixes: rust-lang#79569 Fixes: rust-lang#79566 Fixes: rust-lang#79565 For the first issue (rust-lang#79569), I got hit a `debug_assert!()` before encountering the reported error message (because I have `debug = true` enabled in my config.toml). The assertion showed me that some `SwitchInt`s can have more than one target pointing to the same `BasicBlock`. I had thought that was invalid, but since it seems to be possible, I'm allowing this now. I added a new test for this. ---- In the last two cases above, both tests (intentionally) fail to compile, but the `InstrumentCoverage` pass is invoked anyway. The MIR starts with an `Unreachable` `BasicBlock`, which I hadn't encountered before. (I had assumed the `InstrumentCoverage` pass would only be invoked with MIRs from successful compilations.) I don't have test infrastructure set up to test coverage on files that fail to compile, so I didn't add a new test.
Note that generating MIR with a SwitchInt with more than one target to the same Basic Block may require |
@@ -28,11 +28,8 @@ Counter in file 0 79:14 -> 79:16, 0 | |||
Counter in file 0 81:1 -> 81:2, 0 | |||
Counter in file 0 91:25 -> 91:34, 0 | |||
Counter in file 0 5:1 -> 5:25, #1 | |||
Counter in file 0 5:25 -> 6:14, #1 |
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.
The changes in the counters file in async.txt are just another example of the non-deterministic ordering of output from llvm-cov
.
These 4 lines (from 31-34) moved to line 50 when I added support for multiple SwitchInt
targets to the same BasicBlock
.
The other lines moved after I updated mod.rs
to ignore MIR that starts with Unreachable
.
I don't think these changes should have had any real effect on the existing test results, and they don't except in this one test sample, and only in the debug counters.
The Makefile
based test does not fail based on differences in counter files. So it's not a problem, but it would be nice to make these more deterministic in the future, perhaps by sorting the entire file before comparing.
UPDATED AND SUMMARIZED TO BE EASIER TO DIGEST:
For all of the above, a new check in
For the above, I think the current error is good enough. But should we enable That would prevent some confusion. I don't know if there are any platform-specific issues with
This error is fine.
I now allow someone to run coverage AND override its default symbol-mangling-version to force If they do that, they will get a new warning.
This error is fine. I overrode the test options, and without that flag, it does not fail of course. If we ever want a test like this with coverage enabled, we would simply
Given the nature of the test, I think the error is appropriate. The test does not enable I don't know if we should issue any warnings about combining -Z thinlto (and variants) with -Z instrument-coverage. I think the behavior tested here does not indicate the compile itself failed. Only that the result was not as optimized as it would have been without coverage. So it may not be bad to combine them. Therefore, I'm not going to do anything differently here.
Now, I no longer forcibly skip the
I don't know why this test produces different results with
I don't know why this test produces different results with
I don't know why this test produces different results with
I don't know why this test produces different results with
|
FYI, I updated the previous comment after doing a bit more investigation, to provide a better summarization, grouping like-issues, and providing explanations where I could. The last 4 tests as listed in the comment above show test result differences for which I could not deduce a specific cause. For all of the others, it's pretty clear why they don't work with By generally, the only thing we may want to consider (I guess) is, does it ever make sense to combine Is that even possible? |
I don't think it really makes sense or, at least, without some kind of clear use-case, I don't think we should spend any effort to attempt supporting that now. If someone eventually does need that, then we can consider adding support for it at that time. |
@wesleywiser replied:
Agreed, so instead, I added a check, when loading profiler_builtins, to see if Similarly, I'm checking to see if In both cases I issue a warning now. This improves the error handling in tests, and resolves some ICE cases. It should be a little easier to understand why things like these are failing. |
776d31f
to
77c9a77
Compare
Comment removed because it referred to an error in an earlier comment, which I've now fixed. |
Oh, the changes I made for these new checks and warnings are in the second commit of this PR. |
77c9a77
to
8f8f352
Compare
FYI, here's how I'm testing some of these, for example: $ ./x.py test --rustc-args="-Zinstrument-coverage" src/test/ui/associated-types/associated-types-ICE-when-projecting-out-of-err.rs
$ ./x.py test --rustc-args="-Zinstrument-coverage -Zsymbol-mangling-version=legacy" src/test/ui/const-generics/issues/issue-62579-no-match.rs |
c39bae5
to
3566f3c
Compare
I updated #79958 (comment) again, this time adding commentary on what I've improved in this PR, and/or decided was working as intended. I still don't know what is happening with the last 4 issues. My current theory (at least maybe for 3 of the 4) is--similar to the
|
Adds checks for: * `no_core` attribute * explicitly-enabled `legacy` symbol mangling * mir_opt_level > 1 (which enables inlining) I removed code from the `Inline` MIR pass that forcibly disabled inlining if `-Zinstrument-coverage` was set. The default `mir_opt_level` does not enable inlining anyway. But if the level is explicitly set and is greater than 1, I issue a warning. The new warnings show up in tests, which is much better for diagnosing potential option conflicts in these cases.
3566f3c
to
4f550f1
Compare
I cleaned up a couple of things this morning, but it should be ready for review again. Sorry for the churn. I think these changes were worth it. |
@@ -970,7 +970,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, | |||
mir_emit_retag: bool = (false, parse_bool, [TRACKED], | |||
"emit Retagging MIR statements, interpreted e.g., by miri; implies -Zmir-opt-level=0 \ | |||
(default: no)"), | |||
mir_opt_level: usize = (1, parse_uint, [TRACKED], | |||
mir_opt_level: Option<usize> = (None, parse_opt_uint, [TRACKED], |
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.
I don't see a reason for making this an Option, it doesn't change its default dependent on coverage like symbol mangling does.
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.
I don't know of any other way to know if the option was set on the command line or not.
I need to know that in config.rs when checking for conflicting command line flags.
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.
Ah, I understand your point... Let me think about this a minute. I'm inclined to agree.
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.
To me the value matters more than if it was overridden (which you know it was today if it's > 1).. if the default were changed to 2, we would still want this to fire to warn people who were using coverage. (Probably we'd either keep the default as 1 if coverage were enabled, or add support for inlining counters. But it's unlikely that we turn on inlining by default anytime soon.)
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.
Sorry, yes, I concur. I'll remove the option from mir_opt_level. Thanks!
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.
if the default were changed to 2, we would still want this to fire to warn people who were using coverage.
I agree 100%. Thanks.
Looks good after comment (which I'd like to see addressed because of unnecessary complexity). Thanks! @bors delegate+ |
✌️ @richkadel can now approve this pull request |
2d1f6cc
to
07c632f
Compare
This ensures consistent handling of default values for options that are None if not specified on the command line.
07c632f
to
36c639a
Compare
@bors r=tmandry rollup |
📌 Commit 36c639a has been approved by |
FYI, I re-ran these tests with I also tried forcing The only thing left (I think) is the changes that If that's true, then for each of these 4 tests, the MIR processing implied by the flags and/or attrs seems to be confused by the additional |
…laumeGomez Rollup of 6 pull requests Successful merges: - rust-lang#79379 (Show hidden elements by default when JS is disabled) - rust-lang#79796 (Hide associated constants too when collapsing implementation) - rust-lang#79958 (Fixes reported bugs in Rust Coverage) - rust-lang#80008 (Fix `cargo-binutils` link) - rust-lang#80016 (Use imports instead of rewriting the type signature of `RustcOptGroup::stable`) - rust-lang#80025 (Replace some `println!` with `tidy_error!` to simplify) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
…r=jieyouxu Allow injecting a profiler runtime into `#![no_core]` crates An alternative to rust-lang#133300, allowing `-Cinstrument-coverage` to be used with `-Zbuild-std`. The incompatibility between `profiler_builtins` and `#![no_core]` crates appears to have been caused by profiler_builtins depending on core, and therefore conflicting with core (or minicore). But that's a false dependency, because the profiler doesn't contain any actual Rust code. So we can just mark the profiler itself as `#![no_core]`, and remove the incompatibility error. --- For context, the error was originally added by rust-lang#79958.
Fixes: #79569
Fixes: #79566
Fixes: #79565
For the first issue (#79569), I got hit a
debug_assert!()
beforeencountering the reported error message (because I have
debug = true
enabled in my config.toml).
The assertion showed me that some
SwitchInt
s can have more than onetarget pointing to the same
BasicBlock
.I had thought that was invalid, but since it seems to be possible, I'm
allowing this now.
I added a new test for this.
In the last two cases above, both tests (intentionally) fail to compile,
but the
InstrumentCoverage
pass is invoked anyway.The MIR starts with an
Unreachable
BasicBlock
, which I hadn'tencountered before. (I had assumed the
InstrumentCoverage
passwould only be invoked with MIRs from successful compilations.)
I don't have test infrastructure set up to test coverage on files that
fail to compile, so I didn't add a new test.
r? @tmandry
FYI: @wesleywiser