<div dir="ltr"><div>I&#39;ve updated the wiki page, expanding the descriptions and adding code from the actual implementation: <a href="http://ghc.haskell.org/trac/ghc/wiki/Ghc/Hooks" target="_blank" style="font-size:12.727272033691406px;font-family:arial,sans-serif">http://ghc.haskell.org/trac/ghc/wiki/Ghc/Hooks<br>
</a>An demo program that uses all hooks here: <a href="https://gist.github.com/luite/6444273">https://gist.github.com/luite/6444273</a></div><div>(I&#39;ve listed the users (or proposers) of every hook, and how they use it, Thomas / Edsko, can you check that they indeed do what you need?)</div>
<div>The patch is here:</div><div><a href="https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks.patch">https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-hooks.patch</a><br></div><div><br>
</div><div>In addition to defining the heterogeneous map and the hooks themselves, extra exports have been added to make it possible for users to actually make a hook implementation without copying most of the module&#39;s source code. The demo program implements all hooks to check this.</div>
<div><br></div><div>Also the GHCJS patch is here:</div><div><br></div><div><a href="https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch">https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch</a><br>
</div><div><br></div><div><div>It adds the following:</div></div><div>- in DynFlags an extra WayCustom constructor to add a custom &#39;tag&#39; to generated files (GHCJS builds multiple architectures to support Template Haskell among other things, one with the &#39;js&#39; tag)<br>
</div><div><div>- in ForeignCall the JavaScriptCallConv calling convention</div><div>- in Platform an ArchJavaScript architecture</div><div>- `foreign import javascript&#39; support in the parser and lexer</div><div>- The JavaScriptFFI extension that enables the `foreign import javascript&#39; syntax, only supported on ArchJavaScript (So using it on a regular GHC would always result in a compile error saying that it&#39;s unsupported on the user&#39;s platform)</div>
</div><div><br></div><div>luite</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Sep 5, 2013 at 12:17 AM, Thomas Schilling <span dir="ltr">&lt;<a href="mailto:nominolo@googlemail.com" target="_blank">nominolo@googlemail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I started a wiki page at: <a href="http://ghc.haskell.org/trac/ghc/wiki/Ghc/Hooks" target="_blank">http://ghc.haskell.org/trac/ghc/wiki/Ghc/Hooks</a><br>

<br>
Luite: could you please fill in the hooks that your latest patch defines?<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On 4 Sep 2013, at 19:40, Simon Peyton-Jones &lt;<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>&gt; wrote:<br>
<br>
&gt; I do need more than a patch, please, please.  A wiki page explaining the design, as seen by the user (of the GHC API), the problems it solves, and the use-cases it enables, would be most helpful.<br>
&gt;<br>
&gt; Simon<br>
&gt;<br>
&gt; | -----Original Message-----<br>
&gt; | From: Thomas Schilling [mailto:<a href="mailto:nominolo@googlemail.com">nominolo@googlemail.com</a>]<br>
&gt; | Sent: 04 September 2013 17:26<br>
&gt; | To: Simon Peyton-Jones; Luite Stegeman<br>
&gt; | Cc: Nicolas Frisby; &quot;Pedro Magalhães (<a href="mailto:dreixel@gmail.com">dreixel@gmail.com</a>)&quot;; Richard<br>
&gt; | Eisenberg (<a href="mailto:eir@cis.upenn.edu">eir@cis.upenn.edu</a>); Geoffrey Mainland<br>
&gt; | (<a href="mailto:mainland@cs.drexel.edu">mainland@cs.drexel.edu</a>); Iavor Diatchki; Austin Seipp; Edsko de Vries;<br>
&gt; | Ryan Newton (<a href="mailto:rrnewton@gmail.com">rrnewton@gmail.com</a>); David Luposchainsky; ghc-<br>
&gt; | <a href="mailto:devs@haskell.org">devs@haskell.org</a><br>
&gt; | Subject: Re: GHC 7.8 release status<br>
&gt; |<br>
&gt; |<br>
&gt; | On 4 Sep 2013, at 15:52, Simon Peyton-Jones &lt;<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>&gt;<br>
&gt; | wrote:<br>
&gt; |<br>
&gt; | &gt;  Edsko/Thomas/Luite: if you want anything for 7.8 it&#39;ll have to be<br>
&gt; | jolly soon.  At the moment I don&#39;t even know the motivation or design,<br>
&gt; | let alone implementation.  Could you make a wiki page explaining the<br>
&gt; | proposed design?  Is it really important to do this for 7.8?<br>
&gt; |<br>
&gt; | Yes, it is quite important to get this into 7.8.  Not having these<br>
&gt; | features in GHC makes it very difficult for people to adopt GHCJS.  One<br>
&gt; | could argue that GHCJS is not yet production-ready anyway and users that<br>
&gt; | want to try it can figure out building GHC from source to use it, but<br>
&gt; | this doesn&#39;t quite apply.<br>
&gt; |<br>
&gt; |  1. GHCJS targets a wider audience than users brave enough to compile<br>
&gt; | GHC from source. In addition, the next chance to get these features into<br>
&gt; | GHC is in a year from now, so when GHCJS becomes more mature then this<br>
&gt; | will be a major hurdle for adoption.<br>
&gt; |<br>
&gt; |  2. These changes are also required for IDE tools which really mustn&#39;t<br>
&gt; | require users to build a custom version of GHC.<br>
&gt; |<br>
&gt; |<br>
&gt; | Luite&#39;s design is actually very flexible.  It simply allows GHC API<br>
&gt; | users to provide functions that are called instead of (or in addition<br>
&gt; | to) existing functions in GHC.  Instead of calling, say, &quot;genHardCode&quot;,<br>
&gt; | the driver now looks up whether the user has specified a hook for<br>
&gt; | genHardCode and calls that instead.<br>
&gt; |<br>
&gt; | Currently we only specify a small number of hooks that are sufficient<br>
&gt; | for our use cases.  Future releases of GHC can be extended to include<br>
&gt; | more hooks, if that is needed.<br>
&gt; |<br>
&gt; | Hooks are stored as an untyped map inside the DynFlags (to avoid issues<br>
&gt; | with circular dependencies).  Each hook is looked up using a single-<br>
&gt; | constructor type and type families are used to make this type safe.<br>
&gt; | There is one use of unsafeCoerce to avoid having to make every hook<br>
&gt; | function an instance of Typeable.<br>
&gt; |<br>
&gt; | Unlike CorePlugins, it is only a GHC API feature, and users cannot<br>
&gt; | specify plugins to be added via command line options.  If we can come up<br>
&gt; | with a good design, then we could add this in GHC 7.10, but it is not<br>
&gt; | necessary at this point.<br>
&gt; |<br>
&gt; | Luite: Do you have a link to your latest patch?<br>
<br>
</div></div></blockquote></div><br></div>