Skip to content

Prepare for 5.2 AST bump #340

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 3 commits into from
May 26, 2025
Merged

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.

@Drup
Copy link
Member

Drup commented Oct 29, 2024

Thanks ! Feel free to ping when it's ready.

@smorimoto
Copy link
Member

Blocked by this PR: reasonml/reason#2835

Signed-off-by: Sora Morimoto <sora@morimoto.io>
Signed-off-by: Sora Morimoto <sora@morimoto.io>
@smorimoto
Copy link
Member

@Drup I think we are now ready for review!

@smorimoto
Copy link
Member

I will merge this for now. We can revisit if there is a problem.

@smorimoto smorimoto merged commit c08869c into ocsigen:master May 26, 2025
23 of 24 checks passed
@toastal
Copy link

toastal commented May 27, 2025

$ git checkout master
Already on 'master'
Your branch is up to date with 'origin/master'.
$ git pull --rebase upstream master
From https://github.com/ocsigen/tyxml
 * branch              master     -> FETCH_HEAD
Already up to date.
$ dune test --stop-on-first-error
File "ppx/tyxml_ppx.ml", line 381, characters 18-65:
381 |   | Pexp_function (params, constraint_, (Pfunction_body content)) ->
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error: This pattern matches values of type 'a * 'b * 'c
       but a pattern was expected which matches values of type case list

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants