Split the Id related functions out from Var into Id, document Var and some of Id
[ghc-hetmet.git] / compiler / coreSyn / CoreSyn.lhs
index 6953a52..ea22eb5 100644 (file)
@@ -20,9 +20,8 @@ module CoreSyn (
        isTyVar, isId, cmpAltCon, cmpAlt, ltAlt,
        bindersOf, bindersOfBinds, rhssOfBind, rhssOfAlts, 
        collectBinders, collectTyBinders, collectValBinders, collectTyAndValBinders,
-       collectArgs, 
-       coreExprCc,
-       flattenBinds, 
+       collectArgs, coreExprCc,
+       mkTyBind, flattenBinds, 
 
        isValArg, isTypeArg, valArgCount, valBndrCount, isRuntimeArg, isRuntimeVar,
 
@@ -43,14 +42,14 @@ module CoreSyn (
        -- Core rules
        CoreRule(..),   -- CoreSubst, CoreTidy, CoreFVs, PprCore only
        RuleName, seqRules, ruleArity,
-       isBuiltinRule, ruleName, isLocalRule, ruleIdName
+       isBuiltinRule, ruleName, isLocalRule, ruleIdName, setRuleIdName
     ) where
 
 #include "HsVersions.h"
 
-import StaticFlags
 import CostCentre
 import Var
+import Id
 import Type
 import Coercion
 import Name
@@ -138,7 +137,7 @@ Invariant: The remaining cases are in order of increasing
 Invariant: The list of alternatives is ALWAYS EXHAUSTIVE,
           meaning that it covers all cases that can occur
 
-    An "exhausive" case does not necessarily mention all constructors:
+    An "exhaustive" case does not necessarily mention all constructors:
        data Foo = Red | Green | Blue
 
        ...case x of 
@@ -151,12 +150,23 @@ Invariant: The list of alternatives is ALWAYS EXHAUSTIVE,
 
 
 Note [CoreSyn let goal]
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~~~~~~
 * The simplifier tries to ensure that if the RHS of a let is a constructor
   application, its arguments are trivial, so that the constructor can be
   inlined vigorously.
 
 
+Note [Type let]
+~~~~~~~~~~~~~~~
+We allow a *non-recursive* let to bind a type variable, thus
+       Let (NonRec tv (Type ty)) body
+This can be very convenient for postponing type substitutions until
+the next run of the simplifier.
+
+At the moment, the rest of the compiler only deals with type-let
+in a Let expression, rather than at top level.  We may want to revist
+this choice.
+
 \begin{code}
 data Note
   = SCC CostCentre
@@ -196,8 +206,6 @@ A Rule is
           as the rule itself
 
 \begin{code}
-type RuleName = FastString
-
 data CoreRule
   = Rule { 
        ru_name :: RuleName,
@@ -253,6 +261,9 @@ ruleIdName = ru_fn
 
 isLocalRule :: CoreRule -> Bool
 isLocalRule = ru_local
+
+setRuleIdName :: Name -> CoreRule -> CoreRule
+setRuleIdName nm ru = ru { ru_fn = nm }
 \end{code}
 
 
@@ -389,7 +400,7 @@ neverUnfold _                                   = False
 instance Outputable AltCon where
   ppr (DataAlt dc) = ppr dc
   ppr (LitAlt lit) = ppr lit
-  ppr DEFAULT      = ptext SLIT("__DEFAULT")
+  ppr DEFAULT      = ptext (sLit "__DEFAULT")
 
 instance Show AltCon where
   showsPrec p con = showsPrecSDoc p (ppr con)
@@ -502,6 +513,11 @@ mkCast e co = Cast e co
 %************************************************************************
 
 \begin{code}
+mkTyBind :: TyVar -> Type -> CoreBind
+mkTyBind tv ty      = NonRec tv (Type ty)
+       -- Note [Type let]
+       -- A non-recursive let can bind a type variable
+
 bindersOf  :: Bind b -> [b]
 bindersOf (NonRec binder _) = [binder]
 bindersOf (Rec pairs)       = [binder | (binder, _) <- pairs]
@@ -591,23 +607,18 @@ coreExprCc _                   = noCostCentre
 %*                                                                     *
 %************************************************************************
 
+At one time we optionally carried type arguments through to runtime.
 @isRuntimeVar v@ returns if (Lam v _) really becomes a lambda at runtime,
 i.e. if type applications are actual lambdas because types are kept around
-at runtime.  
-
-Similarly isRuntimeArg.  
+at runtime.  Similarly isRuntimeArg.  
 
 \begin{code}
 isRuntimeVar :: Var -> Bool
-isRuntimeVar | opt_RuntimeTypes = \_ -> True
-            | otherwise        = \v -> isId v
+isRuntimeVar = isId 
 
 isRuntimeArg :: CoreExpr -> Bool
-isRuntimeArg | opt_RuntimeTypes = \_ -> True
-            | otherwise        = \e -> isValArg e
-\end{code}
+isRuntimeArg = isValArg
 
-\begin{code}
 isValArg :: Expr b -> Bool
 isValArg (Type _) = False
 isValArg _        = True
@@ -667,7 +678,7 @@ seqPairs ((b,e):prs) = seqBndr b `seq` seqExpr e `seq` seqPairs prs
 
 seqAlts :: [CoreAlt] -> ()
 seqAlts [] = ()
-seqAlts ((_,bs,e):alts) = seqBndrs bs `seq` seqExpr e `seq` seqAlts alts
+seqAlts ((c,bs,e):alts) = c `seq` seqBndrs bs `seq` seqExpr e `seq` seqAlts alts
 
 seqRules :: [CoreRule] -> ()
 seqRules [] = ()