[commit: ghc] master: Generate Typeable info at definition sites (bef2f03)

git at git.haskell.org git at git.haskell.org
Thu Oct 29 15:15:21 UTC 2015


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/bef2f03e4d56d88a7e9752a7afd6a0a35616da6c/ghc

>---------------------------------------------------------------

commit bef2f03e4d56d88a7e9752a7afd6a0a35616da6c
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Wed Aug 26 18:24:34 2015 +0200

    Generate Typeable info at definition sites
    
    This patch implements the idea floated in Trac #9858, namely that we
    should generate type-representation information at the data type
    declaration site, rather than when solving a Typeable constraint.
    
    However, this turned out quite a bit harder than I expected. I still
    think it's the right thing to do, and it's done now, but it was quite
    a struggle.
    
    See particularly
    
     * Note [Grand plan for Typeable] in TcTypeable (which is a new module)
     * Note [The overall promotion story] in DataCon (clarifies existing stuff)
    
    The most painful bit was that to generate Typeable instances (ie
    TyConRepName bindings) for every TyCon is tricky for types in ghc-prim
    etc:
    
     * We need to have enough data types around to *define* a TyCon
     * Many of these types are wired-in
    
    Also, to minimise the code generated for each data type, I wanted to
    generate pure data, not CAFs with unpackCString# stuff floating about.
    
    Performance
    ~~~~~~~~~~~
    Three perf/compiler tests start to allocate quite a bit more. This isn't
    surprising, because they all allocate zillions of data types, with
    practically no other code, esp. T1969
    
     * T3294:   GHC allocates 110% more (filed #11030 to track this)
     * T1969:   GHC allocates 30% more
     * T4801:   GHC allocates 14% more
     * T5321FD: GHC allocates 13% more
     * T783:    GHC allocates 12% more
     * T9675:   GHC allocates 12% more
     * T5642:   GHC allocates 10% more
     * T9961:   GHC allocates 6% more
    
     * T9203:   Program allocates 54% less
    
    I'm treating this as acceptable. The payoff comes in Typeable-heavy
    code.
    
    Remaining to do
    ~~~~~~~~~~~~~~~
    
     * I think that "TyCon" and "Module" are over-generic names to use for
       the runtime type representations used in GHC.Typeable. Better might be
       "TrTyCon" and "TrModule". But I have not yet done this
    
     * Add more info the the "TyCon" e.g. source location where it was
       defined
    
     * Use the new "Module" type to help with Trac Trac #10068
    
     * It would be possible to generate TyConRepName (ie Typeable
       instances) selectively rather than all the time. We'd need to persist
       the information in interface files. Lacking a motivating reason I have
       not done this, but it would not be difficult.
    
    Refactoring
    ~~~~~~~~~~~
    As is so often the case, I ended up refactoring more than I intended.
    In particular
    
     * In TyCon, a type *family* (whether type or data) is repesented by a
       FamilyTyCon
         * a algebraic data type (including data/newtype instances) is
           represented by AlgTyCon This wasn't true before; a data family
           was represented as an AlgTyCon. There are some corresponding
           changes in IfaceSyn.
    
         * Also get rid of the (unhelpfully named) tyConParent.
    
     * In TyCon define 'Promoted', isomorphic to Maybe, used when things are
       optionally promoted; and use it elsewhere in GHC.
    
     * Cleanup handling of knownKeyNames
    
     * Each TyCon, including promoted TyCons, contains its TyConRepName, if
       it has one. This is, in effect, the name of its Typeable instance.
    
    Requires update of the haddock submodule.
    
    Differential Revision: https://phabricator.haskell.org/D757


>---------------------------------------------------------------

bef2f03e4d56d88a7e9752a7afd6a0a35616da6c
 compiler/basicTypes/DataCon.hs                     | 222 ++++++++---
 compiler/basicTypes/OccName.hs                     |  19 +-
 compiler/basicTypes/Unique.hs                      |  51 ++-
 compiler/coreSyn/MkCore.hs                         |   8 +-
 compiler/deSugar/DsBinds.hs                        | 281 +++++++------
 compiler/deSugar/DsExpr.hs                         |  14 +-
 compiler/deSugar/DsUtils.hs                        |  14 +-
 compiler/ghc.cabal.in                              |   1 +
 compiler/hsSyn/HsUtils.hs                          |   6 +-
 compiler/iface/BuildTyCl.hs                        |  42 +-
 compiler/iface/IfaceSyn.hs                         | 101 +++--
 compiler/iface/MkIface.hs                          |  10 +-
 compiler/iface/TcIface.hs                          |  89 +++--
 compiler/main/HscMain.hs                           |  13 +-
 compiler/main/HscTypes.hs                          |  13 +-
 compiler/prelude/PrelInfo.hs                       | 111 +++---
 compiler/prelude/PrelNames.hs                      |  88 +++--
 compiler/prelude/THNames.hs                        | 105 +++--
 compiler/prelude/TysPrim.hs                        |  38 +-
 compiler/prelude/TysWiredIn.hs                     |  55 ++-
 compiler/simplCore/FloatIn.hs                      |   4 +-
 compiler/typecheck/TcBinds.hs                      |  35 +-
 compiler/typecheck/TcEnv.hs                        |   5 +-
 compiler/typecheck/TcEvidence.hs                   |  69 ++--
 compiler/typecheck/TcGenGenerics.hs                |  41 +-
 compiler/typecheck/TcHsSyn.hs                      |  27 +-
 compiler/typecheck/TcHsType.hs                     |   8 +-
 compiler/typecheck/TcInstDcls.hs                   |  19 +-
 compiler/typecheck/TcInteract.hs                   | 440 ++++++++++++---------
 compiler/typecheck/TcPatSyn.hs                     |   2 +-
 compiler/typecheck/TcRnDriver.hs                   |  40 +-
 compiler/typecheck/TcRnMonad.hs                    |   2 +-
 compiler/typecheck/TcRnTypes.hs                    |   7 +-
 compiler/typecheck/TcTyClsDecls.hs                 |  18 +-
 compiler/typecheck/TcTyDecls.hs                    | 166 +++-----
 compiler/typecheck/TcTypeNats.hs                   |  12 +-
 compiler/typecheck/TcTypeable.hs                   | 206 ++++++++++
 compiler/types/TyCon.hs                            | 412 ++++++++++---------
 compiler/types/Type.hs                             |   9 +
 compiler/utils/Binary.hs                           |  11 +-
 compiler/vectorise/Vectorise/Generic/PData.hs      |   4 +-
 compiler/vectorise/Vectorise/Type/Env.hs           |   4 +-
 compiler/vectorise/Vectorise/Type/TyConDecl.hs     |   7 +-
 ghc/InteractiveUI.hs                               |   4 +-
 libraries/base/Data/Typeable.hs                    |   3 +-
 libraries/base/Data/Typeable/Internal.hs           | 330 ++++++++++------
 libraries/base/GHC/Show.hs                         |  10 +
 libraries/base/GHC/Stack/Types.hs                  |  13 +
 libraries/ghc-prim/GHC/Classes.hs                  |  36 +-
 libraries/ghc-prim/GHC/Magic.hs                    |   2 +
 libraries/ghc-prim/GHC/Tuple.hs                    |   3 +
 libraries/ghc-prim/GHC/Types.hs                    |  60 ++-
 testsuite/tests/codeGen/should_run/cgrun057.stderr |   2 +-
 .../tests/deSugar/should_compile/T2431.stderr      |  29 +-
 testsuite/tests/deriving/should_fail/T9687.stderr  |   4 +-
 testsuite/tests/ghci.debugger/scripts/T2740.stdout |   2 +-
 .../tests/ghci.debugger/scripts/break006.stderr    |   4 +-
 .../tests/ghci.debugger/scripts/break009.stdout    |   4 +-
 .../tests/ghci.debugger/scripts/break010.stdout    |   4 +-
 .../tests/ghci.debugger/scripts/break011.stdout    |   8 +-
 .../tests/ghci.debugger/scripts/break012.stdout    |  16 +-
 .../tests/ghci.debugger/scripts/break018.stdout    |   4 +-
 .../ghci.debugger/scripts/break022/break022.stdout |   2 +-
 .../tests/ghci.debugger/scripts/break028.stdout    |   6 +-
 .../tests/ghci.debugger/scripts/print018.stdout    |   6 +-
 .../tests/ghci.debugger/scripts/print019.stderr    |   4 +-
 .../tests/ghci.debugger/scripts/print031.stdout    |   2 +-
 testsuite/tests/ghci/scripts/T4175.stdout          |   4 +-
 testsuite/tests/ghci/scripts/T5417.stdout          |   2 -
 testsuite/tests/ghci/scripts/T8674.stdout          |   4 +-
 .../indexed-types/should_compile/T3017.stderr      |   0
 .../tests/numeric/should_compile/T7116.stdout      |  29 +-
 .../should_fail/overloadedlistsfail01.stderr       |   4 +-
 .../should_compile/DataFamilyInstanceLHS.stderr    |   2 -
 testsuite/tests/perf/compiler/all.T                |  52 ++-
 testsuite/tests/perf/should_run/all.T              |   3 +-
 testsuite/tests/polykinds/T8132.stderr             |   4 +-
 testsuite/tests/quasiquotation/T7918.stdout        |   3 +
 testsuite/tests/roles/should_compile/Roles1.stderr |  61 +++
 .../tests/roles/should_compile/Roles13.stderr      |  53 ++-
 .../tests/roles/should_compile/Roles14.stderr      |   7 +
 testsuite/tests/roles/should_compile/Roles2.stderr |  13 +
 testsuite/tests/roles/should_compile/Roles3.stderr |  25 ++
 testsuite/tests/roles/should_compile/Roles4.stderr |  13 +
 testsuite/tests/roles/should_compile/T8958.stderr  |   9 +-
 .../tests/simplCore/should_compile/T3234.stderr    |   4 +-
 .../tests/simplCore/should_compile/T3717.stderr    |  29 +-
 .../tests/simplCore/should_compile/T3772.stdout    |  29 +-
 .../tests/simplCore/should_compile/T4908.stderr    |  29 +-
 .../tests/simplCore/should_compile/T4930.stderr    |  29 +-
 .../tests/simplCore/should_compile/T7360.stderr    |  47 ++-
 .../tests/simplCore/should_compile/T8274.stdout    |   8 +
 .../tests/simplCore/should_compile/T9400.stderr    |  17 +-
 .../tests/simplCore/should_compile/rule2.stderr    |   3 +-
 .../simplCore/should_compile/spec-inline.stderr    |  29 +-
 .../tests/stranal/should_compile/T10694.stdout     |   3 +
 .../stranal/sigs/BottomFromInnerLambda.stderr      |   1 +
 testsuite/tests/stranal/sigs/DmdAnalGADTs.stderr   |   2 +
 testsuite/tests/stranal/sigs/HyperStrUse.stderr    |   1 +
 testsuite/tests/stranal/sigs/StrAnalExample.stderr |   1 +
 testsuite/tests/stranal/sigs/T8569.stderr          |   2 +
 testsuite/tests/stranal/sigs/T8598.stderr          |   1 +
 testsuite/tests/stranal/sigs/UnsatFun.stderr       |   1 +
 testsuite/tests/th/TH_Roles2.stderr                |   8 +
 .../tests/typecheck/should_compile/holes2.stderr   |   6 +-
 testsuite/tests/typecheck/should_fail/T5095.stderr |   2 +-
 .../tests/typecheck/should_fail/tcfail072.stderr   |   4 +-
 .../tests/typecheck/should_fail/tcfail133.stderr   |   7 +-
 utils/haddock                                      |   2 +-
 109 files changed, 2609 insertions(+), 1331 deletions(-)

Diff suppressed because of size. To see it, use:

    git diff-tree --root --patch-with-stat --no-color --find-copies-harder --ignore-space-at-eol --cc bef2f03e4d56d88a7e9752a7afd6a0a35616da6c


More information about the ghc-commits mailing list