[project @ 2002-07-30 11:49:17 by simonpj]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcIfaceSig.lhs
index 956096d..e52c8d7 100644 (file)
@@ -14,6 +14,7 @@ module TcIfaceSig ( tcInterfaceSigs,
 #include "HsVersions.h"
 
 import HsSyn           ( TyClDecl(..), HsTupCon(..) )
+import TcHsSyn         ( TypecheckedCoreBind )
 import TcMonad
 import TcMonoType      ( tcIfaceType )
 import TcEnv           ( RecTcEnv, tcExtendTyVarEnv, 
@@ -86,9 +87,9 @@ tcInterfaceSigs unf_env mod decls
 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)
 
@@ -379,20 +380,24 @@ tcConAlt (UfDataAlt con_name)
 
 
 \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]