Skip to content
  • Ben Gamari's avatar
    Defer inlining of Eq for primitive types · 0bd0c31e
    Ben Gamari authored and Ben Gamari's avatar Ben Gamari committed
    Summary:
    This is one solution to #11688, wherein (==) was inlined to soon
    defeating a rewrite rule provided by bytestring. Since the RHSs of Eq's
    methods are simple, there is little to be gained and much to be lost by
    inlining them early.
    
    For instance, the bytestring library provides,
    
    ```lang=haskell
    break :: (Word8 -> Bool) -> ByteString -> (ByteString, ByteString)
    breakByte :: Word8 -> ByteString -> (ByteString, ByteString)
    ```
    
    and a rule
    
    ```
    forall x. break ((==) x) = breakByte x
    ```
    
    since `breakByte` implments an optimized version of `break (== x)` for
    known `x :: Word8`. If we allow `(==)` to be inlined too early, we will
    prevent this rule from firing. This was the cause of #11688.
    
    This patch just defers the `Eq` methods, although it's likely worthwhile
    giving `Ord` this same treatment. This regresses compiler allocations
    for T9661 by about 8% due to the additional inlining that we now require
    the simplifier to perform.
    
    Updates the `bytestring` submodule to include updated rewrite rules
    which match on `eqWord8` instead of `(==)`.
    
    Test Plan:
     * Validate, examine performance impact
    
    Reviewers: simonpj, hvr, austin
    
    Subscribers: thomie
    
    Differential Revision: https://phabricator.haskell.org/D1980
    
    GHC Trac Issues: #11688
    0bd0c31e