Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a bug with [@@deriving make] on type declarations sets #281

Merged
merged 4 commits into from
Apr 15, 2024

Conversation

NathanReb
Copy link
Collaborator

Fixes #272.

There was a bug with [@@deriving make] that caused errors if it was used on a set of type declarations, recursive or non recursive, that contained a non record type.

The deriver was applied to all type declarations in the set, regardless of where the attributes was attached and failed on the ones that weren't record types.

There is no particularly nice way to handle this in ppxlib, I assume the design decision was that one would only attach a single [@@deriving ...] attribute per set and the individual derivers would be responsible to decide which type declarations are relevant.
The driver does allow attaching multiple [@@deriving ...] attributes in the same set but performs a merge of all of them so it can lead to confusing situations for the end user.

With all that in mind, there is currently no proper way to tell to which individual type declarations the deriver was attached and even though there might be a hacky one, I'm not sure it would be desirable to use it as it's unlikely that other derivers do so and we probably don't want to have ppx_deriving.make behave differently to the rest of the ppx universe in that regard.

The fix will derive make for all record types in the set if there is at least one, or will report errors about a misuse of the
deriver otherwise.

The PR contains the initial regression test added in #273 by @shonfeder along with a small refactoring to properly embed errors. This allows us to treat regular errors, for example errors coming from misuse of [@main] or [@split], and the make can only be derived for record types error differently which we use for the actual fix.

I also updated the README to document how to use ppx_deriving.make with type declaration sets.

Tests behavior when deriving on mutually recursive types

ocaml-ppx#272
@NathanReb
Copy link
Collaborator Author

@sim642 I'm pinging you in case you're interested in reviewing this. I'd recommend the per-commit view here, although I'm happy to split out the error handling bits if it makes the review easier.

I was hoping to get the fix in before hitting a new 6.0 release.

Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
It used to fail and raise if the set contained a non record type.

Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
@NathanReb NathanReb force-pushed the fix-make-rec-types branch from 95bb718 to 1573bb4 Compare April 10, 2024 13:06
@NathanReb NathanReb merged commit 0e6e704 into ocaml-ppx:master Apr 15, 2024
1 check passed
NathanReb added a commit to NathanReb/opam-repository that referenced this pull request Apr 15, 2024
CHANGES:

* Fix a bug in `[@@deriving make]` that caused errors when it was used on a set
  of type declarations containing at least one non record type.
  ocaml-ppx/ppx_deriving#281
  (@NathanReb)

* Embed errors instead of raising exceptions when generating code
  with `ppx_deriving.make`
  ocaml-ppx/ppx_deriving#281
  (@NathanReb)

* Remove `[%derive.iter ...]`, `[%derive.map ...]` and `[%derive.fold ...]`
  extensions
  ocaml-ppx/ppx_deriving#278
  (Simmo Saan)

* Port standard plugins to ppxlib registration and attributes
  ocaml-ppx/ppx_deriving#263
  (Simmo Saan)

* Optimize forwarding in eq and ord plugins
  ocaml-ppx/ppx_deriving#252
  (Simmo Saan)

* Delegate quoter to ppxlib
  ocaml-ppx/ppx_deriving#263
  (Simmo Saan)

* Introduce `Ppx_deriving_runtime.Stdlib` with OCaml >= 4.07.
  This module already exists in OCaml < 4.07 but was missing otherwise.
  ocaml-ppx/ppx_deriving#258
  (Kate Deplaix)
NathanReb added a commit to NathanReb/ppx_deriving that referenced this pull request Apr 26, 2024
This was broken by a change in ocaml-ppx#281

Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
NathanReb added a commit to NathanReb/ppx_deriving that referenced this pull request Apr 26, 2024
This was broken by a change in ocaml-ppx#281

Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
NathanReb added a commit to NathanReb/ppx_deriving that referenced this pull request Apr 26, 2024
This was broken by a change in ocaml-ppx#281

Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ppx_deriving.make breaks on mutually recurive types
3 participants