home · projects · papers · blog · gallery · contact
anil madhavapeddy // anil.recoil.org

Easily OPAM switching to any OCaml feature request

25 March 2014   |   Anil Madhavapeddy   |   tags: ocaml,ocamllabs   |   all posts

Gabriel Scherer announced an experiment to host OCaml compiler pull requests on GitHub for six months. There is a general feeling that GitHub would be a more modern hosting platform than the venerable but reliable Mantis setup that has in place for over a decade, but the only way to find out for sure is by trying it out for a while.

One of the great benefits of using GitHub is their excellent API to easily automate workflows around issues and pull requests. After a suggestion from Jeremy Yallop and David Sheets over lunch, I decided to use this to make it easier to locally apply compiler patches. OPAM has a great compiler switch feature that lets you run simultaneous OCaml installations and swap between them easily. For instance, the default setting gives you access to:

$ opam switch
system  C system       System compiler (4.01.0)
--     -- 3.11.2       Official 3.11.2 release
--     -- 3.12.1       Official 3.12.1 release
--     -- 4.00.0       Official 4.00.0 release
--     -- 4.00.1       Official 4.00.1 release
--     -- 4.01.0       Official 4.01.0 release
--     -- 4.01.0beta1  Beta1 release of 4.01.0

I used my GitHub API bindings to knock up a script that converts every GitHub pull request into a custom compiler switch. You can see these by passing the --all option to opam switch, as follows:

$ opam switch --all
--     -- 4.02.0dev+pr10              Add String.{split,rsplit}
--     -- 4.02.0dev+pr13              Add String.{cut,rcut}.
--     -- 4.02.0dev+pr14              Add absolute directory names to bytecode format for ocamldebug to use
--     -- 4.02.0dev+pr15              replace String.blit by String.unsafe_blit
--     -- 4.02.0dev+pr17              Cmm arithmetic optimisations
--     -- 4.02.0dev+pr18              Patch for issue 5584
--     -- 4.02.0dev+pr2               Parse -.x**2. (unary -.) as -.(x**2.).  Fix PR#3414
--     -- 4.02.0dev+pr20              OCamlbuild: Fix the check of ocamlfind
--     -- 4.02.0dev+pr3               Extend record punning to allow destructuring.
--     -- 4.02.0dev+pr4               Fix for PR#4832 (Filling bigarrays may block out runtime)
--     -- 4.02.0dev+pr6               Warn user when a type variable in a type constraint has been instantiated.
--     -- 4.02.0dev+pr7               Extend ocamllex with actions before refilling
--     -- 4.02.0dev+pr8               Adds a .gitignore to ignore all generated files during `make world.opt'
--     -- 4.02.0dev+pr9               FreeBSD 10 uses clang by default, with gcc not available by default
--     -- 4.02.0dev+trunk             latest trunk snapshot

Testing the impact of a particular compiler switch is now pretty straightforward. If you want to play with Stephen Dolan’s optimized arithmetic operations, for instance, you just need to do:

$ opam switch 4.02.0dev+pr17
$ eval `opam config env`

And your local environment now points to the patched OCaml compiler. For the curious, the scripts to generate the OPAM pull requests are in my avsm/opam-sync-github-prs repository. It contains an example of how to query active pull requests, and also to create a new cross-repository pull request (using the git jar binary from my GitHub bindings). The scripts run daily for now, and delete switches once the corresponding pull request is closed. Just run opam update to retrieve the latest switch set from the upstream OPAM package repository.

 
blog comments powered by Disqus