Eliminate so-called "silent superclass parameters"
authorSimon Peyton Jones <simonpj@microsoft.com>
Tue, 23 Dec 2014 15:39:50 +0000 (15:39 +0000)
committerSimon Peyton Jones <simonpj@microsoft.com>
Tue, 23 Dec 2014 16:01:23 +0000 (16:01 +0000)
commita6f0f5ab45b2643b561e0a0a54a4f14745ab2152
treeb9b303cd971dc82bf01849de881eff87e1d48ed3
parent625dd7b646d37177731cad20abd4026f2725472f
Eliminate so-called "silent superclass parameters"

The purpose of silent superclass parameters was to solve the
awkward problem of superclass dictinaries being bound to bottom.
See THE PROBLEM in Note [Recursive superclasses] in TcInstDcls

Although the silent-superclass idea worked,

  * It had non-local consequences, and had effects even in Haddock,
    where we had to discard silent parameters before displaying
    instance declarations

  * It had unexpected peformance costs, shown up by Trac #3064 and its
    test case.  In monad-transformer code, when constructing a Monad
    dictionary you had to pass an Applicative dictionary; and to
    construct that you neede a Functor dictionary. Yet these extra
    dictionaries were often never used.  (All this got much worse when
    we added Applicative as a superclass of Monad.) Test T3064
    compiled *far* faster after silent superclasses were eliminated.

  * It introduced new bugs.  For example SilentParametersOverlapping,
    T5051, and T7862, all failed to compile because of instance overlap
    directly because of the silent-superclass trick.

So this patch takes a new approach, which I worked out with Dimitrios
in the closing hours before Christmas.  It is described in detail
in THE PROBLEM in Note [Recursive superclasses] in TcInstDcls.

Seems to work great!

Quite a bit of knock-on effect

 * The main implementation work is in tcSuperClasses in TcInstDcls
   Everything else is fall-out

 * IdInfo.DFunId no longer needs its n-silent argument
   * Ditto IDFunId in IfaceSyn
   * Hence interface file format changes

 * Now that DFunIds do not have silent superclass parameters, printing
   out instance declarations is simpler. There is tiny knock-on effect
   in Haddock, so that submodule is updated

 * I realised that when computing the "size of a dictionary type"
   in TcValidity.sizePred, we should be rather conservative about
   type functions, which can arbitrarily increase the size of a type.
   Hence the new datatype TypeSize, which has a TSBig constructor for
   "arbitrarily big".

 * instDFunType moves from TcSMonad to Inst

 * Interestingly, CmmNode and CmmExpr both now need a non-silent
   (Ord r) in a couple of instance declarations. These were previously
   silent but must now be explicit.

 * Quite a bit of wibbling in error messages
44 files changed:
compiler/basicTypes/Id.hs
compiler/basicTypes/IdInfo.hs
compiler/basicTypes/MkId.hs
compiler/basicTypes/OccName.hs
compiler/cmm/CmmExpr.hs
compiler/cmm/CmmNode.hs
compiler/coreSyn/CoreUtils.hs
compiler/deSugar/DsBinds.hs
compiler/iface/IfaceSyn.hs
compiler/iface/MkIface.hs
compiler/iface/TcIface.hs
compiler/typecheck/Inst.hs
compiler/typecheck/TcInstDcls.hs
compiler/typecheck/TcInteract.hs
compiler/typecheck/TcMType.hs
compiler/typecheck/TcSMonad.hs
compiler/typecheck/TcSplice.hs
compiler/typecheck/TcUnify.hs
compiler/typecheck/TcValidity.hs
compiler/types/InstEnv.hs
testsuite/tests/deriving/should_fail/drvfail002.stderr
testsuite/tests/indexed-types/should_compile/InstContextNorm.hs
testsuite/tests/indexed-types/should_fail/T7862.hs
testsuite/tests/indexed-types/should_fail/T7862.stderr
testsuite/tests/indexed-types/should_fail/all.T
testsuite/tests/perf/compiler/all.T
testsuite/tests/simplCore/should_compile/Simpl020_A.hs
testsuite/tests/simplCore/should_compile/T8848.stderr
testsuite/tests/simplCore/should_compile/all.T
testsuite/tests/simplCore/should_compile/simpl020.stderr
testsuite/tests/typecheck/should_fail/SilentParametersOverlapping.stderr [deleted file]
testsuite/tests/typecheck/should_fail/T5051.hs
testsuite/tests/typecheck/should_fail/T5051.stderr
testsuite/tests/typecheck/should_fail/T5691.stderr
testsuite/tests/typecheck/should_fail/T6161.hs
testsuite/tests/typecheck/should_fail/T6161.stderr
testsuite/tests/typecheck/should_fail/T8603.stderr
testsuite/tests/typecheck/should_fail/all.T
testsuite/tests/typecheck/should_fail/tcfail017.stderr
testsuite/tests/typecheck/should_fail/tcfail019.stderr
testsuite/tests/typecheck/should_fail/tcfail020.stderr
testsuite/tests/typecheck/should_fail/tcfail042.stderr
testsuite/tests/typecheck/should_fail/tcfail106.stderr
utils/haddock