[commit: ghc] master: Remove superfluous code when deriving Foldable/Traversable (a82956d)

git at git.haskell.org git at git.haskell.org
Wed Feb 17 20:02:52 UTC 2016


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

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

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

commit a82956df5b34175410e0feb9e2febe7d39b60b49
Author: RyanGlScott <ryan.gl.scott at gmail.com>
Date:   Wed Feb 17 12:06:17 2016 +0100

    Remove superfluous code when deriving Foldable/Traversable
    
    Currently, `-XDeriveFoldable` and `-XDeriveTraversable` generate
    unnecessary `mempty` and `pure` expressions when it traverses of an
    argument of a constructor whose type does not mention the last type
    parameter. Not only is this inefficient, but it prevents `Traversable`
    from being derivable for datatypes with unlifted arguments (see
    Trac #11174).
    
    The solution to this problem is to adopt a slight change to the
    algorithms for `-XDeriveFoldable` and `-XDeriveTraversable`, which is
    described in [this wiki
    page](https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/DeriveFu
    nctor#Proposal:alternativestrategyforderivingFoldableandTraversable).
    The wiki page also describes why we don't apply the same changes to the
    algorithm for `-XDeriveFunctor`.
    
    This is techincally a breaking change for users of `-XDeriveFoldable`
    and `-XDeriveTraversable`, since if someone was using a law-breaking
    `Monoid` instance with a derived `Foldable` instance (i.e., one where `x
    <> mempty` does not equal `x`) or a law-breaking `Applicative` instance
    with a derived `Traversable` instance, then the new generated code could
    result in different behavior. I suspect the number of scenarios like
    this is very small, and the onus really should be on those users to fix
    up their `Monoid`/`Applicative` instances.
    
    Fixes #11174.
    
    Test Plan: ./validate
    
    Reviewers: hvr, simonpj, austin, bgamari
    
    Reviewed By: simonpj, bgamari
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1908
    
    GHC Trac Issues: #11174


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

a82956df5b34175410e0feb9e2febe7d39b60b49
 compiler/typecheck/TcGenDeriv.hs                  | 478 ++++++++++++++++++----
 compiler/utils/Util.hs                            |  19 +-
 docs/users_guide/8.0.1-notes.rst                  |   5 +-
 docs/users_guide/glasgow_exts.rst                 |  24 +-
 testsuite/tests/deriving/should_compile/T11174.hs |  14 +
 testsuite/tests/deriving/should_compile/all.T     |   1 +
 6 files changed, 445 insertions(+), 96 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 a82956df5b34175410e0feb9e2febe7d39b60b49


More information about the ghc-commits mailing list