[project @ 2000-10-24 08:40:09 by simonpj]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcTyDecls.lhs
index 6ef01c0..c44fef2 100644 (file)
@@ -20,10 +20,13 @@ import RnHsSyn              ( RenamedTyClDecl, RenamedConDecl, RenamedContext )
 import TcHsSyn         ( TcMonoBinds, idsToMonoBinds )
 import BasicTypes      ( NewOrData(..) )
 
-import TcMonoType      ( tcHsType, tcHsSigType, tcHsBoxedSigType, kcTyVarScope, tcClassContext,
-                         kcHsContext, kcHsSigType, mkImmutTyVars
+import TcMonoType      ( tcHsType, tcHsSigType, tcHsBoxedSigType, tcHsTyVars, tcClassContext,
+                         kcHsContext, kcHsSigType
+                       )
+import TcEnv           ( tcExtendTyVarEnv, 
+                         tcLookupTyCon, tcLookupClass, tcLookupGlobalId, 
+                         TyThingDetails(..)
                        )
-import TcEnv           ( tcExtendTyVarEnv, tcLookupTy, tcLookupValueByKey, TyThing(..), TyThingDetails(..) )
 import TcMonad
 
 import Class           ( ClassContext )
@@ -37,7 +40,7 @@ import Var            ( Id, TyVar )
 import Name            ( Name, isLocallyDefined, NamedThing(..) )
 import Outputable
 import TyCon           ( TyCon, isSynTyCon, isNewTyCon,
-                         tyConDataConsIfAvailable, tyConTyVars
+                         tyConDataConsIfAvailable, tyConTyVars, tyConGenIds
                        )
 import Type            ( tyVarsOfTypes, splitFunTy, applyTys,
                          mkTyConApp, mkTyVarTys, mkForAllTys, 
@@ -45,8 +48,8 @@ import Type           ( tyVarsOfTypes, splitFunTy, applyTys,
                        )
 import TysWiredIn      ( unitTy )
 import VarSet          ( intersectVarSet, isEmptyVarSet )
-import Unique          ( unpackCStringIdKey, unpackCStringUtf8IdKey )
-import Util            ( equivClasses )
+import PrelNames       ( unpackCStringName, unpackCStringUtf8Name )
+import ListSetOps      ( equivClasses )
 \end{code}
 
 %************************************************************************
@@ -56,9 +59,9 @@ import Util           ( equivClasses )
 %************************************************************************
 
 \begin{code}
-tcTyDecl1 :: RenamedTyClDecl -> TcM s (Name, TyThingDetails)
+tcTyDecl1 :: RenamedTyClDecl -> TcM (Name, TyThingDetails)
 tcTyDecl1 (TySynonym tycon_name tyvar_names rhs src_loc)
-  = tcLookupTy tycon_name                      `thenNF_Tc` \ (ATyCon tycon) ->
+  = tcLookupTyCon tycon_name                   `thenNF_Tc` \ tycon ->
     tcExtendTyVarEnv (tyConTyVars tycon)       $
     tcHsType rhs                               `thenTc` \ rhs_ty ->
        -- Note tcHsType not tcHsSigType; we allow type synonyms
@@ -75,8 +78,8 @@ tcTyDecl1 (TySynonym tycon_name tyvar_names rhs src_loc)
 
     returnTc (tycon_name, SynTyDetails rhs_ty)
 
-tcTyDecl1 (TyData new_or_data context tycon_name _ con_decls _ derivings _  src_loc)
-  = tcLookupTy tycon_name                      `thenNF_Tc` \ (ATyCon tycon) ->
+tcTyDecl1 (TyData new_or_data context tycon_name _ con_decls _ derivings src_loc name1 name2)
+  = tcLookupTyCon tycon_name                   `thenNF_Tc` \ tycon ->
     let
        tyvars = tyConTyVars tycon
     in
@@ -90,10 +93,7 @@ tcTyDecl1 (TyData new_or_data context tycon_name _ con_decls _ derivings _  src_
     returnTc (tycon_name, DataTyDetails ctxt data_cons derived_classes)
   where
     tc_derivs Nothing   = returnTc []
-    tc_derivs (Just ds) = mapTc tc_deriv ds
-
-    tc_deriv name = tcLookupTy name `thenTc` \ (AClass clas) ->
-                   returnTc clas
+    tc_derivs (Just ds) = mapTc tcLookupClass ds
 \end{code}
 
 \begin{code}
@@ -125,7 +125,7 @@ mkNewTyConRep tc
 %************************************************************************
 
 \begin{code}
-kcConDetails :: RenamedContext -> ConDetails Name -> TcM s ()
+kcConDetails :: RenamedContext -> ConDetails Name -> TcM ()
 kcConDetails ex_ctxt details
   = kcHsContext ex_ctxt                `thenTc_`
     kc_con_details details
@@ -138,15 +138,11 @@ kcConDetails ex_ctxt details
 
     kc_bty bty = kcHsSigType (getBangType bty)
 
-tcConDecl :: NewOrData -> TyCon -> [TyVar] -> ClassContext -> RenamedConDecl -> TcM s DataCon
+tcConDecl :: NewOrData -> TyCon -> [TyVar] -> ClassContext -> RenamedConDecl -> TcM DataCon
 
 tcConDecl new_or_data tycon tyvars ctxt (ConDecl name wkr_name ex_tvs ex_ctxt details src_loc)
   = tcAddSrcLoc src_loc                                        $
-    kcTyVarScope ex_tvs (kcConDetails ex_ctxt details) `thenTc` \ ex_tv_kinds ->
-    let
-       ex_tyvars = mkImmutTyVars ex_tv_kinds
-    in
-    tcExtendTyVarEnv ex_tyvars                         $
+    tcHsTyVars ex_tvs (kcConDetails ex_ctxt details)   $ \ ex_tyvars ->
     tcClassContext ex_ctxt                             `thenTc` \ ex_theta ->
     case details of
        VanillaCon btys    -> tc_datacon ex_tyvars ex_theta btys
@@ -220,7 +216,7 @@ getBangStrictness (Unpacked _) = markedUnboxed
 %************************************************************************
 
 \begin{code}
-mkImplicitDataBinds :: [TyCon] -> TcM s ([Id], TcMonoBinds)
+mkImplicitDataBinds :: [TyCon] -> TcM ([Id], TcMonoBinds)
 mkImplicitDataBinds [] = returnTc ([], EmptyMonoBinds)
 mkImplicitDataBinds (tycon : tycons) 
   | isSynTyCon tycon = mkImplicitDataBinds tycons
@@ -231,8 +227,8 @@ mkImplicitDataBinds (tycon : tycons)
 mkImplicitDataBinds_one tycon
   = mapTc (mkRecordSelector tycon) groups      `thenTc` \ sel_ids ->
     let
-       unf_ids = sel_ids ++ data_con_wrapper_ids
-       all_ids = map dataConId data_cons ++ unf_ids 
+       unf_ids = sel_ids ++ data_con_wrapper_ids ++ gen_ids
+       all_ids = map dataConId data_cons ++ unf_ids
 
        -- For the locally-defined things
        -- we need to turn the unfoldings inside the selector Ids into bindings,
@@ -245,7 +241,7 @@ mkImplicitDataBinds_one tycon
     data_cons = tyConDataConsIfAvailable tycon
        -- Abstract types mean we don't bring the 
        -- data cons into scope, which should be fine
-
+    gen_ids = tyConGenIds tycon
     data_con_wrapper_ids = map dataConWrapId data_cons
 
     fields = [ (con, field) | con   <- data_cons,
@@ -267,8 +263,8 @@ mkRecordSelector tycon fields@((first_con, first_field_label) : other_fields)
        -- data type use the same type variables
   = checkTc (all (== field_ty) other_tys)
            (fieldTypeMisMatch field_name)      `thenTc_`
-    tcLookupValueByKey unpackCStringIdKey      `thenTc` \ unpack_id ->
-    tcLookupValueByKey unpackCStringUtf8IdKey  `thenTc` \ unpackUtf8_id ->
+    tcLookupGlobalId unpackCStringName         `thenTc` \ unpack_id ->
+    tcLookupGlobalId unpackCStringUtf8Name     `thenTc` \ unpackUtf8_id ->
     returnTc (mkRecordSelId tycon first_field_label unpack_id unpackUtf8_id)
   where
     field_ty   = fieldLabelType first_field_label