-
Notifications
You must be signed in to change notification settings - Fork 409
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
Using PPX #8586
Comments
I'd be up to give this a spin! After a quick offline discussion with @rgrinberg we agreed a good place to start would be to allow use of ppx inside dune via the separate |
I'm surprised you're considering depending on base given the recent announcement https://discuss.ocaml.org/t/ann-v0-16-release-of-jane-street-packages/12398 about reducing support for older ocaml versions. |
Yes, using base "as-is" is a non starter. The idea was to strip it to a 4.08+ compatible subset that is enough to run bin_prot, compare, hash or to port the mentioned ppx's to work without base. |
I started looking into this by getting familiar with the bootstrapping of dune and managed to modify I then proceeded to write a dummy I tried a first prototype using simple rules in dune files but quickly realized that it can't easily be done this way. We'd have to write one for each preprocessed file and we don't easily have access to the ppx driver that dune as already built to preprocess the files as part of a regular dev build. We also can't easily have them generated in a Ideally we'd want to handle this from within dune itself so we can easily access dune files and the relevant I was thinking about adding an alias for this so that running I'm not sure if we could easily disable this alias outside of dune codebase so that it doesn't leak unintentionally. Maybe simply not documenting it, in association with the lack of support for building using preprocessed sources outside of dune is enough of a dissuasion to use this in the wild to build projects. If making this alias strictly private is too much of a hassle, I imagined we could go with a seperate private executable that would do the exact same steps i.e. read dune files, generate preprocessed source files, diff with Let me know what you think and if you have any better suggestions on how to tackle this specific bit of the work. |
Such a ppx preview could also be related to #6897. However we probably don't want to implement anything user facing just yet and get something working internally first. I don't think making it private will be a hassle. We already have |
Isn't it just a matter of creating a dune file in
Do we really need the intermediate diff step? The code is going to be hardly readable and generated. We could just set As for choosing what alias we're going to use to run this promotion step, I'm not sure that it matters. After all, I imagine that we'll need some sort of a project option to enable this feature and the alias would otherwise be disabled. The entire discussion could be side stepped though. I imagine all generated sources could be built with
I might be missing something. Why do we need a private executable? |
We don't, I was just considering this as an alternative if we didn't want to include that feature directly into dune but it seems we're fine with that.
It's a good point, I guess we don't want the intermediate diff step indeed. As long as the CI properly checks everything is kept in sync we should be good.
Do you see this as being hardcoded in dune somehow or rather enabled via some kind of |
I imagine this would work automatically if the rules are setup. The way the all alias is defined in a directory is by building
Sorry, that's just sloppy wording on my part. Rules are never promoted, but can be defined with a mode. So here I just meant the rules with |
I forgot to mention that indeed we're fine with it. Mostly because it's going to be the simplest thing to do and because we've already done it before with other dune only features. |
Background
Dune contains a large amount of manually written code mundane tasks. In particular, we currently write the following by hand:
This is all rather time consuming and error prone. The natural solution is to use ppx to get rid of all this.
Using PPX
Unfortunately, using ppx comes with its own set of problems. In particular, it requires us to commit the generated code so that bootstrapping without ppx is still available. I'm going to describe how we can make this process a little more painless
The obvious thing to do would be to use to
deriving_inline
like base. Unfortunately, this scheme requires a bunch of tooling to be usable. For example, we need an editor extension to hide generated code. Something similar for hiding the generated code in diffs is required as well.The following workflow allows us to avoid working with generated code without these downsides:
$source
is going to live inppx/$source
.ppx
directory for diffing purposes.promote
step to update the generated sources.$source
as follows. First, check for the existence of$source
inppx/$source
. If it exists, then use it. Otherwise use$source
.Potential challenges
dyn
, we will need to write a ppx for itcc @snowleopard
The text was updated successfully, but these errors were encountered: