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

Refactor driver transformer #489

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

patricoferris
Copy link
Collaborator

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).

@patricoferris patricoferris force-pushed the refactor-driver-transformer branch 3 times, most recently from 70ffddf to a3a784b Compare May 11, 2024 17:05
Copy link
Collaborator

@NathanReb NathanReb left a 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 =
Copy link
Collaborator

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.

Copy link
Collaborator

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?

Copy link
Collaborator Author

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]>
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.

2 participants