Automatic simplification of an OCaml program


Sometimes, I have a large research (ugly) code base.

I’d like a tool to automatically and statically, simplify this code
base so that I can release the only interesting part and its dependencies.

Let’s say the code base has N functions; let’s say I consider only functions at
the first level layer of each module (not sub functions).

If N variants of the program are created, each variant missing only one of these functions,
then by compiling the software N times, it would be possible to discover unused functions
(the corresponding program variant does not compile).
Remove them, then iterate until a stable state has been reached.

Do we have tools to implement this easily?

Or, even better, can’t the compiler discover automatically all dead code and tell me about it
with some specific options?

Thanks a lot,

You may be looking for Lexifi/dead_code_analyzer.

If I remember well, this thing does not work if there are no .mli files.
This is a show stopper for me.

Are you sure? (The documentation seems to suggest that .mli files are not required, as .cmt files get used instead.)

I will try again, but that was my recall.