[commit: ghc] master: Refactor DeriveAnyClass's instance context inference (639e702)
git at git.haskell.org
git at git.haskell.org
Fri Feb 10 21:24:13 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/639e702b6129f501c539b158b982ed8489e3d09c/ghc
>---------------------------------------------------------------
commit 639e702b6129f501c539b158b982ed8489e3d09c
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date: Fri Feb 10 16:12:46 2017 -0500
Refactor DeriveAnyClass's instance context inference
Summary:
Currently, `DeriveAnyClass` has two glaring flaws:
* It only works on classes whose argument is of kind `*` or `* -> *` (#9821).
* The way it infers constraints makes no sense. It basically co-opts the
algorithms used to infer contexts for `Eq` (for `*`-kinded arguments) or
`Functor` (for `(* -> *)`-kinded arguments). This tends to produce overly
constrained instances, which in extreme cases can lead to legitimate things
failing to typecheck (#12594). Or even worse, it can trigger GHC panics
(#12144 and #12423).
This completely reworks the way `DeriveAnyClass` infers constraints to fix
these two issues. It now uses the type signatures of the derived class's
methods to infer constraints (and to simplify them). A high-level description
of how this works is included in the GHC users' guide, and more technical notes
on what is going on can be found as comments (and a Note) in `TcDerivInfer`.
Fixes #9821, #12144, #12423, #12594.
Test Plan: ./validate
Reviewers: dfeuer, goldfire, simonpj, austin, bgamari
Subscribers: dfeuer, thomie
Differential Revision: https://phabricator.haskell.org/D2961
>---------------------------------------------------------------
639e702b6129f501c539b158b982ed8489e3d09c
compiler/typecheck/TcDeriv.hs | 50 +--
compiler/typecheck/TcDerivInfer.hs | 357 +++++++++++++++++----
compiler/typecheck/TcDerivUtils.hs | 92 ++++--
compiler/typecheck/TcSimplify.hs | 3 +-
compiler/typecheck/TcType.hs | 6 +-
docs/users_guide/8.2.1-notes.rst | 11 +
docs/users_guide/glasgow_exts.rst | 72 ++++-
.../tests/deriving/should_compile/T12144_1.hs | 6 +
.../tests/deriving/should_compile/T12144_2.hs | 15 +
testsuite/tests/deriving/should_compile/T12423.hs | 10 +
testsuite/tests/deriving/should_compile/T12594.hs | 41 +++
.../{should_fail => should_compile}/T9968a.hs | 0
.../tests/deriving/should_compile/T9968a.stderr | 5 +
testsuite/tests/deriving/should_compile/all.T | 7 +-
.../tests/deriving/should_fail/T10598_fail1.stderr | 6 -
testsuite/tests/deriving/should_fail/T9968a.stderr | 6 -
testsuite/tests/deriving/should_fail/all.T | 1 -
.../tests/deriving/should_fail/drvfail004.stderr | 17 +-
.../tests/deriving/should_fail/drvfail012.stderr | 17 +-
.../tests/typecheck/should_fail/tcfail046.stderr | 31 +-
.../tests/typecheck/should_fail/tcfail169.stderr | 17 +-
21 files changed, 579 insertions(+), 191 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 639e702b6129f501c539b158b982ed8489e3d09c
More information about the ghc-commits
mailing list