X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Ftypecheck%2FTcTyClsDecls.lhs;h=95166861ec668c6e0a09546ffc9f5e52a645de73;hb=6a4854eaa266d994ebd0d471614a52b43dd329d9;hp=6e4e0d6763d7cc9af80af6343644ec34ff77eeb6;hpb=cae34044d89a87bd3da83b0e867b4a5d6994079a;p=ghc-hetmet.git diff --git a/ghc/compiler/typecheck/TcTyClsDecls.lhs b/ghc/compiler/typecheck/TcTyClsDecls.lhs index 6e4e0d6..9516686 100644 --- a/ghc/compiler/typecheck/TcTyClsDecls.lhs +++ b/ghc/compiler/typecheck/TcTyClsDecls.lhs @@ -10,45 +10,51 @@ module TcTyClsDecls ( #include "HsVersions.h" -import HsSyn ( HsDecl(..), TyClDecl(..), - HsType(..), HsTyVarBndr, - ConDecl(..), ConDetails(..), BangType(..), - Sig(..), HsPred(..), HsTupCon(..), - tyClDeclName, hsTyVarNames, isClassDecl, isSynDecl, isClassOpSig, getBangType +import HsSyn ( TyClDecl(..), HsConDetails(..), HsTyVarBndr(..), + ConDecl(..), Sig(..), , NewOrData(..), + tyClDeclTyVars, isSynDecl, LConDecl, + LTyClDecl, tcdName, LHsTyVarBndr, LHsContext ) -import RnHsSyn ( RenamedHsDecl, RenamedTyClDecl, listTyCon_name ) -import BasicTypes ( RecFlag(..), NewOrData(..), Arity ) - -import TcMonad -import TcEnv ( ValueEnv, TyThing(..), TyThingDetails(..), tyThingKind, - tcExtendTypeEnv, tcExtendKindEnv, tcLookupTy - ) -import TcTyDecls ( tcTyDecl1, kcConDetails, mkNewTyConRep ) -import TcClassDcl ( tcClassDecl1 ) -import TcMonoType ( kcHsTyVars, kcHsType, kcHsBoxedSigType, kcHsContext, mkTyClTyVars ) -import TcType ( TcKind, newKindVar, newKindVars, zonkKindEnv ) - +import HsTypes ( HsBang(..), getBangStrictness ) +import BasicTypes ( RecFlag(..), StrictnessMark(..) ) +import HscTypes ( implicitTyThings ) +import BuildTyCl ( buildClass, buildAlgTyCon, buildSynTyCon, buildDataCon, + mkDataTyConRhs, mkNewTyConRhs ) +import TcRnMonad +import TcEnv ( TcTyThing(..), TyThing(..), + tcLookupLocated, tcLookupLocatedGlobal, + tcExtendGlobalEnv, tcExtendKindEnv, + tcExtendRecEnv, tcLookupTyVar ) +import TcTyDecls ( calcTyConArgVrcs, calcRecFlags, calcClassCycles, calcSynCycles ) +import TcClassDcl ( tcClassSigs, tcAddDeclCtxt ) +import TcHsType ( kcHsTyVars, kcHsLiftedSigType, kcHsType, + kcHsContext, tcTyVarBndrs, tcHsKindedType, tcHsKindedContext, + kcHsSigType, tcHsBangType, tcLHsConSig ) +import TcMType ( newKindVar, checkValidTheta, checkValidType, checkFreeness, + UserTypeCtxt(..), SourceTyCtxt(..) ) import TcUnify ( unifyKind ) -import Type ( Kind, mkArrowKind, boxedTypeKind, zipFunTys ) -import Variance ( calcTyConArgVrcs ) -import Class ( Class, mkClass, classTyCon ) -import TyCon ( TyCon, ArgVrcs, AlgTyConFlavour(..), mkSynTyCon, mkAlgTyCon, mkClassTyCon ) -import DataCon ( isNullaryDataCon ) -import Var ( TyVar, tyVarKind, varName ) -import VarEnv -import FiniteMap -import Bag -import Digraph ( stronglyConnComp, SCC(..) ) -import Name ( Name, NamedThing(..), NameEnv, getSrcLoc, isTvOcc, nameOccName, - mkNameEnv, lookupNameEnv_NF - ) +import TcType ( TcKind, ThetaType, TcType, tyVarsOfType, + mkArrowKind, liftedTypeKind, mkTyVarTys, tcEqTypes, + tcSplitSigmaTy, tcEqType ) +import Type ( splitTyConApp_maybe, pprThetaArrow, pprParendType ) +import Generics ( validGenericMethodType, canDoGenerics ) +import Class ( Class, className, classTyCon, DefMeth(..), classBigSig, classTyVars ) +import TyCon ( TyCon, ArgVrcs, + tyConDataCons, mkForeignTyCon, isProductTyCon, isRecursiveTyCon, + tyConStupidTheta, getSynTyConDefn, tyConDataCons, isSynTyCon, tyConName ) +import DataCon ( DataCon, dataConWrapId, dataConName, dataConSig, + dataConFieldLabels, dataConOrigArgTys, dataConTyCon ) +import Type ( zipTopTvSubst, substTys ) +import Var ( TyVar, idType, idName ) +import VarSet ( elemVarSet ) +import Name ( Name ) import Outputable -import Maybes ( mapMaybe, catMaybes ) -import UniqSet ( UniqSet, emptyUniqSet, - unitUniqSet, unionUniqSets, - unionManyUniqSets, uniqSetToList ) -import ErrUtils ( Message ) -import Unique ( Unique, Uniquable(..) ) +import Util ( zipLazy, isSingleton, notNull, sortLe ) +import List ( partition ) +import SrcLoc ( Located(..), unLoc, getLoc ) +import ListSetOps ( equivClasses ) +import Digraph ( SCC(..) ) +import CmdLineOpts ( DynFlag( Opt_GlasgowExts, Opt_Generics, Opt_UnboxStrictFields ) ) \end{code} @@ -58,30 +64,8 @@ import Unique ( Unique, Uniquable(..) ) %* * %************************************************************************ -The main function -~~~~~~~~~~~~~~~~~ -\begin{code} -tcTyAndClassDecls :: ValueEnv -- Knot tying stuff - -> [RenamedHsDecl] - -> TcM s TcEnv - -tcTyAndClassDecls unf_env decls - = sortByDependency decls `thenTc` \ groups -> - tcGroups unf_env groups - -tcGroups unf_env [] - = tcGetEnv `thenNF_Tc` \ env -> - returnTc env - -tcGroups unf_env (group:groups) - = tcGroup unf_env group `thenTc` \ env -> - tcSetEnv env $ - tcGroups unf_env groups -\end{code} - Dealing with a group ~~~~~~~~~~~~~~~~~~~~ - Consider a mutually-recursive group, binding a type constructor T and a class C. @@ -105,96 +89,96 @@ Step 4: buildTyConOrClass Step 5: tcTyClDecl1 In this environment, walk over the decls, constructing the TyCons and Classes. This uses in a strict way items (a)-(c) above, which is why they must - be constructed in Step 4. - Feed the results back to Step 4. + be constructed in Step 4. Feed the results back to Step 4. + For this step, pass the is-recursive flag as the wimp-out flag + to tcTyClDecl1. -The knot-tying parameters: @rec_details_list@ is an alist mapping @Name@s to -@TyThing@s. @rec_vrcs@ is a finite map from @Name@s to @ArgVrcs@s. -\begin{code} -tcGroup :: ValueEnv -> SCC RenamedTyClDecl -> TcM s TcEnv -tcGroup unf_env scc - = -- Step 1 - mapNF_Tc getInitialKind decls `thenNF_Tc` \ initial_kinds -> - - -- Step 2 - tcExtendKindEnv initial_kinds (mapTc kcTyClDecl decls) `thenTc_` - - -- Step 3 - zonkKindEnv initial_kinds `thenNF_Tc` \ final_kinds -> - - -- Tie the knot - fixTc ( \ ~(rec_details_list, _) -> - -- Step 4 - let - kind_env = mkNameEnv final_kinds - rec_details = mkNameEnv rec_details_list - - tyclss, all_tyclss :: [(Name, TyThing)] - tyclss = map (buildTyConOrClass is_rec kind_env rec_vrcs rec_details) decls - - -- Add the tycons that come from the classes - -- We want them in the environment because - -- they are mentioned in interface files - all_tyclss = [ (getName tycon, ATyCon tycon) | (_, AClass clas) <- tyclss, - let tycon = classTyCon clas - ] ++ tyclss - - -- Calculate variances, and (yes!) feed back into buildTyConOrClass. - rec_vrcs = calcTyConArgVrcs [tc | (_, ATyCon tc) <- all_tyclss] - in - -- Step 5 - tcExtendTypeEnv all_tyclss $ - mapTc (tcTyClDecl1 unf_env) decls `thenTc` \ tycls_details -> - tcGetEnv `thenNF_Tc` \ env -> - returnTc (tycls_details, env) - ) `thenTc` \ (_, env) -> - returnTc env - where - is_rec = case scc of - AcyclicSCC _ -> NonRecursive - CyclicSCC _ -> Recursive +Step 6: Extend environment + We extend the type environment with bindings not only for the TyCons and Classes, + but also for their "implicit Ids" like data constructors and class selectors - decls = case scc of - AcyclicSCC decl -> [decl] - CyclicSCC decls -> decls - -tcTyClDecl1 :: ValueEnv -> RenamedTyClDecl -> TcM s (Name, TyThingDetails) - -tcTyClDecl1 unf_env decl - | isClassDecl decl = tcClassDecl1 unf_env decl - | otherwise = tcTyDecl1 decl -\end{code} +Step 7: checkValidTyCl + For a recursive group only, check all the decls again, just + to check all the side conditions on validity. We could not + do this before because we were in a mutually recursive knot. -%************************************************************************ -%* * -\subsection{Step 1: Initial environment} -%* * -%************************************************************************ +The knot-tying parameters: @rec_details_list@ is an alist mapping @Name@s to +@TyThing@s. @rec_vrcs@ is a finite map from @Name@s to @ArgVrcs@s. \begin{code} -getInitialKind :: RenamedTyClDecl -> NF_TcM s (Name, TcKind) -getInitialKind (TySynonym name tyvars _ _) - = kcHsTyVars tyvars `thenNF_Tc` \ arg_kinds -> - newKindVar `thenNF_Tc` \ result_kind -> - returnNF_Tc (name, mk_kind arg_kinds result_kind) - -getInitialKind (TyData _ _ name tyvars _ _ _ _ _) - = kcHsTyVars tyvars `thenNF_Tc` \ arg_kinds -> - returnNF_Tc (name, mk_kind arg_kinds boxedTypeKind) - -getInitialKind (ClassDecl _ name tyvars _ _ _ _ _ _ _ _ _) - = kcHsTyVars tyvars `thenNF_Tc` \ arg_kinds -> - returnNF_Tc (name, mk_kind arg_kinds boxedTypeKind) - -mk_kind tvs_w_kinds res_kind = foldr (mkArrowKind . snd) res_kind tvs_w_kinds +tcTyAndClassDecls :: [Name] -> [LTyClDecl Name] + -> TcM TcGblEnv -- Input env extended by types and classes + -- and their implicit Ids,DataCons +tcTyAndClassDecls boot_names decls + = do { -- First check for cyclic type synonysm or classes + -- See notes with checkCycleErrs + checkCycleErrs decls + ; mod <- getModule + ; traceTc (text "tcTyAndCl" <+> ppr mod <+> ppr boot_names) + ; (syn_tycons, alg_tyclss) <- fixM (\ ~(rec_syn_tycons, rec_alg_tyclss) -> + do { let { -- Calculate variances and rec-flag + ; (syn_decls, alg_decls) = partition (isSynDecl . unLoc) decls } + + -- Extend the global env with the knot-tied results + -- for data types and classes + -- + -- We must populate the environment with the loop-tied T's right + -- away, because the kind checker may "fault in" some type + -- constructors that recursively mention T + ; let { gbl_things = mkGlobalThings alg_decls rec_alg_tyclss } + ; tcExtendRecEnv gbl_things $ do + + -- Kind-check the declarations + { (kc_syn_decls, kc_alg_decls) <- kcTyClDecls syn_decls alg_decls + + ; let { calc_vrcs = calcTyConArgVrcs (rec_syn_tycons ++ rec_alg_tyclss) + ; calc_rec = calcRecFlags boot_names rec_alg_tyclss + ; tc_decl = addLocM (tcTyClDecl calc_vrcs calc_rec) } + -- Type-check the type synonyms, and extend the envt + ; syn_tycons <- tcSynDecls calc_vrcs kc_syn_decls + ; tcExtendGlobalEnv syn_tycons $ do + + -- Type-check the data types and classes + { alg_tyclss <- mappM tc_decl kc_alg_decls + ; return (syn_tycons, alg_tyclss) + }}}) + -- Finished with knot-tying now + -- Extend the environment with the finished things + ; tcExtendGlobalEnv (syn_tycons ++ alg_tyclss) $ do + + -- Perform the validity check + { traceTc (text "ready for validity check") + ; mappM_ (addLocM checkValidTyCl) decls + ; traceTc (text "done") + + -- Add the implicit things; + -- we want them in the environment because + -- they may be mentioned in interface files + ; let { implicit_things = concatMap implicitTyThings alg_tyclss } + ; traceTc ((text "Adding" <+> ppr alg_tyclss) $$ (text "and" <+> ppr implicit_things)) + ; tcExtendGlobalEnv implicit_things getGblEnv + }} + +mkGlobalThings :: [LTyClDecl Name] -- The decls + -> [TyThing] -- Knot-tied, in 1-1 correspondence with the decls + -> [(Name,TyThing)] +-- Driven by the Decls, and treating the TyThings lazily +-- make a TypeEnv for the new things +mkGlobalThings decls things + = map mk_thing (decls `zipLazy` things) + where + mk_thing (L _ (ClassDecl {tcdLName = L _ name}), ~(AClass cl)) + = (name, AClass cl) + mk_thing (L _ decl, ~(ATyCon tc)) + = (tcdName decl, ATyCon tc) \end{code} %************************************************************************ %* * -\subsection{Step 2: Kind checking} + Kind checking %* * %************************************************************************ @@ -211,294 +195,546 @@ Here, the kind of the locally-polymorphic type variable "b" depends on *all the uses of class D*. For example, the use of Monad c in bop's type signature means that D must have kind Type->Type. +However type synonyms work differently. They can have kinds which don't +just involve (->) and *: + type R = Int# -- Kind # + type S a = Array# a -- Kind * -> # + type T a b = (# a,b #) -- Kind * -> * -> (# a,b #) +So we must infer their kinds from their right-hand sides *first* and then +use them, whereas for the mutually recursive data types D we bring into +scope kind bindings D -> k, where k is a kind variable, and do inference. + \begin{code} -kcTyClDecl :: RenamedTyClDecl -> TcM s () - -kcTyClDecl decl@(TySynonym tycon_name hs_tyvars rhs loc) - = tcAddDeclCtxt decl $ - kcTyClDeclBody tycon_name hs_tyvars $ \ result_kind -> - kcHsType rhs `thenTc` \ rhs_kind -> - unifyKind result_kind rhs_kind - -kcTyClDecl decl@(TyData _ context tycon_name hs_tyvars con_decls _ _ _ loc) - = tcAddDeclCtxt decl $ - kcTyClDeclBody tycon_name hs_tyvars $ \ result_kind -> - kcHsContext context `thenTc_` - mapTc_ kc_con_decl con_decls +kcTyClDecls syn_decls alg_decls + = do { -- First extend the kind env with each data + -- type and class, mapping them to a type variable + alg_kinds <- mappM getInitialKind alg_decls + ; tcExtendKindEnv alg_kinds $ do + + -- Now kind-check the type synonyms, in dependency order + -- We do these differently to data type and classes, + -- because a type synonym can be an unboxed type + -- type Foo = Int# + -- and a kind variable can't unify with UnboxedTypeKind + -- So we infer their kinds in dependency order + { (kc_syn_decls, syn_kinds) <- kcSynDecls (calcSynCycles syn_decls) + ; tcExtendKindEnv syn_kinds $ do + + -- Now kind-check the data type and class declarations, + -- returning kind-annotated decls + { kc_alg_decls <- mappM (wrapLocM kcTyClDecl) alg_decls + + ; return (kc_syn_decls, kc_alg_decls) }}} + +------------------------------------------------------------------------ +getInitialKind :: LTyClDecl Name -> TcM (Name, TcKind) + +getInitialKind decl + = newKindVar `thenM` \ kind -> + returnM (unLoc (tcdLName (unLoc decl)), kind) + +---------------- +kcSynDecls :: [SCC (LTyClDecl Name)] + -> TcM ([LTyClDecl Name], -- Kind-annotated decls + [(Name,TcKind)]) -- Kind bindings +kcSynDecls [] + = return ([], []) +kcSynDecls (group : groups) + = do { (decl, nk) <- kcSynDecl group + ; (decls, nks) <- tcExtendKindEnv [nk] (kcSynDecls groups) + ; return (decl:decls, nk:nks) } + +---------------- +kcSynDecl :: SCC (LTyClDecl Name) + -> TcM (LTyClDecl Name, -- Kind-annotated decls + (Name,TcKind)) -- Kind bindings +kcSynDecl (AcyclicSCC ldecl@(L loc decl)) + = tcAddDeclCtxt decl $ + kcHsTyVars (tcdTyVars decl) (\ k_tvs -> + do { traceTc (text "kcd1" <+> ppr (unLoc (tcdLName decl)) <+> brackets (ppr (tcdTyVars decl)) + <+> brackets (ppr k_tvs)) + ; (k_rhs, rhs_kind) <- kcHsType (tcdSynRhs decl) + ; traceTc (text "kcd2" <+> ppr (unLoc (tcdLName decl))) + ; let tc_kind = foldr (mkArrowKind . kindedTyVarKind) rhs_kind k_tvs + ; return (L loc (decl { tcdTyVars = k_tvs, tcdSynRhs = k_rhs }), + (unLoc (tcdLName decl), tc_kind)) }) + +kcSynDecl (CyclicSCC decls) + = do { recSynErr decls; failM } -- Fail here to avoid error cascade + -- of out-of-scope tycons + +------------------------------------------------------------------------ +kcTyClDecl :: TyClDecl Name -> TcM (TyClDecl Name) + -- Not used for type synonyms (see kcSynDecl) + +kcTyClDecl decl@(TyData {tcdND = new_or_data, tcdCtxt = ctxt, tcdCons = cons}) + = kcTyClDeclBody decl $ \ tvs' -> + do { ctxt' <- kcHsContext ctxt + ; cons' <- mappM (wrapLocM kc_con_decl) cons + ; return (decl {tcdTyVars = tvs', tcdCtxt = ctxt', tcdCons = cons'}) } where - kc_con_decl (ConDecl _ _ ex_tvs ex_ctxt details loc) - = tcAddSrcLoc loc $ - kcHsTyVars ex_tvs `thenNF_Tc` \ kind_env -> - tcExtendKindEnv kind_env $ - kcConDetails ex_ctxt details - -kcTyClDecl decl@(ClassDecl context class_name - hs_tyvars fundeps class_sigs - _ _ _ _ _ _ loc) - = tcAddDeclCtxt decl $ - kcTyClDeclBody class_name hs_tyvars $ \ result_kind -> - kcHsContext context `thenTc_` - mapTc_ kc_sig (filter isClassOpSig class_sigs) + kc_con_decl (ConDecl name ex_tvs ex_ctxt details) + = kcHsTyVars ex_tvs $ \ ex_tvs' -> + do { ex_ctxt' <- kcHsContext ex_ctxt + ; details' <- kc_con_details details + ; return (ConDecl name ex_tvs' ex_ctxt' details')} + kc_con_decl (GadtDecl name ty) + = do { ty' <- kcHsSigType ty + ; return (GadtDecl name ty') } + + kc_con_details (PrefixCon btys) + = do { btys' <- mappM kc_larg_ty btys ; return (PrefixCon btys') } + kc_con_details (InfixCon bty1 bty2) + = do { bty1' <- kc_larg_ty bty1; bty2' <- kc_larg_ty bty2; return (InfixCon bty1' bty2') } + kc_con_details (RecCon fields) + = do { fields' <- mappM kc_field fields; return (RecCon fields') } + + kc_field (fld, bty) = do { bty' <- kc_larg_ty bty ; return (fld, bty') } + + kc_larg_ty bty = case new_or_data of + DataType -> kcHsSigType bty + NewType -> kcHsLiftedSigType bty + -- Can't allow an unlifted type for newtypes, because we're effectively + -- going to remove the constructor while coercing it to a lifted type. + -- And newtypes can't be bang'd + +kcTyClDecl decl@(ClassDecl {tcdCtxt = ctxt, tcdSigs = sigs}) + = kcTyClDeclBody decl $ \ tvs' -> + do { ctxt' <- kcHsContext ctxt + ; sigs' <- mappM (wrapLocM kc_sig) sigs + ; return (decl {tcdTyVars = tvs', tcdCtxt = ctxt', tcdSigs = sigs'}) } where - kc_sig (ClassOpSig _ _ op_ty loc) = tcAddSrcLoc loc (kcHsBoxedSigType op_ty) - -kcTyClDeclBody :: Name -> [HsTyVarBndr Name] -- Kind of the tycon/cls and its tyvars - -> (Kind -> TcM s a) -- Thing inside - -> TcM s a --- Extend the env with bindings for the tyvars, taken from --- the kind of the tycon/class. Give it to the thing inside, and --- check the result kind matches -kcTyClDeclBody tc_name hs_tyvars thing_inside - = tcLookupTy tc_name `thenNF_Tc` \ tc -> - let - (tyvars_w_kinds, result_kind) = zipFunTys (hsTyVarNames hs_tyvars) (tyThingKind tc) - in - tcExtendKindEnv tyvars_w_kinds (thing_inside result_kind) + kc_sig (Sig nm op_ty) = do { op_ty' <- kcHsLiftedSigType op_ty + ; return (Sig nm op_ty') } + kc_sig other_sig = return other_sig + +kcTyClDecl decl@(ForeignType {}) + = return decl + +kcTyClDeclBody :: TyClDecl Name + -> ([LHsTyVarBndr Name] -> TcM a) + -> TcM a + -- Extend the env with bindings for the tyvars, taken from + -- the kind of the tycon/class. Give it to the thing inside, and + -- check the result kind matches +kcTyClDeclBody decl thing_inside + = tcAddDeclCtxt decl $ + kcHsTyVars (tyClDeclTyVars decl) $ \ kinded_tvs -> + do { tc_ty_thing <- tcLookupLocated (tcdLName decl) + ; let tc_kind = case tc_ty_thing of { AThing k -> k } + ; unifyKind tc_kind (foldr (mkArrowKind . kindedTyVarKind) + (result_kind decl) + kinded_tvs) + ; thing_inside kinded_tvs } + where + result_kind (TyData { tcdKindSig = Just kind }) = kind + result_kind other = liftedTypeKind + -- On GADT-style declarations we allow a kind signature + -- data T :: *->* where { ... } + +kindedTyVarKind (L _ (KindedTyVar _ k)) = k \end{code} %************************************************************************ %* * -\subsection{Step 4: Building the tycon/class} +\subsection{Type checking} %* * %************************************************************************ \begin{code} -buildTyConOrClass - :: RecFlag -> NameEnv Kind - -> FiniteMap TyCon ArgVrcs -> NameEnv TyThingDetails - -> RenamedTyClDecl -> (Name, TyThing) - -- Can't fail; the only reason it's in the monad - -- is so it can zonk the kinds - -buildTyConOrClass is_rec kenv rec_vrcs rec_details - (TySynonym tycon_name tyvar_names rhs src_loc) - = (tycon_name, ATyCon tycon) +tcSynDecls :: (Name -> ArgVrcs) -> [LTyClDecl Name] -> TcM [TyThing] +tcSynDecls calc_vrcs [] = return [] +tcSynDecls calc_vrcs (decl : decls) + = do { syn_tc <- addLocM (tcSynDecl calc_vrcs) decl + ; syn_tcs <- tcExtendGlobalEnv [syn_tc] (tcSynDecls calc_vrcs decls) + ; return (syn_tc : syn_tcs) } + +tcSynDecl calc_vrcs + (TySynonym {tcdLName = L _ tc_name, tcdTyVars = tvs, tcdSynRhs = rhs_ty}) + = tcTyVarBndrs tvs $ \ tvs' -> do + { traceTc (text "tcd1" <+> ppr tc_name) + ; rhs_ty' <- tcHsKindedType rhs_ty + ; return (ATyCon (buildSynTyCon tc_name tvs' rhs_ty' (calc_vrcs tc_name))) } + +-------------------- +tcTyClDecl :: (Name -> ArgVrcs) -> (Name -> RecFlag) + -> TyClDecl Name -> TcM TyThing + +tcTyClDecl calc_vrcs calc_isrec decl + = tcAddDeclCtxt decl (tcTyClDecl1 calc_vrcs calc_isrec decl) + +tcTyClDecl1 calc_vrcs calc_isrec + (TyData {tcdND = new_or_data, tcdCtxt = ctxt, tcdTyVars = tvs, + tcdLName = L _ tc_name, tcdCons = cons}) + = tcTyVarBndrs tvs $ \ tvs' -> do + { stupid_theta <- tcStupidTheta ctxt cons + ; want_generic <- doptM Opt_Generics + ; tycon <- fixM (\ tycon -> do + { unbox_strict <- doptM Opt_UnboxStrictFields + ; gla_exts <- doptM Opt_GlasgowExts + ; checkTc (gla_exts || h98_syntax) (badGadtDecl tc_name) + + ; data_cons <- mappM (addLocM (tcConDecl unbox_strict new_or_data tycon tvs')) cons + ; let tc_rhs = case new_or_data of + DataType -> mkDataTyConRhs stupid_theta data_cons + NewType -> ASSERT( isSingleton data_cons ) + mkNewTyConRhs tycon (head data_cons) + ; buildAlgTyCon tc_name tvs' tc_rhs arg_vrcs is_rec + (want_generic && canDoGenerics data_cons) + }) + ; return (ATyCon tycon) + } where - tycon = mkSynTyCon tycon_name tycon_kind arity tyvars rhs_ty argvrcs - tycon_kind = lookupNameEnv_NF kenv tycon_name - arity = length tyvar_names - tyvars = mkTyClTyVars tycon_kind tyvar_names - SynTyDetails rhs_ty = lookupNameEnv_NF rec_details tycon_name - argvrcs = lookupWithDefaultFM rec_vrcs bogusVrcs tycon - -buildTyConOrClass is_rec kenv rec_vrcs rec_details - (TyData data_or_new context tycon_name tyvar_names _ nconstrs _ _ src_loc) - = (tycon_name, ATyCon tycon) + arg_vrcs = calc_vrcs tc_name + is_rec = calc_isrec tc_name + h98_syntax = case cons of -- All constructors have same shape + L _ (GadtDecl {}) : _ -> False + other -> True + +tcTyClDecl1 calc_vrcs calc_isrec + (ClassDecl {tcdLName = L _ class_name, tcdTyVars = tvs, + tcdCtxt = ctxt, tcdMeths = meths, + tcdFDs = fundeps, tcdSigs = sigs} ) + = tcTyVarBndrs tvs $ \ tvs' -> do + { ctxt' <- tcHsKindedContext ctxt + ; fds' <- mappM (addLocM tc_fundep) fundeps + ; sig_stuff <- tcClassSigs class_name sigs meths + ; clas <- fixM (\ clas -> + let -- This little knot is just so we can get + -- hold of the name of the class TyCon, which we + -- need to look up its recursiveness and variance + tycon_name = tyConName (classTyCon clas) + tc_isrec = calc_isrec tycon_name + tc_vrcs = calc_vrcs tycon_name + in + buildClass class_name tvs' ctxt' fds' + sig_stuff tc_isrec tc_vrcs) + ; return (AClass clas) } where - tycon = mkAlgTyCon tycon_name tycon_kind tyvars ctxt argvrcs - data_cons nconstrs - derived_classes - flavour is_rec - - DataTyDetails ctxt data_cons derived_classes = lookupNameEnv_NF rec_details tycon_name - - tycon_kind = lookupNameEnv_NF kenv tycon_name - tyvars = mkTyClTyVars tycon_kind tyvar_names - argvrcs = lookupWithDefaultFM rec_vrcs bogusVrcs tycon - - flavour = case data_or_new of - NewType -> NewTyCon (mkNewTyConRep tycon) - DataType | all isNullaryDataCon data_cons -> EnumTyCon - | otherwise -> DataTyCon - -buildTyConOrClass is_rec kenv rec_vrcs rec_details - (ClassDecl context class_name - tyvar_names fundeps class_sigs def_methods pragmas - tycon_name datacon_name datacon_wkr_name sc_sel_names src_loc) - = (class_name, AClass clas) + tc_fundep (tvs1, tvs2) = do { tvs1' <- mappM tcLookupTyVar tvs1 ; + ; tvs2' <- mappM tcLookupTyVar tvs2 ; + ; return (tvs1', tvs2') } + + +tcTyClDecl1 calc_vrcs calc_isrec + (ForeignType {tcdLName = L _ tc_name, tcdExtName = tc_ext_name}) + = returnM (ATyCon (mkForeignTyCon tc_name tc_ext_name liftedTypeKind 0 [])) + +----------------------------------- +tcConDecl :: Bool -- True <=> -funbox-strict_fields + -> NewOrData -> TyCon -> [TyVar] + -> ConDecl Name -> TcM DataCon + +tcConDecl unbox_strict NewType tycon tc_tvs -- Newtypes + (ConDecl name ex_tvs ex_ctxt details) + = ASSERT( null ex_tvs && null (unLoc ex_ctxt) ) + do { let tc_datacon field_lbls arg_ty + = do { arg_ty' <- tcHsKindedType arg_ty -- No bang on newtype + ; buildDataCon (unLoc name) False {- Prefix -} + True {- Vanilla -} [NotMarkedStrict] + (map unLoc field_lbls) + tc_tvs [] [arg_ty'] + tycon (mkTyVarTys tc_tvs) } + ; case details of + PrefixCon [arg_ty] -> tc_datacon [] arg_ty + RecCon [(field_lbl, arg_ty)] -> tc_datacon [field_lbl] arg_ty } + +tcConDecl unbox_strict DataType tycon tc_tvs -- Ordinary data types + (ConDecl name ex_tvs ex_ctxt details) + = tcTyVarBndrs ex_tvs $ \ ex_tvs' -> do + { ex_ctxt' <- tcHsKindedContext ex_ctxt + ; let + is_vanilla = null ex_tvs && null (unLoc ex_ctxt) + -- Vanilla iff no ex_tvs and no context + + tc_datacon is_infix field_lbls btys + = do { let { bangs = map getBangStrictness btys } + ; arg_tys <- mappM tcHsBangType btys + ; buildDataCon (unLoc name) is_infix is_vanilla + (argStrictness unbox_strict tycon bangs arg_tys) + (map unLoc field_lbls) + (tc_tvs ++ ex_tvs') + ex_ctxt' + arg_tys + tycon (mkTyVarTys tc_tvs) } + ; case details of + PrefixCon btys -> tc_datacon False [] btys + InfixCon bty1 bty2 -> tc_datacon True [] [bty1,bty2] + RecCon fields -> do { checkTc is_vanilla (exRecConErr name) + ; let { (field_names, btys) = unzip fields } + ; tc_datacon False field_names btys } } + +tcConDecl unbox_strict DataType tycon tc_tvs -- GADTs + decl@(GadtDecl name con_ty) + = do { traceTc (text "tcConDecl" <+> ppr name) + ; (tvs, theta, bangs, arg_tys, tc, res_tys) <- tcLHsConSig con_ty + + ; traceTc (text "tcConDecl1" <+> ppr name) + ; let -- Now dis-assemble the type, and check its form + is_vanilla = null theta && mkTyVarTys tvs `tcEqTypes` res_tys + + -- Vanilla datacons guarantee to use the same + -- type variables as the parent tycon + (tvs', arg_tys', res_tys') + | is_vanilla = (tc_tvs, substTys subst arg_tys, substTys subst res_tys) + | otherwise = (tvs, arg_tys, res_tys) + subst = zipTopTvSubst tvs (mkTyVarTys tc_tvs) + + ; traceTc (text "tcConDecl3" <+> ppr name) + ; buildDataCon (unLoc name) False {- Not infix -} is_vanilla + (argStrictness unbox_strict tycon bangs arg_tys) + [{- No field labels -}] + tvs' theta arg_tys' tycon res_tys' } + +------------------- +tcStupidTheta :: LHsContext Name -> [LConDecl Name] -> TcM (Maybe ThetaType) +-- For GADTs we don't allow a context on the data declaration +-- whereas for standard Haskell style data declarations, we do +tcStupidTheta ctxt (L _ (ConDecl _ _ _ _) : _) + = do { theta <- tcHsKindedContext ctxt; return (Just theta) } +tcStupidTheta ctxt other -- Includes an empty constructor list + = ASSERT( null (unLoc ctxt) ) return Nothing + +------------------- +argStrictness :: Bool -- True <=> -funbox-strict_fields + -> TyCon -> [HsBang] + -> [TcType] -> [StrictnessMark] +argStrictness unbox_strict tycon bangs arg_tys + = ASSERT( length bangs == length arg_tys ) + zipWith (chooseBoxingStrategy unbox_strict tycon) arg_tys bangs + +-- We attempt to unbox/unpack a strict field when either: +-- (i) The field is marked '!!', or +-- (ii) The field is marked '!', and the -funbox-strict-fields flag is on. + +chooseBoxingStrategy :: Bool -> TyCon -> TcType -> HsBang -> StrictnessMark +chooseBoxingStrategy unbox_strict_fields tycon arg_ty bang + = case bang of + HsNoBang -> NotMarkedStrict + HsStrict | unbox_strict_fields && can_unbox -> MarkedUnboxed + HsUnbox | can_unbox -> MarkedUnboxed + other -> MarkedStrict where - clas = mkClass class_name tyvars fds - sc_theta sc_sel_ids op_items - tycon - - tycon = mkClassTyCon tycon_name class_kind tyvars - argvrcs dict_con - clas -- Yes! It's a dictionary - flavour - - ClassDetails sc_theta sc_sel_ids op_items dict_con = lookupNameEnv_NF rec_details class_name - - class_kind = lookupNameEnv_NF kenv class_name - tyvars = mkTyClTyVars class_kind tyvar_names - argvrcs = lookupWithDefaultFM rec_vrcs bogusVrcs tycon - n_fields = length sc_sel_ids + length op_items - - flavour | n_fields == 1 = NewTyCon (mkNewTyConRep tycon) - | otherwise = DataTyCon - - -- We can find the functional dependencies right away, - -- and it is vital to do so. Why? Because in the next pass - -- we check for ambiguity in all the type signatures, and we - -- need the functional dependcies to be done by then - fds = [(map lookup xs, map lookup ys) | (xs,ys) <- fundeps] - tyvar_env = mkNameEnv [(varName tv, tv) | tv <- tyvars] - lookup = lookupNameEnv_NF tyvar_env - -bogusVrcs = panic "Bogus tycon arg variances" + can_unbox = case splitTyConApp_maybe arg_ty of + Nothing -> False + Just (arg_tycon, _) -> not (isRecursiveTyCon tycon) && + isProductTyCon arg_tycon \end{code} - %************************************************************************ %* * \subsection{Dependency analysis} %* * %************************************************************************ -Dependency analysis -~~~~~~~~~~~~~~~~~~~ +Validity checking is done once the mutually-recursive knot has been +tied, so we can look at things freely. + \begin{code} -sortByDependency :: [RenamedHsDecl] -> TcM s [SCC RenamedTyClDecl] -sortByDependency decls - = let -- CHECK FOR CLASS CYCLES - cls_sccs = stronglyConnComp (mapMaybe mk_cls_edges tycl_decls) - cls_cycles = [ decls | CyclicSCC decls <- cls_sccs] - in - checkTc (null cls_cycles) (classCycleErr cls_cycles) `thenTc_` - - let -- CHECK FOR SYNONYM CYCLES - syn_sccs = stronglyConnComp (filter is_syn_decl edges) - syn_cycles = [ decls | CyclicSCC decls <- syn_sccs] - - in - checkTc (null syn_cycles) (typeCycleErr syn_cycles) `thenTc_` - - -- DO THE MAIN DEPENDENCY ANALYSIS - let - decl_sccs = stronglyConnComp edges - in - returnTc decl_sccs +checkCycleErrs :: [LTyClDecl Name] -> TcM () +checkCycleErrs tyclss + | null cls_cycles + = return () + | otherwise + = do { mappM_ recClsErr cls_cycles + ; failM } -- Give up now, because later checkValidTyCl + -- will loop if the synonym is recursive where - tycl_decls = [d | TyClD d <- decls] - edges = map mk_edges tycl_decls - - is_syn_decl (d, _, _) = isSynDecl d -\end{code} + cls_cycles = calcClassCycles tyclss + +checkValidTyCl :: TyClDecl Name -> TcM () +-- We do the validity check over declarations, rather than TyThings +-- only so that we can add a nice context with tcAddDeclCtxt +checkValidTyCl decl + = tcAddDeclCtxt decl $ + do { thing <- tcLookupLocatedGlobal (tcdLName decl) + ; traceTc (text "Validity of" <+> ppr thing) + ; case thing of + ATyCon tc -> checkValidTyCon tc + AClass cl -> checkValidClass cl + ; traceTc (text "Done validity of" <+> ppr thing) + } + +------------------------- +checkValidTyCon :: TyCon -> TcM () +checkValidTyCon tc + | isSynTyCon tc + = checkValidType syn_ctxt syn_rhs + | otherwise + = -- Check the context on the data decl + checkValidTheta (DataTyCtxt name) (tyConStupidTheta tc) `thenM_` + + -- Check arg types of data constructors + mappM_ (checkValidDataCon tc) data_cons `thenM_` -Edges in Type/Class decls -~~~~~~~~~~~~~~~~~~~~~~~~~ + -- Check that fields with the same name share a type + mappM_ check_fields groups -\begin{code} ----------------------------------------------------- --- mk_cls_edges looks only at the context of class decls --- Its used when we are figuring out if there's a cycle in the --- superclass hierarchy - -mk_cls_edges :: RenamedTyClDecl -> Maybe (RenamedTyClDecl, Unique, [Unique]) - -mk_cls_edges decl@(ClassDecl ctxt name _ _ _ _ _ _ _ _ _ _) - = Just (decl, getUnique name, map getUnique (catMaybes (map get_clas ctxt))) -mk_cls_edges other_decl - = Nothing - ----------------------------------------------------- -mk_edges :: RenamedTyClDecl -> (RenamedTyClDecl, Unique, [Unique]) - -mk_edges decl@(TyData _ ctxt name _ condecls _ derivs _ _) - = (decl, getUnique name, uniqSetToList (get_ctxt ctxt `unionUniqSets` - get_cons condecls `unionUniqSets` - get_deriv derivs)) - -mk_edges decl@(TySynonym name _ rhs _) - = (decl, getUnique name, uniqSetToList (get_ty rhs)) - -mk_edges decl@(ClassDecl ctxt name _ _ sigs _ _ _ _ _ _ _) - = (decl, getUnique name, uniqSetToList (get_ctxt ctxt `unionUniqSets` - get_sigs sigs)) - - ----------------------------------------------------- -get_ctxt ctxt = unionManyUniqSets (map set_name (catMaybes (map get_clas ctxt))) -get_clas (HsPClass clas _) = Just clas -get_clas _ = Nothing - ----------------------------------------------------- -get_deriv Nothing = emptyUniqSet -get_deriv (Just clss) = unionManyUniqSets (map set_name clss) - ----------------------------------------------------- -get_cons cons = unionManyUniqSets (map get_con cons) - ----------------------------------------------------- -get_con (ConDecl _ _ _ ctxt details _) - = get_ctxt ctxt `unionUniqSets` get_con_details details - ----------------------------------------------------- -get_con_details (VanillaCon btys) = unionManyUniqSets (map get_bty btys) -get_con_details (InfixCon bty1 bty2) = unionUniqSets (get_bty bty1) (get_bty bty2) -get_con_details (RecCon nbtys) = unionManyUniqSets (map (get_bty.snd) nbtys) - ----------------------------------------------------- -get_bty bty = get_ty (getBangType bty) - ----------------------------------------------------- -get_ty (HsTyVar name) | isTvOcc (nameOccName name) = emptyUniqSet - | otherwise = set_name name -get_ty (HsAppTy ty1 ty2) = unionUniqSets (get_ty ty1) (get_ty ty2) -get_ty (HsFunTy ty1 ty2) = unionUniqSets (get_ty ty1) (get_ty ty2) -get_ty (HsListTy ty) = set_name listTyCon_name `unionUniqSets` get_ty ty -get_ty (HsTupleTy (HsTupCon n _) tys) = set_name n `unionUniqSets` get_tys tys -get_ty (HsUsgTy _ ty) = get_ty ty -get_ty (HsUsgForAllTy _ ty) = get_ty ty -get_ty (HsForAllTy _ ctxt mty) = get_ctxt ctxt `unionUniqSets` get_ty mty -get_ty (HsPredTy (HsPClass name _)) = set_name name -get_ty (HsPredTy (HsPIParam _ _)) = emptyUniqSet -- I think - ----------------------------------------------------- -get_tys tys = unionManyUniqSets (map get_ty tys) - ----------------------------------------------------- -get_sigs sigs - = unionManyUniqSets (map get_sig sigs) - where - get_sig (ClassOpSig _ _ ty _) = get_ty ty - get_sig (FixSig _) = emptyUniqSet - get_sig other = panic "TcTyClsDecls:get_sig" - ----------------------------------------------------- -set_name name = unitUniqSet (getUnique name) -set_to_bag set = listToBag (uniqSetToList set) -\end{code} + where + syn_ctxt = TySynCtxt name + name = tyConName tc + (_, syn_rhs) = getSynTyConDefn tc + data_cons = tyConDataCons tc + + groups = equivClasses cmp_fld (concatMap get_fields data_cons) + cmp_fld (f1,_) (f2,_) = f1 `compare` f2 + get_fields con = dataConFieldLabels con `zip` dataConOrigArgTys con + -- dataConFieldLabels may return the empty list, which is fine + + check_fields fields@((first_field_label, field_ty) : other_fields) + -- These fields all have the same name, but are from + -- different constructors in the data type + = -- Check that all the fields in the group have the same type + -- NB: this check assumes that all the constructors of a given + -- data type use the same type variables + checkTc (all (tcEqType field_ty . snd) other_fields) + (fieldTypeMisMatch first_field_label) + +------------------------------- +checkValidDataCon :: TyCon -> DataCon -> TcM () +checkValidDataCon tc con + = addErrCtxt (dataConCtxt con) $ + do { checkTc (dataConTyCon con == tc) (badDataConTyCon con) + ; checkValidType ctxt (idType (dataConWrapId con)) } + + -- This checks the argument types and + -- ambiguity of the existential context (if any) + -- + -- Note [Sept 04] Now that tvs is all the tvs, this + -- test doesn't actually check anything +-- ; checkFreeness tvs ex_theta } + where + ctxt = ConArgCtxt (dataConName con) + (tvs, ex_theta, _, _, _) = dataConSig con -%************************************************************************ -%* * -\subsection{Error management -%* * -%************************************************************************ +------------------------------- +checkValidClass :: Class -> TcM () +checkValidClass cls + = do { -- CHECK ARITY 1 FOR HASKELL 1.4 + gla_exts <- doptM Opt_GlasgowExts -\begin{code} -tcAddDeclCtxt decl thing_inside - = tcAddSrcLoc loc $ - tcAddErrCtxt ctxt $ - thing_inside + -- Check that the class is unary, unless GlaExs + ; checkTc (notNull tyvars) (nullaryClassErr cls) + ; checkTc (gla_exts || unary) (classArityErr cls) + + -- Check the super-classes + ; checkValidTheta (ClassSCCtxt (className cls)) theta + + -- Check the class operations + ; mappM_ check_op op_stuff + + -- Check that if the class has generic methods, then the + -- class has only one parameter. We can't do generic + -- multi-parameter type classes! + ; checkTc (unary || no_generics) (genericMultiParamErr cls) + } where - (name, loc, thing) - = case decl of - (ClassDecl _ name _ _ _ _ _ _ _ _ _ loc) -> (name, loc, "class") - (TySynonym name _ _ loc) -> (name, loc, "type synonym") - (TyData NewType _ name _ _ _ _ _ loc) -> (name, loc, "data type") - (TyData DataType _ name _ _ _ _ _ loc) -> (name, loc, "newtype") - - ctxt = hsep [ptext SLIT("In the"), text thing, - ptext SLIT("declaration for"), quotes (ppr name)] -\end{code} + (tyvars, theta, _, op_stuff) = classBigSig cls + unary = isSingleton tyvars + no_generics = null [() | (_, GenDefMeth) <- op_stuff] + + check_op (sel_id, dm) + = addErrCtxt (classOpCtxt sel_id tau) $ do + { checkValidTheta SigmaCtxt (tail theta) + -- The 'tail' removes the initial (C a) from the + -- class itself, leaving just the method type + + ; checkValidType (FunSigCtxt op_name) tau + + -- Check that the type mentions at least one of + -- the class type variables + ; checkTc (any (`elemVarSet` tyVarsOfType tau) tyvars) + (noClassTyVarErr cls sel_id) + + -- Check that for a generic method, the type of + -- the method is sufficiently simple + ; checkTc (dm /= GenDefMeth || validGenericMethodType tau) + (badGenericMethodType op_name op_ty) + } + where + op_name = idName sel_id + op_ty = idType sel_id + (_,theta,tau) = tcSplitSigmaTy op_ty + -\begin{code} -typeCycleErr, classCycleErr :: [[RenamedTyClDecl]] -> Message -typeCycleErr syn_cycles - = vcat (map (pp_cycle "Cycle in type declarations:") syn_cycles) +--------------------------------------------------------------------- +fieldTypeMisMatch field_name + = sep [ptext SLIT("Different constructors give different types for field"), quotes (ppr field_name)] -classCycleErr cls_cycles - = vcat (map (pp_cycle "Cycle in class declarations:") cls_cycles) +dataConCtxt con = sep [ptext SLIT("When checking the data constructor:"), + nest 2 (ex_part <+> pprThetaArrow ex_theta <+> ppr con <+> arg_part)] + where + (ex_tvs, ex_theta, arg_tys, _, _) = dataConSig con + ex_part | null ex_tvs = empty + | otherwise = ptext SLIT("forall") <+> hsep (map ppr ex_tvs) <> dot + -- The 'ex_theta' part could be non-empty, if the user (bogusly) wrote + -- data T a = Eq a => T a a + -- So we make sure to print it + + fields = dataConFieldLabels con + arg_part | null fields = sep (map pprParendType arg_tys) + | otherwise = braces (sep (punctuate comma + [ ppr n <+> dcolon <+> ppr ty + | (n,ty) <- fields `zip` arg_tys])) + +classOpCtxt sel_id tau = sep [ptext SLIT("When checking the class method:"), + nest 2 (ppr sel_id <+> dcolon <+> ppr tau)] + +nullaryClassErr cls + = ptext SLIT("No parameters for class") <+> quotes (ppr cls) + +classArityErr cls + = vcat [ptext SLIT("Too many parameters for class") <+> quotes (ppr cls), + parens (ptext SLIT("Use -fglasgow-exts to allow multi-parameter classes"))] + +noClassTyVarErr clas op + = sep [ptext SLIT("The class method") <+> quotes (ppr op), + ptext SLIT("mentions none of the type variables of the class") <+> + ppr clas <+> hsep (map ppr (classTyVars clas))] + +genericMultiParamErr clas + = ptext SLIT("The multi-parameter class") <+> quotes (ppr clas) <+> + ptext SLIT("cannot have generic methods") + +badGenericMethodType op op_ty + = hang (ptext SLIT("Generic method type is too complex")) + 4 (vcat [ppr op <+> dcolon <+> ppr op_ty, + ptext SLIT("You can only use type variables, arrows, lists, and tuples")]) + +recSynErr syn_decls + = setSrcSpan (getLoc (head sorted_decls)) $ + addErr (sep [ptext SLIT("Cycle in type synonym declarations:"), + nest 2 (vcat (map ppr_decl sorted_decls))]) + where + sorted_decls = sortLocated syn_decls + ppr_decl (L loc decl) = ppr loc <> colon <+> ppr decl + +recClsErr cls_decls + = setSrcSpan (getLoc (head sorted_decls)) $ + addErr (sep [ptext SLIT("Cycle in class declarations (via superclasses):"), + nest 2 (vcat (map ppr_decl sorted_decls))]) + where + sorted_decls = sortLocated cls_decls + ppr_decl (L loc decl) = ppr loc <> colon <+> ppr (decl { tcdSigs = [] }) -pp_cycle str decls - = hang (text str) - 4 (vcat (map pp_decl decls)) +sortLocated :: [Located a] -> [Located a] +sortLocated things = sortLe le things where - pp_decl decl - = hsep [quotes (ppr name), ptext SLIT("at"), ppr (getSrcLoc name)] - where - name = tyClDeclName decl + le (L l1 _) (L l2 _) = l1 <= l2 + +exRecConErr name + = ptext SLIT("Can't combine named fields with locally-quantified type variables or context") + $$ + (ptext SLIT("In the declaration of data constructor") <+> ppr name) + +badDataConTyCon data_con + = hang (ptext SLIT("Data constructor does not return its parent type:")) + 2 (ppr data_con) + +badGadtDecl tc_name + = vcat [ ptext SLIT("Illegal generalised algebraic data declaration for") <+> quotes (ppr tc_name) + , nest 2 (parens $ ptext SLIT("Use -fglasgow-exts to allow GADTs")) ] \end{code}