summaryrefslogtreecommitdiff
path: root/compiler/GHC/Tc/Deriv
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2021-11-08 19:11:58 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-11-09 19:55:07 -0500
commitbdd7b2be6e61f24d467e7b4881b7309d524e2034 (patch)
treec126bbff4ca33303908eb9174b56642bd916eb29 /compiler/GHC/Tc/Deriv
parent983a99f0730b230367a327c5ef28cb5ec5dfedc2 (diff)
downloadhaskell-bdd7b2be6e61f24d467e7b4881b7309d524e2034.tar.gz
Flesh out Note [The stupid context] and reference it
`Note [The stupid context]` in `GHC.Core.DataCon` talks about stupid contexts from `DatatypeContexts`, but prior to this commit, it was rather outdated. This commit spruces it up and references it from places where it is relevant.
Diffstat (limited to 'compiler/GHC/Tc/Deriv')
-rw-r--r--compiler/GHC/Tc/Deriv/Generics.hs1
-rw-r--r--compiler/GHC/Tc/Deriv/Infer.hs10
-rw-r--r--compiler/GHC/Tc/Deriv/Utils.hs3
3 files changed, 7 insertions, 7 deletions
diff --git a/compiler/GHC/Tc/Deriv/Generics.hs b/compiler/GHC/Tc/Deriv/Generics.hs
index 3d71c25b7d..eee7496b6f 100644
--- a/compiler/GHC/Tc/Deriv/Generics.hs
+++ b/compiler/GHC/Tc/Deriv/Generics.hs
@@ -119,6 +119,7 @@ following constraints are satisfied.
alpha-renaming).
(b) D cannot have a "stupid context".
+ See Note [The stupid context] in GHC.Core.DataCon.
(c) The right-hand side of D cannot include existential types, universally
quantified types, or "exotic" unlifted types. An exotic unlifted type
diff --git a/compiler/GHC/Tc/Deriv/Infer.hs b/compiler/GHC/Tc/Deriv/Infer.hs
index 7276bfde83..2466931219 100644
--- a/compiler/GHC/Tc/Deriv/Infer.hs
+++ b/compiler/GHC/Tc/Deriv/Infer.hs
@@ -194,13 +194,9 @@ inferConstraintsStock (DerivInstTys { dit_cls_tys = cls_tys
]
-- Stupid constraints from DatatypeContexts. Note that we
-- must gather these constraints from the data constructors,
- -- not from the parent type constructor, as the latter can
- -- lead to redundant constraints in some cases. For example,
- -- the derived Eq instance for:
- --
- -- data Show a => T a = MkT deriving Eq
- --
- -- Should not have Show in the instance context (#20501).
+ -- not from the parent type constructor, as the latter could
+ -- lead to redundant constraints due to thinning.
+ -- See Note [The stupid context] in GHC.Core.DataCon.
stupid_theta =
[ substTyWith (dataConUnivTyVars data_con)
all_rep_tc_args
diff --git a/compiler/GHC/Tc/Deriv/Utils.hs b/compiler/GHC/Tc/Deriv/Utils.hs
index d97db525eb..dfd1b557a7 100644
--- a/compiler/GHC/Tc/Deriv/Utils.hs
+++ b/compiler/GHC/Tc/Deriv/Utils.hs
@@ -930,6 +930,9 @@ cond_functorOK allowFunctions allowExQuantifiedLastTyVar _ _ rep_tc
| null tc_tvs
= NotValid $ DerivErrMustHaveSomeParameters rep_tc
+ -- We can't handle stupid contexts that mention the last type argument,
+ -- so error out if we encounter one.
+ -- See Note [The stupid context] in GHC.Core.DataCon.
| not (null bad_stupid_theta)
= NotValid $ DerivErrMustNotHaveClassContext rep_tc bad_stupid_theta