We’re happy to announce that we just released ppxlib.0.34.0.
The full patch notes are available on the release page over here.
The main features are OCaml 5.3 compatibility, new AST pretty-printing utilities and the ppxlib-tools package, support for [@@deriving ...]
on class types and the addition of missing Pprintast
entry points.
Changes summary
5.3 compatibility
ppxlib.0.34.0 is the first official ppxlib release that’s compatible with the new 5.3 compiler.
The ppxlib driver now also comes with a -keywords
CLI option, similar to the compiler’s that allow you to compile and preprocess with the 5.3 compiler code that uses effect
as an identifier. This is pretty niche but it’s there should you need it.
Please note that means you can use ppx-es with a 5.3 compiler but not that ppx-es can consume/produce 5.3 language features. We’re currently working on a fix allowing you to use the effect syntax in files that require preprocessing as it’s not possible with 0.34.0. The fix should be released in the next few days as 0.34.1.
AST pretty-printing
We added a new Pp_ast
module that allows you to pretty print AST fragments.
The only way ppxlib would print ASTs before were as S-expressions. In practice we found that it was not always helpful and wanted a more readable and human friendly way of displaying the AST.
The default output of those printer is a simplified version of the AST to keep things clear and avoid cluttering the output with information that is not always useful. For example, if you run Ppxlib.Pp_ast.Default.expression
on the AST for x + 2
, you’ll get the following:
Pexp_apply
( Pexp_ident (Lident "+")
, [ ( Nolabel, Pexp_ident (Lident "x"))
; ( Nolabel, Pexp_constant (Pconst_integer ( "2", None)))
]
)
The alert reader will note that there are no locations or attributes and that the expression
record layer is omitted here.
You can of course configure the printer to display more information if you need to.
We’ve been using these new printers internally to debug migration code and they have been a huge help so we hope they will make working with ppxlib easier for you too.
In addition to this new module, we also added a command line utility called ppxlib-pp-ast
to pretty print ASTs from source files, source code fragments or even marshalled AST files. It is very similar to the old ppx_tools
’s dumpast
.
Note that it will print ppxlib’s internal AST after it’s been migrated from the installed compiler’s version. This is something that we could not simply achieve with OCaml’s own -dparsetree
.
This should be a useful tool for debugging ppx related bugs or learning about the AST and we hope ppx authors and users will like it.
Other changes
As mentioned above, we also added some missing Pprintast
* entries such as binding
, longident
and payload
.
It is now possible to use [@@deriving ...]
on class type declarations and therefore to write derivers for class types.
*: To the confused readers: Pprintast
is entirely different from Pp_ast
mentioned above as it prints the source code corresponding to a given AST.
Plans for the next release
Internal AST bump to 5.2
Our next release will bump our internal AST to 5.2. It is a pretty big change because 5.2 changed how functions were represented in the AST and this impacts A LOT of ppx-es.
@patricoferris has been working very hard on this over the past few months to minimize the amount of breakage and to send patches upstream where that was not possible to get the rest of the ecosystem ready for the bump.
We wanted to first release the 5.3 compatibility but now that’s out of the way we’re able to focus on the bump again.
@patricoferris will create a dedicated thread shortly to explain a bit what’s been going on and what to expect from this release.
Drop support for OCaml < 4.08
It is time for us to drop support for very old compilers. Keeping support for OCaml 4.07 and before requires maintenances of quite heavy compatibility layers and prevents us from using some language features in ppxlib’s source code while providing little to no benefits since the vast majority of users already upgraded to much more recent compilers.
If you’re still relying on those older compilers and the newest ppxlib, please reach out, either here or via a ppxlib issue.
Special thanks
We wanted to thank our external contributors for this release: @hhugo, @nojb and @dra27 for their help on the 5.3 compat and @mattiasdrp for bringing the Pprintast
module up to speed.
Special thanks as well to @pedrobslisboa who started integrating their excellent ppx-by-example into ppxlib’s documentation.
Finally, I’d also like to thank the OCaml Software Foundation who’s been funding all my work on ppxlib and made this release possible!
Happy preprocessing to you all!