Implementing a compilation server

Domínguez, Facundo facundo.dominguez at tweag.io
Thu May 5 00:05:18 UTC 2022


Dear ghc devs,

I'm using the ghc API to write a compilation server (a.k.a. persistent
worker). The idea is to serve requests to compile individual modules. In
this fashion, we can compile modules with different compilation flags and
yet pay only once for the startup overheads of the compiler.

One challenge of this approach is to reuse as much as possible from the ghc
API session/environment from one compilation request to the next, so we
save the trouble of reconstructing it each time. This message is to ask for
advise on how to better accomplish this reuse.

I tried reusing the whole environment for multiple requests, but I'm
conjecturing that this might cause troubles when the requests require
building modules with different values of -this-unit-id. Another problem
that streams from this is that recompiling a module which defines a type
class instance fails because it encounters in the environment the type
class instance from the
previous compilation.

My work-in-progress implementation is here [1]. There appears to be
multiple ways to compile a module in the API, so far I have been trying
DriverPipeline.compileFile.

My best lead right now is to look for inspiration in how GHCi implements
the load command, but this does a sort of --make compilation while I'm
going here for the one-shot style.

Thanks in advance,
Facundo

[1]
https://github.com/tweag/rules_haskell/blob/16ba422457ea4daa5dbf40d46327ebcb20588e97/tools/haskell_module_worker/src/Compile.hs#L188
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20220504/82e02e26/attachment.html>


More information about the ghc-devs mailing list