Instead of trying to heuristically recover source-code spans from MIR soup, we
can now take advantage of the `CoverageKind::Point` statements injected for
specific HIR expressions.
This is a transitional implementation that lets us remove the old MIR-soup
code, but still relies heavily on the existing span-refinement heuristics, and
does not take advantage of the full possibilities of HIR-aware coverage
instrumentation.
In order to avoid annoying never-executed spans in code that contains
assertions, a heuristic has been added that ignores any expression within the
arguments of a macro-expanded function call that returns `!`.
Some coverage tests now require `//@ min-llvm-version: 23`, due to changes in
how LLVM sorts the coverage mapping entries.
In order to make coverage instrumentation HIR-aware, we need to have MIR
building inject marker statements at key locations, so that instrumentation can
accurately reconstruct the relationship between HIR constructs and MIR-level
control flow.
The most important of these is `PointKind::Expr`, which associates a HIR
expression with the start of the MIR that will evaluate that expression. There
isn't a single convenient place to inject these, but we can get close by
observing that THIR building wraps every expression in a
`thir::ExprKind::Scope` node, which also contains the `HirId` of that
expression. If we inject a marker whenever `thir::ExprKind::Scope` is lowered,
that results in an accurate marker for every expression.
Other markers are also injected at key points that don't correspond directly to
a HIR node, to avoid major regressions in coverage-map quality.
When making changes that have a large impact on coverage counter creation, this
makes it easier to see whether the number of physical counters has changed.
(The highest counter ID seen in coverage maps is not necessarily the same as
the number of physical counters actually used by the instrumented code, but
it's the best approximation we can get from looking only at the coverage maps,
and it should be reasonably accurate in most cases.)
Currently we can't automatically enforce formatting on tests (see #125637), but
we can at least keep things relatively tidy by occasionally running the
formatter manually.
This was done by temporarily commenting out the `"/tests/"` exclusion in
`rustfmt.toml`, and then running `x fmt tests/coverage` and
`x test coverage --bless`.