lwt icon indicating copy to clipboard operation
lwt copied to clipboard

Prepare for 5.2 AST bump

Open patricoferris opened this issue 1 year ago • 2 comments

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.

patricoferris avatar Oct 21 '24 15:10 patricoferris

I've tested after

  • rebased on top of recent master
  • installed ppxlib.0.36.0

The only issue is that ppxlib.0.36.0 is incompatible with ppx_let (which is used in tests, to make sure that lwt exports the values that ppx_let needs).

Ultimately, the ppx_let test could be run in a different, separate environment. It's a test of lwt only. But this is a bit difficult to do from a purely technical pov…

Maybe we can wait until ppx_let releases a version compatible with ppxlib.36.0

raphael-proust avatar Mar 07 '25 10:03 raphael-proust

PR for ppx_let https://github.com/janestreet/ppx_let/pull/16 (which also needs the PR to ppxlib_jane https://github.com/janestreet/ppxlib_jane/pull/5). Hopefully these get reviewed/merged promptly and we can get a release of the library.

patricoferris avatar Mar 07 '25 23:03 patricoferris

Now that the janestreet packages have been updated and merged into opam-repository, could this PR be looked at again? This is required for lwt_ppx to be compatible with OCaml 5.4

kit-ty-kate avatar Jun 18 '25 12:06 kit-ty-kate

We have to send a patch to bisect_ppx as well, I guess.

smorimoto avatar Jun 20 '25 07:06 smorimoto

I'm taking a look at bisect_ppx today

patricoferris avatar Jun 20 '25 10:06 patricoferris

Is bisect_ppx really necessary to merge this? I really don't think such CI tool should block the release of such a key ecosystem package.

kit-ty-kate avatar Jul 14 '25 12:07 kit-ty-kate

Ref: https://github.com/ocsigen/lwt/pull/1063

smorimoto avatar Jul 14 '25 13:07 smorimoto

Hi, any news on this? The release of the OCaml 5.4 beta is imminent.

kit-ty-kate avatar Jul 21 '25 16:07 kit-ty-kate

Tested this.
Merging.

Thanks for the contribution!! I'll make a last 5.x release to include this before releasing the 6.x branch.

raphael-proust avatar Jul 22 '25 13:07 raphael-proust

I won't merge until I've fixed the CI: I need to deactivate the ppx tests for ocaml<5.1

raphael-proust avatar Jul 22 '25 14:07 raphael-proust

Thanks a lot! Could we have a release? I'm able to help if needed

kit-ty-kate avatar Aug 19 '25 20:08 kit-ty-kate

@kit-ty-kate https://github.com/ocaml/opam-repository/pull/28384 :heart_decoration:

raphael-proust avatar Aug 22 '25 12:08 raphael-proust

Thank you so much

kit-ty-kate avatar Aug 22 '25 12:08 kit-ty-kate