[ANN] ppxlib.0.33.0

The Ppxlib dev team is happy to announce the release of ppxlib.0.33.0.

You can find the full changelog for this release here.

Warning silencing for [@@deriving ..] generated code

This release’s main feature is a series of improvement to flags controlling unused value/module/type warnings silencing.

The ppxlib driver generates warning silencing items to prevent [@@deriving ...]
generated code to trigger unused code warnings. Three warnings are disabled that
way:

  • Warning 32: unused value
  • Warning 60: unused module
  • Warning 34: unused type

The first two are disabled for values and modules generated by the deriver while the third is disabled for the types in the type declaration to which the [@@deriving ...] attribute is attached.

This feature was added a long time ago to avoid manually disabling those warnings when working with derivers that generate a set of values and modules only to use a subset of those. Alternatively, the unused type warning silencing was added to allow defining an alias type only to be consumed by a deriver, e.g.:

type error = [`Not_found | `Invalid_arg] [@@deriving to_string]

We since then believe that we should not disable warnings lightly, as this behaviour makes it difficult to find and remove dead code. The right approach in those situations should be to fix the PPX derivers so that they are more configurable and can be used without triggering such warnings.

We will start to move toward removing this feature, but since it is still useful in some places, we had to come up with a plan to allow transitioning out of it.

In ppxlib.0.31.0 we added the -unused-code-warnings driver flag and the
?unused_code_warnings’s Deriving.V2.make optional argument to control whether to silence Warnings 32 and 60. When both are set to true, by the user and the deriver authors, the warnings are not silenced.

As of ppxlib.0.33.0, these also control the silencing of Warning 34 (unused type). force can now be passed to the -unused-code-warnings flag in order to disable warnings silencing, regardless of the derivers opting in.

This allows users to test whether their codebase and their set of derivers rely on warning silencing or not and to use those results to eliminate dead code and/or report issues upstream to the derivers they use.

We also added a separate -unused-type-warnings flag that works similarly to
-unused-code-warnings (i.e., depends on the value of the ?unused_code_warnings argument), but it only controls Warning 34 silencing, as it turns out it is less likely to cause unwanted warnings than with the other two. This will allow users to disable it more easily, without having to deal with Warnings 32 and 60 straight away.

We want to encourage users to try those on their codebase in order to see the impact it has. Did you have dead code lying around that slipped past undetected? Does this trigger unwanted warnings because of deriver’s generated code?

The plan is to give the ecosystem some time to try those features and adapt by fixing individual derivers and flipping ?unused_code_warnings to true as they do. After a while, we will swap the default value of the driver flag to true so that only derivers that haven’t opted in will enable warning silencing. Then as time goes we will swap the default of the Deriving.make argument so that derivers will instead have to explicitly opt out to get the warning silencing. Finally, once we are confident the ecosystem is in a good enough state, we will remove this feature altogether.

Other features

ppxlib.0.33.0 also comes with a couple of new features for PPX authors:

  • A couple new Ast_builder functions: elist_tail and plist_tail
    that can be used to build list expressions and patterns with a custom tail:
    elist_tail [expr1; expr2] tail_expr returns the expression for
    expr1::expr2::tail_expr.
  • Context_free.special_function', a new version of special_function that
    allows passing a Longident.t directly rather that relying on parsing the
    string argument to a Longident.t.

Finally, the release includes a few bug fixes to Longident.parse and
Code_path.main_module_name and fixes the location-check flag so it is not
required to also pass -check to enable location checks. It also fixes the 5.2
migrations locations, as we used to build nodes with inconsistent locations when
migrating Pexp_function nodes.

Huge thanks to our external contributors

We would like to thank our external contributors who have been a huge part of this release: @octachron, @vg-b, and @jchavarri, and a special mention to @mbarbin, who has not only contributed a lot to the warning silencing features but has been extensively testing and providing very useful feedback on them.

And of course, as usual, we’d like to thank the OCaml Software Foundation who has been funding my work on Ppxlib and on this release, making all of this possible!

10 Likes