<div dir="ltr">Thanks for digging into this Felipe! That's certainly an interesting result, though I similarly have no idea why that's what the simplifier is doing.<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">

On Thu, Jul 31, 2014 at 5:27 PM, Felipe Lessa <span dir="ltr"><<a href="mailto:felipe.lessa@gmail.com" target="_blank">felipe.lessa@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Checking a bit deeper using:<br>
<br>
  $ ghc-core --no-cast --no-asm snoyberg.hs -O1 -ddump-simpl \<br>
             -dverbose-core2core -dcore-lint<br>
<br>
This is the last time we see the "inlinePerformIO" function call (before<br>
it being optimized away):<br>
<br>
lvl_s2R1 =<br>
  \ (vm_a2gL [OS=ProbOneShot]<br>
       :: Data.Vector.Mutable.MVector<br>
            RealWorld Char) -><br>
    thenIO<br>
      @ ()<br>
      @ ()<br>
      lvl_s2QY<br>
      (let {<br>
         a_s2QN<br>
           :: State# RealWorld<br>
              -> (# State# RealWorld, () #)<br>
<br>
         a_s2QN =<br>
           \ (eta_Xm [OS=OneShot] :: State# RealWorld) -><br>
             ((bindIO<br>
                 @ (Data.Vector.Vector Char)<br>
                 @ ()<br>
                 (Data.Vector.unsafeFreeze<br>
                    @ IO<br>
                    @ Char<br>
                    Control.Monad.Primitive.$fPrimMonadIO<br>
                    (vm_a2gL `cast` ...))<br>
                 lvl_s2QV)<br>
              `cast` ...)<br>
               eta_Xm } in<br>
       thenIO<br>
         @ ()<br>
         @ ()<br>
         (a_s2QN `cast` ...)<br>
         (case $<br>
                 @ (IO ())<br>
                 @ ()<br>
                 (Data.ByteString.Internal.inlinePerformIO @ ())<br>
                 (Data.Vector.Mutable.write<br>
                    @ IO<br>
                    @ Char<br>
                    Control.Monad.Primitive.$fPrimMonadIO<br>
                    (vm_a2gL `cast` ...)<br>
                    lvl_s2QZ<br>
                    lvl_s2R0)<br>
          of _ [Occ=Dead] { () -><br>
          a_s2QN `cast` ...<br>
          }))<br>
<br>
lvl_s2QV is the action that prints the array contents.  The above<br>
snippet prints the contents, writes the new value then prints the<br>
contents again.<br>
<br>
But then comes a simplifier phase which lead us to:<br>
<br>
    ...<br>
    of _ [Occ=Dead] { (# ipv_X3cp [OS=OneShot], ipv1_X3cr #) -><br>
    let {<br>
      a_s2QN<br>
        :: State# RealWorld<br>
           -> (# State# RealWorld, () #)<br>
      [LclId,<br>
       Arity=1,<br>
<br>
       Unf=Unf{Src=<vanilla>, TopLvl=False, Arity=1, Value=True,<br>
               ConLike=True, WorkFree=True, Expandable=True,<br>
               Guidance=IF_ARGS [0] 91 0}]<br>
      a_s2QN =<br>
        \ (eta_Xm [OS=OneShot] :: State# RealWorld) -><br>
          case unsafeFreezeArray#<br>
<div class="">                 @ (Control.Monad.Primitive.PrimState IO)<br>
                 @ Char<br>
</div>                 ipv1_a2NI<br>
                 (eta_Xm `cast` ...)<br>
          of _ [Occ=Dead] { (# ipv_a2Oy [OS=OneShot], ipv1_a2Oz #) -><br>
          Handle.Text.hPutStr2<br>
            Handle.FD.stdout<br>
            (Data.Vector.$fShowVector_$cshow<br>
               @ Char<br>
               $fShowChar<br>
               (Data.Vector.Vector @ Char 0 1 ipv1_a2Oz))<br>
            True<br>
            (ipv_a2Oy `cast` ...)<br>
          } } in<br>
    case a_s2QN ipv_X3cp<br>
    of _ [Occ=Dead] { (# ipv_X3cv [OS=OneShot], ipv1_X3dt #) -><br>
    a_s2QN ipv_X3cv<br>
    ...<br>
<br>
Note that a_s2QN has changed due to inlining but still performs the same<br>
action.  However!  ipv_X3cp is *not* the same as the big case with our<br>
inlinePerformIO, it's merely the resulting RealWorld from printing<br>
"inlinePerformIO"!  This is the spot.<br>
<br>
Now I'm stuck, though.  I have no idea why the simplifier did this.<br>
<br>
Cheers!<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
Felipe.<br>
<br>
</font></span><br>_______________________________________________<br>
Haskell-Cafe mailing list<br>
<a href="mailto:Haskell-Cafe@haskell.org">Haskell-Cafe@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/haskell-cafe" target="_blank">http://www.haskell.org/mailman/listinfo/haskell-cafe</a><br>
<br></blockquote></div><br></div>