--- title: Call 2023-08-10 tags: S+S, Semantics --- # !11034 # #23813 https://gitlab.haskell.org/ghc/ghc/-/issues/23813 * SG: add note to #23813 with an example of what `multDmd C0N` would do, and how it would differ from zapping. https://gitlab.haskell.org/ghc/ghc/-/issues/21392 Two sub-issues 1. If you float a join point to top level, and *then* do demand analysis, you might get less good info than if you don't float. 2. (#213992) If you do demand analysis and *then* float a join point to top level, then if you do demand analysis *again* you may get less-good info. * But the earlier, better, info remain semantically sound despite the floating.) ``` go x y = x `seq` if y then go x (not y) else 1 go2 x y = if x `seq` x `seq`y then x `seq` go2 x (not y) else x ``` ``` fst (join j x = (x+1,x-1) in j y) -- let_sd = P(1!L,A) ``` We will compute that `j` is strict in `x`. Not needed: Could put the threshold demand into the demand signature. **In second run of the demand analyser, look at the DemandInfo (not signature) on the top-level binding, and *use that to choose the threshold for LetDown*.** To to this we need to do the `multDmd C0N` business (see #23813 above). Note that for a join-point, on the *first* run, from the incoming demand. ``` fst (join j x = (x+1,x-1) in j y) -- let_sd = P(1!L,A) ``` The incoming demand is `P(1!L,A)`. Threshold demand on `j` is `C(1,P(1!L,A))`. Need add one `C` for each value arg of `j`. (NB: `ww_arity` might be less than `threshold_arity`.) We already doing this. Related to !10232. Change is this: * For a non-join point, use `idDemandInfo id` (not `topDmd`) in `dmdAnalRhsSig` You could do this in !10232, and that would solve #21392. Cool! Also: * good idea to check in second run that DmdInfo and DmdSigs do not get worse. (Except used-once.) * zap dmd info in SetLevels more carefully `multDmd C0N`. ``` fst (join j x = (x+1,x-1) in j y) -- let_sd = P(1!L,A) fst (join j x = let v1 = x+1; v2=x-1 in (v1,v2) in j y) -- let_sd = P(1!L,A) ===> fst (join j x = case x+1 of y -> (y,error "abs") in j y) -- let_sd = P(1!L,A) ``` Re (22): Come to think of it: Inserting seqs to "preserve" the strictness signature seems like a great solution to the problem! Unfortunately, we won't be able to drop them again after the second run of DmdAnal...