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 ppx from andreypopp/ppx_deriving #10

Merged
merged 77 commits into from
Aug 16, 2024
Merged

Port ppx from andreypopp/ppx_deriving #10

merged 77 commits into from
Aug 16, 2024

Conversation

jchavarri
Copy link
Member

@jchavarri jchavarri commented Aug 14, 2024

This PR ports @andreypopp's PPX to this repo.

For now, the current state is "dune build works" 😅 . But it's a good point to open discussion. Edit: all issues have now been fixed.

Proposal

The idea is to offer the json PPX as part of the melange-json package. As an addition, native compatibility is offered as well through Yojson.

Having everything in a single repo / package makes maintenance easier for maintainers, and usage more straight forward for users.

(As a nice side effect, we got GH actions workflow for opam 💰 )

Questions

  • Should we modify the native ppx so that it works with a flag -native? I personally think it's cleaner to leave the current approach with its own ppx / exe
  • Are internal names for libraries ok? e.g. ppx_deriving_json_browser
  • Are browser and native suffixes (suffices?) ok?

TODO

  • Add changelog entry
  • Fix nix build
  • Fix 4.14 build

@jchavarri
Copy link
Member Author

I renamed all appearances of browser to js in 460e4a4.

Another thing might be worth looking at (but can do later) is to trim Ppx_deriving_tools module, it has more code than needed for this ppx and more things exposed than needed for this ppx.

I tried cleaning this up but didn't see any obvious / easy things to remove. For now I just moved tools folder inside ppx to keep things tidy, as this folder is exclusively needed in the ppx.

I also updated the ppx readme to remove custom opam repo addition as it won't be needed anymore, added a changelog entry, and fixed the 4.14 compatibility.

The last remaining thing that I can think of is fixing CI for nix, @anmonteiro could you give me a hand with that please? 🥺

@andreypopp
Copy link
Collaborator

another thought on naming, maybe for ppx it's better to have ppx in its name?

  • melange-json.ppx for js ppx
  • melange-json.ppx-native for native ppx
  • melange-json.ppx-runtime for runtime (both js and native)

I quite often use ocamlfind list | rg ... to see what's available and having ppx in there will hint how to use the lib

@jchavarri
Copy link
Member Author

Yes, I like that naming much more. It's also consistent with other ppxs in Melange ecosystem, like the pervasive melange.ppx.

@jchavarri
Copy link
Member Author

@andreypopp I did the renaming in d3c6e5d.

melange-json.ppx-runtime for runtime (both js and native)

I wasn't sure how to use the same name for both (there can only exist one public lib name at the moment), so I went with melange-json.ppx-runtime for js, and melange-json.ppx-native-runtime for native.

@jchavarri
Copy link
Member Author

and melange-json.ppx-native-runtime for native.

Actually melange-json.ppx-runtime-native after last commit 😓

@andreypopp
Copy link
Collaborator

ah, yeah, not possible to have clashes in public names, but not a big deal, these libs will be added by dune automatically once you use a corresponding ppx

@anmonteiro
Copy link
Member

I'm also wondering what your preference is regarding the ppx being its own package, e.g.

  • melange-json for the melange library
  • melange-json-ppx for the ppx? and the library names could be:
    • melange-json-ppx for the melange ppx
    • melange-json-ppx.native for the native ppx

No strong preference here, just providing an alternative

@anmonteiro
Copy link
Member

The last remaining thing that I can think of is fixing CI for nix, @anmonteiro could you give me a hand with that please? 🥺

I pushed a commit fixing this

@andreypopp
Copy link
Collaborator

andreypopp commented Aug 16, 2024

few more points:

  • need to unify exceptions between melange-json and the ppx, I think this is important
  • let's leave the native part undocumented for now, I think we'd want to transition to Yojson.Safe.t before making it public

@andreypopp
Copy link
Collaborator

I'm also wondering what your preference is regarding the ppx being its own package

other options:

  • have js ppx in melange-json package but split away native ppx into a separate package
  • split js ppx and native ppx into separate packages (3 packages total counting melange-json)

the nice thing about splitting away native ppx is that we won't impose yojson dep on melange users and we won't impose melange dep on native users

@jchavarri
Copy link
Member Author

need to unify exceptions between melange-json and the ppx, I think this is important

@andreypopp could you elaborate on how this unification would look like? melange-json has DecodeError and ParseError. the new ppx has Error, which is used exclusively for the "Not supported" messages. I don't see how they could be unified?

I'm also wondering what your preference is regarding the ppx being its own package

other options:

* have js ppx in melange-json package but split away native ppx into a separate package

* split js ppx and native ppx into separate packages (3 packages total counting melange-json)

I prefer the "single package, until proved otherwise" approach. Having a single package makes things easier for maintainers and users. The "until proved otherwise" means that if some user some day (or ourselves), comes with a legit use case where separate packages are needed, then we can always split. Otherwise, it seems like a preoptimization.

A couple of examples where multi package made things harder for us in the past (in this case, it's reason-react and reason-react-ppx):

  • As maintainers, publishing in opam might lead to cycles in dependencies between the packages, example
  • As users, I spent (just yesterday) 20min blocked on some issue with the code not updating, to later realize I was pinning reason-react, but not reason-react-ppx

Maybe I am missing what are the main upsides of having multiple packages? The "worst" part of single package is that as a user I am downloading and installing deps that I am not using, but all things considered it doesn't outweight the downsides imo.

jchavarri added a commit that referenced this pull request Aug 16, 2024
@jchavarri
Copy link
Member Author

jchavarri commented Aug 16, 2024

let's leave the native part undocumented for now, I think we'd want to transition to Yojson.Safe.t before making it public

Done in 3a31039.

@andreypopp
Copy link
Collaborator

@andreypopp could you elaborate on how this unification would look like? melange-json has DecodeError and ParseError. the new ppx has Error, which is used exclusively for the "Not supported" messages. I don't see how they could be unified?

@jchavarri the ppx runtime uses this exception and melange-json has DecodeError, so I think ppx runtime should also use DecodeError — that way if users would want to catch the exception and recover — they will only have to do this for DecodeError.

@andreypopp
Copy link
Collaborator

let's leave the native part undocumented for now, I think we'd want to transition to Yojson.Safe.t before making it public

Done in 3a31039.

The README still mentions yojson/native. By the way, should we move docs from this README to the main project README, why have two?

@jchavarri
Copy link
Member Author

jchavarri commented Aug 16, 2024

the ppx runtime uses this exception and melange-json has DecodeError, so I think ppx runtime should also use DecodeError — that way if users would want to catch the exception and recover — they will only have to do this for DecodeError.

updated the ppx to use DecodeError in b02fb3c. pls lmk if this is what you had in mind.

The README still mentions yojson/native. By the way, should we move docs from this README to the main project README, why have two?

both should be fixed in 19fcb09.

Copy link
Collaborator

@andreypopp andreypopp left a comment

Choose a reason for hiding this comment

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

All looks good to me, thank you!

@jchavarri jchavarri merged commit c615cb1 into main Aug 16, 2024
7 checks passed
@jchavarri jchavarri deleted the ppx branch August 16, 2024 10:16
jchavarri added a commit to jchavarri/opam-repository that referenced this pull request Aug 16, 2024
avsm pushed a commit to avsm/opam-repository that referenced this pull request Sep 5, 2024
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