Lint types in newFamInst

Authored by RyanGlScott on Apr 19 2018, 11:54 AM.



We weren't linting the types used in newFamInst, which
might have been why Trac #15012 went undiscovered for so long. Let's fix

One has to be surprisingly careful with expanding type synonyms in
lintType, since in the offending program (simplified):

type FakeOut a = Int

type family TF a
type instance TF Int = FakeOut a

If one expands type synonyms, then FakeOut a will expand to
Int, which masks the issue (that a is unbound). I added an
extra Lint flag to configure whether type synonyms should be
expanded or not in Lint, and disabled this when calling lintTypes
from newFamInst.

As evidence that this works, I ran it on the offending program from
Trac #15012, and voilà:

$ ghc3/inplace/bin/ghc-stage2 Bug.hs -dcore-lint
[1 of 1] Compiling Foo              ( Bug.hs, Bug.o )
ghc-stage2: panic! (the 'impossible' happened)
  (GHC version 8.5.20180417 for x86_64-unknown-linux):
        Core Lint error
  <no location info>: warning:
      In the type ‘... (Rec0 (FakeOut b_a1Qt))))’
      @ b_a1Qt is out of scope
Test Plan

make test TEST=T15057

Diff Detail

rGHC Glasgow Haskell Compiler
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.
RyanGlScott created this revision.Apr 19 2018, 11:54 AM
RyanGlScott requested review of this revision.Apr 19 2018, 11:55 AM
RyanGlScott added inline comments.

I'm not sure what the usual way to report Core Lint errors is, so I just went with pprPanic. If there is a better way to do this, I'm all ears.

RyanGlScott edited the summary of this revision. (Show Details)Apr 19 2018, 11:56 AM
bgamari accepted this revision.Apr 19 2018, 1:49 PM

Looks good to me.


TcIface.tcPragExpr, which uses lintUnfolding also uses pprPanic, so I think this is fine.

This revision is now accepted and ready to land.Apr 19 2018, 1:49 PM
This revision was automatically updated to reflect the committed changes.