X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FcoreSyn%2FCoreFVs.lhs;h=fc0d7bdb90aa160e16bef8a7912c7aa1f51525b9;hb=4161ba13916463f8e67259498eacf22744160e1f;hp=c501255e3fe1ec411b7baf1802485536bb7ddc3a;hpb=db95d6e8d319b0c5cee1ccc23751e8190152ade3;p=ghc-hetmet.git diff --git a/ghc/compiler/coreSyn/CoreFVs.lhs b/ghc/compiler/coreSyn/CoreFVs.lhs index c501255..fc0d7bd 100644 --- a/ghc/compiler/coreSyn/CoreFVs.lhs +++ b/ghc/compiler/coreSyn/CoreFVs.lhs @@ -5,20 +5,20 @@ Taken quite directly from the Peyton Jones/Lester paper. \begin{code} module CoreFVs ( + isLocalVar, mustHaveLocalBinding, + exprFreeVars, exprsFreeVars, exprSomeFreeVars, exprsSomeFreeVars, - idRuleVars, idFreeVars, + idRuleVars, idFreeVars, idFreeTyVars, ruleSomeFreeVars, ruleSomeLhsFreeVars, ruleRhsFreeVars, - mustHaveLocalBinding, - CoreExprWithFVs, CoreBindWithFVs, freeVars, freeVarsOf, ) where #include "HsVersions.h" import CoreSyn -import Id ( Id, idFreeTyVars, hasNoBinding, idSpecialisation ) +import Id ( Id, idName, idType, isLocalId, hasNoBinding, idSpecialisation ) import VarSet import Var ( Var, isId ) import Type ( tyVarsOfType ) @@ -29,6 +29,29 @@ import Outputable %************************************************************************ %* * +\subsection{isLocalVar} +%* * +%************************************************************************ + +@isLocalVar@ returns True of all TyVars, and of Ids that are defined in +this module and are not constants like data constructors and record selectors. +These are the variables that we need to pay attention to when finding free +variables, or doing dependency analysis. + +\begin{code} +isLocalVar :: Var -> Bool +isLocalVar v = isTyVar v || isLocalId v +\end{code} + +\begin{code} +mustHaveLocalBinding :: Var -> Bool +-- True <=> the variable must have a binding in this module +mustHaveLocalBinding v = isTyVar v || (isLocalId v && not (hasNoBinding v)) +\end{code} + + +%************************************************************************ +%* * \section{Finding the free variables of an expression} %* * %************************************************************************ @@ -138,12 +161,19 @@ expr_fvs (Let (Rec pairs) body) \begin{code} -idRuleVars ::Id -> VarSet -idRuleVars id = ASSERT( isId id) rulesRhsFreeVars (idSpecialisation id) - idFreeVars :: Id -> VarSet idFreeVars id = ASSERT( isId id) idRuleVars id `unionVarSet` idFreeTyVars id +idFreeTyVars :: Id -> TyVarSet +-- Only local Ids conjured up locally, can have free type variables. +-- (During type checking top-level Ids can have free tyvars) +idFreeTyVars id = tyVarsOfType (idType id) +-- | isLocalId id = tyVarsOfType (idType id) +-- | otherwise = emptyVarSet + +idRuleVars ::Id -> VarSet +idRuleVars id = ASSERT( isId id) rulesRhsFreeVars (idSpecialisation id) + rulesSomeFreeVars :: InterestingVarFun -> CoreRules -> VarSet rulesSomeFreeVars interesting (Rules rules _) = foldr (unionVarSet . ruleSomeFreeVars interesting) emptyVarSet rules