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

Expand structure and signature items before applying attribute rules #279

Merged
merged 1 commit into from
Sep 14, 2021

Conversation

NathanReb
Copy link
Collaborator

@NathanReb NathanReb commented Sep 10, 2021

This PR changes the order in which context-free rules are applied.

It is a follow up to #276 and "fixes" the behaviour observed there. With this PR a node with attributes attached will be first expanded and then the inline attribute rules applied instead of the other way around.

Imagine the following:

type t = [%some_ext ...]
[@@deriving some_deriver]

Before this PR, the some_deriver transformation would be applied first, now it is applied to the result of the expansion of the type declaration, meaning after the some_ext transformation was applied.

@kit-ty-kate is gracefully testing this on the opam universe to see if it has any serious impact. I don't expect anyone to rely on this behaviour but better be safe than sorry.

Edit: You might want to review this while hiding whitespace diffs as a whole block in Context_free has gained one level of identation without any further change.

@NathanReb NathanReb force-pushed the expand-before-deriving branch from d2d5dd4 to ce0183a Compare September 10, 2021 13:42
Copy link
Contributor

@kit-ty-kate kit-ty-kate left a comment

Choose a reason for hiding this comment

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

The check in opam-repository didn't reveal any packages broken by this

@NathanReb NathanReb force-pushed the expand-before-deriving branch from ce0183a to 53adb13 Compare September 13, 2021 12:36
@NathanReb NathanReb marked this pull request as ready for review September 13, 2021 12:36
@NathanReb NathanReb requested a review from a user September 13, 2021 12:36
@NathanReb NathanReb requested a review from pitag-ha as a code owner September 13, 2021 12:36
@NathanReb
Copy link
Collaborator Author

I updated the internal documentation and the tests description to reflect this change. I think this should be ready for review now.

@jeremiedimino @ceastlund, I don't really expect anything to break here but it might be good to test this change inside JS' monorepo. What do you think?

@NathanReb NathanReb force-pushed the expand-before-deriving branch from 53adb13 to 330744e Compare September 13, 2021 15:53
Signed-off-by: Nathan Rebours <nathan.p.rebours@gmail.com>
@NathanReb NathanReb force-pushed the expand-before-deriving branch from 330744e to eadedc8 Compare September 13, 2021 17:17
@NathanReb
Copy link
Collaborator Author

Rebased on top of (formatted!) main and fixed the bug found by @pitag-ha where I forgot to remove a self#structure_item call in Context_free.map_top_down#structure resulting in some structure item being traversed twice.

Copy link
Member

@pitag-ha pitag-ha left a comment

Choose a reason for hiding this comment

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

Looks good also to me. Thanks!

@NathanReb NathanReb merged commit f6b7146 into ocaml-ppx:main Sep 14, 2021
pitag-ha added a commit to pitag-ha/opam-repository that referenced this pull request Dec 8, 2021
CHANGES:

- Add support for OCaml 4.14 (ocaml-ppx/ppxlib#304, @kit-ty-kate)

- Expand nodes before applying derivers or other inline attributes based
  transformation, allowing better interactions between extensions and
  derivers (ocaml-ppx/ppxlib#279, ocaml-ppx/ppxlib#297, @NathanReb)

- Add support for registering ppx_import as a pseudo context-free rule (ocaml-ppx/ppxlib#271, @NathanReb)

- Add `input_name` to the `Expansion_context.Extension` and `Expansion_context.Deriver` modules (ocaml-ppx/ppxlib#284, @tatchi)

- Improve `gen_symbol` to strip previous unique suffix before adding a new one (ocaml-ppx/ppxlib#285, @ceastlund)

- Improve `name_type_params_in_td` to use prefixes `a`, `b`, ... instead of `v_x`. (ocaml-ppx/ppxlib#285, @ceastlund)

- Fix a bug in `type_is_recursive` and `really_recursive` where they would
  consider a type declaration recursive if the type appeared inside an attribute
  payload (ocaml-ppx/ppxlib#299, @NathanReb)
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