feb879394a
coverage: Simplify the heuristic for ignoring `async fn` return spans The code for extracting coverage spans from MIR has a special heuristic for dealing with `async fn`, so that the function's closing brace does not have a confusing double count. The code implementing that heuristic is currently mixed in with the code for flushing remaining spans after the main refinement loop, making the refinement code harder to understand. We can solve that by hoisting the heuristic to an earlier stage, after the spans have been extracted and sorted but before they have been processed by the refinement loop. The coverage tests verify that the heuristic is still effective, so coverage mappings/reports for `async fn` have not changed. --- This PR also has the side-effect of fixing the `None some_prev` panic that started appearing after #118525. The old code assumed that `prev` would always be present after the refinement loop. That was only true if the list of collected spans was non-empty, but prior to #118525 that didn't seem to come up in practice. After that change, the list of collected spans could be empty in some specific circumstances, leading to panics. The new code uses an `if let` to inspect `prev`, which correctly does nothing if there is no span present.
The tests in this directory are shared by two different test modes, and can be run in multiple different ways:
./x.py test coverage-map
(compiles to LLVM IR and checks coverage mappings)./x.py test coverage-run
(runs a test binary and checks its coverage report)./x.py test coverage
(runs bothcoverage-map
andcoverage-run
)
Maintenance note
These tests can be sensitive to small changes in MIR spans or MIR control flow, especially in HIR-to-MIR lowering or MIR optimizations.
If you haven't touched the coverage code directly, and the tests still pass in
coverage-run
mode, then it should usually be OK to just re-bless the mappings
as necessary with ./x.py test coverage-map --bless
, without worrying too much
about the exact changes.