Using GHC API to compile Haskell file
Edward Z. Yang
ezyang at mit.edu
Mon Sep 7 18:30:16 UTC 2015
Hello Neil,
It looks like my second message got eaten. Let's try again.
> 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.
> 2) Is there any way to do the link alone through the GHC API.
I am confused by your code. There are two ways you can do linking:
1. Explicitly specify all of the objects to link together. This
works even if the source files aren't available.
2. Run ghc --make. This does dependency analysis to figure out what
objects to link together, but since everything is already compiled,
it just links.
Your code seems to be trying to do (1) and (2) simultaneously (you set
the mode to OneShot, but then you call load which calls into GhcMake).
If you want to use (1), stop calling load and call 'oneShot' instead.
If you want to use (2), just reuse your working --make code.
(BTW, how did I figure this all out? By looking at ghc/Main.hs).
Cheers,
Edward
More information about the ghc-devs
mailing list