coverage: Hoist some complex code out of the main span refinement loop The span refinement loop in `spans.rs` takes the spans that have been extracted from MIR, and modifies them to produce more helpful output in coverage reports. It is also one of the most complicated pieces of code in the coverage instrumentor. It has an abundance of moving pieces that make it difficult to understand, and most attempts to modify it end up accidentally changing its behaviour in unacceptable ways. This PR nevertheless tries to make a dent in it by hoisting two pieces of special-case logic out of the main loop, and into separate preprocessing passes. Coverage tests show that the resulting mappings are *almost* identical, with all known differences being unimportant. This should hopefully unlock further simplifications to the refinement loop, since it now has fewer edge cases to worry about.
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.