<div dir="ltr">This sounds somewhat complementary to some of the Template Haskell work being done by Geoff Mainland to support Manuel&#39;s Inline Objective C style template haskell machinery. Have you looked at that work at all? Sounds like there might be some overlap! <div>

<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Jun 24, 2013 at 10:56 PM, Nicolas Frisby <span dir="ltr">&lt;<a href="mailto:nicolas.frisby@gmail.com" target="_blank">nicolas.frisby@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Just a quick update: I patched a local copy of 7.6.3 to add FastString.string_table to the CoreMonad.reinitializeGlobals mechanism. After that change, I can invoke the front-end (parser,renamer,typechecker,desugarer) from within my plugin on a simple example.<div>



<br></div><div>Original module:</div><div><br></div><div><div>&gt; module Test where</div><div>&gt; <br></div><div>&gt; data X = X Int Int</div><div><br></div><div>Syntax parser from within the plugin:</div><div>

<br></div><div>&gt; data Y = Y X X</div><div>&gt; f (Y (X a b) (X c d)) = a + b + c + d<br></div><div><br></div><div>Perhaps this simple example is luckily avoiding some nasty pitfalls, but it seems to be working.</div>

</div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Jun 20, 2013 at 11:27 AM, Nicolas Frisby <span dir="ltr">&lt;<a href="mailto:nicolas.frisby@gmail.com" target="_blank">nicolas.frisby@gmail.com</a>&gt;</span> wrote:<br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I&#39;d like to generate new declarations/bindings from within a GHC plugin. My current concrete goal is just to add a new vanilla data definition, but long-term it could be more open-ended. Crucially, these new declarations will reference variables bound by the original module and its imports.<div>




<br></div><div>Long-term, it&#39;d be nice if we could invoke the parser/renamer/typechecker in order to do so. Broadly, the required plumbing seems doable. I wrote a custom initTc that initializes the TcGblEnv from the ModGuts that the plugin receives. This is enough to invoke the renamer/typechecker/desugarer. The resulting new ModGuts can then be merged into the original ModGuts, perhaps after some Simplification.</div>




<div><br></div><div>Has anyone explored/designed down this path? I&#39;ve got some questions about a snag I hit.<div><div><br></div><div><div>Parsing seems fine (superficially) but the renamer fails. I&#39;m re-using the global Rdr environment from the plugin&#39;s input ModGuts, so that free vars from the new syntax will reference other bindings in the original module and its imports. However, that environment is keyed on the uniques of FastStrings, ultimately raising &quot;name not found&quot; errors.<br>




</div></div><div><br></div><div>This happens because the global variable for the FastString Table is not being shared between the actual compiler and the new image of the GHC library that the plugin is using. One solution seems to be including the FastString Table in the  &quot;reinitializeGlobals&quot; mechanism. This would require a GHC patch.</div>




<div><br></div><div>Questions:</div><div><br></div><div>1) Was the FastString Table intentionally left out of the reinitializeGlobals mechanism?</div><div><br></div><div>2) Are there similar obstacles lurking beyond this one that people know about? How incompatible is the invocation of front-end phases wrt the current plugin architecture?</div>




<div><br></div><div>My design assumes the HscEnv and ModGuts received by the plugin include enough information to reconstruct a meaningful TcGblEnv representing the original module. This seems to be at least nearly true. I am, however, not very well-versed with how imports are handled (EPS and such), so I don&#39;t know if the FastString Table issue is just the tip of the iceberg. <br>




</div></div></div><div><br></div><div>Thanks for your thoughts.</div></div>
</blockquote></div><br></div>
</div></div><br>_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org">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><br>
<br></blockquote></div><br></div>