Skip to content

Conversation

@patricoferris
Copy link
Contributor

This PR is a patch for an upcoming release of ppxlib where the internal AST is bumped from 4.14 to 5.2. Until that is merged and released, there is no reason to merge this PR.

To test these changes, you can use the following opam-based workflow. I've made releases of most of these patches to an opam-repository overlay.

opam switch create ppxlib-bump --repos=ppxlib=git+https://github.com/patricoferris/opam-repository#5.2-ast-bump
opam install <your-package>

The following describes the most notable changes to the AST.

Note: no update has been made of the opam file, but ppxlib will likely need a lower-bound before merging/releasing.

Functions


Currently

In the parsetree currently, functions like:

fun x y z -> ...

Are represented roughly as

Pexp_fun(x, Pexp_fun (y, Pexp_fun(z, ...)))

Functions like:

function A -> ... | B -> ...

Are represented roughly as

Pexp_function ([ case A; case B ])

Since 5.2

All of these functions now map to a single AST node Pexp_function (note, this is the same name as the old cases function). The first argument is a list of parameters meaning:

fun x y z -> ...

Now looks like:

Pexp_function([x; y; z], _constraint, body)

And the body is where we can either have more expressions (Pfunction_body _) or cases (Pfunction_cases _). That means:

function A -> ... | B -> ...

Has an empty list of parameters:

Pexp_function([], _, Pfunction_cases ([case A; case B]))

Local Module Opens for Types

Another feature added in 5.2 was the ability to locally open modules in type definitions.

module M = struct
  type t = A | B | C
end

type t = Local_open_coming of M.(t)

This has a Ptyp_open (module_identifier, core_type) AST node. Just like normal module opens this does create some syntactic ambiguity about where things come from inside the parentheses.

recursive ~lib var.txt inner)
else derive_core c
| Ptyp_object _ | Ptyp_class _ -> invalid_arg "unsupported"
| Ptyp_object _ | Ptyp_class _ | Ptyp_open _ -> invalid_arg "unsupported"

Choose a reason for hiding this comment

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

As the derive_cor function is independent of the typing environment, I think it would be better to traverse the Ptyp_open _ node.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed! Thanks @Octachron :)

@patricoferris
Copy link
Contributor Author

Ah! We're actually going to have to hold off until ocaml-ppx/ppxlib#588

@kit-ty-kate
Copy link
Member

any news on that?

@samoht
Copy link
Member

samoht commented Sep 29, 2025

@patricoferris is this ready to go now?

@patricoferris
Copy link
Contributor Author

Still waiting for the PR I mentioned (being released as we speak ocaml/opam-repository#28610!)

@patricoferris
Copy link
Contributor Author

I have updated this PR (and removed the ocamlformat change to make it easier to read).

We're in a bit of an annoying position where our (ppxlib) 0.37.0~5.4previewrelease does not have the changes in our 0.36.2 release. This should be fixed by our upcoming, full 0.37.0 release.

@kit-ty-kate
Copy link
Member

@patricoferris would you be able to update the PR?

@kit-ty-kate
Copy link
Member

ah nevermind it's ready but ocaml-ci hasn't updated with the full 0.37.0 release

@samoht
Copy link
Member

samoht commented Oct 14, 2025

@patricoferris -- do you mind rebasing the PR to pick up the latest releases?

@kit-ty-kate
Copy link
Member

@samoht i believe the PR doesn't need rebasing. ocaml/opam-repository#28686 hasn't been merged yet actually

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