Skip to content

Display results of GHC.Core.Lint.lint* functions consistently

Ryan Scott requested to merge wip/T18770 into master

Previously, the functions in GHC.Core.Lint used a patchwork of different ways to display Core Lint errors:

  • lintPassResult (which is the source of most Core Lint errors) renders Core Lint errors with a distinctive banner (e.g., *** Core Lint errors : in result of ... ***) that sets them apart from ordinary GHC error messages.

  • lintAxioms, in contrast, uses a completely different code path that displays Core Lint errors in a rather confusing manner. For example, the program in #18770 (closed) would give these results:

    Bug.hs:1:1: error:
        Bug.hs:12:1: warning:
            Non-*-like kind when *-like expected: RuntimeRep
            when checking the body of forall: 'TupleRep '[r]
            In the coercion axiom Bug.N:T :: []. Bug.T ~_R Any
            Substitution: [TCvSubst
                             In scope: InScope {r}
                             Type env: [axl :-> r]
                             Co env: []]
      |
    1 | {-# LANGUAGE DataKinds #-}
      | ^
  • Further digging reveals that GHC.IfaceToCore displays Core Lint errors for iface unfoldings as though they were a GHC panic. See, for example, this excerpt from #17723 (closed):

    ghc: panic! (the 'impossible' happened)
      (GHC version 8.8.2 for x86_64-unknown-linux):
            Iface Lint failure
      In interface for Lib
      ...

This patch makes all of these code paths display Core Lint errors and warnings consistently. I decided to adopt the conventions that lintPassResult currently uses, as they appear to have been around the longest (and look the best, in my subjective opinion). We now use the displayLintResult function for all three scenarios mentioned above. For example, here is what the Core Lint error for the program in #18770 (closed) looks like after this patch:

[1 of 1] Compiling Bug              ( Bug.hs, Bug.o )
*** Core Lint errors : in result of TcGblEnv axioms ***
Bug.hs:12:1: warning:
    Non-*-like kind when *-like expected: RuntimeRep
    when checking the body of forall: 'TupleRep '[r_axn]
    In the coercion axiom N:T :: []. T ~_R Any
    Substitution: [TCvSubst
                     In scope: InScope {r_axn}
                     Type env: [axn :-> r_axn]
                     Co env: []]
*** Offending Program ***
axiom N:T :: T = Any -- Defined at Bug.hs:12:1
*** End of Offense ***

<no location info>: error:
Compilation had errors

Fixes #18770 (closed).

Merge request reports