HIE files compatibility across different GHC versions
Motivation
When developing Haskell tools, it's desirable to be able to build the binary of your tool in advance and allow users to download the pre-built binary rather than asking them to build the tool from scratch on their machines. Building Haskell packages can take a significant amount of time, so having already built binaries is a much friendlier UX.
Fortunately, it's possible to build Haskell binaries on Linux (even statically linked!), macOS and Windows. However, if the tooling uses GHC API and, specifically, analyses HIE files, it's quite challenging to prepare a single binary that works on a variety of projects that use different GHC versions.
For example, if my tool that reads HIE files is built with GHC-8.8.3 and the library is built with GHC-8.8.2, I see the following error message:
stan: stan: panic! (the 'impossible' happened)
(GHC version 8.8.3 for x86_64-unknown-linux):
readHieFile: hie file versions don't match for file: .hie/Relude.hie Expected 8083 but got 8082
Please report this as a GHC bug: https://www.haskell.org/ghc/reportabug
This is quite unfortunate, and it would be nice if the fact that different GHCs were used to build the tool and a Haskell project wouldn't matter.
Proposal
Implement backwards compatibility scheme for HIE files.
If some Haskell library was built with the GHC version X, and the tool was built with the GHC version Y, the tool should be able to read HIE files for that library if one of the following criteria satisfies:
- X < Y
- X and Y are different minor versions of the same major GHC version