Description
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
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 current instance
. For example, in both functions, the first counter is 1
. 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 MIR Coverage
statement data.
Everywhere self.instance
is used in the codegen_coverage()
function should (probably) be replaced with an instance derived from the original def_id
. This will apply those counters to the correct FunctionCoverage
, 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.