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

Added ?warning flag to Deriving.Generator.make to enable warnings in derived code #440

Merged
merged 3 commits into from
Jun 30, 2023

Conversation

ceastlund
Copy link
Collaborator

Adds the ability for ppx derivers to opt in to unused code warnings, which ppxlib would otherwise disable for derived code. This will help, over time, clean up unused code from derivers.

We made this property opt-in because currently, many ppxes are not compatible with these warnings. For example, ppx_hash derives hash and hash_fold_t. If one were used and not the other, there's no way to derive "half" of the ppx. So we can't opt ppx_hash in until we have a way to request it piecemeal. Over time, we'll have to make more ppxes compatible with this option in order to clean up unused code.

ceastlund added a commit to janestreet/ppxlib that referenced this pull request Jun 28, 2023
Signed-off-by: Carl Eastlund <ceastlund@janestreet.com>
@ceastlund ceastlund marked this pull request as ready for review June 28, 2023 19:46
@ceastlund
Copy link
Collaborator Author

@pitag-ha and @panglesd, this is part of an intern project here at janestreet by @jacksonzou123. Let us know how this looks. We should also think how upgrading will go for external clients as we opt ppxes into this. I mostly think it won't be that hard, because manually silencing warnings is not hard if people need to.

Copy link
Collaborator

@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.

Code looks good to me, with minor comments (and the need to format with the right version/profile of ocamlformat)!

I'm curious about the reason for willing to restrict the generated code.
Is it to improve compile time performances?

(I expect the compiler to remove unused values anyway, so this should not affect runtime performances).

src/deriving.ml Outdated
Comment on lines 676 to 677
if List.is_empty items
then []
Copy link
Collaborator

Choose a reason for hiding this comment

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

This test is to avoid adding removing warnings in an empty structure, in case no code is generated, such as in:

include struct [@@@ocaml.warning "-32"] end[@@ocaml.doc "@inline"][@@merlin.hide]

That was not the original behaviour: the useless inline struct was added in any case. So this is an unrelated bonus feature from this PR!

However, those chains of shadowing can be hard to read: we now have three wrap_sig and wrap_str one after the other, and we don't know which function does what.
Maybe you could add at least a comment on what are the invariant the function expect, and what it does?
For instance, the last wrap_sig function is handling the empty case, and the middle wrap_sig invariant is that it takes a non-empty signature.

src/deriving.ml Outdated Show resolved Hide resolved
@ceastlund
Copy link
Collaborator Author

I'm curious about the reason for willing to restrict the generated code.
Is it to improve compile time performances?

I don't understand what you're asking here, @panglesd.

… in derived code.

Signed-off-by: Carl Eastlund <ceastlund@janestreet.com>
Signed-off-by: Carl Eastlund <ceastlund@janestreet.com>
@ceastlund
Copy link
Collaborator Author

If you mean, why do we want to remove unused code, then yes, it's for compilation performance. It's also to restrict final binary size, which can even improve runtime performance.

Signed-off-by: Carl Eastlund <ceastlund@janestreet.com>
@ceastlund ceastlund force-pushed the deriving-with-warnings-enabled branch from d796cd4 to e3982fe Compare June 30, 2023 16:11
@ceastlund ceastlund merged commit c1387c7 into ocaml-ppx:main Jun 30, 2023
ceastlund added a commit that referenced this pull request Jun 30, 2023
Signed-off-by: Carl Eastlund <ceastlund@janestreet.com>
@pitag-ha
Copy link
Member

pitag-ha commented Jul 3, 2023

We should also think how upgrading will go for external clients as we opt ppxes into this. I mostly think it won't be that hard, because manually silencing warnings is not hard if people need to.

Do I understand correctly that you're planning to opt the public releases of the Jane Street derivers into this? Have you had a look at how big the impact would be?

@ceastlund
Copy link
Collaborator Author

No we haven't. We can leave it off in the public release if need be. But probably we're not the only ones who want the benefit.

@ceastlund
Copy link
Collaborator Author

It's definitely worth some thought about how we proceed with this rollout, though.

@pitag-ha
Copy link
Member

pitag-ha commented Jul 6, 2023

But probably we're not the only ones who want the benefit.

Yes, I definitely agree. Still, I'd expect quite a widespread breakage, both inside the opam-repo and for other users. Let's indeed give this some thought.

Two of the first things we can do when the time comes are get a clearer idea of the breakage on the opam-repo by running a health-check, and get an impression on what community members think about this by asking on discuss. Also, I'll keep this change in mind for the release highlights on the ocaml.org changelog for the next release to already give this change some visibility.

avsm pushed a commit to ocaml/opam-repository that referenced this pull request Oct 5, 2023
CHANGES:

- Fix support for OCaml 5.1: migrated code preserves generative
  functor warnings, without creating more. Locations are better
  preserved. (ocaml-ppx/ppxlib#432, @pitag-ha, @panglesd)

- Driver: Add `-unused-code-warnings` command-line flag. (ocaml-ppx/ppxlib#444, @ceastlund)

- Add `?warning` flag to `Deriving.Generator.make`. (ocaml-ppx/ppxlib#440, @jacksonzou123 via @ceastlund)

- Restore the "path_arg" functionality in the V3 API (ocaml-ppx/ppxlib#431, @ELLIOTTCABLE)

- Expose migration/copying/etc. functions for all AST types needed by `Pprintast` (ocaml-ppx/ppxlib#454, @antalsz)

- Preserve quoted attributes on antiquotes in metaquot (ocaml-ppx/ppxlib#441, @ncik-roberts)

- Attribute namespaces: Fix semantics of reserving multi-component namespaces (ocaml-ppx/ppxlib#443, @ncik-roberts)
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

- Fix support for OCaml 5.1: migrated code preserves generative
  functor warnings, without creating more. Locations are better
  preserved. (ocaml-ppx/ppxlib#432, @pitag-ha, @panglesd)

- Driver: Add `-unused-code-warnings` command-line flag. (ocaml-ppx/ppxlib#444, @ceastlund)

- Add `?warning` flag to `Deriving.Generator.make`. (ocaml-ppx/ppxlib#440, @jacksonzou123 via @ceastlund)

- Restore the "path_arg" functionality in the V3 API (ocaml-ppx/ppxlib#431, @ELLIOTTCABLE)

- Expose migration/copying/etc. functions for all AST types needed by `Pprintast` (ocaml-ppx/ppxlib#454, @antalsz)

- Preserve quoted attributes on antiquotes in metaquot (ocaml-ppx/ppxlib#441, @ncik-roberts)

- Attribute namespaces: Fix semantics of reserving multi-component namespaces (ocaml-ppx/ppxlib#443, @ncik-roberts)
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.

3 participants