-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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: Collect HIR info during MIR building #118237
Conversation
r? @wesleywiser (rustbot has picked a reviewer for you, use r? to override) |
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
@@ -106,7 +104,6 @@ fn get_body_span<'tcx>( | |||
} | |||
|
|||
fn hash_mir_source<'tcx>(tcx: TyCtxt<'tcx>, hir_body: &'tcx rustc_hir::Body<'tcx>) -> u64 { | |||
// FIXME(cjgillot) Stop hashing HIR manually here. |
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.
@rustbot label +A-code-coverage |
7f3f9d3
to
e8381de
Compare
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.
In addition to general MIR-pass cleanliness, part of the motivation here is to make it easier to collect additional coverage information from HIR/THIR in the future, because much of the plumbing has been established by this PR.
There is a premise here that I can't quite agree with. Looking at HIR from a MIR pass is not an issue. What kind of information would you need to channel in the future?
The concrete motivation is branch coverage instrumentation (#118305). I want to have an accurate association between the span of an So the approach I've taken in my branch coverage draft is to add code to the lowering of |
So the two main things I care about from this PR are:
Putting the signature/body span in that field is kind of secondary. I've done it so that this PR doesn't end up looking kind of pointless (in isolation), and also because the comments on that code gave me the impression that looking backwards at HIR from a MIR pass was gently discouraged. But in truth it's not really the central focus of this PR. |
da6f75e
to
1bc26f4
Compare
If the function signature span comes after the body span (due to macro expansion), expanding it towards the start of the body span would produce nonsense.
The coverage instrumentor pass operates on MIR, but it needs access to some source-related information that is normally not present in MIR. Historically, that information was obtained by looking back at HIR during MIR transformation. This patch arranges for the necessary information to be collected ahead of time during MIR building instead.
Another thing I could do with this PR is remove the part that actually moves code into Then I could integrate the MIR building changes into #118305, where they would be easier to justify. |
☔ The latest upstream changes (presumably #118500) made this pull request unmergeable. Please resolve the merge conflicts. |
This needed some intensive manual rebasing, so I've instead reworked it into #118929. |
coverage: Tidy up early parts of the instrumentor pass This is extracted from rust-lang#118237, which needed to be manually rebased anyway. Unlike that PR, this one only affects the coverage instrumentor, and doesn't attempt to move any code into the MIR builder. That can be left to a future version of rust-lang#118305, which can still benefit from these improvements. So this is now mostly a refactoring of some internal parts of the instrumentor.
Rollup merge of rust-lang#118929 - Zalathar:look-hir, r=cjgillot coverage: Tidy up early parts of the instrumentor pass This is extracted from rust-lang#118237, which needed to be manually rebased anyway. Unlike that PR, this one only affects the coverage instrumentor, and doesn't attempt to move any code into the MIR builder. That can be left to a future version of rust-lang#118305, which can still benefit from these improvements. So this is now mostly a refactoring of some internal parts of the instrumentor.
The coverage instrumentor pass operates on MIR, but it needs access to some source-related information that is normally not present in MIR.
Historically, that information was obtained by looking back at HIR during MIR transformation. This PR arranges for the necessary information to be collected ahead of time during MIR building instead.
Fixes #79625.
In addition to general MIR-pass cleanliness, part of the motivation here is to make it easier to collect additional coverage information from HIR/THIR in the future, because much of the plumbing has been established by this PR.