<div dir="ltr">ghc-devs is probably a better location for GHC API questions.<div><br></div><div>Anyhow, you might want to look at some code in the Clash compiler: <a href="https://github.com/clash-lang/clash-compiler/blob/6ec3ca426bfaaaddcd3692775c25614bc19482fa/clash-ghc/src-ghc/Clash/GHC/LoadInterfaceFiles.hs#L168-L225">https://github.com/clash-lang/clash-compiler/blob/6ec3ca426bfaaaddcd3692775c25614bc19482fa/clash-ghc/src-ghc/Clash/GHC/LoadInterfaceFiles.hs#L168-L225</a></div><div>We use that to find the following annotations in compiled packages: <a href="http://hackage.haskell.org/package/clash-prelude-0.99/docs/Clash-Annotations-Primitive.html">http://hackage.haskell.org/package/clash-prelude-0.99/docs/Clash-Annotations-Primitive.html</a></div><div><br></div><div>Anyhow, the gist of: 

<span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><a href="https://github.com/clash-lang/clash-compiler/blob/6ec3ca426bfaaaddcd3692775c25614bc19482fa/clash-ghc/src-ghc/Clash/GHC/LoadInterfaceFiles.hs#L168-L225">https://github.com/clash-lang/clash-compiler/blob/6ec3ca426bfaaaddcd3692775c25614bc19482fa/clash-ghc/src-ghc/Clash/GHC/LoadInterfaceFiles.hs#L168-L225</a> is:</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">* You need a `Module` to start with (you can e.g. get one from a `CoreBndr`)</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">* You need to load the interface file (.hi) for that module.</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">* One you have the contents of the interface file, you can do `TcIface.tcIfaceAnnotations (GHC.mi_anns iface)` to get something of the `Annotation` type.</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">Hope that helps.</span></div><div><span style="color:rgb(34,34,34);font-family:arial,sans-serif;font-size:small;font-style:normal;font-variant-ligatures:normal;font-variant-caps:normal;font-weight:400;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><br></span></div><div>-- Christiaan<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On 18 April 2018 at 23:01, Ranjit Jhala <span dir="ltr"><<a href="mailto:jhala@cs.ucsd.edu" target="_blank">jhala@cs.ucsd.edu</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"><br>Hi all,<br><br>I'm looking for some help using the GHC API to<br><br>access the 'Annotations' (created using the 'ANN'<br><br>mechanism) within modules of *external* packages<br><br>i.e. non-home modules.Currently I'm using<br><br>  hscEPS :: HscEnv -> IO ExternalPackageState<br><br>and then using the field<br><br>  eps_PIT :: !PackageIfaceTable<br><br>and from there, accessing the<br><br>  mi_anns :: [IfaceAnnotation]<br><br>field of the<br><br>  data ModIface<br><br>stored in the PackageIfaceTable but this ends in an unfortunate:<br><br>```<br>panic! (the 'impossible' happened)<br>  (GHC version 8.2.2 for x86_64-apple-darwin):<br>    No mi_anns in PIT<br><br>Please report this as a GHC bug:  <a href="http://www.haskell.org/ghc/reportabug" target="_blank">http://www.haskell.org/ghc/<wbr>reportabug</a><br>```<br><br>Perhaps this is because, as the documentation for `mi_anns` says:<br><br>   Annotations NOT STRICT! we read this field lazily from the interface file<br><br>but I am not sure how to proceed at this point? Do I need a _different_ HscEnv? Or perhaps I need to set up/initialize the HscEnv separately? <br><br>Any pointers would be most welcome!<br><br>Thanks!<span class="HOEnZb"><font color="#888888"><br><br>Ranjit.<dfn class="m_-5303418884849237329gmail-src"></dfn><br><dfn class="m_-5303418884849237329gmail-src"></dfn><div class="gmail_default" style="font-family:monospace,monospace"><dfn class="m_-5303418884849237329gmail-src"><br><br><br></dfn></div><div class="gmail_default" style="font-family:monospace,monospace"><dfn class="m_-5303418884849237329gmail-src"><br></dfn></div><div class="gmail_default" style="font-family:monospace,monospace"><br></div><div class="gmail_default" style="font-family:monospace,monospace"> <br></div></font></span></div>
<br>______________________________<wbr>_________________<br>
Glasgow-haskell-users mailing list<br>
<a href="mailto:Glasgow-haskell-users@haskell.org">Glasgow-haskell-users@haskell.<wbr>org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-<wbr>bin/mailman/listinfo/glasgow-<wbr>haskell-users</a><br>
<br></blockquote></div><br></div>