Sequester deriving-related validity check into cond_stdOK
authorRyan Scott <ryan.gl.scott@gmail.com>
Thu, 1 Feb 2018 02:36:51 +0000 (21:36 -0500)
committerBen Gamari <ben@smart-cactus.org>
Thu, 1 Feb 2018 04:29:30 +0000 (23:29 -0500)
commit1a911f217a18c8c0362ab2bf2b6ec7f7da015622
tree3fc5a47c58ed231880286fa2e0fd351155036124
parentbe84823b956f0aa09c58d94d1901f2dff13546b4
Sequester deriving-related validity check into cond_stdOK

Currently, any standalone-derived instance must satisfy the
property that the tycon of the data type having an instance being
derived for it must be either a normal ADT tycon or a data family
tycon. But there are several other primitive tycons—such as `(->)`,
`Int#`, and others—which cannot have standalone-derived instances
(via the `anyclass` strategy) as a result of this check! See
https://ghc.haskell.org/trac/ghc/ticket/13154#comment:8 for an
example of where this overly conservative restriction bites.

Really, this validity check only makes sense in the context of
`stock` deriving, where we need the property that the tycon is that
of a normal ADT or a data family in order to inspect its data
constructors. Other deriving strategies don't require this validity
check, so the most sensible way to fix this error is to move the
logic of this check into `cond_stdOK`, which is specific to
`stock` deriving.

This makes progress towards fixing (but does not entirely fix)

Test Plan: make test TEST=T13154a

Reviewers: bgamari

Reviewed By: bgamari

Subscribers: rwbarton, thomie, carter

GHC Trac Issues: #13154

Differential Revision: https://phabricator.haskell.org/D4337
compiler/typecheck/TcDeriv.hs
compiler/typecheck/TcDerivUtils.hs
testsuite/tests/deriving/should_compile/T13154a.hs [new file with mode: 0644]
testsuite/tests/deriving/should_compile/all.T