2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1996
4 \section[SaLib]{Basic datatypes, functions for the strictness analyser}
6 See also: the ``library'' for the ``back end'' (@SaBackLib@).
12 AbsValEnv{-abstract-}, StrictEnv, AbsenceEnv,
13 nullAbsValEnv, addOneToAbsValEnv, growAbsValEnvList,
18 #include "HsVersions.h"
20 import CoreSyn ( CoreExpr )
21 import Id ( nullIdEnv, addOneToIdEnv, growIdEnvList,
25 import IdInfo ( StrictnessInfo(..) )
26 import Demand ( Demand{-instance Outputable-} )
30 %************************************************************************
32 \subsection[AbsVal-datatype]{@AbsVal@: abstract values (and @AbsValEnv@)}
34 %************************************************************************
36 @AnalysisKind@ tells what kind of analysis is being done.
40 = StrAnal -- We're doing strictness analysis
41 | AbsAnal -- We're doing absence analysis
45 @AbsVal@ is the data type of HNF abstract values.
49 = AbsTop -- AbsTop is the completely uninformative
52 | AbsBot -- An expression whose abstract value is
53 -- AbsBot is sure to fail to terminate.
54 -- AbsBot represents the abstract
55 -- *function* bottom too.
57 | AbsProd [AbsVal] -- (Lifted) product of abstract values
58 -- "Lifted" means that AbsBot is *different* from
59 -- AbsProd [AbsBot, ..., AbsBot]
61 | AbsFun -- An abstract function, with the given:
64 AbsValEnv -- and environment
66 | AbsApproxFun -- This is used to represent a coarse
67 Demand -- approximation to a function value. It's an
68 AbsVal -- abstract function which is strict in its
69 -- argument if the Demand so indicates.
71 instance Outputable AbsVal where
72 ppr AbsTop = ptext SLIT("AbsTop")
73 ppr AbsBot = ptext SLIT("AbsBot")
74 ppr (AbsProd prod) = hsep [ptext SLIT("AbsProd"), ppr prod]
75 ppr (AbsFun arg body env)
76 = hsep [ptext SLIT("AbsFun{"), ppr arg,
77 ptext SLIT("???"), -- text "}{env:", ppr (keysFM env `zip` eltsFM env),
79 ppr (AbsApproxFun demand val)
80 = hsep [ptext SLIT("AbsApprox "), ppr demand, ppr val]
85 An @AbsValEnv@ maps @Ids@ to @AbsVals@. Any unbound @Ids@ are
86 implicitly bound to @AbsTop@, the completely uninformative,
87 pessimistic value---see @absEval@ of a @Var@.
90 newtype AbsValEnv = AbsValEnv (IdEnv AbsVal)
92 type StrictEnv = AbsValEnv -- Environment for strictness analysis
93 type AbsenceEnv = AbsValEnv -- Environment for absence analysis
95 nullAbsValEnv -- this is the one and only way to create AbsValEnvs
98 addOneToAbsValEnv (AbsValEnv idenv) y z = AbsValEnv (addOneToIdEnv idenv y z)
99 growAbsValEnvList (AbsValEnv idenv) ys = AbsValEnv (growIdEnvList idenv ys)
101 lookupAbsValEnv (AbsValEnv idenv) y
102 = lookupIdEnv idenv y
106 absValFromStrictness :: AnalysisKind -> StrictnessInfo -> AbsVal
108 absValFromStrictness anal NoStrictnessInfo = AbsTop
110 absValFromStrictness StrAnal BottomGuaranteed = AbsBot -- Guaranteed bottom
111 absValFromStrictness AbsAnal BottomGuaranteed = AbsTop -- Check for poison in
112 -- arguments (if any)
113 absValFromStrictness anal (StrictnessInfo args_info _) = foldr AbsApproxFun AbsTop args_info