base: Make raw buffer IO operations more strict
authorBen Gamari <bgamari.foss@gmail.com>
Tue, 13 Dec 2016 19:49:20 +0000 (14:49 -0500)
committerBen Gamari <ben@smart-cactus.org>
Tue, 13 Dec 2016 20:38:32 +0000 (15:38 -0500)
commitcc2e3ec06ce5ac979ff2ecf453ad85b0e5ff326d
tree88fcc4a264cfa7aa84921740453777b41d5a044d
parentf723ba2f3b6d778f903fb1de4a5af93fe65eed10
base: Make raw buffer IO operations more strict

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
libraries/base/GHC/IO/FD.hs
libraries/base/changelog.md