Skip to content
  • Simon Peyton Jones's avatar
    Make the demand on a binder compatible with type (fixes Trac #8569) · 4b355cd2
    Simon Peyton Jones authored
    Because of GADTs and casts we were getting binders whose
    demand annotation was more deeply nested than made sense
    for its type.
    
    See Note [Trimming a demand to a type], in Demand.lhs,
    which I reproduce here:
    
       Note [Trimming a demand to a type]
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
       Consider this:
    
         f :: a -> Bool
         f x = case ... of
                 A g1 -> case (x |> g1) of (p,q) -> ...
                 B    -> error "urk"
    
       where A,B are the constructors of a GADT.  We'll get a U(U,U) demand
       on x from the A branch, but that's a stupid demand for x itself, which
       has type 'a'. Indeed we get ASSERTs going off (notably in
       splitUseProdDmd, Trac #8569).
    
       Bottom line: we really don't want to have a binder whose demand is more
       deeply-nested than its type.  There are various ways to tackle this.
       When processing (x |> g1), we could "trim" the incoming demand U(U,U)
       to match x's type.  But I'm currently doing so just at the moment when
       we pin a demand on a binder, in DmdAnal.findBndrDmd.
    4b355cd2