X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2Fstranal%2FSaLib.lhs;h=ac9c267916ab8dfb68c2a1b54f1d451e7b3abeed;hb=e0b2097136f30331bae67cb01e66bba749d272c1;hp=9b6751ccc7e5ce55137a40651b352dda4d076ecb;hpb=2c8f04b5b883db74f449dfc8c224929fe28b027d;p=ghc-hetmet.git diff --git a/ghc/compiler/stranal/SaLib.lhs b/ghc/compiler/stranal/SaLib.lhs index 9b6751c..ac9c267 100644 --- a/ghc/compiler/stranal/SaLib.lhs +++ b/ghc/compiler/stranal/SaLib.lhs @@ -1,5 +1,5 @@ % -% (c) The GRASP/AQUA Project, Glasgow University, 1993-1996 +% (c) The GRASP/AQUA Project, Glasgow University, 1993-1998 % \section[SaLib]{Basic datatypes, functions for the strictness analyser} @@ -10,6 +10,7 @@ module SaLib ( AbsVal(..), AnalysisKind(..), AbsValEnv{-abstract-}, StrictEnv, AbsenceEnv, + mkAbsApproxFun, nullAbsValEnv, addOneToAbsValEnv, growAbsValEnvList, lookupAbsValEnv, absValFromStrictness @@ -17,13 +18,10 @@ module SaLib ( #include "HsVersions.h" -import CoreSyn ( CoreExpr ) -import Id ( nullIdEnv, addOneToIdEnv, growIdEnvList, - lookupIdEnv, IdEnv, - Id - ) +import Type ( Type ) +import VarEnv import IdInfo ( StrictnessInfo(..) ) -import Demand ( Demand{-instance Outputable-} ) +import Demand ( Demand ) import Outputable \end{code} @@ -39,7 +37,7 @@ import Outputable data AnalysisKind = StrAnal -- We're doing strictness analysis | AbsAnal -- We're doing absence analysis - deriving Text + deriving Show \end{code} @AbsVal@ is the data type of HNF abstract values. @@ -59,25 +57,31 @@ data AbsVal -- AbsProd [AbsBot, ..., AbsBot] | AbsFun -- An abstract function, with the given: - Id -- argument - CoreExpr -- body - AbsValEnv -- and environment + Type -- Type of the *argument* to the function + (AbsVal -> AbsVal) -- The function | AbsApproxFun -- This is used to represent a coarse - Demand -- approximation to a function value. It's an + [Demand] -- approximation to a function value. It's an AbsVal -- abstract function which is strict in its - -- argument if the Demand so indicates. + -- arguments if the Demand so indicates. + -- INVARIANT: the [Demand] is non-empty + + -- AbsApproxFun has to take a *list* of demands, no just one, + -- because function spaces are now lifted. Hence, (f bot top) + -- might be bot, but the partial application (f bot) is a *function*, + -- not bot. + +mkAbsApproxFun :: Demand -> AbsVal -> AbsVal +mkAbsApproxFun d (AbsApproxFun ds val) = AbsApproxFun (d:ds) val +mkAbsApproxFun d val = AbsApproxFun [d] val instance Outputable AbsVal where ppr AbsTop = ptext SLIT("AbsTop") ppr AbsBot = ptext SLIT("AbsBot") ppr (AbsProd prod) = hsep [ptext SLIT("AbsProd"), ppr prod] - ppr (AbsFun arg body env) - = hsep [ptext SLIT("AbsFun{"), ppr arg, - ptext SLIT("???"), -- text "}{env:", ppr (keysFM env `zip` eltsFM env), - char '}' ] - ppr (AbsApproxFun demand val) - = hsep [ptext SLIT("AbsApprox "), ppr demand, ppr val] + ppr (AbsFun bndr_ty body) = ptext SLIT("AbsFun") + ppr (AbsApproxFun demands val) + = ptext SLIT("AbsApprox") <+> brackets (interpp'SP demands) <+> ppr val \end{code} %----------- @@ -93,22 +97,26 @@ type StrictEnv = AbsValEnv -- Environment for strictness analysis type AbsenceEnv = AbsValEnv -- Environment for absence analysis nullAbsValEnv -- this is the one and only way to create AbsValEnvs - = AbsValEnv nullIdEnv + = AbsValEnv emptyVarEnv -addOneToAbsValEnv (AbsValEnv idenv) y z = AbsValEnv (addOneToIdEnv idenv y z) -growAbsValEnvList (AbsValEnv idenv) ys = AbsValEnv (growIdEnvList idenv ys) +addOneToAbsValEnv (AbsValEnv idenv) y z = AbsValEnv (extendVarEnv idenv y z) +growAbsValEnvList (AbsValEnv idenv) ys = AbsValEnv (extendVarEnvList idenv ys) lookupAbsValEnv (AbsValEnv idenv) y - = lookupIdEnv idenv y + = lookupVarEnv idenv y \end{code} \begin{code} absValFromStrictness :: AnalysisKind -> StrictnessInfo -> AbsVal -absValFromStrictness anal NoStrictnessInfo = AbsTop - -absValFromStrictness StrAnal BottomGuaranteed = AbsBot -- Guaranteed bottom -absValFromStrictness AbsAnal BottomGuaranteed = AbsTop -- Check for poison in - -- arguments (if any) -absValFromStrictness anal (StrictnessInfo args_info _) = foldr AbsApproxFun AbsTop args_info +absValFromStrictness anal NoStrictnessInfo = AbsTop +absValFromStrictness anal (StrictnessInfo args_info bot_result) + = case args_info of -- Check the invariant that the arg list on + [] -> res -- AbsApproxFun is non-empty + _ -> AbsApproxFun args_info res + where + res | not bot_result = AbsTop + | otherwise = case anal of + StrAnal -> AbsBot + AbsAnal -> AbsTop \end{code}