Introduce DerivingVia
authorRyan Scott <ryan.gl.scott@gmail.com>
Tue, 5 Jun 2018 01:20:02 +0000 (21:20 -0400)
committerBen Gamari <ben@smart-cactus.org>
Tue, 5 Jun 2018 02:37:19 +0000 (22:37 -0400)
commit8ed8b037fee9611b1c4ef49adb6cf50bbd929a27
treeff3907f0412085a78e694597c1bdba700740403f
parent85309a3cda367425cca727dfa45e5e6c63b47391
Introduce DerivingVia

This implements the `DerivingVia` proposal put forth in
https://github.com/ghc-proposals/ghc-proposals/pull/120.

This introduces the `DerivingVia` deriving strategy. This is a
generalization of `GeneralizedNewtypeDeriving` that permits the user
to specify the type to `coerce` from.

The major change in this patch is the introduction of the
`ViaStrategy` constructor to `DerivStrategy`, which takes a type
as a field. As a result, `DerivStrategy` is no longer a simple
enumeration type, but rather something that must be renamed and
typechecked. The process by which this is done is explained more
thoroughly in section 3 of this paper
( https://www.kosmikus.org/DerivingVia/deriving-via-paper.pdf ),
although I have inlined the relevant parts into Notes where possible.

There are some knock-on changes as well. I took the opportunity to
do some refactoring of code in `TcDeriv`, especially the
`mkNewTypeEqn` function, since it was bundling all of the logic for
(1) deriving instances for newtypes and
(2) `GeneralizedNewtypeDeriving`
into one huge broth. `DerivingVia` reuses much of part (2), so that
was factored out as much as possible.

Bumps the Haddock submodule.

Test Plan: ./validate

Reviewers: simonpj, bgamari, goldfire, alanz

Subscribers: alanz, goldfire, rwbarton, thomie, mpickering, carter

GHC Trac Issues: #15178

Differential Revision: https://phabricator.haskell.org/D4684
38 files changed:
compiler/basicTypes/BasicTypes.hs
compiler/deSugar/DsMeta.hs
compiler/hsSyn/Convert.hs
compiler/hsSyn/HsDecls.hs
compiler/hsSyn/HsExtension.hs
compiler/hsSyn/HsInstances.hs
compiler/main/DynFlags.hs
compiler/parser/ApiAnnotation.hs
compiler/parser/Lexer.x
compiler/parser/Parser.y
compiler/prelude/THNames.hs
compiler/rename/RnSource.hs
compiler/typecheck/TcDeriv.hs
compiler/typecheck/TcDerivUtils.hs
compiler/typecheck/TcHsType.hs
docs/users_guide/8.6.1-notes.rst
docs/users_guide/glasgow_exts.rst
libraries/ghc-boot-th/GHC/LanguageExtensions/Type.hs
libraries/template-haskell/Language/Haskell/TH/Lib.hs
libraries/template-haskell/Language/Haskell/TH/Lib/Internal.hs
libraries/template-haskell/Language/Haskell/TH/Ppr.hs
libraries/template-haskell/Language/Haskell/TH/Syntax.hs
libraries/template-haskell/changelog.md
testsuite/tests/deriving/should_compile/all.T
testsuite/tests/deriving/should_compile/deriving-via-compile.hs [new file with mode: 0644]
testsuite/tests/deriving/should_compile/deriving-via-standalone.hs [new file with mode: 0644]
testsuite/tests/deriving/should_fail/all.T
testsuite/tests/deriving/should_fail/deriving-via-fail.hs [new file with mode: 0644]
testsuite/tests/deriving/should_fail/deriving-via-fail.stderr [new file with mode: 0644]
testsuite/tests/deriving/should_fail/deriving-via-fail2.hs [new file with mode: 0644]
testsuite/tests/deriving/should_fail/deriving-via-fail2.stderr [new file with mode: 0644]
testsuite/tests/deriving/should_fail/deriving-via-fail3.hs [new file with mode: 0644]
testsuite/tests/deriving/should_fail/deriving-via-fail3.stderr [new file with mode: 0644]
testsuite/tests/deriving/should_fail/deriving-via-fail4.hs [new file with mode: 0644]
testsuite/tests/deriving/should_fail/deriving-via-fail4.stderr [new file with mode: 0644]
testsuite/tests/driver/T4437.hs
testsuite/tests/ghc-api/annotations/T10312.stdout
utils/haddock