• Ben Gamari's avatar
    base: Make raw buffer IO operations more strict · cc2e3ec0
    Ben Gamari authored
    Ticket #9696 reported that `readRawBufferPtr` and `writeRawBufferPtr`
    allocated unnecessarily. The binding is question was,
    ```
    let {
      buf_s4VD [Dmd=<L,U(U)>] :: GHC.Ptr.Ptr GHC.Word.Word8
      [LclId, Unf=OtherCon []] =
          NO_CCS GHC.Ptr.Ptr! [ds1_s4Vy];
    } in
      case
          GHC.IO.FD.$wreadRawBufferPtr
              Main.main5
              0#
              0#
              buf_s4VD
              Main.main4
              Main.main3
              GHC.Prim.void#
      of ...
    ```
    The problem was that GHC apparently couldn't tell that
    `readRawBufferPtr` would always demand the buffer. Here we simple add
    bang patterns on all of the small arguments of these functions to ensure
    that worker/wrappers can eliminate these allocations.
    
    Test Plan: Look at STG produced by testcase in #9696, verify no
    allocations
    
    Reviewers: austin, hvr, simonmar
    
    Reviewed By: simonmar
    
    Subscribers: RyanGlScott, simonmar, thomie
    
    Differential Revision: https://phabricator.haskell.org/D2813
    
    GHC Trac Issues: #9696
    cc2e3ec0
FD.hs 22.7 KB