Store a SrcSpan instead of a SrcLoc inside a Name
[ghc-hetmet.git] / compiler / coreSyn / CoreTidy.lhs
index ba60466..95c3ac4 100644 (file)
@@ -1,7 +1,11 @@
 %
+% (c) The University of Glasgow 2006
 % (c) The AQUA Project, Glasgow University, 1996-1998
 %
 
+This module contains "tidying" code for *nested* expressions, bindings, rules.
+The code for *top-level* bindings is in TidyPgm.
+
 \begin{code}
 module CoreTidy (
        tidyExpr, tidyVarOcc, tidyRule, tidyRules 
@@ -10,30 +14,21 @@ module CoreTidy (
 #include "HsVersions.h"
 
 import CoreSyn
-import CoreUtils       ( exprArity )
-import Unify           ( coreRefineTys )
-import DataCon         ( DataCon, isVanillaDataCon )
-import Id              ( Id, mkUserLocal, idInfo, setIdInfo, idUnique,
-                         idType, setIdType )
-import IdInfo          ( setArityInfo, vanillaIdInfo,
-                         newStrictnessInfo, setAllStrictnessInfo,
-                         newDemandInfo, setNewDemandInfo )
-import Type            ( Type, tidyType, tidyTyVarBndr, substTy, mkOpenTvSubst )
-import Var             ( Var, TyVar, varName )
+import CoreUtils
+import Id
+import IdInfo
+import Type
+import Var
 import VarEnv
-import UniqFM          ( lookupUFM )
-import Name            ( Name, getOccName )
-import OccName         ( tidyOccName )
-import SrcLoc          ( noSrcLoc )
-import Maybes          ( orElse )
-import Outputable
-import Util            ( mapAccumL )
+import UniqFM
+import Name hiding (tidyNameOcc)
+import OccName
+import SrcLoc
+import Maybes
+import Util
 \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}
@@ -57,11 +52,12 @@ tidyBind env (Rec prs)
 
 ------------  Expressions  --------------
 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
-tidyExpr env (App f a)         =  App (tidyExpr env f) (tidyExpr env a)
-tidyExpr env (Note n e) =  Note (tidyNote env n) (tidyExpr env e)
+tidyExpr env (Var v)            =  Var (tidyVarOcc env v)
+tidyExpr env (Type ty)          =  Type (tidyType env ty)
+tidyExpr env (Lit lit)          =  Lit lit
+tidyExpr env (App f a)          =  App (tidyExpr env f) (tidyExpr env a)
+tidyExpr env (Note n e)  =  Note (tidyNote env n) (tidyExpr env e)
+tidyExpr env (Cast e co) =  Cast (tidyExpr env e) (tidyType env co)
 
 tidyExpr env (Let b e) 
   = tidyBind env b     =: \ (env', b') ->
@@ -77,42 +73,11 @@ tidyExpr env (Lam b e)
     Lam b (tidyExpr env' e)
 
 ------------  Case alternatives  --------------
-tidyAlt case_bndr env (DataAlt con, vs, rhs)
-  | not (isVanillaDataCon con) -- GADT case
-  = tidyBndrs env tvs          =: \ (env1, tvs') ->
-    let 
-       env2 = refineTidyEnv env con tvs' scrut_ty
-    in
-    tidyBndrs env2 ids         =: \ (env3, ids') ->
-    (DataAlt con, tvs' ++ ids', tidyExpr env3 rhs)
-  where 
-    (tvs, ids) = span isTyVar vs
-    scrut_ty = idType case_bndr
-
 tidyAlt case_bndr env (con, vs, rhs)
   = tidyBndrs env vs   =: \ (env', vs) ->
     (con, vs, tidyExpr env' rhs)
 
-refineTidyEnv :: TidyEnv -> DataCon -> [TyVar] -> Type -> TidyEnv
--- Refine the TidyEnv in the light of the type refinement from coreRefineTys
-refineTidyEnv tidy_env@(occ_env, var_env)  con tvs scrut_ty
-  = case coreRefineTys con tvs scrut_ty of
-       Nothing -> tidy_env
-       Just (tv_subst, all_bound_here)
-           | all_bound_here    -- Local type refinement only
-           -> tidy_env
-           | otherwise         -- Apply the refining subst to the tidy env
-                               -- This ensures that occurences have the most refined type
-                               -- And that means that exprType will work right everywhere
-           -> (occ_env, mapVarEnv (refine subst) var_env)
-           where
-             subst = mkOpenTvSubst tv_subst
-  where
-    refine subst var | isId var  = setIdType var (substTy subst (idType var)) 
-                    | otherwise = var
-
 ------------  Notes  --------------
-tidyNote env (Coerce t1 t2)  = Coerce (tidyType env t1) (tidyType env t2)
 tidyNote env note            = note
 
 ------------  Rules  --------------
@@ -148,7 +113,7 @@ tidyNameOcc :: TidyEnv -> Name -> Name
 -- Fortunately, we can lookup in the VarEnv with a name
 tidyNameOcc (_, var_env) n = case lookupUFM var_env n of
                                Nothing -> n
-                               Just v  -> varName v
+                               Just v  -> idName v
 
 tidyVarOcc :: TidyEnv -> Var -> Var
 tidyVarOcc (_, var_env) v = lookupVarEnv var_env v `orElse` v
@@ -181,13 +146,16 @@ tidyLetBndr env (id,rhs)
        -- CorePrep to turn the let into a case.
        --
        -- Similarly arity info for eta expansion in CorePrep
-       --
+       -- 
+       -- Set inline-prag info so that we preseve it across 
+       -- separate compilation boundaries
     final_id = new_id `setIdInfo` new_info
     idinfo   = idInfo id
     new_info = vanillaIdInfo
                `setArityInfo`          exprArity rhs
                `setAllStrictnessInfo`  newStrictnessInfo idinfo
                `setNewDemandInfo`      newDemandInfo idinfo
+               `setInlinePragInfo`     inlinePragInfo idinfo
 
     -- Override the env we get back from tidyId with the new IdInfo
     -- so it gets propagated to the usage sites.
@@ -208,7 +176,7 @@ tidyIdBndr env@(tidy_env, var_env) id
        -- 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
+       id'               = mkUserLocal occ' (idUnique id) ty' noSrcSpan
                                `setIdInfo` vanillaIdInfo
        var_env'          = extendVarEnv var_env id id'
     in