|Version 1 (modified by 4 years ago) (diff),|
Relevant GHC parts for Demand Analysis results
compiler/basicTypes/Demand.lhs-- contains all information about demands and operations on them, as well as about serialization/deserialization of demand signatures. This module is supposed to be changes whenever the demand nature should be enhanced;
compiler/stranal/DmdAnal.lhs-- the demand analysis itself. Check multiple comments for to figure out main principles of the algorithm.
compiler/stranal/WorkWrap.lhs-- a worker-wrapper transform, main client of the demand analysis. The function split is performed in
worthSplittingFunbasing on demand annotations of a function's parameters.
compiler/stranal/WwLib.lhs-- a helper module for the worker-wrapper machinery. The "deep" splitting of a product type argument makes use of the strictness info and is implemented by the function
mkWWstr_one. The function
mkWWcprmakes use of the CPR info.
compiler/basicTypes/Id.lhs-- implementation of identifiers contains a number of utility functions to check/set demand annotations of binders. All of them are just delegating to appropriate functions/fields of the
IdInforecord contains all information about demand and strictness annotations of an identifier.
strictnessInfocontains a representation of an abstract two-point demand transformer of a binder, considered as a reference to a value.
demandInfoindicates, which demand is put to the identifier, which is a function parameter, if the function is called in a strict/used context.
seq*-functions are invoked to avoid memory leaks caused by transforming new ASTs by each of the compiler passes (i.e., no thunks pointing to the parts of the processed trees are left).
compiler/basicTypes/MkId.lhs-- A machinery, responsible for generation of worker-wrappers makes use of demands. For instance, when a signature for a worker is generated, the following strictness signature is created:
wkr_sig = mkStrictSig (mkTopDmdType (replicate wkr_arity top) cpr_info)
In words, a non-bottoming demand type with
Nlazy/used arguments (
top) is created for a worker, where
Nis just a worker's pre-computed arity. Also, particular demands are used when creating signatures for dictionary selectors (see
compiler/prelude/primops.txt.pp-- this file defines demand signatures for primitive operations, which are inserted by
cpppass on the module
compiler/coreSyn/CoreArity.lhs-- demand signatures are used in order to compute the unfolding info of a function: bottoming functions should no be unfolded. See
compiler/coreSyn/CoreLint.lhs-- the checks are performed (in
- whether arity and demand type are consistent (only if demand analysis already happened);
- if the binder is top-level or recursive, it's not demanded (i.e., its demand is not strict).
compiler/coreSyn/CorePrep.lhs-- strictness signatures are examining before converting expression to A-normal form.
compiler/coreSyn/MkCore.lhs-- a bottoming strictness signature created for
error-like functions (see
compiler/coreSyn/PprCore.lhs-- standard pretty-printing machinery, should be modified to change PP of demands.
compiler/iface/IfaceSyn.lhs-- serialization, grep for
compiler/iface/MkIface.lhs-- a client of
IfaceSyn, see usages of
compiler/iface/TcIface.lhs-- the function
tcUnfoldingchecks if an identifier binds a bottoming function in order to decide if it should be unfolded or not
compiler/main/TidyPgm.lhs-- Multiple checks of an identifier to bind a bottoming expression, running a cheap-an-cheerful bottom analyser. See
addExternaland occurrences of
compiler/simplCore/SetLevels.lhs-- It is important to zap demand information, when an identifier is moved to a top-level (due to let-floating), hence look for occurrences of
compiler/simplCore/SimplCore.lhs-- this module is responsible for running the demand analyser and the subsequent worker-wrapper split passes.
compiler/simplCore/SimplUtils.lhs-- is a new arity is less than the arity of the demand type, a warning is emitted; check
compiler/specialise/SpecConstr.lhs-- strictness info is used when creating a specialized copy of a function, see