Commit 4a03012a authored by Ryan Scott's avatar Ryan Scott

Refactor TcDeriv and TcGenDeriv

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:
parent 58ecdf83
...@@ -405,10 +405,13 @@ Library ...@@ -405,10 +405,13 @@ Library
TcClassDcl TcClassDcl
TcDefaults TcDefaults
TcDeriv TcDeriv
TcEnv TcEnv
TcExpr TcExpr
TcForeign TcForeign
TcGenDeriv TcGenDeriv
TcGenGenerics TcGenGenerics
TcHsSyn TcHsSyn
TcHsType TcHsType
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -17,6 +17,7 @@ import HsSyn ...@@ -17,6 +17,7 @@ import HsSyn
import Type import Type
import TcType import TcType
import TcGenDeriv import TcGenDeriv
import TcGenFunctor
import DataCon import DataCon
import TyCon import TyCon
import FamInstEnv ( FamInst, FamFlavor(..), mkSingleCoAxiom ) import FamInstEnv ( FamInst, FamFlavor(..), mkSingleCoAxiom )
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment