deriving: infer DatatypeContexts from data constructors, not type constructor
Previously, derived instances that use deriving
clauses would infer
DatatypeContexts
by using tyConStupidTheta
. But this sometimes causes
redundant constraints to be included in the derived instance contexts, as the
constraints that appear in the tyConStupidTheta
may not actually appear in
the types of the data constructors (i.e., the dataConStupidTheta
s). For
instance, in data Show a => T a = MkT deriving Eq
, the type of MkT
does
not require Show
, so the derived Eq
instance should not require Show
either. This patch makes it so with some small tweaks to
inferConstraintsStock
.
Fixes #20501 (closed).