<div dir="ltr"><div><div>On further reflection of the goals for the annotation, I would like to put forward the following proposal for comment<br><br><br>Instead of physically placing a "node-key" in each AST Node, a virtual<br>node key can be generated from any `GenLocated SrcSpan e' comprising a<br>combination of the `SrcSpan` value and a unique identifier from the<br>constructor for `e`, perhaps using its `TypeRep`, since the entire AST<br>derives Typeable.<br><br>To further reduce the intrusiveness, a base Annotation type can be<br>defined that captures the location of noise tokens for each AST<br>constructor. This can then be emitted from the parser, if the<br>appropriate flag is set to enable it.<br><br>So<br><br>    data ApiAnnKey = AK SrcSpan TypeRep<br><br>    mkApiAnnKey :: (Located e) -> ApiAnnKey<br>    mkApiAnnKey = ...<br><br>    data Ann =<br>      ....<br>      | AnnHsLet    SrcSpan -- of the word "let"<br>                    SrcSpan -- of the word "in"<br><br>      | AnnHsDo     SrcSpan -- of the word "do"<br><br>And then in the parser<br><br>        | 'let' binds 'in' exp   { mkAnnHsLet $1 $3 (LL $ HsLet (unLoc $2) $4) }<br><br>The helper is<br><br>    mkAnnHsLet :: Located a -> Located b -> LHsExpr RdrName -> P (LHsExpr RdrName)<br>    mkAnnHsLet (L l_let _) (L l_in _) e = do<br>      addAnnotation (mkAnnKey e) (AnnHsLet l_let l_in)<br>      return e;<br><br>The Parse Monad would have to accumulate the annotations to be<br>returned at the end, if called with the appropriate flag.<br><br>There will be some boilerplate in getting the annotations and helper<br>functions defined, but it will not pollute the rest.<br><br>This technique can also potentially be backported to support older GHC<br>versions via a modification to ghc-parser.<br><br>    <a href="https://hackage.haskell.org/package/ghc-parser">https://hackage.haskell.org/package/ghc-parser</a><br><br></div>Regards<br></div>  Alan<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 30, 2014 at 2:04 PM, Alan & Kim Zimmerman <span dir="ltr"><<a href="mailto:alan.zimm@gmail.com" target="_blank">alan.zimm@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>I tend to agree that this change is much too intrusive for what it attempts to do.<br><br></div>I think the concept of a node key could be workable, and ties in to the approach I am taking in ghc-exactprint [1], which uses a SrcSpan together with node type as the annotation key.<br><br>[1]  <a href="https://github.com/alanz/ghc-exactprint" target="_blank">https://github.com/alanz/ghc-exactprint</a><br><br></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Sep 30, 2014 at 11:19 AM, Simon Peyton Jones <span dir="ltr"><<a href="mailto:simonpj@microsoft.com" target="_blank">simonpj@microsoft.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I'm anxious about it being too big a change too.<br>
<br>
I'd be up for it if we had several "customers" all saying "yes, this is precisely what we need to make our usage of the GHC API far far easier".  With enough detail so we can understand their use-case.<br>
<br>
Otherwise I worry that we might go to a lot of effort to solve the wrong problem; or to build a solution that does not, in the end, work for the actual use-case.<br>
<br>
Another way to tackle this would be to ensure that syntax tree nodes have a "node-key" (a bit like their source location) that clients could use in a finite map, to map node-key to values of their choice.<br>
<br>
I have not reviewed your patch in detail, but it's uncomfortable that the 'l' parameter gets into IfGblEnv and DsM.  That doesn't smell right.<br>
<br>
Ditto DynFlags/HscEnv, though I think here that you are right that the "hooks" interface is very crucial.  After all, the WHOLE POINT is too make the client interface more flexible. I would consult Luite and Edsko, who were instrumental in designing the new hooks interface<br>
        <a href="https://ghc.haskell.org/trac/ghc/wiki/Ghc/Hooks" target="_blank">https://ghc.haskell.org/trac/ghc/wiki/Ghc/Hooks</a><br>
(I'm not sure if that page is up to date, but I hope so)<br>
<br>
A good way to proceed might be to identify some of the big users of the GHC API (I'm sure I don't know them all), discuss with them what would help them, and share the results on a wiki page.<br>
<span><font color="#888888"><br>
Simon<br>
</font></span><div><div><br>
|  -----Original Message-----<br>
|  From: ghc-devs [mailto:<a href="mailto:ghc-devs-bounces@haskell.org" target="_blank">ghc-devs-bounces@haskell.org</a>] On Behalf Of<br>
|  Richard Eisenberg<br>
|  Sent: 30 September 2014 03:04<br>
|  To: Edward Z. Yang<br>
|  Cc: <a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
|  Subject: Re: Feedback request for #9628 AST Annotations<br>
|<br>
|  I'm only speaking up because Alan is specifically requesting feedback:<br>
|  I'm really ambivalent about this. I agree with Edward that this is a<br>
|  big change and adds permanent noise in a lot of places. But, I also<br>
|  really respect the goal here -- better tool support. Is it worthwhile<br>
|  to do this using a dynamically typed bit (using Typeable and such),<br>
|  which would avoid the noise? Maybe.<br>
|<br>
|  What do other languages do? Do we know what, say, Agda does to get<br>
|  such tight coupling with an editor? Does, say, Eclipse have such a<br>
|  chummy relationship with a Java compiler to do its refactoring, or is<br>
|  that separately implemented? Haskell/GHC is not the first project to<br>
|  have this problem, and there's plenty of solutions out there. And,<br>
|  unlike most other times, I don't think Haskell is exceptional in this<br>
|  regard (there's nothing very special about Haskell's AST, maybe beyond<br>
|  indentation-awareness), so we can probably adopt other solutions<br>
|  nicely.<br>
|<br>
|  Richard<br>
|<br>
|  On Sep 29, 2014, at 8:58 PM, "Edward Z. Yang" <<a href="mailto:ezyang@mit.edu" target="_blank">ezyang@mit.edu</a>> wrote:<br>
|<br>
|  > Excerpts from Alan & Kim Zimmerman's message of 2014-09-29 13:38:45<br>
|  -0700:<br>
|  >> 1. Is this change too big, should I scale it back to just update<br>
|  the<br>
|  >>   HsSyn structures and then lock it down to Located SrcSpan for all<br>
|  >>   the rest?<br>
|  ><br>
|  > I don't claim to speak for the rest of the GHC developers, but I<br>
|  think<br>
|  > this change is too big.  I am almost tempted to say that we<br>
|  shouldn't<br>
|  > add the type parameter at all, and do something else (maybe Backpack<br>
|  > can let us extend SrcSpan in a modular way, or even use a<br>
|  dynamically<br>
|  > typed map for annotations.)<br>
|  ><br>
|  > Edward<br>
|  > _______________________________________________<br>
|  > ghc-devs mailing list<br>
|  > <a href="mailto:ghc-devs@haskell.org" target="_blank">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>
|  _______________________________________________<br>
|  ghc-devs mailing list<br>
|  <a href="mailto:ghc-devs@haskell.org" target="_blank">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>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">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>
</div></div></blockquote></div><br></div>
</div></div></blockquote></div><br></div>