-
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
Possible solution to allow MIR inlining with -Zinstrument-coverage #83061
Comments
One other note I forgot. Since an inlined function can be generated more than once, we need to make sure the coverage data isn't re-added. I suspect this is already checked, but there should be a test for this, once it's implemented. |
I'm not sure why you cc-ed me, I'm not very familiar with either MIR inlining or instrument-coverage (or codegen in general for that matter). |
No important reason Josh. Sorry. I know you typically add the coverage label, so that was the only reason |
Addendum: I glossed over some details. One thing I just remembered, which is actually quite helpful, is we will need an actual Then in This allows different parameterized versions of an inlined function to get different coverage results, just like non-inlined generics do now. |
It is possible to derive an inlined instance from a scope information associated with a statement, and use that when creating a counter. The general approach seems to work just fine, although I did only very limited amount of testing (I also relaxed checks for duplicate ids, allowing them as long as code regions & expressions are the same). |
Make source-based code coverage compatible with MIR inlining When codegenning code coverage use the instance that coverage data was originally generated for, to ensure basic level of compatibility with MIR inlining. Fixes rust-lang#83061
Today, the MIR
Inline
pass is skipped if-Zinstrument-coverage
is enabled.I have an idea for a workaround that will allow MIR inlining.
I believe the problem is, when generating the LLVM coverage counters, and related coverage info used to generate the coverage map, each
Coverage
MIR statement assumes the coverage data should be associated with the current function being codegenned.See
rust/compiler/rustc_codegen_ssa/src/mir/coverageinfo.rs
Line 23 in 1973f84
The
self.instance
is the function instance being generated. But if MIR inlining is performed, the original coverage counters for the inlined function will conflict with coverage counters of the currentinstance
. For example, in both functions, the first counter is1
. But there will be two occurrences of that counter, for different functions in the original source. (That's essentially the problem.)To fix this, I believe we can just add the original function's
def_id
to the MIRCoverage
statement data.Everywhere
self.instance
is used in thecodegen_coverage()
function should (probably) be replaced with an instance derived from the originaldef_id
. This will apply those counters to the correctFunctionCoverage
, and there will be no conflicts.I may not be able to work on this very soon, and disabling MIR inlining is an OK workaround for now, but I wanted to capture the idea for me or someone else to try in the future.
The text was updated successfully, but these errors were encountered: