Tooling for working on ocaml compiler


I’ve just started trying to tackle some of the junior-jobs on the ocaml issues page:

I’m trying to follow

opam switch create . --empty
opam install .

however it fails at the point of compiling ocaml:

ocaml-variants is now pinned to git+file:///~/dev/ocaml/ocaml-src#trunk (version 4.10.0+trunk)
[NOTE] It seems you have not updated your repositories for a while. Consider updating them with:
       opam update

The following actions will be performed:
  ∗ install ocaml-variants 4.10.0+trunk*
  ∗ install base-bigarray  base
  ∗ install base-threads   base
  ∗ install base-unix      base
  ∗ install ocaml-config   1
  ∗ install ocaml          4.10.0
===== ∗ 6 =====
Do you want to continue? [Y/n] Y

<><> Gathering sources ><><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
[ocaml-variants.4.10.0+trunk] synchronised from git+file:///~/dev/ocaml/ocaml-src#trunk

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><>  🐫
∗ installed base-bigarray.base
∗ installed base-threads.base
∗ installed base-unix.base
∗ installed ocaml-variants.4.10.0+trunk
∗ installed ocaml-config.1
[ERROR] The compilation of ocaml failed at "/~/.opam/opam-init/hooks/ build ocaml /~/dev/ocaml/ocaml-src/_opam/share/ocaml-config/ 4.10.0 ocaml".

#=== ERROR while compiling ocaml.4.10.0 =======================================#
# context     2.0.1 | macos/x86_64 |  |
# path        ~/dev/ocaml/ocaml-src/_opam/.opam-switch/build/ocaml.4.10.0
# command     ~/.opam/opam-init/hooks/ build ocaml ~/dev/ocaml/ocaml-src/_opam/share/ocaml-config/ 4.10.0 ocaml
# exit-code   1
# env-file    ~/.opam/log/ocaml-12656-03b1a4.env
# output-file ~/.opam/log/ocaml-12656-03b1a4.out
### output ###
# OCaml version mismatch: 4.11.0, expected 4.10.0

so clearly its a version mismatch - is there an environment variable or opam variable or something that I am supposed to set?

Follow up question: given this sort of setup (local switch with self built ocaml env) how to install tools like merlin, ocp-indent etc? Again I get the version error for those but now its things like

merline requires ocaml <=4.08.0

and such?


EDIT: by the way, I can get everything to build and run tests etc without using switches, but I’m looking to get the standard tooling working on the ocaml source too.

Unfortunately there is no generic answer to this question, because the “standard tooling” (especially Merlin) is tightly coupled with the compiler output format, and requires changes for new compiler releases. If you work on OCaml’s trunk, two thirds of the release cycle will produce object files that are incompatible with the last release of Merlin.

I created an issue for this in Merlin ( merlin#846 ), but there is no good silver-bullet solution – and currently the Merlin maintainers don’t have enough manpower available to systematically provide a bronze-bullet solution, or at least I haven’t asked them flippantly enough.

Your best bet is to develop your compiler patches on top of the last released version of OCaml, instead of working in the development branch, and hope that the patchset will be easy to forward-port when it is ready. This flow has many good properties (eg.: if you decide to check how changes affect OPAM packages, those packages are actually installable), but of course sometimes you’re out of luck and the files you want to modify have been heavily modified in the development version.