[project @ 2004-08-16 09:51:20 by simonpj]
[ghc-hetmet.git] / ghc / compiler / coreSyn / CoreTidy.lhs
index 7e50e9c..093067e 100644 (file)
@@ -9,8 +9,7 @@
 
 \begin{code}
 module CoreTidy (
-       tidyBind, tidyExpr, 
-       tidyBndr, tidyBndrs, tidyVarOcc,
+       tidyExpr, tidyVarOcc,
        tidyIdRules, pprTidyIdRules
     ) where
 
@@ -19,8 +18,9 @@ module CoreTidy (
 import CoreSyn
 import CoreUtils       ( exprArity )
 import PprCore         ( pprIdRules )
-import Id              ( Id, mkUserLocal, idInfo, setIdInfo, idUnique, idType, idCoreRules )
-import IdInfo          ( vanillaIdInfo, setArityInfo, 
+import Id              ( Id, mkUserLocal, idInfo, setIdInfo, idUnique,
+                         idType, idCoreRules )
+import IdInfo          ( setArityInfo, vanillaIdInfo,
                          newStrictnessInfo, setAllStrictnessInfo,
                          newDemandInfo, setNewDemandInfo )
 import Type            ( tidyType, tidyTyVarBndr )
@@ -35,6 +35,9 @@ import Util           ( mapAccumL )
 \end{code}
 
 
+This module contains "tidying" code for *nested* expressions, bindings, rules.
+The code for *top-level* bindings is in TidyPgm.
+
 %************************************************************************
 %*                                                                     *
 \subsection{Tidying expressions, rules}
@@ -47,19 +50,17 @@ tidyBind :: TidyEnv
         ->  (TidyEnv, CoreBind)
 
 tidyBind env (NonRec bndr rhs)
-  = tidyLetBndr env (bndr,rhs)         =: \ (env', bndr') ->
+  = tidyLetBndr env (bndr,rhs) =: \ (env', bndr') ->
     (env', NonRec bndr' (tidyExpr env' rhs))
 
 tidyBind env (Rec prs)
-  = mapAccumL tidyLetBndr env prs      =: \ (env', bndrs') ->
+  = mapAccumL tidyLetBndr  env prs     =: \ (env', bndrs') ->
     map (tidyExpr env') (map snd prs)  =: \ rhss' ->
     (env', Rec (zip bndrs' rhss'))
 
 
 ------------  Expressions  --------------
-tidyCoreExpr :: CoreExpr -> IO CoreExpr
-tidyCoreExpr expr = return (tidyExpr emptyTidyEnv expr)
-
+tidyExpr :: TidyEnv -> CoreExpr -> CoreExpr
 tidyExpr env (Var v)           =  Var (tidyVarOcc env v)
 tidyExpr env (Type ty)         =  Type (tidyType env ty)
 tidyExpr env (Lit lit)         =  Lit lit
@@ -134,8 +135,9 @@ tidyLetBndr env (id,rhs)
   where
     ((tidy_env,var_env), new_id) = tidyIdBndr env id
 
-       -- We need to keep around any interesting strictness and demand info
-       -- because later on we may need to use it when converting to A-normal form.
+       -- We need to keep around any interesting strictness and
+       -- demand info because later on we may need to use it when
+       -- converting to A-normal form.
        -- eg.
        --      f (g x),  where f is strict in its argument, will be converted
        --      into  case (g x) of z -> f z  by CorePrep, but only if f still
@@ -145,9 +147,10 @@ tidyLetBndr env (id,rhs)
        -- CorePrep to turn the let into a case.
        --
        -- Similarly arity info for eta expansion in CorePrep
+       --
     final_id = new_id `setIdInfo` new_info
     idinfo   = idInfo id
-    new_info = vanillaIdInfo 
+    new_info = vanillaIdInfo
                `setArityInfo`          exprArity rhs
                `setAllStrictnessInfo`  newStrictnessInfo idinfo
                `setNewDemandInfo`      newDemandInfo idinfo
@@ -167,10 +170,12 @@ tidyIdBndr env@(tidy_env, var_env) id
        -- The SrcLoc isn't important now, 
        -- though we could extract it from the Id
        -- 
-       -- All nested Ids now have the same IdInfo, namely none,
+       -- All nested Ids now have the same IdInfo, namely vanillaIdInfo,
        -- which should save some space.
+       -- But note that tidyLetBndr puts some of it back.
         ty'              = tidyType env (idType id)
        id'               = mkUserLocal occ' (idUnique id) ty' noSrcLoc
+                               `setIdInfo` vanillaIdInfo
        var_env'          = extendVarEnv var_env id id'
     in
      ((tidy_env', var_env'), id')
@@ -180,5 +185,3 @@ tidyIdBndr env@(tidy_env, var_env) id
 \begin{code}
 m =: k = m `seq` k m
 \end{code}
-
-