GHC API: Using runGhc twice or from multiple threads?

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

GHC API: Using runGhc twice or from multiple threads?

p.k.f.holzenspies@utwente.nl
Dear Benno, Simon,

> I think that both ought to be ok, but I'd welcome other input.
>
> GHC.runGHC calls initGhcMonad, which allocates an entirely new session (in
> newHscEnv).   So the two will work entirely independently.
>
> Unfortunately that's not 100% true. If you search for GLOBAL_VAR you'll see
> a handful of disgusting global state variables, and they *will* be shared
> between GHC sessions.
>
> There really aren't many.  I'd love someone to eliminate them!  (NB ghc-
> devs)

There is one open question about what you intend to do with the results of running those GHC-sessions.

Correct me if I'm wrong (Simon, or anyone), but methinks you should be very careful with assigned Uniques, i.e. (Rdr/Occ)Name-things from one session shouldn't be used in the other and vice versa.

I was wondering about this earlier; it would be nice to have some more explicit combinators for manipulating GHC API states (e.g. combining two HscEnvs, such that any NamedThing defined in either will also exist in the result). I thinks some updated documentation on some of the states (HscEnv, GblEnv, LclEnv, etc.) would help people not well-versed with the GHC-innerts to bend their mind around the API.

Regards,
Philip