[commit: ghc] master: Refactor TcDeriv and TcGenDeriv (4a03012)
git at git.haskell.org
git at git.haskell.org
Thu Oct 6 13:17:43 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : master
Link : http://ghc.haskell.org/trac/ghc/changeset/4a03012aeb4cb6685221b30aea2b1a78145d902b/ghc
>---------------------------------------------------------------
commit 4a03012aeb4cb6685221b30aea2b1a78145d902b
Author: Ryan Scott <ryan.gl.scott at gmail.com>
Date: Thu Oct 6 09:14:49 2016 -0400
Refactor TcDeriv and TcGenDeriv
Summary:
Keeping a promise I made to Simon to clean up these modules.
This change splits up the massive `TcDeriv` and `TcGenDeriv` modules into
somewhat more manageable pieces. The new modules are:
* `TcGenFunctor`: This contains the deriving machinery for `Functor`,
`Foldable`, and `Traversable` (which all use the same underlying algorithm).
* `TcDerivInfer`: This is the new home for `inferConstraints`,
`simplifyInstanceContexts`, and related functions, whose role is to come up
with the derived instance context and subsequently simplify it.
* `TcDerivUtils`: This is a grab-bag module that contains several
error-checking utilities originally in `TcDeriv`, as well as some functions
that `TcDeriv` and `TcDerivInfer` both need.
The end result is that `TcDeriv` is now less than 1,600 SLOC (originally 2,686
SLOC), and `TcGenDeriv` is now about 2,000 SLOC (originally 2,964).
In addition, this also implements a couple of tiny refactorings:
* I transformed `type Condition = (DynFlags, TyCon) -> Validity` into
`type Condition = DynFlags -> TyCon -> Validity`
* I killed the `DerivSpecGeneric` constructor for `DerivSpecMechanism`, and
merged its functionality into `DerivSpecStock`. In addition,
`hasStockDeriving` now contains key-value pairs for `Generic` and `Generic1`,
so they're no longer treated as an awkward special case in `TcDeriv`.
Test Plan: ./validate
Reviewers: simonpj, austin, bgamari
Reviewed By: simonpj
Subscribers: thomie, mpickering
Differential Revision: https://phabricator.haskell.org/D2568
>---------------------------------------------------------------
4a03012aeb4cb6685221b30aea2b1a78145d902b
compiler/ghc.cabal.in | 3 +
compiler/typecheck/TcDeriv.hs | 1168 +----------------------------------
compiler/typecheck/TcDerivInfer.hs | 653 ++++++++++++++++++++
compiler/typecheck/TcDerivUtils.hs | 610 ++++++++++++++++++
compiler/typecheck/TcGenDeriv.hs | 923 +--------------------------
compiler/typecheck/TcGenFunctor.hs | 875 ++++++++++++++++++++++++++
compiler/typecheck/TcGenGenerics.hs | 1 +
7 files changed, 2184 insertions(+), 2049 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 4a03012aeb4cb6685221b30aea2b1a78145d902b
More information about the ghc-commits
mailing list