[ANN] Vaast 0.0.0 + Design discussion

Hi all,

This is a bit of mixed post.

I am excited to announce the 1st prototype of Vaast !
Vaast is a library to handle multiple versions of the Typedtree at once. It is meant as a replacement for the current compiler-version-dependent techniques (be it preprocessing or branching).

Similarly to ppxlib for the Parsetree, it provides a single representation of the Typedtree. Unlike ppxlib, it does not select a compiler version’s representation but provides a form of super-representation which embeds the Typedtree from OCaml 4.14 to 5.5 at once. It does so via a dedicated type encoding which explicitly and precisely identifies the differences in-between versions.Vaast’s Typedtree representation is a shallow replacement for OCaml’s Typedtree, making it cheap to use and easy to integrate incrementally in existing code.

More details on its design are available on my blog:

This leads us to the second part of this post: discussing the design.
The prototype is usable as a replacement for the compiler’s Typedtree (and I experimented it on the dead_code_analyzer). Overall its design resembles the Typedtree but limits the breakages in user-code when updating to a more recent OCaml version.

Here is an example of code in odoc, relying on cppo to handle the different versions of the Typedtree:

#if defined OXCAML
          | Tpat_alias (_, id, loc, _uid, _, _, _) -> (
#elif OCAML_VERSION >= (5, 4, 0)
          | Tpat_alias (_, id, loc, _uid, _ty) -> (
#elif OCAML_VERSION >= (5, 2, 0)
          | Tpat_alias (_, id, loc, _uid) -> (
#else
          | Tpat_alias (_, id, loc) -> (
#endif
              match maybe_localvalue id loc.loc with
              | Some x -> poses := x :: !poses
              | None -> ())

And here is the equivalent using Vaast (and discarding the OxCaml case):

          | Tpat_alias {id; name; _} -> (
              match maybe_localvalue id name.loc with
              | Some x -> poses := x :: !poses
              | None -> ())

There are some rough edges (Texp_function, flattenable versioned types), and, before diving deeper into building the library, I would appreciate feedback and participation of those interested in its development and its use.
I opened a dedicated issue for that purpose.

The mid-term goal is to add utility functions for usual operations, support a few mainstream modules of compiler-libs (Parsetree, Types), and make Vaast a basic building block for static analyzers.
The long-term goal is to interface most of compiler-libs.

Thanks !

Thanks a lot for providing this library. This will be of great help for many tools!

I am definitely interested in experimenting with porting the Salto analyzer to Vaast. I’ll provide some feedback once the port has started!

Note that Vaast is not available via opam yet (because it is still experimental). You will need to
opam pin add vaast https://github.com/fantazio/vaast.git#0.0.0.

Let me know if there is anything I can help with :wink: