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

cumbersome flag attributes #408

Merged
merged 7 commits into from
Sep 26, 2023

Conversation

dianaoigo
Copy link
Contributor

@panglesd i have made some progress from the very helpful pointers you gave. kindly review and advise.
In my solution, i added specification in the src/attribute.mli then declared the attribute with a unit continuation. an empty payload pattern is created and passed to declare_with_all_args with a unit continuation. The has_flag function then checks if the attribute is present for the given value of x and returns a boolean value accordingly, with an optional mark_as_seen parameter that can be used to mark the attribute as seen if needed.

Copy link
Contributor

@marrious11 marrious11 left a comment

Choose a reason for hiding this comment

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

Nice one @dianaoigo.
Could you try to add a DCO check

There is a requirement in ppxlib's to have signed commits... I think you just need to run:

git commit --amend --signoff

and force push to replace the current commit with a signed commit.

@panglesd
Copy link
Collaborator

Thanks!

The code is perfect. You need a few things to make the CI happy though:

  • The code needs to be formatted. For this, you need the right version of ocamlformat installed (0.24.1), and to run dune fmt --auto-promote.
  • As marrious11 said, you need to "sign-off" all your commits: they need to be created with the --sign-off argument.
  • You need to add an entry in the Changes.md file!

And to make the documentation happy, you need to move your new entries in the signature. Indeed, the .mli file is used to generate the API page https://ocaml.org/p/ppxlib/latest/doc/Ppxlib/Attribute/index.html. Since you added the entries at the bottom of the file, they will be rendered at the bottom of the page. I think it would be more logic to have declare_flag next to the declare function, and has_flag next to get.
Finally, you should add "doc-comments" (the comments enclosed in (** ... *)) associated to the new values, that describe what they do.

@dianaoigo
Copy link
Contributor Author

@panglesd thank you so much for your guidance. switching between working on different projects sometimes makes one forget some things. i will make the changes asap.

@Burnleydev1
Copy link
Contributor

Burnleydev1 commented Mar 30, 2023

Hello @dianaoigo, I think to sign-off the commits that have already been pushed,

Use git log to find the hash of the commit that you want to edit.

Run git rebase -i <enter the commit hash here> to start a rebase session that includes the commit you want to edit and its parent commit. This will open a text editor with a list of commits and instructions for how to edit them.

Find the line that corresponds to the commit you want to edit, and change the command from pick to edit. Save and close the file.

Run git commit --amend -s to make changes to the commit. This will open a text editor where you can modify the commit message and/or the contents of the commit.

After making your changes, save and close the file.

Run git rebase --continue to continue the rebase process. This will apply your changes and modify the commit history.
When you're done, run git push --force-with-lease origin cumbersome_flag_attributes

@dianaoigo dianaoigo closed this Mar 30, 2023
@dianaoigo dianaoigo reopened this Mar 30, 2023
@dianaoigo dianaoigo force-pushed the cumbersome_flag_attributes branch 4 times, most recently from 68f6ce3 to 615ff2b Compare March 30, 2023 19:44
@dianaoigo
Copy link
Contributor Author

@panglesd after some serious fight and going in circles, i believe everything is in order.

@dianaoigo
Copy link
Contributor Author

@Burnleydev1 @marrious11 thank you so much for the help

@panglesd
Copy link
Collaborator

@dianaoigo nice job! Indeed, all commits are now signed :)

I still have a few comments:

  • As you can see in the list of modifications, your commit introduced many changes in the Changes.md file that are not necessary. Usually, it's because your editor reformatted the file at some point, which changed the layout. It would be better to have only the modification relevant to your change entry.
  • The changelog (the Changes.md file) is used for users of ppxlib to know quickly the set of ppxlib new features/bugfixes that happened in between each release. So you should not add a 0.30.0 section, but add your entry to the unreleased section. Moreover, the text should be informative for someone who knows ppxlib, but who does not know about this PR or the corresponding issue. You should precise what it is about (e.g. attributes with no payload that can be checked for presence).
  • Similarly, the doc comments should not just describe the type: that information is already there! The doc comment should explain what this function is for, what it does (only the comment in the .mli file is important, since it is the one rendered in the API.)

Writing good doc-comment is not an easy job, especially for newcomers in this codebase, but it is a very good exercise!

@dianaoigo
Copy link
Contributor Author

@panglesd thank you for the guidance, i will familiarize myself more with writing good-doc. Do i still need to make the changes suggested?

@panglesd
Copy link
Collaborator

Unless you don't want to or don't have time (which I'll perfectly understand and do the changes myself!), yes the changes are necessary to get the PR merged!

@dianaoigo
Copy link
Contributor Author

@panglesd i would love to do them but i will kindly request that you do them so that i can learn from what you do

@panglesd panglesd force-pushed the cumbersome_flag_attributes branch from 4e5a938 to 3f43ec1 Compare April 14, 2023 13:02
@panglesd
Copy link
Collaborator

@dianaoigo I finally fixed the docstrings! (Sorry for the long delay).

I added a non raising version of has_flag: has_flag_res.
I also spotted a mistake in your handling of mark_as_seen. That variable should be passed to get_res. Your previous handling of it did not have a real effect!

Finally, I added a test.

Feel free to ask any question if you want some clarifications!

@dianaoigo
Copy link
Contributor Author

@panglesd you made it look too easy with writing the docs. I'll get it with more practice
In my code mark_as_seen only determines whether to set the seen variable to true but doesn't carry out any modification. basically mark_as_seen is supposed to be effect the behavior of get_res? Error handling part was a good tip, i'll remember that part always

@panglesd panglesd force-pushed the cumbersome_flag_attributes branch from 3f43ec1 to bae3fa8 Compare September 26, 2023 08:37
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
@panglesd panglesd force-pushed the cumbersome_flag_attributes branch from ee15399 to ade4878 Compare September 26, 2023 09:46
@panglesd panglesd merged commit ef01fe6 into ocaml-ppx:main Sep 26, 2023
panglesd added a commit to panglesd/ppxlib that referenced this pull request Sep 26, 2023
@panglesd
Copy link
Collaborator

Thanks @dianaoigo !
Sorry for the slow merging process. Your changes will be incorporated in the next ppxlib release!

NathanReb added a commit to NathanReb/opam-repository that referenced this pull request Feb 1, 2024
CHANGES:

- Fix `Longident.parse` so it properly handles unparenthesized dotted operators
  such as `+.` or `*.`. (ocaml-ppx/ppxlib#111, @rgrinberg, @NathanReb)

- raising an exception does no longer cancel the whole context free phase(ocaml-ppx/ppxlib#453, @Burnleydev1)

- Sort embedded errors that are appended to the AST by location so the compiler
  reports the one closer to the beginning of the file first. (ocaml-ppx/ppxlib#463, @NathanReb)

- Update `Attribute.get` to ignore `loc_ghost`. (ocaml-ppx/ppxlib#460, @ceastlund)

- Add API to manipulate attributes that are used as flags (ocaml-ppx/ppxlib#408, @dianaoigo)

- Update changelog to use ISO 8061 date format: YYYY-MM-DD. (ocaml-ppx/ppxlib#445, @ceastlund)

- Replace `Caml` with `Stdlib`. (ocaml-ppx/ppxlib#427, @ceastlund)

- When a transformation raises, the last valid AST is used as input to the upcoming
  transformations. All such errors are collected and appended as
  extension nodes to the final AST (ocaml-ppx/ppxlib#447, @Burnleydev1)

- Fix a small mistake in the man pages: Embededding errors is done by default with
  `-as-pp`, not with `-dump-ast` (ocaml-ppx/ppxlib#464, @pitag-ha)

- Set appropriate binary mode when writing to `stdout` especially for Windows
  compatibility. (ocaml-ppx/ppxlib#466, @jonahbeckford)
NathanReb added a commit to NathanReb/opam-repository that referenced this pull request Feb 5, 2024
CHANGES:

- Add an optional `embed_errors` argument to `Context_free.map_top_down` that
  controls how to deal with exceptions thrown by context-free rules.
  (ocaml-ppx/ppxlib#468, @NathanReb)

- Fix `Longident.parse` so it properly handles unparenthesized dotted operators
  such as `+.` or `*.`. (ocaml-ppx/ppxlib#111, @rgrinberg, @NathanReb)

- raising an exception does no longer cancel the whole context free phase(ocaml-ppx/ppxlib#453, @Burnleydev1)

- Sort embedded errors that are appended to the AST by location so the compiler
  reports the one closer to the beginning of the file first. (ocaml-ppx/ppxlib#463, @NathanReb)

- Update `Attribute.get` to ignore `loc_ghost`. (ocaml-ppx/ppxlib#460, @ceastlund)

- Add API to manipulate attributes that are used as flags (ocaml-ppx/ppxlib#408, @dianaoigo)

- Update changelog to use ISO 8061 date format: YYYY-MM-DD. (ocaml-ppx/ppxlib#445, @ceastlund)

- Replace `Caml` with `Stdlib`. (ocaml-ppx/ppxlib#427, @ceastlund)

- When a transformation raises, the last valid AST is used as input to the upcoming
  transformations. All such errors are collected and appended as
  extension nodes to the final AST (ocaml-ppx/ppxlib#447, @Burnleydev1)

- Fix a small mistake in the man pages: Embededding errors is done by default with
  `-as-pp`, not with `-dump-ast` (ocaml-ppx/ppxlib#464, @pitag-ha)

- Set appropriate binary mode when writing to `stdout` especially for Windows
  compatibility. (ocaml-ppx/ppxlib#466, @jonahbeckford)
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

- Add an optional `embed_errors` argument to `Context_free.map_top_down` that
  controls how to deal with exceptions thrown by context-free rules.
  (ocaml-ppx/ppxlib#468, @NathanReb)

- Fix `Longident.parse` so it properly handles unparenthesized dotted operators
  such as `+.` or `*.`. (ocaml-ppx/ppxlib#111, @rgrinberg, @NathanReb)

- raising an exception does no longer cancel the whole context free phase(ocaml-ppx/ppxlib#453, @Burnleydev1)

- Sort embedded errors that are appended to the AST by location so the compiler
  reports the one closer to the beginning of the file first. (ocaml-ppx/ppxlib#463, @NathanReb)

- Update `Attribute.get` to ignore `loc_ghost`. (ocaml-ppx/ppxlib#460, @ceastlund)

- Add API to manipulate attributes that are used as flags (ocaml-ppx/ppxlib#408, @dianaoigo)

- Update changelog to use ISO 8061 date format: YYYY-MM-DD. (ocaml-ppx/ppxlib#445, @ceastlund)

- Replace `Caml` with `Stdlib`. (ocaml-ppx/ppxlib#427, @ceastlund)

- When a transformation raises, the last valid AST is used as input to the upcoming
  transformations. All such errors are collected and appended as
  extension nodes to the final AST (ocaml-ppx/ppxlib#447, @Burnleydev1)

- Fix a small mistake in the man pages: Embededding errors is done by default with
  `-as-pp`, not with `-dump-ast` (ocaml-ppx/ppxlib#464, @pitag-ha)

- Set appropriate binary mode when writing to `stdout` especially for Windows
  compatibility. (ocaml-ppx/ppxlib#466, @jonahbeckford)
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.

4 participants