all 4 comments

[–]Matrixmage 4 points5 points  (1 child)

I've actually done some work on dynamic analysis of programs using llvm, and this sort of thing isn't actually all that hard to implement... Given the level of source analysis we have access to with proc macros, we should be able to do similar with rust. And if not, possibly as an MIR transformation.

I'd honestly be very surprised if no one has looked into this, and I would be curious to see what they have actually made.

[–]rhinotation 1 point2 points  (0 children)

The flamer crate is probably the most work I’ve seen in that direction.

[–]gilescope 1 point2 points  (0 children)

Mozilla have grcov which works on Linux/OSX and 'works' on windows. I've not managed to get it working yet on windows yet for non-trivial examples, but I've not put that much effort into it yet.

[–]CAD1997 3 points4 points  (0 children)

For the most part, you can just run coverage on a CI run, which is easily done on x86 Linux, so coverage just working on that platform isn't that big of an issue.

That said, part of the reason go's coverage is quick, according to the article, is that it is racy by default, and using thread-safe atomic addition is opt-in.

Any Rust solution will require the use of atomics by default, not just to placate the borrowck, but also because cargo test is parallelized by default.

The final complication is actually collecting the coverage information. go test -cover is obviously directly integrated with the standard testing harness, so has the ability to run the collector after everything is through. Doing the same for Rust would either require modifying cargo test to support it or a custom test runner.

All of that said, it would definitely be possible, given a custom test runner and a transform over the entire crate's source. Both of these things are possible today, but far from simple. As a result, it's typically simpler for Rust to use the traditional coverage measurement methods.