<div dir="ltr">just a quick heads-up:<div><br></div><div>After discussing with Thomas at ZuriHac I now have a review-ready patch (and a demo program that uses all the hooks) that should do everything Thomas, Edsko and I need, and is extensible if new things come up. I&#39;m still in Switzerland though, and my internet connection is spotty, I&#39;ll try to submit it tonight or tomorrow morning</div>
<div><br></div><div>luite</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Aug 27, 2013 at 6:18 PM, 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 think there are a couple of things that are worth exposing.  Looking<br>
at Luite&#39;s patch, for example, there are a few that a basic high-level<br>
platform wouldn&#39;t solve.  A few things an API might reasonably want to<br>
customise:<br>
<br>
  - Parse custom flags (when wrapping GHC)<br>
<br>
  - Hook into GHC&#39;s compilation manager or use one-shot mode and use<br>
Shake as a more flexible compilation manager<br>
<br>
  - Foreign function calling conventions (e.g., for GHCJS)<br>
<br>
  - Compilation ways (can&#39;t think of a good example here)<br>
<br>
  - The location of built-in / hardcoded identifiers (i.e., the PrelNames stuff)<br>
<br>
  - How modules are found (Finder) and where they are stored (e.g.,<br>
network-backed store, in-memory only)<br>
<br>
  - Wrap/Adapt various stages of the<br>
renamer/typechecker/optimiser/codegen.  Mostly for IDE tools<br>
(including tools to examine compiler transformations), but custom<br>
backends also need to replace the codegen bits<br>
<br>
  - Run custom stages in DriverPipeline or adapt existing ones<br>
(including not running them)<br>
<br>
  - Both Lambdachine and GHCJS implement a custom code generator.  I<br>
think GHCJS is translating from STG.  Lambdachine used to start from<br>
CorePrep, but due to the weird &quot;unarise&quot; stuff I had to switch to<br>
using STG which isn&#39;t too bad as it also seems more stable. A custom<br>
code generator requires disabling the &quot;Asm&quot; pass and all subsequent<br>
passes from DriverPipeline<br>
<br>
  - I&#39;m not so sure about syntactic extensions.  They might be better<br>
implemented using haskell-src-exts and then translated into plain<br>
Haskell<br>
<br>
If we can get these things integrated nicely then it would be<br>
worthwhile to wait another year.<br>
<div class="HOEnZb"><div class="h5"><br>
On 27 August 2013 09:17, Simon Peyton-Jones &lt;<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>&gt; wrote:<br>
&gt; I’m sympathetic to supporting GHCJS.  But, as described in my email, there<br>
&gt; seems to be several different proposals for extending plugins swirling<br>
&gt; around, and I’m not sure how they relate to each other.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; My suggestion (for you guys to lead J):<br>
&gt;<br>
&gt; ·         Identify the minimum necessary for GHCJS in 7.8<br>
&gt;<br>
&gt; ·         Debate the remaining proposals under less time pressure<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Simon<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; From: Carter Schonwald [mailto:<a href="mailto:carter.schonwald@gmail.com">carter.schonwald@gmail.com</a>]<br>
&gt; Sent: 23 August 2013 19:36<br>
&gt; To: Daniel F<br>
&gt; Cc: Simon Peyton-Jones; ghc-devs<br>
&gt; Subject: Re: extending GHC plugins with Hooks<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; indeed, ghcjs is one of the things i&#39;m most looking forward to!<br>
&gt;<br>
&gt; That the hooks machinery needed to nicely support GHCJS will enable many<br>
&gt; other use cases is also something i&#39;m excited about too... would be a shame<br>
&gt; for neither to work with 7.8 ....<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; -Carter<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Fri, Aug 23, 2013 at 2:09 PM, Daniel F &lt;<a href="mailto:difrumin@gmail.com">difrumin@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; Hello<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Thu, Aug 22, 2013 at 8:13 PM, Simon Peyton-Jones &lt;<a href="mailto:simonpj@microsoft.com">simonpj@microsoft.com</a>&gt;<br>
&gt; wrote:<br>
&gt;<br>
&gt; Luite, Edsko, Thomas, Nicolas<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; You have all variously proposed improvements to the GHC API and/or the<br>
&gt; plug-in mechanism.  I have been so swamped in the last few months that I<br>
&gt; have not had a chance to look carefully at your proposals, nor how they<br>
&gt; relate to each other.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; We are now only three weeks away from wanting to do a feature freeze on GHC<br>
&gt; 7.8, and there are a lot of other things that we want to complete<br>
&gt;<br>
&gt;                 <a href="http://ghc.haskell.org/trac/ghc/wiki/Status/GHC-7.8" target="_blank">http://ghc.haskell.org/trac/ghc/wiki/Status/GHC-7.8</a><br>
&gt;<br>
&gt; (Mostly they have gestating for some time.)<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; So I’m hoping you’ll be ok with not putting these plugin-related changes<br>
&gt; into 7.8.  I have the sense that they’d benefit from more discussion among<br>
&gt; the folk interested in plugins.  Perhaps some of the ideas could be combined<br>
&gt; nicely; I don’t know.  And the people who are going to write plugins are<br>
&gt; also probably up for building HEAD anyhow.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; (Exception: Luite, I think you have some fairly narrow, specific changes<br>
&gt; that would help GHCJS, and I’m probably fine with those if you care to send<br>
&gt; patches.)<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Does this mean that GHCJS patches will be accepted, but it has to use some<br>
&gt; other mechanism (not Hooks)?<br>
&gt;<br>
&gt; It would be really nice to see ghcjs support in the upcoming GHC.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Please say if you think there’s a really strong reason for putting stuff in<br>
&gt; the 7.8.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Thanks<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Simon<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; From: ghc-devs [mailto:<a href="mailto:ghc-devs-bounces@haskell.org">ghc-devs-bounces@haskell.org</a>] On Behalf Of Luite<br>
&gt; Stegeman<br>
&gt; Sent: 21 August 2013 03:51<br>
&gt; To: ghc-devs<br>
&gt; Subject: extending GHC plugins with Hooks<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; hi all,<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Sorry for taking so long to get back with this. I&#39;m proposing a somewhat<br>
&gt; general way for adding &#39;hooks&#39; to the GHC API, where users can override<br>
&gt; parts of the default compiling pipeline.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Hooks are simply functions or actions that replace existing compiler<br>
&gt; functionality. This means that usually only one application can use a<br>
&gt; specific hook at a time.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; The obvious data structure to store the hooks is DynFlags. Unfortunately<br>
&gt; defining hooks in DynFlags directly would give birth to the mother of all<br>
&gt; import cycles, and it would also break the split-dll scheme on Windows. So<br>
&gt; here&#39;s the idea:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; - Define each hook in the module where it&#39;s exported<br>
&gt;<br>
&gt; - For each hook make a &#39;phantom&#39; DataType and an instance for the Hook type<br>
&gt; familiy<br>
&gt;<br>
&gt; - Add a TypeRep based map in DynFlags [0]<br>
&gt;<br>
&gt; - For each hooked function, check for existence of a hook in DynFlags,<br>
&gt; otherwise run the default. Example:<br>
&gt; <a href="https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch#L83" target="_blank">https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch#L83</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; Now this approach does have some disadvantages:<br>
&gt;<br>
&gt; - No clear integration with existing plugins (I&#39;ve tried adding an<br>
&gt; onLoadPlugin field to Plugin, where the Plugin could update DynFlags when<br>
&gt; it&#39;s loaded, but it was a bit messy, and plugins would not be loaded in time<br>
&gt; for some hooks, particularly what Edsko needs)<br>
&gt;<br>
&gt; - More of GHC depends on type families<br>
&gt;<br>
&gt; - Decentralized hooks definitions feel a bit messy<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; So I&#39;m open to suggestions for improvements (or replacements) of this<br>
&gt; scheme. I have some time the coming weeks to clean up or change the patch.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; We&#39;ve been testing some hooks with GHCJS for a while, and so far they seem<br>
&gt; to provide what we need (but I&#39;m going to doublecheck the coming weeks that<br>
&gt; we don&#39;t have missing functionality):<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; - Customizations for linking JavaScript code with our own library locations<br>
&gt; [1]<br>
&gt;<br>
&gt; - Hooking into the DriverPipeline so we can use the compilation manager [2]<br>
&gt;<br>
&gt; - Desugaring customizations to remove some C-isms from the FFI code [3]<br>
&gt;<br>
&gt; - Typechecking foreign import javascript imports [4]<br>
&gt;<br>
&gt; - Override the built-in GHC.Prim so we can customize primop types [5]<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; I think it&#39;s easy to add those for Edsko and Thomas as well.<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; luite<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; [0]<br>
&gt; <a href="https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch#L239" target="_blank">https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch#L239</a><br>
&gt;<br>
&gt; [1]<br>
&gt; <a href="https://github.com/ghcjs/ghcjs/blob/master/src/Compiler/GhcjsHooks.hs#L44" target="_blank">https://github.com/ghcjs/ghcjs/blob/master/src/Compiler/GhcjsHooks.hs#L44</a><br>
&gt;<br>
&gt; [2]<br>
&gt; <a href="https://github.com/ghcjs/ghcjs/blob/master/src/Compiler/GhcjsHooks.hs#L192" target="_blank">https://github.com/ghcjs/ghcjs/blob/master/src/Compiler/GhcjsHooks.hs#L192</a><br>
&gt;<br>
&gt; <a href="https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch#L335" target="_blank">https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch#L335</a><br>
&gt;<br>
&gt; [3] <a href="https://github.com/ghcjs/ghcjs/blob/master/src/Gen2/Foreign.hs#L67" target="_blank">https://github.com/ghcjs/ghcjs/blob/master/src/Gen2/Foreign.hs#L67</a><br>
&gt;<br>
&gt; <a href="https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch#L83" target="_blank">https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch#L83</a><br>
&gt;<br>
&gt; [4] <a href="https://github.com/ghcjs/ghcjs/blob/master/src/Gen2/Foreign.hs#L68" target="_blank">https://github.com/ghcjs/ghcjs/blob/master/src/Gen2/Foreign.hs#L68</a><br>
&gt;<br>
&gt; <a href="https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch#L1374" target="_blank">https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch#L1374</a><br>
&gt;<br>
&gt; [5]<br>
&gt; <a href="https://github.com/ghcjs/ghcjs/blob/master/src/Compiler/GhcjsHooks.hs#L191" target="_blank">https://github.com/ghcjs/ghcjs/blob/master/src/Compiler/GhcjsHooks.hs#L191</a><br>
&gt;<br>
&gt; <a href="https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch#L239" target="_blank">https://github.com/ghcjs/ghcjs-build/blob/master/refs/patches/ghc-ghcjs.patch#L239</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; (sorry the linked patch also contains other modifications required for<br>
&gt; GHCJS, that i&#39;m going to submit separately)<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; ghc-devs mailing list<br>
&gt; <a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; Sincerely yours,<br>
&gt; -- Daniil Frumin<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; ghc-devs mailing list<br>
&gt; <a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; _______________________________________________<br>
&gt; ghc-devs mailing list<br>
&gt; <a href="mailto:ghc-devs@haskell.org">ghc-devs@haskell.org</a><br>
&gt; <a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
&gt;<br>
</div></div></blockquote></div><br></div>