diff options
Diffstat (limited to 'compiler/GHC/Tc')
-rw-r--r-- | compiler/GHC/Tc/Deriv/Generics.hs | 1 | ||||
-rw-r--r-- | compiler/GHC/Tc/Deriv/Infer.hs | 10 | ||||
-rw-r--r-- | compiler/GHC/Tc/Deriv/Utils.hs | 3 | ||||
-rw-r--r-- | compiler/GHC/Tc/Gen/Expr.hs | 3 | ||||
-rw-r--r-- | compiler/GHC/Tc/Gen/Head.hs | 4 | ||||
-rw-r--r-- | compiler/GHC/Tc/Gen/Pat.hs | 3 | ||||
-rw-r--r-- | compiler/GHC/Tc/TyCl.hs | 3 | ||||
-rw-r--r-- | compiler/GHC/Tc/TyCl/Build.hs | 2 | ||||
-rw-r--r-- | compiler/GHC/Tc/TyCl/Utils.hs | 3 |
9 files changed, 20 insertions, 12 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 diff --git a/compiler/GHC/Tc/Gen/Expr.hs b/compiler/GHC/Tc/Gen/Expr.hs index c9e9129251..6739e9a375 100644 --- a/compiler/GHC/Tc/Gen/Expr.hs +++ b/compiler/GHC/Tc/Gen/Expr.hs @@ -790,7 +790,8 @@ tcExpr expr@(RecordUpd { rupd_expr = record_expr, rupd_flds = Left rbnds }) res_ -- Typecheck the bindings ; rbinds' <- tcRecordUpd con1 con1_arg_tys' rbinds - -- STEP 6: Deal with the stupid theta + -- STEP 6: Deal with the stupid theta. + -- See Note [The stupid context] in GHC.Core.DataCon. ; let theta' = substThetaUnchecked scrut_subst (conLikeStupidTheta con1) ; instStupidTheta RecordUpdOrigin theta' diff --git a/compiler/GHC/Tc/Gen/Head.hs b/compiler/GHC/Tc/Gen/Head.hs index bfaba5efcc..821b118ded 100644 --- a/compiler/GHC/Tc/Gen/Head.hs +++ b/compiler/GHC/Tc/Gen/Head.hs @@ -905,7 +905,9 @@ being able to reconstruct the exact original program. Note [Instantiating stupid theta] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider a data type with a "stupid theta": +Consider a data type with a "stupid theta" (see +Note [The stupid context] in GHC.Core.DataCon): + data Ord a => T a = MkT (Maybe a) We want to generate an Ord constraint for every use of MkT; but diff --git a/compiler/GHC/Tc/Gen/Pat.hs b/compiler/GHC/Tc/Gen/Pat.hs index a09d77b6f7..a235c43236 100644 --- a/compiler/GHC/Tc/Gen/Pat.hs +++ b/compiler/GHC/Tc/Gen/Pat.hs @@ -1311,7 +1311,8 @@ tcConArg penv (arg_pat, Scaled arg_mult arg_ty) addDataConStupidTheta :: DataCon -> [TcType] -> TcM () -- Instantiate the "stupid theta" of the data con, and throw --- the constraints into the constraint set +-- the constraints into the constraint set. +-- See Note [The stupid context] in GHC.Core.DataCon. addDataConStupidTheta data_con inst_tys | null stupid_theta = return () | otherwise = instStupidTheta origin inst_theta diff --git a/compiler/GHC/Tc/TyCl.hs b/compiler/GHC/Tc/TyCl.hs index 5dfa4cec86..17b6e2fc43 100644 --- a/compiler/GHC/Tc/TyCl.hs +++ b/compiler/GHC/Tc/TyCl.hs @@ -3312,7 +3312,8 @@ dataDeclChecks tc_name new_or_data mctxt cons ; let gadt_syntax = consUseGadtSyntax cons ; checkTc (gadtSyntax_ok || not gadt_syntax) (badGadtDecl tc_name) - -- Check that the stupid theta is empty for a GADT-style declaration + -- Check that the stupid theta is empty for a GADT-style declaration. + -- See Note [The stupid context] in GHC.Core.DataCon. ; checkTc (null stupid_theta || not gadt_syntax) (badStupidTheta tc_name) -- Check that a newtype has exactly one constructor diff --git a/compiler/GHC/Tc/TyCl/Build.hs b/compiler/GHC/Tc/TyCl/Build.hs index 7206fe70bd..4b44069950 100644 --- a/compiler/GHC/Tc/TyCl/Build.hs +++ b/compiler/GHC/Tc/TyCl/Build.hs @@ -192,6 +192,8 @@ buildDataCon fam_envs src_name declared_infix prom_info src_bangs impl_bangs -- the type variables mentioned in the arg_tys -- ToDo: Or functionally dependent on? -- This whole stupid theta thing is, well, stupid. +-- +-- See Note [The stupid context] in GHC.Core.DataCon. mkDataConStupidTheta :: TyCon -> [Type] -> [TyVar] -> [PredType] mkDataConStupidTheta tycon arg_tys univ_tvs | null stupid_theta = [] -- The common case diff --git a/compiler/GHC/Tc/TyCl/Utils.hs b/compiler/GHC/Tc/TyCl/Utils.hs index 1ce9ef8f82..347a7e57ff 100644 --- a/compiler/GHC/Tc/TyCl/Utils.hs +++ b/compiler/GHC/Tc/TyCl/Utils.hs @@ -906,7 +906,8 @@ mkOneRecordSelector all_cons idDetails fl has_sel || has_sel == NoFieldSelectors sel_ty | is_naughty = unitTy -- See Note [Naughty record selectors] | otherwise = mkForAllTys (tyVarSpecToBinders data_tvbs) $ - mkPhiTy (conLikeStupidTheta con1) $ -- Urgh! + -- Urgh! See Note [The stupid context] in GHC.Core.DataCon + mkPhiTy (conLikeStupidTheta con1) $ -- req_theta is empty for normal DataCon mkPhiTy req_theta $ mkVisFunTyMany data_ty $ |