Skip to content
  • Simon Peyton Jones's avatar
    Fix egregious sharing bug in LiberateCase · da5b25fe
    Simon Peyton Jones authored
    Andy Gill writes: consider the following code
    
           f = g (case v of
                    V a b -> a : t f)
    
    where g is expensive. Liberate case will turn this into
    
           f = g (case v of
                   V a b -> a : t (letrec f = g (case v of
                                                 V a b -> a : f t)
                                    in f)
                 )
    Yikes! We evaluate g twice. This leads to a O(2^n) explosion
    if g calls back to the same code recursively.
    
    This may be the same as Trac #1366.  
    
    da5b25fe