#include "HsVersions.h"
import HsSyn ( TyClDecl(..), HsTupCon(..) )
+import TcHsSyn ( TypecheckedCoreBind )
import TcMonad
import TcMonoType ( tcIfaceType )
import TcEnv ( RecTcEnv, tcExtendTyVarEnv,
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)
\begin{code}
-tcCoreBinds :: [RenamedTyClDecl]
- -> TcM [(Id, Type, CoreExpr)]
-tcCoreBinds ls = mapTc tcOne ls
- where
- tcOne (CoreDecl { tcdName = nm, tcdType = ty, tcdRhs = rhs }) =
- tcVar nm `thenTc` \ i ->
- tcIfaceType ty `thenTc` \ ty' ->
- tcCoreExpr rhs `thenTc` \ rhs' ->
- returnTc (i,ty',rhs')
-
+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]