Ppxlib 0.33.0

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

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 deadcode. 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 came up with a plan to do this iteratively. In ppxlib.0.31.0 we added the -unused-code-warnings driver flag and the ?unused_code_warnings 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 deadcode 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 deadcode 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 setting ?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.

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.

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!

See full changelog
  • Fix a bug where Code_path.main_module_name would not properly remove extensions from the filename and therefore return an invalid module name. (#512, @NathanReb)

  • Add -unused-type-warnings flag to the driver to allow users to disable only the generation of Warning 34 silencing structure items when using [@@deriving ...] on type declarations. (#511, @mbarbin, @NathanReb)

  • Make the -unused-code-warnings driver flag also control Warning 34 silencing for type declarations with [@@deriving ...] attached. (#510, @mbarbin, @NathanReb)

  • Add -unused-code-warnings=force driver command-line flag argument. (#490, @mbarbin)

  • Add new functions Ast_builder.{e,p}list_tail that take an extra tail expression/pattern argument parameter compared to Ast_builder.{e,p}list, so they can build ASTs like a :: b :: c instead of only [ a; b ]. (#498, #502, @v-gb, @NathanReb)

  • Fix Longident.parse so it also handles indexing operators such as .!(), .%(;..)<-, or Vec.(.%()) (#494, @octachron)

  • Add a special_function' variant that directly takes a Longident.t argument in order to avoid the issue with Longident.t covering distinct syntactic classes that cannot be easily parsed by a common parser (#496, @octachron).

  • Keep location ranges consistent when migrating Pexp_function nodes from 5.2+ to older versions (#504, @jchavarri)

  • Fix -locations-check behaviour so it is no longer required to pass -check and can enable location checks. (#506, @NathanReb)