2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1995
4 \section[SaLib]{Basic datatypes, functions for the strictness analyser}
6 See also: the ``library'' for the ``back end'' (@SaBackLib@).
9 #include "HsVersions.h"
14 AbsValEnv{-abstract-}, StrictEnv(..), AbsenceEnv(..),
15 StrAnalFlags(..), getStrAnalFlags,
16 nullAbsValEnv, addOneToAbsValEnv, growAbsValEnvList,
20 -- and to make the interface self-sufficient...
28 %************************************************************************
30 \subsection[AbsVal-datatype]{@AbsVal@: abstract values (and @AbsValEnv@)}
32 %************************************************************************
34 @AnalysisKind@ tells what kind of analysis is being done.
38 = StrAnal -- We're doing strictness analysis
39 | AbsAnal -- We're doing absence analysis
43 @AbsVal@ is the data type of HNF abstract values.
47 = AbsTop -- AbsTop is the completely uninformative
50 | AbsBot -- An expression whose abstract value is
51 -- AbsBot is sure to fail to terminate.
52 -- AbsBot represents the abstract
53 -- *function* bottom too.
55 | AbsProd [AbsVal] -- (Lifted) product of abstract values
56 -- "Lifted" means that AbsBot is *different* from
57 -- AbsProd [AbsBot, ..., AbsBot]
59 | AbsFun -- An abstract function, with the given:
62 AbsValEnv -- and environment
64 | AbsApproxFun -- This is used to represent a coarse
65 [Demand] -- approximation to a function value. It's an
66 -- abstract function which is strict in its i'th
67 -- argument if the i'th element of the Demand
69 -- The list of arguments is always non-empty.
70 -- In effect, AbsApproxFun [] = AbsTop
72 instance Outputable AbsVal where
73 ppr sty AbsTop = ppStr "AbsTop"
74 ppr sty AbsBot = ppStr "AbsBot"
75 ppr sty (AbsProd prod) = ppCat [ppStr "AbsProd", ppr sty prod]
76 ppr sty (AbsFun args body env)
77 = ppCat [ppStr "AbsFun{", ppr sty args,
78 ppStr "???", -- ppStr "}{env:", ppr sty (keysFM env `zip` eltsFM env),
80 ppr sty (AbsApproxFun demands)
81 = ppCat [ppStr "AbsApprox{", ppr sty demands, ppStr "}" ]
86 An @AbsValEnv@ maps @Ids@ to @AbsVals@. Any unbound @Ids@ are
87 implicitly bound to @AbsTop@, the completely uninformative,
88 pessimistic value---see @absEval@ of a @Var@.
91 data AbsValEnv = AbsValEnv StrAnalFlags (IdEnv AbsVal)
94 = (Bool, -- True <=> AllStrict flag is set
95 Bool) -- True <=> NumbersStrict flag is set
97 type StrictEnv = AbsValEnv -- Environment for strictness analysis
98 type AbsenceEnv = AbsValEnv -- Environment for absence analysis
100 nullAbsValEnv flags -- this is the one and only way to create AbsValEnvs
101 = AbsValEnv flags nullIdEnv
103 addOneToAbsValEnv (AbsValEnv x idenv) y z = AbsValEnv x (addOneToIdEnv idenv y z)
104 growAbsValEnvList (AbsValEnv x idenv) ys = AbsValEnv x (growIdEnvList idenv ys)
106 lookupAbsValEnv (AbsValEnv _ idenv) y
107 = lookupIdEnv idenv y
109 getStrAnalFlags (AbsValEnv flags _) = flags
113 absValFromStrictness :: AnalysisKind -> StrictnessInfo -> AbsVal
115 absValFromStrictness anal NoStrictnessInfo = AbsTop
117 absValFromStrictness StrAnal BottomGuaranteed = AbsBot -- Guaranteed bottom
118 absValFromStrictness AbsAnal BottomGuaranteed = AbsTop -- Check for poison in
119 -- arguments (if any)
120 absValFromStrictness anal (StrictnessInfo [] _) = AbsTop
121 absValFromStrictness anal (StrictnessInfo args_info _) = AbsApproxFun args_info