Proposal: Allow passing in linkable files from TH

Alec Theriault alec.theriault at gmail.com
Tue Oct 3 03:58:18 UTC 2017


Hello,

I have a TH feature request and I'd like to hear what people have to say
about it. Here is the [Trac ticket][0].
I'm new to this, so if anything here sounds completely wrong, it probably
is.

TH currently lets you add in arbitrary C (and other languages usually
supported by C compilers).
That code is compiled for you and then linked in automatically. This is
what makes the
[`inline-c`][1] package possible.

I'm proposing to extend this so that TH lets you pass in something that is
already compiled and
ready to be linked. The idea is that this would allow TH-level FFI to any
language that can
produce object files or libraries that have the C ABI. My immediate
use-case is to make an
`inline-rust` package where one can write Rust code straight into a Haskell
quasiquote.

In terms of a concrete API change, it would suffice to

  1. add a `LangLinkable` constructor to the `ForeignSrcLang` data type
  2. add a `qAddForeignFilePath :: ForeignSrcLang -> FilePath -> m ()`
method to `Quasi`

The code change is pretty small too (60 additions, 30 deletions) since the
`addForeignFile`
machinery is fully reusable (we just have to skip past the phase of calling
the C compiler).

# Pros:

  * Better TH FFI support
  * Simple to implement

# Cons:

  * The proposed API is suboptimal: it allows for `qAddForeignFile
LangLinkable "..."` although that
 that pretty much never makes sense since the thing being linked is not
subject to `String`  encoding

Any thoughts?

Alec

  [0]: https://ghc.haskell.org/trac/ghc/ticket/14298
  [1]: https://hackage.haskell.org/package/inline-c
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20171002/4f8e71fc/attachment.html>


More information about the ghc-devs mailing list