[Haskell-cafe] Bad interaction of inlinePerformIO and mutable vectors

Felipe Lessa felipe.lessa at gmail.com
Thu Jul 31 11:35:56 UTC 2014


Hey, Michael!

I'm not going to give you the answer to your question, just a new bit of
information.

If you check the core generated from -O2 you'll see that this is what
the IORef version of "inlinePerformIO" looks like:

    -- prints "inlinePerformIO"
    case Handle.Text.hPutStr2
           Handle.FD.stdout lvl2_r5GX True ipv28_X3s6
    of _ [Occ=Dead] { (# ipv30_X3vu, ipv31_X3sc #) ->
    -- reads current value
    case readMutVar#
           @ RealWorld @ Char ipv3_a3pa ipv30_X3vu
    of _ [Occ=Dead] { (# ipv32_X3uU, ipv33_X3uX #) ->
    -- prints current value
    case Handle.Text.hPutStr2
           Handle.FD.stdout
           ($fShowChar_$cshow ipv33_X3uX)
           True
           ipv32_X3uU
    of _ [Occ=Dead] { (# ipv34_X3si, ipv35_X3sk #) ->
    -- sets new value
    case writeMutVar#
           @ RealWorld
           @ Char
           ipv3_a3pa
           lvl10_r5H5
           realWorld#
    of _ [Occ=Dead] { __DEFAULT ->
    -- reads current value
    case readMutVar#
           @ RealWorld @ Char ipv3_a3pa ipv34_X3si
    of _ [Occ=Dead] { (# ipv36_X3v6, ipv37_X3v9 #) ->
    -- prints current value
    case Handle.Text.hPutStr2
           Handle.FD.stdout
           ($fShowChar_$cshow ipv37_X3v9)
           True
           ipv36_X3v6
    -- ...

While this is what the Vector version of "inlinePerformIO" looks like:

    -- prints "inlinePerformIO"
    case Handle.Text.hPutStr2
           Handle.FD.stdout lvl2_r5GX True ipv72_X3zS
    of _ [Occ=Dead] { (# ipv74_X3uq, ipv75_X3us #) ->
    -- prints current value
    case a_s32R ipv74_X3uq
    of _ [Occ=Dead] { (# ipv76_X3uu, ipv77_X3uw #) ->
    -- prints current value
    case a_s32R ipv76_X3uu
    of _ [Occ=Dead] { (# ipv78_X3v5, ipv79_X3v7 #) ->
    -- ...

Ouch!  Everything was optimized away :(.  For reference, this is what
the "inlinePerformIO + read" version looks like:

    -- prints "inlinePerformIO + read"
    case Handle.Text.hPutStr2
           Handle.FD.stdout lvl1_r5GW True ipv78_X3v5
    of _ [Occ=Dead] { (# ipv80_X3Bs, ipv81_X3vb #) ->
    -- prints current value
    case a_s32R ipv80_X3Bs
    of _ [Occ=Dead] { (# ipv82_X3vd, ipv83_X3vf #) ->
    -- sets new value then read it
    case readArray#
           @ (Control.Monad.Primitive.PrimState IO)
           @ Char
           ipv55_a2Ze
           0
           (writeArray#
              @ (Control.Monad.Primitive.PrimState IO)
              @ Char
              ipv55_a2Ze
              0
              lvl_r5GV
              (realWorld#
               `cast` ((State#
                          (Sym
Control.Monad.Primitive.TFCo:R:PrimStateIO[0]))_R
                       :: State# RealWorld
                            ~#
                          State# (Control.Monad.Primitive.PrimState IO))))
    of _ [Occ=Dead] { (# ipv84_s5yV, ipv85_s5yW #) ->
    -- prints current value
    a_s32R ipv82_X3vd

Hmmmm...

-- 
Felipe.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140731/ca96e958/attachment-0001.sig>


More information about the Haskell-Cafe mailing list