Hi,
I’m glad to announce ocamlmig, a command line tool for rewriting ocaml source code with access to scope and type information.
As the simplest example of what it’s intended for, let’s say an opam-installed library A provides this interface:
val new_name : int -> int
val old_name : int -> int
[@@migrate { repl = Rel.new_name }]
and your repository contains a file b.ml:
let _ = A.old_name 1
then you could run:
$ git diff b.ml
$ ocamlmig migrate -w
$ git diff b.ml
-let _ = A.old_name 1
+let _ = A.new_name 1
Obviously, it’s not limited to renames.
When I meant by “complement [@@deprecated]
” is that instead of providing a textual description [@@deprecated "please use this thing instead" ]
, you get to provide an executable description. The goal is to reduce the friction when the interface of a library evolves. If people get in the habit of running this regularly (after every opam upgrade
/dune pkg lock
, say), then it could also be a way to get users to switch to new interfaces without having to deprecate the old interfaces immediately.
Additionally, using that and a couple of other builtin transformations like removing open
s, you can execute some refactorings, without learning anything like ppxlib or the ocaml ast, for instance:
- Renaming operators (not easy with sed or the like, because the operators change precedence)
- Switching code using both Stdlib and Core to mostly Core
If that piqued your interest, here is more information about what ocamlmig does, and using it.
This is decidedly work in progress, many things are not fully implemented, and it needs a lot of polish, but the existing functionality as is should still be interesting.