Generalize kind of the (->) tycon
authorBen Gamari <ben@smart-cactus.org>
Thu, 2 Feb 2017 01:25:33 +0000 (20:25 -0500)
committerBen Gamari <ben@smart-cactus.org>
Sat, 18 Feb 2017 05:07:03 +0000 (00:07 -0500)
commitb207b536ded40156f9adb168565ca78e1eef2c74
treec7e074201603ac54abb60856010ef82478a2113d
parentefeaf9e436109cb35b491e08b5407c0598108186
Generalize kind of the (->) tycon

This is generalizes the kind of `(->)`, as discussed in #11714.

This involves a few things,

 * Generalizing the kind of `funTyCon`, adding two new `RuntimeRep`
binders,
  ```lang=haskell
(->) :: forall (r1 :: RuntimeRep) (r2 :: RuntimeRep)
               (a :: TYPE r1) (b :: TYPE r2).
        a -> b -> *
  ```

 * Unsaturated applications of `(->)` are expressed as explicit
`TyConApp`s

 * Saturated applications of `(->)` are expressed as `FunTy` as they are
currently

 * Saturated applications of `(->)` are expressed by a new `FunCo`
constructor in coercions

 * `splitTyConApp` needs to ensure that `FunTy`s are split to a
`TyConApp`
   of `(->)` with the appropriate `RuntimeRep` arguments

 * Teach CoreLint to check that all saturated applications of `(->)` are
represented with `FunTy`

At the moment I assume that `Constraint ~ *`, which is an annoying
source of complexity. This will
be simplified once D3023 is resolved.

Also, this introduces two known regressions,

`tcfail181`, `T10403`
=====================
Only shows the instance,

    instance Monad ((->) r) -- Defined in ‘GHC.Base’

in its error message when -fprint-potential-instances is used. This is
because its instance head now mentions 'LiftedRep which is not in scope.
I'm not entirely sure of the right way to fix this so I'm just accepting
the new output for now.

T5963 (Typeable)
================

T5963 is now broken since Data.Typeable.Internals.mkFunTy computes its
fingerprint without the RuntimeRep variables that (->) expects. This
will be fixed with the merge of D2010.

Haddock performance
===================

The `haddock.base` and `haddock.Cabal` tests regress in allocations by
about 20%. This certainly hurts, but it's also not entirely unexpected:
the size of every function type grows with this patch and Haddock has a
lot of functions in its heap.
31 files changed:
compiler/coreSyn/CoreFVs.hs
compiler/coreSyn/CoreLint.hs
compiler/coreSyn/CoreSubst.hs
compiler/coreSyn/TrieMap.hs
compiler/iface/ToIface.hs
compiler/prelude/TysPrim.hs
compiler/specialise/Rules.hs
compiler/typecheck/TcCanonical.hs
compiler/typecheck/TcSMonad.hs
compiler/typecheck/TcTyDecls.hs
compiler/typecheck/TcType.hs
compiler/typecheck/TcUnify.hs
compiler/typecheck/TcValidity.hs
compiler/types/Coercion.hs
compiler/types/Coercion.hs-boot
compiler/types/FamInstEnv.hs
compiler/types/OptCoercion.hs
compiler/types/TyCoRep.hs
compiler/types/TyCon.hs
compiler/types/Type.hs
compiler/types/Unify.hs
libraries/base/tests/all.T
testsuite/tests/ghci/scripts/T8535.stdout
testsuite/tests/ghci/scripts/ghci020.stdout
testsuite/tests/ghci/should_run/T10145.stdout
testsuite/tests/partial-sigs/should_compile/T10403.stderr
testsuite/tests/perf/compiler/all.T
testsuite/tests/perf/haddock/all.T
testsuite/tests/typecheck/should_compile/all.T
testsuite/tests/typecheck/should_compile/tc167.stderr [deleted file]
testsuite/tests/typecheck/should_fail/tcfail181.stderr