Skip to content

Expose exhaustivity checks in the GHC API

Motivation

I'm working on the Haskell Language Server, and would like to add functionality that creates missing matches for otherwise inexhaustive pattern matches. The right way to do this IMO is to reuse GHC's exhaustivity checking machinery, and to create new matches for the uncovered cases.

However, all of the machinery exposed by GHC.HsToCore.PmCheck assumes the caller wants to just emit the warnings. Despite having a rich data structure below the surface, none of it is exposed, and is simply immediately consumed to produce warnings.

This leaves HLS in the unfortunate position of needing to parse error messages in order to get its hands on the exhaustivity data!

Proposal

Expose GHC.HsToCore.PmCheck.checkMatches', possibly with fewer assumptions baked in that callers want to immediately turn the result into a warning. E.g. I'm not convinced it needs to call getNFirstUncovered, though this is based on a very cursory reading of the code.

Edited by isovector
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information