Note [DmdSig: demand signatures, and demand-sig arity]
See also * Note [Demand signatures semantically] * Note [Understanding DmdType and DmdSig] In a let-bound Id we record its demand signature. In principle, this demand signature is a demand transformer, mapping a demand on the Id into a DmdType, which gives a) the free vars of the Id's value b) the Id's arguments c) an indication of the result of applying the Id to its arguments However, in fact we store in the Id an extremely emasculated demand transformer, namely a single DmdType (Nevertheless we dignify DmdSig as a distinct type.) The DmdSig for an Id is a semantic thing. Suppose a function `f` has a DmdSig of DmdSig (DmdType (fv_dmds,res) [d1..dn]) Here `n` is called the "demand-sig arity" of the DmdSig. The signature means: * If you apply `f` to n arguments (the demand-sig-arity) * then you can unleash demands d1..dn on the arguments * and demands fv_dmds on the free variables. Also see Note [Demand type Divergence] for the meaning of a Divergence in a demand signature. If `f` is applied to fewer value arguments than its demand-sig arity, it means that the demand on the function at a call site is weaker than the vanilla call demand, used for signature inference. Therefore we place a top demand on all arguments. For example, the demand transformer described by the demand signature DmdSig (DmdType {x -> <1L>} <A><1P(L,L)>) says that when the function is applied to two arguments, it unleashes demand 1L on the free var x, A on the first arg, and 1P(L,L) on the second. If this same function is applied to one arg, all we can say is that it uses x with 1L, and its arg with demand 1P(L,L).
References 3
- Demand signatures semantically GHC.Types.Demand
- Demand type Divergence GHC.Types.Demand
- Understanding DmdType and DmdSig GHC.Types.Demand
Referenced by 6
- GHC.Types.Demand call site ×2
- GHC.Core.Opt.DmdAnal call site
- The demand for the RHS of a binding GHC.Core.Opt.DmdAnal
- mkDmdSigForArity GHC.Core.Opt.DmdAnal
- Understanding DmdType and DmdSig GHC.Types.Demand