Using GHC API to compile Haskell file

Edward Z. Yang ezyang at mit.edu
Tue Sep 15 07:56:54 UTC 2015


Excerpts from Neil Mitchell's message of 2015-09-14 14:07:14 -0700:
> >> 1) Is there any way to do the two compilations sharing some cached
> >> state, e.g. loaded packages/.hi files, so each compilation goes
> >> faster.
> >
> > You can, using withTempSession in the GhcMonad.  The external package
> > state will be preserved across calls here, but things put in the HPT
> > will get thrown out.
> 
> So as far as I can tell, you are suggesting I basically do getSession
> in one session, grab the cache bits of the HscEnv, and inject them
> into the start of the next session with setSession? (withTempSession
> and all the other session functions just seem to be some variation on
> that pattern). I tried that, but even storing just hsc_EPS between
> sessions (which seemed like it should both be something that never
> changes), causes weird compile failures. Is moving things like hsc_EPS
> between sessions supported? Or were you suggesting I do something
> else?

No, something a bit different: I'm suggesting that you use this
functionality to "fork" a session: so you do some work, getting a
session, snapshot the session, do some more work, and then use
the snapshot to rollback before the work.

I haven't actually tested this, however.

Edward


More information about the ghc-devs mailing list