Simon Peyton Jones pushed to branch wip/T26722 at Glasgow Haskell Compiler / GHC

Commits:

2 changed files:

Changes:

  • compiler/GHC/Core/Opt/Simplify/Utils.hs
    ... ... @@ -1066,18 +1066,18 @@ interestingArg env e = go env 0 e
    1066 1066
                DFunUnfolding {} -> ValueArg   -- We konw that idArity=0
    
    1067 1067
                CoreUnfolding{ uf_cache = cache }
    
    1068 1068
                  | uf_is_conlike cache -> ValueArg    -- Includes constructor applications
    
    1069
    -             | uf_is_value cache   -> NonTrivArg  -- Things like partial applications
    
    1069
    +             | uf_expandable cache -> NonTrivArg  -- Things like partial applications,
    
    1070
    +                                                  -- and strict data constructors
    
    1070 1071
                  | otherwise           -> TrivArg
    
    1071 1072
                BootUnfolding           -> TrivArg
    
    1072 1073
                NoUnfolding             -> TrivArg
    
    1073 1074
     
    
    1074 1075
     
    
    1075
    -************************************************************************
    
    1076
    +{- *********************************************************************
    
    1076 1077
     *                                                                      *
    
    1077 1078
                       SimplMode
    
    1078 1079
     *                                                                      *
    
    1079
    -************************************************************************
    
    1080
    --}
    
    1080
    +********************************************************************* -}
    
    1081 1081
     
    
    1082 1082
     updModeForStableUnfoldings :: ActivationGhc -> SimplMode -> SimplMode
    
    1083 1083
     -- See Note [The environments of the Simplify pass]
    

  • compiler/GHC/Core/Utils.hs
    ... ... @@ -1509,6 +1509,22 @@ going to put up with this, because the previous more aggressive inlining
    1509 1509
     (which treated 'noFactor' as work-free) was duplicating primops, which
    
    1510 1510
     in turn was making inner loops of array calculations runs slow (#5623)
    
    1511 1511
     
    
    1512
    +Wrinkles
    
    1513
    +
    
    1514
    +(WF1) Strict constructor fields.  We regard (K x) as work-free even if
    
    1515
    +  K is a strict data constructor (see Note [Strict fields in Core])
    
    1516
    +      data T a = K !a
    
    1517
    +  If we have
    
    1518
    +    let t = K x in ...(case t of K y -> blah)...
    
    1519
    +  we want to treat t's binding as expandable so that `exprIsConApp_maybe`
    
    1520
    +  will look through its unfolding. (NB: exprIsWorkFree implies
    
    1521
    +  exprIsExpandable.)
    
    1522
    +
    
    1523
    +  Because K is strict, after inlining we'll get a leftover eval on x, which may
    
    1524
    +  or may not disappear
    
    1525
    +    let t = K x in ...(case x of y -> blah)...
    
    1526
    +  In effect we count duplicating the eval as work-free
    
    1527
    +
    
    1512 1528
     Note [Case expressions are work-free]
    
    1513 1529
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    1514 1530
     Are case-expressions work-free?  Consider
    
    ... ... @@ -1650,7 +1666,8 @@ isWorkFreeApp fn n_val_args
    1650 1666
       = True
    
    1651 1667
       | otherwise
    
    1652 1668
       = case idDetails fn of
    
    1653
    -      DataConWorkId {} -> True
    
    1669
    +      DataConWorkId {} -> True  -- Even if the data constructor is strict
    
    1670
    +                                -- See (WF1) in Note [exprIsWorkFree]
    
    1654 1671
           PrimOpId op _    -> primOpIsWorkFree op
    
    1655 1672
           _                -> False
    
    1656 1673
     
    
    ... ... @@ -1751,6 +1768,8 @@ expansion. Specifically:
    1751 1768
       duplicate the (a +# b) primop, which we should not do lightly.
    
    1752 1769
       (It's quite hard to trigger this bug, but T13155 does so for GHC 8.0.)
    
    1753 1770
     
    
    1771
    +NB: exprIsWorkFree implies exprIsExpandable.
    
    1772
    +
    
    1754 1773
     Note [isExpandableApp: bottoming functions]
    
    1755 1774
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    1756 1775
     It's important that isExpandableApp does not respond True to bottoming