[BLOG] The Flambda2 Snippets, by OCamlPro

Greetings Cameleers,

Today, we are excited to share with you a first glance at some redactional work
that has been brewing behind at the scenes at OCamlPro for quite a some time
now!

We are starting a series of blogposts on the Flambda2 project. The goals are
plenty, one of them being to give all readers an idea of the inner workings of
this great piece of software, 10 years of research & development in the making.

The first two episodes are rather special to the series:

  • Episode 0 gives context and broader information on both the Flambda2 Optimising Compiler project, and the series of blogposts itself.

  • Episode 1, on the other hand, steps right into the subject at hand and covers some of the foundational design decisions of this compiler.

We await your feedback below, and hope that you will enjoy reading these posts, and all ensuing ones!

Kind regards,
The OCamlPro Team

22 Likes

This all looks very interesting. Is there an easy way for me to try out flambda2?

The instructions for compiling from source on GitHub - ocaml-flambda/flambda-backend: The Flambda backend project for OCaml should work. I’ve been using those on MacOS ARM64 and x86_64.

There is also a section for building an opam switch, I haven’t used it so can’t confirm it works.

I wasn’t familiar with First-Class CPS (thanks for introducing me to this!), but shouldn’t the last line of the Tail-recursive CPS implementation of map be

| x :: r -> let fx = f x in map_cps f r (fun r -> k(fx :: r))

i.e., include k?

You’re right, that’s a mistake. We should have the correct version up now. Thanks for reporting !

Trying flambda2 is really an issue. I tried to report it but with no luck. Could you help?

Opam support is still in progress. We have something that seems to work, but we need a bit more testing and haven’t updated yet the instructions in the readme. We hope to have instructions that boil down to “add the janestreet-bleeding repo, then install this opam package”, but finding how to generate our opam package correctly took a while and it’s possible that some subtle bugs are still hidden somewhere.

A couple of questions:

As far as I can tell, we’re doing exactly what they propose, but they worry about continuations being interpreted as first-class functions so they call them join-points, while we don’t care and call them continuations.

This is about first-class CPS, so our second-class CPS compilation scheme will not have any impact on those issues.

@kakadu You might be interested in the following paper which was born out of an attempt to reproduce the “Compiling without continuations” paper (with apologies to people who already saw it the previous times I mentioned it): Compiling with continuations, or without? whatever. | Proceedings of the ACM on Programming Languages.

And of course it is very interesting to hear about everything the Flambda2 team has to tell us about their experience.