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

Port standard plugins to ppxlib registration and attributes #263

Merged
merged 23 commits into from
Mar 7, 2024

Conversation

sim642
Copy link
Contributor

@sim642 sim642 commented Jul 19, 2022

This realizes part of #250:

  1. All the standard deriving plugins defined here are switched to register themselves directly with ppxlib and declare their attributes directly with ppxlib.
  2. Deprecates only parts of ppx_deriving API, namely ppx_deriving deriver registration and attribute support. All the other utility functions remain undeprecated since many are still missing from ppxlib (Ppx_deriving utility functions ppxlib#317).
  3. Delegates ppx_deriving quoter to ppxlib quoter.

Notably, this makes [@@deriving_inline ...] work on these standard derivers.

TODO

src/api/ppx_deriving.cppo.ml Show resolved Hide resolved
src/api/ppx_deriving.cppo.mli Outdated Show resolved Hide resolved
src_plugins/create/ppx_deriving_create.cppo.ml Outdated Show resolved Hide resolved
src_plugins/create/ppx_deriving_create.cppo.ml Outdated Show resolved Hide resolved
src_test/deriving/test_ppx_deriving.ml Outdated Show resolved Hide resolved
src_test/deriving/test_ppx_deriving.ml Outdated Show resolved Hide resolved
Comment on lines 315 to 321
(* TODO: add to ppxlib? *)
let ebool: _ Ast_pattern.t -> _ Ast_pattern.t =
Ast_pattern.map1 ~f:(function
| [%expr true] -> true
| [%expr false] -> false
| _ -> failwith "not bool")
let args () = Deriving.Args.(empty +> arg "with_path" (ebool __))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handling the arguments in show { with_path = false } using ppxlib was surprisingly annoying. Especially since the argument is always option, so the default case needs to be handled below separately. Maybe would be useful to have some arguments with defaults in ppxlib?

src_plugins/show/ppx_deriving_show.cppo.ml Outdated Show resolved Hide resolved
@pitag-ha
Copy link
Member

pitag-ha commented Sep 6, 2022

Hey @sim642, even though I'm still not finding the time to review (as we've mentioned already, finding time to work on PPX-related things is rare), I at least already wanted to take the time to thank you. Thanks for the PR! I personally would have preferred to write a new bunch of standard derivers to have more freedom to improve things (as started here, but never finished/gotten far). However, I appreciate the work and it's definitely good to have these standard derivers written in ppxlib. It might still take a bit, but when we some have time for PPX we'll review this - if not me, then @panglesd. Feel free to ping us once in a while.

@sim642
Copy link
Contributor Author

sim642 commented Mar 9, 2023

@pitag-ha @panglesd ping!

@panglesd
Copy link
Contributor

Very sorry about the delay. I'll put that on the top of my todo list. (Although next week I'm on holidays).

Copy link
Contributor

@panglesd panglesd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments, restricted to the API part (I'll continue with the plugins tomorrow).

Is Arg deprecated in favour of Ast_pattern?

I guess functions which have a direct equivalent in ppxlib should be deprecated. So Quoting functions should be deprecated, as well as mangle_lid, and mangle_type_decl.
(Or is there a reason not to do so?)

Finally, it could be nice to add a message to the deprecated alerts: [@@ocaml.deprecated "Use Ppxlib.register ... instead] (I think that is valid OCaml).

src/api/ppx_deriving.cppo.ml Outdated Show resolved Hide resolved
ppx_deriving.opam Outdated Show resolved Hide resolved
src/api/ppx_deriving.cppo.ml Show resolved Hide resolved
src/api/ppx_deriving.cppo.mli Outdated Show resolved Hide resolved
src/api/ppx_deriving.cppo.mli Outdated Show resolved Hide resolved
@sim642
Copy link
Contributor Author

sim642 commented Mar 21, 2023

Regarding the deprecations, it would be fine to also just exclude them from this PR. If I remember correctly, the original inspiration was #250, which proposes to deprecate the entire API. However, given warnings-as-errors in many projects, this might cause unnecessary breakage of derivers still built on ppx_deriving. Having everything ported would be nice, but these things don't have to be coupled.

I might've also used the deprecation warnings as a guide to find any usages to port within these standard plugins.

Is Arg deprecated in favour of Ast_pattern?

It's not even marked deprecated here right now, but I think I wanted to make as big step towards fully using ppxlib as possible, hence the switch to Ast_pattern which should replace it.
In a way, this PR serves as an exercise in porting such derivers and revealing places where ppx_deriving's old API is more convenient than ppxlib's new one.

Copy link
Contributor

@panglesd panglesd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went through the plugins, and the modifications look good!

However, I agree that they sometimes show some holes or defects in the ppxlib API. I summarize them here:

val declare_flag : string -> 'a Context.t -> ('a, unit) t
val check_flag : ('a, unit) t -> ?mark_as_seen:bool -> 'a -> bool
  • Add a way to define arguments with defaults
val arg_with_default : 
  string ->
  (expression, 'a -> 'a, 'a) Ast_pattern.t ->
  default:'a ->
  'a param

Most of them are not too hard to solve. I will open the relevant issues, and label them as good first issues (can be useful for an Outreachy applicant)!
For turning Recursive to NonrecursiveinQuoter`, you can make a PR directly with this, since you offered it, thanks!

src_plugins/enum/ppx_deriving_enum.cppo.ml Outdated Show resolved Hide resolved
src/api/ppx_deriving.cppo.mli Outdated Show resolved Hide resolved
@panglesd
Copy link
Contributor

About the inclusion of deprecation of the API in this PR: I don't have a strong opinion at all...

If there is a clear indication of what should be used instead, and it's easy to fix (for instance, the mangle function, but not the Arg module), then I think it is OK: when built by opam, warnings are not errors, and when built locally, it is easy to follow the instructions to fix the deprecations warning.

But, I agree that it is not completely necessary, and might upset some people. Maybe, a mention in the ppx_deriving documentation is enough.

@sim642
Copy link
Contributor Author

sim642 commented Mar 23, 2023

I've just excluded all the deprecations from this PR right now to avoid blocking this by those additional discussions and decisions.

@gasche
Copy link
Contributor

gasche commented Nov 5, 2023

I'm one of the few maintainers of ppx_deriving, mostly inactive. I can give some time next week to look at this again and move towards merging, but I prefer to let other people take care of releases. Do we have a volunteer to cut out a new release? (I'm happy to give commit rights to enable this.)

@sim642
Copy link
Contributor Author

sim642 commented Nov 5, 2023

Hey! This has been sitting around for quite a while now. It'd be great to get this merged and released as well. It's been a long while since ppx_deriving has seen a release (even #252 hasn't made it).

@kit-ty-kate
Copy link
Collaborator

@pitag-ha @panglesd do you want the merge rights by any chance?

@panglesd
Copy link
Contributor

panglesd commented Nov 8, 2023

Hello ! Sorry I'm off during one month, I will assess whether I accept this responsibility when I come back!

@pitag-ha
Copy link
Member

@pitag-ha @panglesd do you want the merge rights by any chance?

I don't :) Let's see if @panglesd happens to want them when he's back. Btw, what's the current maintenance status of ppx_deriving? And what's the current general status of ppx_deriving? From what I remember, ppx_deriving is still used in a few contexts:

  1. A few derivers are still registered with ppx_deriving. IIRC, ppx_deriving just forwards the registration to ppxlib in that case.
    a) The ppx_deriving.std plug-ins are still registered with ppx_deriving (changes with this PR).
    b) A few other derivers are still registered with ppx_deriving (e.g. visitors?).
  2. The ppx_deriving driver is still used in a few cases.
    a) utop, and possibly other toplevels as well, use the ppx_deriving driver for derivers rather than the ppxlib driver.
    b) Is there any build system that uses ppx_deriving? (dune doesn't, but I don't know about other build systems or people who write their custom build Makefiles)

Is that right?

I can give some time next week to look at this again and move towards merging

Thank you, @gasche! If that would help, I could answer questions about Ppxlib if they come up.

@panglesd
Copy link
Contributor

Sorry for the long delay, I'm back.

@NathanReb since you have joined as a ppxlib maintainer, there is a new variable in the equation! Would you be interested in any activity involving this repository?

If not, I will be happy to take care of cutting a release that includes this change. That being said, I can't commit to be an active maintainer in the long run!

@NathanReb
Copy link
Collaborator

NathanReb commented Jan 4, 2024

I'd be happy to take part in smoothing things out here yes! Will need to catch up a bit but merging and releasing this work seems important for the ppx ecosystem so I'll gladly to take care of it!

@kit-ty-kate
Copy link
Collaborator

@gasche could you add @NathanReb ? I thought i had the rights to do that but turns out i only have access to some of the settings and not this one (github maintainer vs. admin)

@gasche
Copy link
Contributor

gasche commented Jan 5, 2024

Done, and I made you @kit-ty-kate an Admin. Thanks!

@NathanReb
Copy link
Collaborator

@sim642 sorry for the long wait. I will work on getting this merged and will start reviewing it.

Are you still willing to work on this if there are changes to be made?

@sim642
Copy link
Contributor Author

sim642 commented Mar 6, 2024

Are you still willing to work on this if there are changes to be made?

Yes, that shouldn't be an issue.

Copy link
Collaborator

@NathanReb NathanReb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good! I only have one suggestion to make the attribute_get2 a bit easier to use and more readable!

src_plugins/create/ppx_deriving_create.cppo.ml Outdated Show resolved Hide resolved
src_plugins/create/ppx_deriving_create.cppo.ml Outdated Show resolved Hide resolved
src_plugins/show/ppx_deriving_show.cppo.ml Outdated Show resolved Hide resolved
@NathanReb
Copy link
Collaborator

Sorry again for the long delays and thanks for taking the time to get back to this @sim642. Really appreciate it!

Let's merge this!

@NathanReb NathanReb merged commit 4b5b9ff into ocaml-ppx:master Mar 7, 2024
1 check passed
NathanReb added a commit to NathanReb/opam-repository that referenced this pull request Mar 12, 2024
CHANGES:

* 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/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)
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.

6 participants