4

For my PHP LLVM backend I'd like to try out the OCaml GC. Is it possible to use it with LLVM? Especially:

  1. Is the OCaml GC decoupled enough to be used outside of the compiler?
  2. Is the LLVM GC interface mature enough to be used with the OCaml GC?
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57

2 Answers2

2

While it appears as though it would be relatively easy to tear out the OCaml GC and Frankenstein it into a different project, I'm not sure this is really something you would want to do in practice.

The OCaml garbage collector was designed with a functional programming style in mind, and this GC architecture might be a liability for a language such as PHP, which is usually not used in a functional style.

If you are set on doing this then I would suggest either waiting a few months for multicore support to be accepted into the OCaml compiler/runtime or using one of the various projects trying to bring multicore support to OCaml at the moment (the most serious of these would probably be this project by the people over at OCamllabs). Right now the OCaml GC lacks true multicore support, and while this isn't really much of a problem in practice, some people can't seem to live without it.

chrismamo1
  • 917
  • 1
  • 7
  • 15
  • Are you referring to generational GC? That is used in Java, too, so not only in functional programming languages. Also, waiting for multicore support does not make much sense for PHP. – Olle Härstedt Aug 12 '15 at 10:52
  • I am referring the the generational GC. As for multicore support, I'm not very familiar with how PHP works, so I wasn't sure if it tried to parallelize everything, or how important that might be to you. I am fairly excited to see an LLVM implementation of PHP, especially with a high performance garbage collector such as the one used by OCaml. – chrismamo1 Aug 12 '15 at 22:53
  • Yeah, some tuning will need to be done, of course, especially since the amount of immutable objects will not exist in PHP as it does in OCaml. If you're interested in updates about my progress, PM me your mail and I'll add you to my "blogging" mail list (approx one mail/month). Ciao! – Olle Härstedt Aug 12 '15 at 23:01
  • Stackoverflow doesn't appear to have a private message feature. Is there some other way to contact you? – chrismamo1 Aug 13 '15 at 19:09
2

This shouldn't represent too much work as the OCaml GC is already handled in some way in LLVM: http://llvm.org/docs/GarbageCollection.html#the-erlang-and-ocaml-gcs . This means that stack frames descriptors are correctly emitted for function calls (not the smallest ones, but this should improve with current LLVM GC handling developments). An old version of LLVM's documentation tells that OCaml gc doesn't use write barriers, which is erroneous. So you should be careful to ensure that the generated code is correct for assignments.

For the LLVM GC interface, the current one is quite restricted and does not allows to generate very efficient code, but this should be sufficient to prototype while waiting for the next version that should contain some important changes on that side.

Pierre Chambart
  • 1,469
  • 12
  • 17