<div dir="ltr">i'm doing a bit of benchmarking today, and it may very well be that youre absolutely correct about all of this in practice, at least the way things are trending. </div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Nov 25, 2014 at 1:47 AM, Carter Schonwald <span dir="ltr"><<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>ok attached is the log of <br></div><div>./inplace/bin/ghc-stage2 codetester.hs  -O2 -dcore-lint  -fforce-recomp -ddump-simpl -ddump-to-file -dverbose-core2core -ddump-occur-anal -ddump-inlinings  > output ^&1<br></div><div><br></div><div><br></div><div>the relevant snippet is bellow.</div><div><br></div><div>It looks like the Float-Out transformation is what tripping it.</div><div><br></div><div><br></div><div>That said, reading through what the semantics are implied by has_side_effects = True, the prefetch* family of operations ARE side effectful with respect the fact that they DO modify the CPU cache in a way that changes what memory locations are in various levels of CPU cache, so despite seeming read-like, they are modifying the state of the system, just in a way that is ONLY visible wrt the performance characteristics/runtime  of the resulting program. </div><div><br></div><div>specifically, Duplication, Floating out, and Specultive evaluation all change *when* the prefetch runs and changes the CPU state, and Discard means this "mutation" of the CPU cache state would not happen.</div><div><br></div><div>if prefetch was pure semantically (ie equiv to a -> ()  ) , they'd just be no op, they're exclusively a tool for performance engineering, and accordingly when and where they appear in code matters!</div><div><br></div><div>i'm more than happy to write out a more detailed version of this explanation somewhere if you like.</div><div><br></div><div>-Carter</div><div><br></div><div>""""</div><div><br></div><div><div>*** Core Linted result of Simplifier:</div><div>*** Float out(FOS {Lam = Just 0, Consts = True, OverSatApps = True}):</div><div>*** Core Linted result of Float out(FOS {Lam = Just 0, Consts = True, OverSatApps = True}):</div><div>*** Core Lint errors : in result of Float out(FOS {Lam = Just 0,</div><div>                                                   Consts = True,</div><div>                                                   OverSatApps = True}) ***</div><div><no location info>: Warning:</div><div>    In the expression: prefetchValue2#</div><div>                         @ [Char]</div><div>                         @ RealWorld</div><div>                         lvl_s3Oi</div><div>                         (prefetchValue1#</div><div>                            @ Int</div><div>                            @ RealWorld</div><div>                            lvl_s3Oj</div><div>                            (prefetchAddr3# @ RealWorld ds1_a3zg 0 ds_a3zf))</div><div>    This argument does not satisfy the let/app invariant:</div><div>      prefetchValue1#</div><div>        @ Int</div><div>        @ RealWorld</div><div>        lvl_s3Oj</div></div><div><div class="h5"><div><br></div><div><br></div><div>"""</div><div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 24, 2014 at 10:43 PM, Carter Schonwald <span dir="ltr"><<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">huh, apparently i was mixing up '-' and some other similar dash character, time to let my rebuild of ghc go through then try gain :) </div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 24, 2014 at 10:37 PM, Carter Schonwald <span dir="ltr"><<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr">when i run <div>./inplace/bin/ghc-stage2 codetester.hs  -O2 -dcore-lint -S  -fforce-recomp -ddump-simpl -ddump-to-file –dverbose-core2core –ddump-occur-anal –ddump-inlinings<div>i get </div><div>target ‘–dverbose-core2core’ is not a module name or a source file<br></div><div><br></div><div>what am I doing wrong in this CLI invocation? </div></div></div><div><div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 24, 2014 at 10:23 AM, Simon Peyton Jones <span dir="ltr"><<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">





<div lang="EN-GB" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif">Carter<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif">That smells wrong to me.  These flags have a very carefully defined meaning; see<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif">            Note [PrimOp can_fail and has_side_effects]<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif">in PrimOp.lhs<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif">If you say it has side effects when it doesn’t, you’ll confuse your successor reading the code in five years time.
<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif">Better to find out what is going on and why.  Might you do that? What transformation invalidates the let/app invariant?  Make a small test case, use –dverbose-core2core
 –ddump-occur-anal –ddump-inlinings.  I would far rather that than install a land-mine in the code.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif">Simon<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-family:Calibri,sans-serif"><u></u> <u></u></span></p>
<div style="border-style:none none none solid;border-left-color:blue;border-left-width:1.5pt;padding:0cm 0cm 0cm 4pt">
<div>
<div style="border-style:solid none none;border-top-color:rgb(225,225,225);border-top-width:1pt;padding:3pt 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif">From:</span></b><span lang="EN-US" style="font-size:11pt;font-family:Calibri,sans-serif"> Carter Schonwald [mailto:<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>]
<br>
<b>Sent:</b> 24 November 2014 00:54<br>
<b>To:</b> Edward Kmett<br>
<b>Cc:</b> <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>; Simon Peyton Jones; Joachim Breitner<br>
<b>Subject:</b> Re: let app invariant failure, HALP Re: how to write a ghc primop that acts on an unevaluated argument?<u></u><u></u></span></p>
</div>
</div><div><div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
woot, solved it, at least in a way thats OK for now.<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
if I mark the prefetchValue operations as has_side_effects=True, the core lint failure goes away! I'm not sure if thats the right semantics in the long term, but it does give me a simple way to make sure it works safely for 7.10<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
pardon all the noise <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
-Carter <u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
On Sun, Nov 23, 2014 at 4:26 PM, Carter Schonwald <<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border-style:none none none solid;border-left-color:rgb(204,204,204);border-left-width:1pt;padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm">
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
ok, i'm getting a let/app invariant failure when i build my test case with O1 or O2 but not without<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<a href="http://lpaste.net/114881" target="_blank">http://lpaste.net/114881</a><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
any help would be appreciated on how to address that<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
On Sun, Nov 23, 2014 at 4:13 PM, Carter Schonwald <<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border-style:none none none solid;border-left-color:rgb(204,204,204);border-left-width:1pt;padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm">
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
yup, i have that!<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
    wrapFetch prefetchValue0# (error "this shouldn't get evaluated")<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
in the test suite! <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
in contrast <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
    wrapFetch prefetchValue0# $! (error "this shouldn't get evaluated") does explode<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
shall I add a "should fail" test with the latter? (it doesn't seem worthwhile)<u></u><u></u></p>
</div>
</div>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
On Sun, Nov 23, 2014 at 3:53 PM, Edward Kmett <<a href="mailto:ekmett@gmail.com" target="_blank">ekmett@gmail.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border-style:none none none solid;border-left-color:rgb(204,204,204);border-left-width:1pt;padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm">
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
Maybe test for laziness in the argument by just putting something in that goes boom when forced, e.g. 'undefined'?<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
<div>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
On Sun, Nov 23, 2014 at 2:04 PM, Carter Schonwald <<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>> wrote:<u></u><u></u></p>
</div>
</div>
<blockquote style="border-style:none none none solid;border-left-color:rgb(204,204,204);border-left-width:1pt;padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm">
<div>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
Hey All,<u></u><u></u></p>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
as part of trying to get some fixups for how prefetch works into 7.10,<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
i'm adding a "prefetchValue" primop that prefetchs the memory location of a lifted heap value <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
namely <u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
several operations of the following form<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
primop PrefetchValueOp1 "prefetchValue1#" GenPrimOp<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
   a -> State# s -> State# s<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
   with strictness  = { \ _arity -> mkClosedStrictSig [botDmd, topDmd] topRes }<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
I'd like some feedback on the strictness information design by someone who's familiar with how that piece of GHC. the idea being that prefetchValue is lazy in its polymorphic argument (it doesn't force it, it just does a prefetch on the heap location, which
 may or may not be evaluated).<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<a href="https://phabricator.haskell.org/D350" target="_blank">https://phabricator.haskell.org/D350</a><u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
is the code in question. And i *believe* i'm testing for being lazy in that argument correctly.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
thoughts?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
many thanks!<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<span style="color:rgb(136,136,136)">-Carter<u></u><u></u></span></p>
</div>
<div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<span style="color:rgb(136,136,136)"><u></u> <u></u></span></p>
</div>
</div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
</div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:12pt;margin-left:0cm">
_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><u></u><u></u></p>
</blockquote>
</div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
</blockquote>
</div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal" style="margin-right:0cm;margin-bottom:6pt;margin-left:0cm">
<u></u> <u></u></p>
</div>
</div></div></div>
</div>
</div>

</blockquote></div><br></div>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div></div></div></div>
</blockquote></div><br></div>