-
Notifications
You must be signed in to change notification settings - Fork 98
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
Refactor driver transformer #489
base: main
Are you sure you want to change the base?
Refactor driver transformer #489
Conversation
70ffddf
to
a3a784b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! We'll really benefit from these changes.
I probably did not specify this work very well and I apologize for the inconvenience. What I had in mind was not to replace the record type all the way here.
Instead, I would like to keep the original record type but only use it to represent the transformations as registered by ppx authors and to use better suited types to represent the ordered list of transformations to apply.
In other words, I'd like the types you introduced or similar types to be used to turn a Transform.t list
into a list of str -> str
/sig -> sig
.
This task is currently split between apply_transforms
, get_whole_ast_passes
, partition_transformations
and merge_into_generic_mappers
which all take Transform.t
and roughly return modified Transform.t
where all but relevant fields are set to None
. I'd like for them to instead take a Transform.t
and return a structured type that represent exactly what we want here.
Does it make more sense? I'm happy to discuss this over a voice channel if that helps or to try and write signatures for the above mentioned functions if you'd like.
src/driver.ml
Outdated
type 'result sig_fun = | ||
Expansion_context.Base.t -> Parsetree.signature -> 'result | ||
|
||
type impl_intf_pass = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you think about something along the lines of full_ast_rewrite_pass
instead?
I think it would clarify a bit what those are about.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm also thinking it might be good to add a tiny bit of documentation next to each individual type decl here. Just a one liner for the ones that need clarification. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes!
To make the driver's handling of transformations clearer, we convert them into specific kinds of passes on the AST (e.g. distinguishing between linters and preprocessors). Signed-off-by: Patrick Ferris <[email protected]>
a3a784b
to
220fdb2
Compare
This builds on top of #482 after a conversation about the confusion around the
Transform.t
data structure and how it relates to ppxlib applying various preprocessors to OCaml code.This PR changes the
Transform.t
from a record to a polymorphic variant with the intention to make it clearer how the driver works in terms of transforming code. Most notably, what was once accessing fields is now a lookup in a list where the list is always in the order of 10 elements (max).As a newcomer to ppxlib, I find this approach a little easier to understand as there are more types and names to help guide a new developer, and the various kinds of passes are grouped under distinct types (rather than a big record where everything is optional).