Do you rely on `-fhpc` accumulating coverage over multiple runs?

If you use GHC’s -fhpc flag to generate coverage reports, do you rely on the fact that running the executable multiple times accumulates the coverage over all runs? This is the behaviour currently implemented by default, and which I propose to change in this GHC proposal: Change semantics of `-fhpc` to not accumulate data over multiple runs by BinderDavid · Pull Request #612 · ghc-proposals/ghc-proposals · GitHub

Here is an example to illustrate the behaviour:

> cat Example.hs
module Main where
main = print "hello"
> ghc -fhpc Example.hs
[1 of 2] Compiling Main             ( Example.hs, Example.o )
[2 of 2] Linking Example
> ./Example
"hello"
> cat Example.tix
Tix [ TixModule "Main" 2243069736 3 [1,1,1]]
> ./Example
"hello"
> cat Example.tix
Tix [ TixModule "Main" 2243069736 3 [2,2,2]]

I have been bitten by this behaviour multiple times now, and propose to change it so that you have to do any accumulation of multiple runs yourself. But I would like to know whether anyone is relying on this behaviour, or if you are surprised, as I was when I discovered this.

I haven’t used -fhpc specifically, but whenever I configure ghc to produce executables that generate extra files I wish I had to choose the name of the generate file explicitly (through a flag to ghc, through a +RTS flag to the executable, or both). Implicit behaviour is the source of all this confusion!

1 Like

I also don’t use the accumulate feature (and would like to see it gone), but I do use HPCTIXFILE to send parallel processes to different tix files which are then merged.

I’ve been continually annoyed by “tix doesn’t match” for something like 15 years now, as far as I can tell it cannot be worked around (writing scripts to clear out tix files constantly never worked, I figured out why once long ago but forget now). It just means I either don’t use hpc, or my ghci sessions will regularly die and I have to restart them. So if your change will fix that too, then my only request is you go back in time and commit it 15 years ago!

2 Likes

Thanks :slight_smile: I had a very similar experience with trying to delete tixfiles in scripts. Can you post what you wrote above in the GitHub issue, or else can I copy your comment there?

1 Like