Question

I have the following problem. I am playing with the OCaml type-checker and am testing it on files from another project. Those files, however, depend on cmi and cmo files that were compiled by some previous compiler version. Thus, I cannot fully type-check those files with my compiler as it seem to not recognize those cmo and cmi files. Is there a way to go around this?

Note that I cannot switch to the old compiler version and that I don't have the source code to those cmo and cmi files. I thought of looking at the OCaml files, infer the function signatures, and create new cmi and cmo files with same signatures. This would probably work since I am interested in type checking only. However, I thought there might be a better way of doing it.

Was it helpful?

Solution

If you are purely interested in the types of compiled modules by an old OCaml compiler, your best bet is:

  • Download the corresponding old OCaml compiler source code
  • Build a small tool using the old OCaml code to load cmi file and dump the signature into text. If you are used to OCaml compiler internal you can do it in less than one hour.
  • Extract signatures of cmi files to mli files with the tool
  • Type mli files by a new compiler and create cmi files for the new compiler

Resurrection of old cmo files should be much, much harder. Linking them with the fixed cmi files should end into an unexpected result, I am afraid. Decompile cmo files to ml source code is theoretically possible --- js_of_ocaml decompiles cmo and create (somehow) readable JavaScript for example --- but it is a hard task.

OTHER TIPS

The obvious thing is to compile the files with your new compiler, rather than just looking at them. Maybe this is too obvious, sorry.

I don't know of any tool that dumps out the interfaces of cmi files. The closest thing is ocamlobjinfo, but it falls far short. You could try loading the cmo files into the old toplevel. The toplevel will tell you the type of a value.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top