<div dir="ltr">One other thing:<br><div><div class="gmail_extra"><br><div class="gmail_quote">On 22 June 2016 at 14:36, Richard Eisenberg <span dir="ltr"><<a href="mailto:eir@cis.upenn.edu" target="_blank">eir@cis.upenn.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>It seems there are nice advantages to this approach, and so I'm fine requiring support from TH. But here is a comment I just posted on D2286 requesting more comments in the code:</div><div><br></div><div>---</div><div><span>I've
 just spent some time staring at GHCi/TH.hs and friends, and it's 
starting to make sense. Would it be possible to add some comments/Notes 
there? It would be great to know what is run on the client (GHC, right?)
 and what on the server (TH, right?). Also, why do we need a <tt>RemoteRef</tt> of an <tt>IORef</tt>?
 This, at first, strikes me as odd. I'm sure it makes great sense once I
 understand all the other moving parts, but it would be helpful to have a
 primer. I also find it a bit confusing that the <tt>Message</tt> type contains both messages to the server and messages from the server. For example, I would expect <tt>StartTH</tt> and <tt>Reify</tt> to live in different datatypes, because the two should never mix. Or am I horribly mistaken?</span></div>---<div><br></div><div>Before we require -fexternal-interpreter (which seems to be the endgoal here), has anyone looked at performance implications? All the marshaling and unmarshaling has to take a toll.</div></div></blockquote><div><br></div><div>Yes, I've looked at performance and done a fair bit of optimisation of the current implementation, but mainly for GHCi, not so much for TH yet.  For GHCi I think it was <10% of compile time, mainly in shipping the byte code over the pipe.  I'll need to do some measurements of TH performance before making it the default.  We can probably claw back quite a lot of perf by switching from binary to something else (binary-cbor or store).<br></div><div><br></div><div>Cheers<br></div><div>Simon<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div><br></div><div>Richard</div><div><br><div><span class=""><div>On Jun 22, 2016, at 8:27 AM, Simon Peyton Jones via ghc-devs <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>> wrote:</div><br></span><blockquote type="cite"><div link="blue" vlink="purple" style="font-family:Helvetica;font-size:medium;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:-webkit-auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" lang="EN-GB"><div><span class=""><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif">It’s a great start, thanks<u></u><u></u></span></div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif"> </span></div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif">Simon<u></u><u></u></span></div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif"> </span></div></span><div style="border-style:none none none solid;border-left-width:1.5pt;border-left-color:blue;padding:0cm 0cm 0cm 4pt"><span class=""><div><div style="border-style:solid none none;border-top-width:1pt;border-top-color:rgb(225,225,225);padding:3pt 0cm 0cm"><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><b><span style="font-size:11pt;font-family:Calibri,sans-serif" lang="EN-US">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif" lang="EN-US"><span> </span>Simon Marlow [mailto:<a href="mailto:marlowsd@" target="_blank">marlowsd@</a><a href="http://gmail.com" target="_blank">gmail.com</a>]<span> </span><br><b>Sent:</b><span> </span>22 June 2016 12:32<br><b>To:</b><span> </span>Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>><br><b>Cc:</b><span> </span><a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br><b>Subject:</b><span> </span>Re: Require -fexternal-interpreter support for future TH changes?<u></u><u></u></span></div></div></div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></span><div><div><div><span class=""><div><p class="MsoNormal" style="margin:0cm 0cm 12pt;font-size:12pt;font-family:'Times New Roman',serif">How's this?<span> </span><a href="https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/ExternalInterpreter" style="color:purple;text-decoration:underline" target="_blank">https://ghc.haskell.org/trac/ghc/wiki/Commentary/Compiler/ExternalInterpreter</a><u></u><u></u></p></div></span><p class="MsoNormal" style="margin:0cm 0cm 12pt;font-size:12pt;font-family:'Times New Roman',serif">I don't want to go into too much detail in the wiki, because details are more likely to stay current if they're in Notes in the code.  There are already a few Notes (e.g.<a href="https://phabricator.haskell.org/diffusion/GHC/browse/master/compiler/ghci/GHCi.hs;619958832cbe11096cae3dac9a0a7a5591163a00$86" style="color:purple;text-decoration:underline" target="_blank">https://phabricator.haskell.org/diffusion/GHC/browse/master/compiler/ghci/GHCi.hs;619958832cbe11096cae3dac9a0a7a5591163a00$86</a>) but if anything is confusing I'll happily add more Notes.<u></u><u></u></p></div><p class="MsoNormal" style="margin:0cm 0cm 6pt;font-size:12pt;font-family:'Times New Roman',serif">Cheers<u></u><u></u></p></div><p class="MsoNormal" style="margin:0cm 0cm 6pt;font-size:12pt;font-family:'Times New Roman',serif">Simon<u></u><u></u></p><div><p class="MsoNormal" style="margin:0cm 0cm 6pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></p><div><div><div class="h5"><p class="MsoNormal" style="margin:0cm 0cm 6pt;font-size:12pt;font-family:'Times New Roman',serif">On 22 June 2016 at 11:50, Simon Marlow <<a href="mailto:marlowsd@gmail.com" style="color:purple;text-decoration:underline" target="_blank">marlowsd@gmail.com</a>> wrote:<u></u><u></u></p></div></div><blockquote style="border-style:none none none solid;border-left-width:1pt;border-left-color:rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm"><div><div><div class="h5"><p class="MsoNormal" style="margin:0cm 0cm 6pt;font-size:12pt;font-family:'Times New Roman',serif">On 22 June 2016 at 11:37, Simon Peyton Jones <<a href="mailto:simonpj@microsoft.com" style="color:purple;text-decoration:underline" target="_blank">simonpj@microsoft.com</a>> wrote:<u></u><u></u></p><blockquote style="border-style:none none none solid;border-left-width:1pt;border-left-color:rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm"><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif">I’m ok with this.  <span> </span><i>It would certainly be great not to support TWO mechanisms indefinitely</i>.</span><u></u><u></u></div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif"> </span><u></u><u></u></div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif">What are the disadvantages to committing to this path?  Would anyone even notice?</span><u></u><u></u></div></blockquote><div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Yes, people who are making changes to TH will need to ensure that their changes work with -fexternal-interpreter.  In some cases that might mean extra work, e.g. if we do<span> </span><a href="https://ghc.haskell.org/trac/ghc/wiki/TemplateHaskell/Introspective" style="color:purple;text-decoration:underline" target="_blank">TemplateHaskell/Introspective</a><span> </span>then potentially the whole of HsSyn needs to be binary serializable.  That worries me quite a lot - THSyn is big but tractable, Generic deriving handled the generation of the binary instances easily enough, but HsSyn is another matter entirely.<u></u><u></u></div></div><div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></div></div><blockquote style="border-style:none none none solid;border-left-width:1pt;border-left-color:rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm"><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif">There are a lot of moving parts to the implementation, and I for one am utterly ignorant of how it all works.  I would love to see an implementation overview, either somewhere in the code or on a wiki page.  Things like:</span><u></u><u></u></div><p style="margin-right:0cm;margin-left:0cm;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Symbol">·</span><span style="font-size:7pt">        <span> </span></span><span style="font-family:Calibri,sans-serif">How, when, and where in the compiler is the separate process started?</span><u></u><u></u></p><p style="margin-right:0cm;margin-left:0cm;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Symbol">·</span><span style="font-size:7pt">        <span> </span></span><span style="font-family:Calibri,sans-serif">How do the compiler and server communicate?  Unix pipes? Is it the same on Windows and Unix?</span><u></u><u></u></p><p style="margin-right:0cm;margin-left:0cm;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Symbol">·</span><span style="font-size:7pt">        <span> </span></span><span style="font-family:Calibri,sans-serif">What is serialised, when, and how?  For example, GHC has some TH code to run.  Do we send a syntax tree?  Or compile to bytecode and send that?  Or what?</span><u></u><u></u></p><p style="margin-right:0cm;margin-left:0cm;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Symbol">·</span><span style="font-size:7pt">        <span> </span></span><span style="font-family:Calibri,sans-serif">How are external references managed.  E.g. if the code to be run refers to ‘map’ I’m sure we don’t serialise the code for ‘map’.</span><u></u><u></u></p><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif">I’m sure there is a lot more. E.g the [wiki:RemoteGHCi wiki page] refers to “a library implementing a message type…” but I don’t know what that library is called or where it lives.</span><u></u><u></u></div></blockquote><div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div><div><p class="MsoNormal" style="margin:0cm 0cm 12pt;font-size:12pt;font-family:'Times New Roman',serif">Yes, we should really have a page in the commentary with an overview of the pieces and the main implementation strategy. I'll write one.<u></u><u></u></p></div><div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Cheers<u></u><u></u></div></div><div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="color:rgb(136,136,136)">Simon<u></u><u></u></span></div></div><div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></div></div></div></div><blockquote style="border-style:none none none solid;border-left-width:1pt;border-left-color:rgb(204,204,204);padding:0cm 0cm 0cm 6pt;margin-left:4.8pt;margin-right:0cm"><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif"> </span><u></u><u></u></div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif">Thanks</span><u></u><u></u></div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif"> </span><u></u><u></u></div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif">Simon</span><u></u><u></u></div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><span style="font-family:Calibri,sans-serif"> </span><u></u><u></u></div><div style="border-style:none none none solid;border-left-width:1.5pt;border-left-color:windowtext;padding:0cm 0cm 0cm 4pt"><div><div class="h5"><div><div style="border-style:solid none none;border-top-width:1pt;border-top-color:windowtext;padding:3pt 0cm 0cm"><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><b><span style="font-size:11pt;font-family:Calibri,sans-serif" lang="EN-US">From:</span></b><span style="font-size:11pt;font-family:Calibri,sans-serif" lang="EN-US"><span> </span>ghc-devs [mailto:<a href="mailto:ghc-devs-bounces@haskell.org" style="color:purple;text-decoration:underline" target="_blank">ghc-devs-bounces@haskell.org</a>]<span> </span><b>On Behalf Of<span> </span></b>Simon Marlow<br><b>Sent:</b><span> </span>22 June 2016 09:51<br><b>To:</b><span> </span><a href="mailto:ghc-devs@haskell.org" style="color:purple;text-decoration:underline" target="_blank">ghc-devs@haskell.org</a><br><b>Subject:</b><span> </span>Require -fexternal-interpreter support for future TH changes?</span><u></u><u></u></div></div></div></div></div><div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></div><div><div><div class="h5"><div><div><p class="MsoNormal" style="margin:0cm 0cm 12pt;font-size:12pt;font-family:'Times New Roman',serif"><b>Background</b><u></u><u></u></p></div><p class="MsoNormal" style="margin:0cm 0cm 6pt;font-size:12pt;font-family:'Times New Roman',serif">A few months ago I added -fexternal-interpreter to GHC:<u></u><u></u></p><ul style="margin-bottom:0cm" type="disc"><li class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">docs:<span> </span><a href="https://na01.safelinks.protection.outlook.com/?url=http:%2f%2fdownloads.haskell.org%2f~ghc%2flatest%2fdocs%2fhtml%2fusers_guide%2fghci.html%23ghc-flag--fexternal-interpreter&data=01%7C01%7Csimonpj%40064d.mgd.microsoft.com%7C5ca29759b5c9483e03fb08d39a7a60ea%7C72f988bf86f141af91ab2d7cd011db47%7C1&sdata=6t6FA3nUkP5FOi%2fqCBSr3GxMH2rwWNk89je1qBH9GfI%3d" style="color:purple;text-decoration:underline" target="_blank">http://downloads.haskell.org/~ghc/latest/docs/html/users_guide/ghci.html#ghc-flag--fexternal-interpreter</a><u></u><u></u></li><li class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">wiki, rationale:<span> </span><a href="https://ghc.haskell.org/trac/ghc/wiki/RemoteGHCi" style="color:purple;text-decoration:underline" target="_blank">https://ghc.haskell.org/trac/ghc/wiki/RemoteGHCi</a><u></u><u></u></li></ul></div><div><p class="MsoNormal" style="margin:0cm 0cm 12pt;font-size:12pt;font-family:'Times New Roman',serif">When -fexternal-interpreter is used, GHC runs interpreted code in a separate subprocess, and communicates with it using binary messages over a pipe.<u></u><u></u></p></div><div><p class="MsoNormal" style="margin:0cm 0cm 12pt;font-size:12pt;font-family:'Times New Roman',serif">-fexternal-interpreter currently implements all of TH, quasi-quoting, annotations, and all the GHCi features except for some features of the debugger.  It is also now implemented on Windows, thanks to Tamar Christina.<u></u><u></u></p></div><div><p class="MsoNormal" style="margin:0cm 0cm 12pt;font-size:12pt;font-family:'Times New Roman',serif"><b>Proposal</b><u></u><u></u></p></div><div><p class="MsoNormal" style="margin:0cm 0cm 12pt;font-size:12pt;font-family:'Times New Roman',serif">I'd like to propose that going forward we commit to maintaining full support for -fexternal-interpreter, with a view to making it the default.<u></u><u></u></p></div><div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Why?<u></u><u></u></div></div><ul style="margin-bottom:0cm" type="disc"><li class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">-fexternal-interpreter will be a prerequisite for GHCJS support, so maintaining full support for TH in -fexternal-interpreter will ensure that everything that works with GHC works with GHCJS.<u></u><u></u></li><li class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">We will be able to make simplifications in GHC and the build system once -fexternal-interpreter is the default, because when compiling with -prof or -dynamic we won't have to compile things twice any more.<u></u><u></u></li><li class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">Ultimately we don't want to have two ways of doing everything, because that's harder to maintain.<u></u><u></u></li></ul><div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">How?<u></u><u></u></div></div></div></div><div><div><div class="h5"><ul style="margin-bottom:0cm" type="disc"><li class="MsoNormal" style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif">I'll make all the TH and quasi-quoting tests run with and without -fexternal-interpreter, so it will break validate if one of these fails.<u></u><u></u></li></ul><p style="margin-right:0cm;margin-left:0cm;font-size:12pt;font-family:'Times New Roman',serif"><b>Why now?</b><u></u><u></u></p></div></div><p style="margin-right:0cm;margin-left:0cm;font-size:12pt;font-family:'Times New Roman',serif">There are some TH changes in the pipeline that will need special attention to work with -fexternal-interpreter.  e.g.<a href="https://phabricator.haskell.org/D2286" style="color:purple;text-decoration:underline" target="_blank">https://phabricator.haskell.org/D2286</a><span> </span>and<span> </span><a href="https://ghc.haskell.org/trac/ghc/wiki/TemplateHaskell/Introspective" style="color:purple;text-decoration:underline" target="_blank">https://ghc.haskell.org/trac/ghc/wiki/TemplateHaskell/Introspective</a>, so I'd like to raise it now so we can keep the issue in mind.<u></u><u></u></p><p style="margin-right:0cm;margin-left:0cm;font-size:12pt;font-family:'Times New Roman',serif"> <u></u><u></u></p><p style="margin-right:0cm;margin-left:0cm;font-size:12pt;font-family:'Times New Roman',serif">Cheers<u></u><u></u></p><p style="margin-right:0cm;margin-left:0cm;font-size:12pt;font-family:'Times New Roman',serif">Simon<u></u><u></u></p></div></div></div></div></blockquote></div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></blockquote></div><div style="margin:0cm 0cm 0.0001pt;font-size:12pt;font-family:'Times New Roman',serif"><u></u> <u></u></div></div></div></div></div>_______________________________________________<br>ghc-devs mailing list<br><a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a></div></blockquote></div><br></div></div></blockquote></div><br></div></div></div>