Accessing 'Annotations' of modules in external packages

Hi all, I'm looking for some help using the GHC API to access the 'Annotations' (created using the 'ANN' mechanism) within modules of *external* packages i.e. non-home modules.Currently I'm using hscEPS :: HscEnv -> IO ExternalPackageState and then using the field eps_PIT :: !PackageIfaceTable and from there, accessing the mi_anns :: [IfaceAnnotation] field of the data ModIface stored in the PackageIfaceTable but this ends in an unfortunate: ``` panic! (the 'impossible' happened) (GHC version 8.2.2 for x86_64-apple-darwin): No mi_anns in PIT Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug ``` Perhaps this is because, as the documentation for `mi_anns` says: Annotations NOT STRICT! we read this field lazily from the interface file 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? Any pointers would be most welcome! Thanks! Ranjit.

ghc-devs is probably a better location for GHC API questions.
Anyhow, you might want to look at some code in the Clash compiler:
https://github.com/clash-lang/clash-compiler/blob/6ec3ca426bfaaaddcd3692775c...
We use that to find the following annotations in compiled packages:
http://hackage.haskell.org/package/clash-prelude-0.99/docs/Clash-Annotations...
Anyhow, the gist of:
https://github.com/clash-lang/clash-compiler/blob/6ec3ca426bfaaaddcd3692775c...
is:
* You need a `Module` to start with (you can e.g. get one from a `CoreBndr`)
* You need to load the interface file (.hi) for that module.
* 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.
Hope that helps.
-- Christiaan
On 18 April 2018 at 23:01, Ranjit Jhala
Hi all,
I'm looking for some help using the GHC API to
access the 'Annotations' (created using the 'ANN'
mechanism) within modules of *external* packages
i.e. non-home modules.Currently I'm using
hscEPS :: HscEnv -> IO ExternalPackageState
and then using the field
eps_PIT :: !PackageIfaceTable
and from there, accessing the
mi_anns :: [IfaceAnnotation]
field of the
data ModIface
stored in the PackageIfaceTable but this ends in an unfortunate:
``` panic! (the 'impossible' happened) (GHC version 8.2.2 for x86_64-apple-darwin): No mi_anns in PIT
Please report this as a GHC bug: http://www.haskell.org/ghc/reportabug ```
Perhaps this is because, as the documentation for `mi_anns` says:
Annotations NOT STRICT! we read this field lazily from the interface file
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?
Any pointers would be most welcome!
Thanks!
Ranjit.
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/glasgow-haskell-users
participants (2)
-
Christiaan Baaij
-
Ranjit Jhala