Hi Jon and Peter,

My version of the bindings was constructed to directly wrap the underlying externals and replace the existing interface, but there's no reason it couldn't be changed to wrap the existing unsafe bindings instead, and leave the unsafe interface exposed as well. I'm working on updating my code to the latest version of LLVM, and I can incorporate that change.

I haven't looked at the Haskell bindings, but I don't think I've been very tricky with mine. My goal was simply to take the existing bindings over the unsafe C interface and re-establish the type safety that exists in LLVM's C++ code by reintroducing the inheritance hierarchy on the OCaml side. I need a couple unusual patterns for this, but otherwise it's still the low-level C API, you just don't have everything represented as a top-level function anymore. For example, "val function_call_conv : llvalue -> int" becomes "method call_conv : int" inside class Function.c. Translating code from the existing bindings to my version would be straightforward and mechanical.

Aside from compatibility with existing code though, I can't imagine why any OCaml programmer would want to use a type-unsafe version of the LLVM bindings. The C API gets a pass for flattening LLVM's deep inheritance hierarchies into opaque pointers like llvalue and lltype, since that's all C lets you do. But that's just not acceptable to me in OCaml, where I have the tools to correct the situation. If I have to give up static type safety to work with LLVM in OCaml, then I might as well not use OCaml on that project.

If the Haskell bindings expose more capabilities than the OCaml ones, it would be great to add these additional functions. But I'm curious, how are they getting additional functions? Can Haskell bind directly to C++ without going through C? Or have the Haskell folks made major changes to the LLVM C API? And if so, why wouldn't they push those changes upstream themselves?


On Fri, Nov 8, 2013 at 3:31 AM, Jon Harrop <jon@ffconsultancy.com> wrote:
> I'm not going to change APIs in any way which needs nontrivial, significant fixes to clients, there's simply no need.

Ok, great.

Jeff Meister was talking about writing more type safe bindings. I think that would be fine as long as it wraps the existing less-safe bindings so people can continue to use them. I tried using LLVM from Haskell and had a lot of problems because they'd used every trick in the book to write the most type safe possible bindings and it makes it much harder to learn and use. I'd personally much rather see more complete bindings...

BTW, what are your thoughts on MSJIT? I just started reading about it and it seems very underwhelming. Sounds like they're struggling to refactor their C++ code so they're reinventing things but not doing it significantly better. So I don't think I'll be rushing to switch to MSJIT unless they actually deprecate the old JIT.

Cheers,
Jon.

-----Original Message-----
From: Peter Zotov [mailto:whitequark@whitequark.org]
Sent: 08 November 2013 10:19
To: jon@ffconsultancy.com
Cc: caml-list@inria.fr
Subject: RE: [Caml-list] LLVM OCaml bindings

Jon Harrop писал 08.11.2013 13:36:
> I just wanted to check: you're not breaking the existing bindings,
> right?

Sorry, realized the previous letter was phrased ambiguously.
I'm asking because I do want to break existing bindings. The changes would mainly touch two areas:
1) Memory management. I want to get rid of most or all of dispose functions and allow to use OCaml's GC.
2) Llvm_target interface is very outdated and it could be updated to integrate much better with the TargetMachine interface.

There are also two or three Llvm functions which need minor changes.

I'm not going to change APIs in any way which needs nontrivial, significant fixes to clients, there's simply no need.

--
   WBR, Peter Zotov.


--
Caml-list mailing list.  Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs