\section[TcIfaceSig]{Type checking of type signatures in interface files}
\begin{code}
-module TcIfaceSig ( tcInterfaceSigs, tcDelay, tcVar, tcCoreExpr, tcCoreLamBndrs ) where
+module TcIfaceSig ( tcInterfaceSigs,
+ tcDelay,
+ tcVar,
+ tcCoreExpr,
+ tcCoreLamBndrs,
+ tcCoreBinds ) where
#include "HsVersions.h"
import HsSyn ( TyClDecl(..), HsTupCon(..) )
+import TcHsSyn ( TypecheckedCoreBind )
import TcMonad
import TcMonoType ( tcIfaceType )
import TcEnv ( RecTcEnv, tcExtendTyVarEnv,
import Module ( Module )
import MkId ( mkFCallId )
import IdInfo
-import TyCon ( tyConDataCons )
-import DataCon ( DataCon, dataConId, dataConSig, dataConArgTys )
-import Type ( mkTyVarTys, splitTyConApp )
+import TyCon ( tyConDataCons, tyConTyVars )
+import DataCon ( DataCon, dataConWorkId, dataConExistentialTyVars, dataConArgTys )
+import Type ( Type, mkTyVarTys, splitTyConApp )
import TysWiredIn ( tupleCon )
import Var ( mkTyVar, tyVarKind )
import Name ( Name, nameIsLocalOrFrom )
tcIdInfo unf_env in_scope_vars name ty info_ins
= foldlTc tcPrag init_info info_ins
where
- -- set the CgInfo to something sensible but uninformative before
- -- we start, because the default CgInfo is a panic.
- init_info = vanillaIdInfo `setCgInfo` vanillaCgInfo
+ -- Set the CgInfo to something sensible but uninformative before
+ -- we start; default assumption is that it has CAFs
+ init_info = hasCafIdInfo
tcPrag info (HsNoCafRefs) = returnTc (info `setCafInfo` NoCafRefs)
-- Check for type consistency in the unfolding
tcGetSrcLoc `thenNF_Tc` \ src_loc ->
- getDOptsTc `thenTc` \ dflags ->
+ getDOptsTc `thenNF_Tc` \ dflags ->
case lintUnfolding dflags src_loc in_scope_vars core_expr' of
(Nothing,_) -> returnTc (Just core_expr') -- ignore warnings
(Just fail_msg,_) -> failWithTc ((doc <+> text "failed Lint") $$ fail_msg)
in
returnTc (mkApps (Var con_id) con_args)
where
- con_id = dataConId (tupleCon boxity arity)
+ con_id = dataConWorkId (tupleCon boxity arity)
tcCoreExpr (UfLam bndr body)
tcCoreAlt scrut_ty alt@(con, names, rhs)
= tcConAlt con `thenTc` \ con ->
let
- (main_tyvars, _, ex_tyvars, _, _, _) = dataConSig con
-
- (tycon, inst_tys) = splitTyConApp scrut_ty -- NB: not tcSplitTyConApp
+ ex_tyvars = dataConExistentialTyVars con
+ (tycon, inst_tys) = splitTyConApp scrut_ty -- NB: not tcSplitTyConApp
-- We are looking at Core here
- ex_tyvars' = [mkTyVar name (tyVarKind tv) | (name,tv) <- names `zip` ex_tyvars]
- ex_tys' = mkTyVarTys ex_tyvars'
- arg_tys = dataConArgTys con (inst_tys ++ ex_tys')
- id_names = dropList ex_tyvars names
+ main_tyvars = tyConTyVars tycon
+ ex_tyvars' = [mkTyVar name (tyVarKind tv) | (name,tv) <- names `zip` ex_tyvars]
+ ex_tys' = mkTyVarTys ex_tyvars'
+ arg_tys = dataConArgTys con (inst_tys ++ ex_tys')
+ id_names = dropList ex_tyvars names
arg_ids
#ifdef DEBUG
| not (equalLength id_names arg_tys)
Nothing -> pprPanic "tcCoreAlt" (ppr con_id))
\end{code}
+%************************************************************************
+%* *
+\subsection{Core decls}
+%* *
+%************************************************************************
+
+
+\begin{code}
+tcCoreBinds :: [RenamedTyClDecl] -> TcM [TypecheckedCoreBind]
+-- We don't assume the bindings are in dependency order
+-- So first build the environment, then check the RHSs
+tcCoreBinds ls = mapTc tcCoreBinder ls `thenTc` \ bndrs ->
+ tcExtendGlobalValEnv bndrs $
+ mapTc tcCoreBind ls
+
+tcCoreBinder (CoreDecl { tcdName = nm, tcdType = ty })
+ = tcIfaceType ty `thenTc` \ ty' ->
+ returnTc (mkLocalId nm ty')
+
+tcCoreBind (CoreDecl { tcdName = nm, tcdRhs = rhs })
+ = tcVar nm `thenTc` \ id ->
+ tcCoreExpr rhs `thenTc` \ rhs' ->
+ returnTc (id, rhs')
+\end{code}
+
+
\begin{code}
ifaceSigCtxt sig_name
= hsep [ptext SLIT("In an interface-file signature for"), ppr sig_name]