[project @ 2001-11-26 10:33:40 by simonpj]
[ghc-hetmet.git] / ghc / compiler / typecheck / TcIfaceSig.lhs
index 8b255e4..ebfd83f 100644 (file)
@@ -4,7 +4,7 @@
 \section[TcIfaceSig]{Type checking of type signatures in interface files}
 
 \begin{code}
-module TcIfaceSig ( tcInterfaceSigs, tcVar, tcCoreExpr, tcCoreLamBndrs ) where
+module TcIfaceSig ( tcInterfaceSigs, tcDelay, tcVar, tcCoreExpr, tcCoreLamBndrs ) where
 
 #include "HsVersions.h"
 
@@ -35,10 +35,9 @@ import Type          ( mkTyVarTys, splitTyConApp )
 import TysWiredIn      ( tupleCon )
 import Var             ( mkTyVar, tyVarKind )
 import Name            ( Name, nameIsLocalOrFrom )
-import Demand          ( wwLazy )
 import ErrUtils                ( pprBagOfErrors )
 import Outputable      
-import Util            ( zipWithEqual )
+import Util            ( zipWithEqual, dropList, equalLength )
 import HscTypes                ( TyThing(..) )
 \end{code}
 
@@ -87,11 +86,9 @@ tcIdInfo unf_env in_scope_vars name ty info_ins
     init_info = vanillaIdInfo `setCgInfo` vanillaCgInfo
 
     tcPrag info (HsNoCafRefs)   = returnTc (info `setCafInfo`   NoCafRefs)
-    tcPrag info HsCprInfo       = returnTc (info `setCprInfo`   ReturnsCPR)
 
     tcPrag info (HsArity arity) = 
-       returnTc (info `setArityInfo` arity
-                      `setCgArity`   arity)
+       returnTc (info `setArityInfo` arity)
 
     tcPrag info (HsUnfold inline_prag expr)
        = tcPragExpr unf_env name in_scope_vars expr    `thenNF_Tc` \ maybe_expr' ->
@@ -107,7 +104,7 @@ tcIdInfo unf_env in_scope_vars name ty info_ins
          returnTc info2
 
     tcPrag info (HsStrictness strict_info)
-       = returnTc (info `setStrictnessInfo` strict_info)
+       = returnTc (info `setAllStrictnessInfo` Just strict_info)
 
     tcPrag info (HsWorker nm arity)
        = tcWorkerInfo unf_env ty info nm arity
@@ -115,7 +112,7 @@ tcIdInfo unf_env in_scope_vars name ty info_ins
 
 \begin{code}
 tcWorkerInfo unf_env ty info worker_name arity
-  = uniqSMToTcM (mkWrapper ty arity demands res_bot cpr_info) `thenNF_Tc` \ wrap_fn ->
+  = uniqSMToTcM (mkWrapper ty strict_sig) `thenNF_Tc` \ wrap_fn ->
     let
        -- Watch out! We can't pull on unf_env too eagerly!
        info' = case tcLookupRecId_maybe unf_env worker_name of
@@ -128,15 +125,11 @@ tcWorkerInfo unf_env ty info worker_name arity
     in
     returnTc info'
   where
-       -- We are relying here on cpr and strictness info always appearing 
+       -- We are relying here on strictness info always appearing 
        -- before worker info,  fingers crossed ....
-      cpr_info   = cprInfo info
-
-      (demands, res_bot)
-       = case strictnessInfo info of
-               StrictnessInfo d r -> (d,r)
-               _                  -> (take arity (repeat wwLazy),False)
-                                       -- Noncommittal
+      strict_sig = case newStrictnessInfo info of
+                       Just sig -> sig
+                       Nothing  -> pprPanic "Worker info but no strictness for" (ppr worker_name)
 \end{code}
 
 For unfoldings we try to do the job lazily, so that we never type check
@@ -144,24 +137,23 @@ an unfolding that isn't going to be looked at.
 
 \begin{code}
 tcPragExpr unf_env name in_scope_vars expr
-  = tcDelay unf_env doc $
+  = tcDelay unf_env doc Nothing $
        tcCoreExpr expr         `thenTc` \ core_expr' ->
 
                -- Check for type consistency in the unfolding
        tcGetSrcLoc             `thenNF_Tc` \ src_loc -> 
        getDOptsTc              `thenTc` \ dflags ->
        case lintUnfolding dflags src_loc in_scope_vars core_expr' of
-         (Nothing,_)       -> returnTc core_expr'  -- ignore warnings
+         (Nothing,_)       -> returnTc (Just core_expr')  -- ignore warnings
          (Just fail_msg,_) -> failWithTc ((doc <+> text "failed Lint") $$ fail_msg)
   where
     doc = text "unfolding of" <+> ppr name
 
-tcDelay :: RecTcEnv -> SDoc -> TcM a -> NF_TcM (Maybe a)
-tcDelay unf_env doc thing_inside
+tcDelay :: RecTcEnv -> SDoc -> a -> TcM a -> NF_TcM a
+tcDelay unf_env doc bad_ans thing_inside
   = forkNF_Tc (
        recoverNF_Tc bad_value (
-               tcSetEnv unf_env thing_inside   `thenTc` \ r ->
-               returnTc (Just r)
+               tcSetEnv unf_env thing_inside
     ))                 
   where
        -- The trace tells what wasn't available, for the benefit of
@@ -169,7 +161,7 @@ tcDelay unf_env doc thing_inside
     bad_value = getErrsTc              `thenNF_Tc` \ (warns,errs) ->
                returnNF_Tc (pprTrace "Failed:" 
                                         (hang doc 4 (pprBagOfErrors errs))
-                                        Nothing)
+                                        bad_ans)
 \end{code}
 
 
@@ -345,10 +337,10 @@ tcCoreAlt scrut_ty alt@(con, names, rhs)
        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            = drop (length ex_tyvars) names
+       id_names            = dropList ex_tyvars names
        arg_ids
 #ifdef DEBUG
-               | length id_names /= length arg_tys
+               | not (equalLength id_names arg_tys)
                = pprPanic "tcCoreAlts" (ppr (con, names, rhs) $$
                                         (ppr main_tyvars <+> ppr ex_tyvars) $$
                                         ppr arg_tys)
@@ -356,7 +348,7 @@ tcCoreAlt scrut_ty alt@(con, names, rhs)
 #endif
                = zipWithEqual "tcCoreAlts" mkLocalId id_names arg_tys
     in
-    ASSERT( con `elem` tyConDataCons tycon && length inst_tys == length main_tyvars )
+    ASSERT( con `elem` tyConDataCons tycon && equalLength inst_tys main_tyvars )
     tcExtendTyVarEnv ex_tyvars'                        $
     tcExtendGlobalValEnv arg_ids               $
     tcCoreExpr rhs                                     `thenTc` \ rhs' ->