[commit: ghc] ghc-8.0: Improve typechecking of instance defaults (54b887b)

git at git.haskell.org git at git.haskell.org
Thu Sep 15 17:50:40 UTC 2016


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

On branch  : ghc-8.0
Link       : http://ghc.haskell.org/trac/ghc/changeset/54b887b5abf6ee723c6ac6aaa2d2f4c14cf74060/ghc

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

commit 54b887b5abf6ee723c6ac6aaa2d2f4c14cf74060
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Thu Jun 23 14:51:22 2016 +0100

    Improve typechecking of instance defaults
    
    In an instance declaration when you don't specify the code for a
    method, GHC fills in from the default binding in the class.
    The type of the default method can legitmiately be ambiguous ---
    see Note [Default methods in instances] in TcInstDcls --- so
    typechecking it can be tricky.
    
    Trac #12220 showed that although we were dealing with that ambiguity
    for /vanilla/ default methods, we were not doing so for /generic/
    default methods.  Moreover we were dealing with it clumsily, by
    generating post-typechecked code.
    
    This patch fixes the bug AND deletes code!  We now use the same code
    path for both vanilla and generic default methods; and generate
    /pre-typechecked/ code in both cases.  The key trick is that we can use
    Visible Type Application to deal with the ambiguity, which wasn't
    possible before.  Hooray.
    
    There is a small hit to performance in compiler/perf/T1969 which
    consists of nothing BUT instance declarations with several default
    methods to fill, which we now have to typecheck. The actual hit is
    from 724 -> 756 or 4% in that extreme example.  Real world programs
    have vastly fewer instance decls.
    
    (cherry picked from commit d2958bd08a049b61941f078e51809c7e63bc3354)


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

54b887b5abf6ee723c6ac6aaa2d2f4c14cf74060
 compiler/coreSyn/TrieMap.hs                        |   3 +-
 compiler/iface/IfaceType.hs                        |   3 -
 compiler/typecheck/TcClassDcl.hs                   |  19 +-
 compiler/typecheck/TcInstDcls.hs                   | 136 +++--
 testsuite/tests/generics/GShow/GShow.hs            |   3 +-
 testsuite/tests/generics/GenDerivOutput.stderr     |   6 +
 .../tests/generics/T10604/T10604_deriving.stderr   | 549 +++++++++++++++++++++
 testsuite/tests/generics/T12220.hs                 |  37 ++
 testsuite/tests/generics/all.T                     |   1 +
 testsuite/tests/perf/compiler/all.T                |   3 +-
 10 files changed, 669 insertions(+), 91 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 54b887b5abf6ee723c6ac6aaa2d2f4c14cf74060


More information about the ghc-commits mailing list