<br><br><div class="gmail_quote">On 26 January 2012 16:33, JP Moresmau <span dir="ltr">&lt;<a href="mailto:jpmoresmau@gmail.com" target="_blank">jpmoresmau@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">


Thomas, thank you for that explanation about the different type of<br>
identifiers in the different phases of analysis. I&#39;ve never seen that<br>
information so clearly laid out before, can it be added to the wikis<br>
(in <a href="http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/API" target="_blank">http://hackage.haskell.org/trac/ghc/wiki/Commentary/Compiler/API</a><br>
or <a href="http://www.haskell.org/haskellwiki/GHC/As_a_library" target="_blank">http://www.haskell.org/haskellwiki/GHC/As_a_library</a> maybe)? I think<br>
it would be helpful to all people that want to dive into the GHC API.<br></blockquote><div><br>Will do.<br> </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">



<br>
On a side note, I&#39;m going to do something very similar in my<br>
BuildWrapper project (which is now the backend of the EclipseFP IDE<br>
plugins): instead of going back to the API every time the user<br>
requests to know the type of &quot;something&quot; in the AST, I&#39;m thinking of<br>
sending the whole typed AST to the Java code. Maybe that&#39;s something<br>
Christopher could use. Both the BuildWrapper code and Thomas&#39;s scion<br>
code are available on GitHub, as they provide examples on how to use<br>
the GHC API.<br></blockquote><div><br>I really don&#39;t think you want to do much work on the front-end as that will just need to be duplicated for each front-end.  That was the whole point of building Scion in the first place.  I understand, of course, that Scion is not useful enough at this time.<br>


<br>Well, I currently don&#39;t have much time to work on Scion, but the plan is as follows:<br><br>  - Scion becomes a multi-process architecture.  It has to be since it&#39;s not safe to run multiple GHC sessions inside the same process.  Even if that were possible, you wouldn&#39;t be able to, say, have a profiling compiler and a release compiler in the same process due to how static flags work.  Separate processes have the additional advantage that you can kill them if they use too much memory (e.g., because you can&#39;t unload loaded interfaces).<br>


<br>  - Scion will be based on Shake and GHC will mostly be used in one-shot mode (i.e., not --make).  This makes it easier to handle preprocessed files.  It also allows us to generate and update meta-information on demand.  I.e., instead of parsing and typechecking a file and then caching the result for the current file, Scion will simply generate meta information whenever it (re-)compiles a source file and writes that meta information to a file.  Querying or caching that meta information then is completely orthogonal to generating it.  The most basic meta information would be a type-annotated version of the compiled AST (possibly + warnings and errors from the last time it was compiled).  Any other meta information can then be generated from that.<br>


<br> - The GHCi debugger probably needs to be treated specially.  There also should be automatic detection of files that aren&#39;t supported by the bytecode compiler (e.g., those using UnboxedTuples) and force compilation to machine code for those.<br>


<br> - The front-end protocol should be specified somewhere.  I&#39;m thinking about using protobuf specifications and then use ways to generate custom formats from that (e.g., JSON, Lisp S-Expressions, XML?).  And if the frontend supports protocol buffers, then it can use that and be fast.  That also means that all serialisation code can be auto-generated.<br>

<br>I won&#39;t have time to work on this before the ICFP deadline (and only very little afterwards), but Scion is not dead (just hibernating).<br>
 </div><blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span><font color="#888888"><br>
JP<br>
</font></span><div><div><br>
<br>
On Thu, Jan 26, 2012 at 2:31 PM, Thomas Schilling<br>
&lt;<a href="mailto:nominolo@googlemail.com" target="_blank">nominolo@googlemail.com</a>&gt; wrote:<br>
&gt;<br>
&gt;<br>
&gt; On 26 January 2012 09:24, Christopher Brown &lt;<a href="mailto:cmb21@st-andrews.ac.uk" target="_blank">cmb21@st-andrews.ac.uk</a>&gt; wrote:<br>
&gt;&gt; Hi Thomas,<br>
&gt;&gt;<br>
&gt;&gt; By static semantics I mean use and bind locations for every name in the<br>
&gt;&gt; AST.<br>
&gt;<br>
&gt; Right, that&#39;s what the renamer does in GHC.  The GHC AST is parameterised<br>
&gt; over the type of identifiers used.  The three different identifier types<br>
&gt; are:<br>
&gt;<br>
&gt; RdrName: is the name as it occurred in source code. This is the output of<br>
&gt; the parser.<br>
&gt; Name: is basically RdrName + unique ID, so you can distinguish two &quot;x&quot;s<br>
&gt; bound at different locations (this is what you want). This is the output of<br>
&gt; the renamer.<br>
&gt; Id: is Name + Type information and consequently is the output of the type<br>
&gt; checker.<br>
&gt;<br>
&gt; Diagram:<br>
&gt;<br>
&gt;    String  --parser--&gt;  HsModule RdrName  --renamer--&gt;  HsModule Name<br>
&gt;  --type-checker--&gt;  HsBinds Id<br>
&gt;<br>
&gt; Since you can&#39;t hook in-between renamer and type checker, it&#39;s perhaps more<br>
&gt; accurately depicted as:<br>
&gt;<br>
&gt;    String  --parser--&gt;  HsModule RdrName  --renamer+type-checker--&gt;<br>
&gt;  (HsModule Name,  HsBinds Id)<br>
&gt;<br>
&gt; The main reasons why it&#39;s tricky to use the GHC API are:<br>
&gt;<br>
&gt; You need to setup the environment of packages etc.  E.g., the renamer needs<br>
&gt; to look up imported modules to correctly resolve imported names (or give a<br>
&gt; error).<br>
&gt; The second is that the current API is not designed for external use.  As I<br>
&gt; mentioned, you cannot run renamer and typechecker independently, there are<br>
&gt; dozens of invariants, there are environments being updated by the various<br>
&gt; phases, etc.  For example, if you want to generate code it&#39;s probably best<br>
&gt; to either generate HsModure RdrName or perhaps the Template Haskell API<br>
&gt; (never tried that path).<br>
&gt;<br>
&gt;<br>
</div></div><div>&gt; / Thomas<br>
&gt;<br>
&gt; --<br>
&gt; Push the envelope. Watch it bend.<br>
&gt;<br>
<br>
<br>
<br>
</div><div><div>--<br>
JP Moresmau<br>
<a href="http://jpmoresmau.blogspot.com/" target="_blank">http://jpmoresmau.blogspot.com/</a><br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br>Push the envelope. Watch it bend.<br>