Fix Haddock errors.
[ghc-hetmet.git] / compiler / coreSyn / CoreSubst.lhs
index 9cedf2d..ac95987 100644 (file)
@@ -6,13 +6,6 @@
 Utility functions on @Core@ syntax
 
 \begin{code}
-{-# OPTIONS -w #-}
--- The above warning supression flag is a temporary kludge.
--- While working on this module you are encouraged to remove it and fix
--- any warnings in the module. See
---     http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
--- for details
-
 module CoreSubst (
        -- Substitution stuff
        Subst, TvSubstEnv, IdSubstEnv, InScopeSet,
@@ -23,7 +16,7 @@ module CoreSubst (
 
        emptySubst, mkEmptySubst, mkSubst, substInScope, isEmptySubst, 
        extendIdSubst, extendIdSubstList, extendTvSubst, extendTvSubstList,
-       extendSubstList, zapSubstEnv,
+       extendSubst, extendSubstList, zapSubstEnv,
        extendInScope, extendInScopeList, extendInScopeIds, 
        isInScope,
 
@@ -50,8 +43,7 @@ import UniqSupply
 import Maybes
 import Outputable
 import PprCore         ()              -- Instances
-import Util
-import FastTypes
+import FastString
 
 import Data.List
 \end{code}
@@ -65,10 +57,10 @@ import Data.List
 
 \begin{code}
 data Subst 
-  = Subst InScopeSet   -- Variables in in scope (both Ids and TyVars)
-                       -- *after* applying the substitution
-         IdSubstEnv    -- Substitution for Ids
-         TvSubstEnv    -- Substitution for TyVars
+  = Subst InScopeSet  -- Variables in in scope (both Ids and TyVars) /after/
+                      -- applying the substitution
+          IdSubstEnv  -- Substitution for Ids
+          TvSubstEnv  -- Substitution for TyVars
 
        -- INVARIANT 1: The (domain of the) in-scope set is a superset
        --              of the free vars of the range of the substitution
@@ -172,24 +164,26 @@ extendTvSubstList :: Subst -> [(TyVar,Type)] -> Subst
 extendTvSubstList (Subst in_scope ids tvs) prs = Subst in_scope ids (extendVarEnvList tvs prs)
 
 extendSubstList :: Subst -> [(Var,CoreArg)] -> Subst
-extendSubstList subst [] 
-  = subst
-extendSubstList (Subst in_scope ids tvs) ((tv,Type ty):prs)
-  = ASSERT( isTyVar tv ) extendSubstList (Subst in_scope ids (extendVarEnv tvs tv ty)) prs
-extendSubstList (Subst in_scope ids tvs) ((id,expr):prs)
-  = ASSERT( isId id ) extendSubstList (Subst in_scope (extendVarEnv ids id expr) tvs) prs
+extendSubstList subst []             = subst
+extendSubstList subst ((var,rhs):prs) = extendSubstList (extendSubst subst var rhs) prs
+
+extendSubst :: Subst -> Var -> CoreArg -> Subst
+extendSubst (Subst in_scope ids tvs) tv (Type ty)
+  = ASSERT( isTyVar tv ) Subst in_scope ids (extendVarEnv tvs tv ty)
+extendSubst (Subst in_scope ids tvs) id expr
+  = ASSERT( isId id ) Subst in_scope (extendVarEnv ids id expr) tvs
 
 lookupIdSubst :: Subst -> Id -> CoreExpr
-lookupIdSubst (Subst in_scope ids tvs) v 
+lookupIdSubst (Subst in_scope ids _) v
   | not (isLocalId v) = Var v
   | Just e  <- lookupVarEnv ids       v = e
   | Just v' <- lookupInScope in_scope v = Var v'
        -- Vital! See Note [Extending the Subst]
-  | otherwise = WARN( True, ptext SLIT("CoreSubst.lookupIdSubst") <+> ppr v ) 
+  | otherwise = WARN( True, ptext (sLit "CoreSubst.lookupIdSubst") <+> ppr v ) 
                Var v
 
 lookupTvSubst :: Subst -> TyVar -> Type
-lookupTvSubst (Subst _ ids tvs) v = lookupVarEnv tvs v `orElse` Type.mkTyVarTy v
+lookupTvSubst (Subst _ _ tvs) v = lookupVarEnv tvs v `orElse` Type.mkTyVarTy v
 
 ------------------------------
 isInScope :: Var -> Subst -> Bool
@@ -216,9 +210,9 @@ Pretty printing, for debugging only
 \begin{code}
 instance Outputable Subst where
   ppr (Subst in_scope ids tvs) 
-       =  ptext SLIT("<InScope =") <+> braces (fsep (map ppr (varEnvElts (getInScopeVars in_scope))))
-       $$ ptext SLIT(" IdSubst   =") <+> ppr ids
-       $$ ptext SLIT(" TvSubst   =") <+> ppr tvs
+       =  ptext (sLit "<InScope =") <+> braces (fsep (map ppr (varEnvElts (getInScopeVars in_scope))))
+       $$ ptext (sLit " IdSubst   =") <+> ppr ids
+       $$ ptext (sLit " TvSubst   =") <+> ppr tvs
         <> char '>'
 \end{code}
 
@@ -343,7 +337,7 @@ substIdBndr rec_subst subst@(Subst in_scope env tvs) old_id
 
     no_change = id1 == old_id
        -- See Note [Extending the Subst]
-       -- *not* necessary to check mb_new_info and no_type_change
+       -- it's /not/ necessary to check mb_new_info and no_type_change
 \end{code}
 
 Now a variant that unconditionally allocates a new unique.
@@ -398,7 +392,7 @@ substTyVarBndr (Subst in_scope id_env tv_env) tv
           -> (Subst in_scope' id_env tv_env', tv')
 
 substTy :: Subst -> Type -> Type 
-substTy (Subst in_scope id_env tv_env) ty 
+substTy (Subst in_scope _id_env tv_env) ty
   = Type.substTy (TvSubst in_scope tv_env) ty
 \end{code}
 
@@ -411,7 +405,7 @@ substTy (Subst in_scope id_env tv_env) ty
 
 \begin{code}
 substIdType :: Subst -> Id -> Id
-substIdType subst@(Subst in_scope id_env tv_env) id
+substIdType subst@(Subst _ _ tv_env) id
   | isEmptyVarEnv tv_env || isEmptyVarSet (Type.tyVarsOfType old_ty) = id
   | otherwise  = setIdType id (substTy subst old_ty)
                -- The tyVarsOfType is cheaper than it looks
@@ -441,7 +435,7 @@ substWorker :: Subst -> WorkerInfo -> WorkerInfo
        -- Seq'ing on the returned WorkerInfo is enough to cause all the 
        -- substitutions to happen completely
 
-substWorker subst NoWorker
+substWorker _ NoWorker
   = NoWorker
 substWorker subst (HasWorker w a)
   = case lookupIdSubst subst w of
@@ -473,6 +467,7 @@ substSpec subst new_fn spec@(SpecInfo rules rhs_fvs)
          (subst', bndrs') = substBndrs subst bndrs
 
 ------------------
+substVarSet :: Subst -> VarSet -> VarSet
 substVarSet subst fvs 
   = foldVarSet (unionVarSet . subst_fv subst) emptyVarSet fvs
   where