Skip to content
  • Simon Peyton Jones's avatar
    Trim the demand for recursive product types · 42953902
    Simon Peyton Jones authored and Marge Bot's avatar Marge Bot committed
    Ticket #18304 showed that we need to be very careful
    when exploring the demand (esp usage demand) on recursive
    product types.
    
    This patch solves the problem by trimming the demand on such types --
    in effect, a form of "widening".
    
    See the Note [Trimming a demand to a type] in DmdAnal, which explains
    how I did this by piggy-backing on an existing mechansim for trimming
    demands becuase of GADTs.  The significant payload of this patch is
    very small indeed:
    
    * Make GHC.Core.Opt.WorkWrap.Utils.typeShape use RecTcChecker to
      avoid looking through recursive types.
    
    But on the way
    
    * I found that ae_rec_tc was entirely inoperative and did nothing.
      So I removed it altogether from DmdAnal.
    
    * I moved some code around in DmdAnal and Demand.
      (There are no actual changes in dmdFix.)
    
    * I changed the API of DmsAnal.dmdAnalRhsLetDown to return
      a StrictSig rather than a decorated Id
    
    * I removed the dead function peelTsFuns from Demand
    
    Performance effects:
    
    Nofib: 0.0% changes.  Not surprising, because they don't
           use recursive products
    
    Perf tests
    
    T12227:
      1% increase in compiler allocation, becuase $cto gets w/w'd.
      It did not w/w before because it takes a deeply nested
      argument, so the worker gets too many args, so we abandon w/w
      altogether (see GHC.Core.Opt.WorkWrap.Utils.isWorkerSmallEnough)
    
      With this patch we trim the demands.  That is not strictly
      necessary (since these Generic type constructors are like
      tuples -- they can't cause a loop) but the net result is that
      we now w/w $cto which is fine.
    
    UniqLoop:
      16% decrease in /runtime/ allocation. The UniqSupply is a
      recursive product, so currently we abandon all strictness on
      'churn'.  With this patch 'churn' gets useful strictness, and
      we w/w it.  Hooray
    
    Metric Decrease:
        UniqLoop
    
    Metric Increase:
        T12227
    42953902