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 nullAbsValEnv, addOneToAbsValEnv, growAbsValEnvList,
19 -- and to make the interface self-sufficient...
20 CoreExpr, Id, IdEnv(..), UniqFM, Unique,
21 Demand, PlainCoreExpr(..)
26 --import FiniteMap -- debugging only
30 import Util -- for pragmas only
33 %************************************************************************
35 \subsection[AbsVal-datatype]{@AbsVal@: abstract values (and @AbsValEnv@)}
37 %************************************************************************
39 @AnalysisKind@ tells what kind of analysis is being done.
43 = StrAnal -- We're doing strictness analysis
44 | AbsAnal -- We're doing absence analysis
48 @AbsVal@ is the data type of HNF abstract values.
52 = AbsTop -- AbsTop is the completely uninformative
55 | AbsBot -- An expression whose abstract value is
56 -- AbsBot is sure to fail to terminate.
57 -- AbsBot represents the abstract
58 -- *function* bottom too.
60 | AbsProd [AbsVal] -- (Lifted) product of abstract values
61 -- "Lifted" means that AbsBot is *different* from
62 -- AbsProd [AbsBot, ..., AbsBot]
64 | AbsFun -- An abstract function, with the given:
67 AbsValEnv -- and environment
69 | AbsApproxFun -- This is used to represent a coarse
70 [Demand] -- approximation to a function value. It's an
71 -- abstract function which is strict in its i'th
72 -- argument if the i'th element of the Demand
74 -- The list of arguments is always non-empty.
75 -- In effect, AbsApproxFun [] = AbsTop
77 instance Outputable AbsVal where
78 ppr sty AbsTop = ppStr "AbsTop"
79 ppr sty AbsBot = ppStr "AbsBot"
80 ppr sty (AbsProd prod) = ppCat [ppStr "AbsProd", ppr sty prod]
81 ppr sty (AbsFun args body env)
82 = ppCat [ppStr "AbsFun{", ppr sty args,
83 ppStr "???", -- ppStr "}{env:", ppr sty (keysFM env `zip` eltsFM env),
85 ppr sty (AbsApproxFun demands)
86 = ppCat [ppStr "AbsApprox{", ppr sty demands, ppStr "}" ]
91 An @AbsValEnv@ maps @Ids@ to @AbsVals@. Any unbound @Ids@ are
92 implicitly bound to @AbsTop@, the completely uninformative,
93 pessimistic value---see @absEval@ of a @CoVar@.
96 data AbsValEnv = AbsValEnv StrAnalFlags (IdEnv AbsVal)
97 type StrAnalFlags = Bool -- True <=> make everything strict
99 type StrictEnv = AbsValEnv -- Environment for strictness analysis
100 type AbsenceEnv = AbsValEnv -- Environment for absence analysis
102 nullAbsValEnv x = AbsValEnv x 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 do_all_strict idenv) y
109 else lookupIdEnv idenv y
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