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.

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. The approach of these patches is to locally open the same module in any code that is generated.

This PR assumes ppxlib.0.35.0 will be the ppxlib that contains the 5.2 AST bump. ppxlib.0.34.0 will likely be the stable release of ppxlib with 5.3 support.

@kit-ty-kate
Copy link
Member

cc @edwintorok @mseri

@edwintorok
Copy link
Collaborator

edwintorok commented Aug 8, 2025

The CI probably needs to be rerun, looks like ocaml-ppx/ppxlib@108ae3a is contained in ppxlib 0.36.0. I don't see a rerun button in the CI though, I'm adding an empty commit to trigger the CI.

@edwintorok
Copy link
Collaborator

edwintorok commented Aug 8, 2025

I can try adding a >= 0.36.0 dependency on ppxlib, but then opam fails to find a solution on 4.14.2 due to Async:

opam install async ppxlib.0.36.0
[NOTE] Package ppxlib is already installed (current version is 0.36.0).
[ERROR] Package conflict!
  * No agreement on the version of ocaml-base-compiler:
    - (invariant) → ocaml-base-compiler = 4.14.2
    - async → core_kernel < v0.13 → ocaml < 4.12.0 → ocaml-base-compiler (<= 3.07+1 | = 3.08.1 | = 3.08.2 |
      = 3.08.3 | = 3.09.0 | = 3.09.1 | = 3.09.2 | = 3.09.3 | = 3.10.0 | = 3.10.1 | = 3.10.2 | = 3.11.0 | =
      3.11.1 | = 3.11.2 | = 3.12.1 | = 4.00.0 | = 4.00.1 | = 4.02.0 | = 4.02.1 | = 4.02.2 | = 4.02.3 | =
      4.03.0 | = 4.04.0 | = 4.04.1 | = 4.04.2 | = 4.05.0 | = 4.06.0 | = 4.06.1 | = 4.07.0 | = 4.07.1 | =
      4.08.0 | = 4.08.1 | = 4.09.1 | = 4.10.0 | = 4.10.1 | = 4.11.1 | = 4.11.2)
    You can temporarily relax the switch invariant with `--update-invariant'
  * No agreement on the version of ppxlib:
    - async → core_kernel < v0.15 → ppx_sexp_conv >= v0.14 → ppxlib < 0.36.0
    - ppxlib = 0.36.0
  * No agreement on the version of ocaml-base-compiler:
    - (invariant) → ocaml-base-compiler = 4.14.2
    - async → core_kernel < v0.15 → ppx_sexp_conv >= v0.14 → ocaml >= 5.1.0 → ocaml-base-compiler >= 5.1.0~
  * No agreement on the version of ocaml:
    - (invariant) → ocaml-base-compiler = 4.14.2 → ocaml = 4.14.2
    - async → core >= v0.15 → ppx_sexp_conv < v0.16 → base < v0.14 → ocaml < 4.12
  * No agreement on the version of ocaml-base-compiler:
    - (invariant) → ocaml-base-compiler = 4.14.2
    - async → core_kernel < v0.15 → ppx_sexp_conv >= v0.14 → ppxlib < 0.26.0 → ocaml < 4.14 →
      ocaml-base-compiler < 4.13.2~
  * No agreement on the version of ocaml-base-compiler:
    - (invariant) → ocaml-base-compiler = 4.14.2
    - async → core_kernel < v0.15 → ppx_sexp_conv >= v0.14 → ppxlib < 0.15.0 → ocaml-migrate-parsetree <
      2.0.0 → ocaml < 4.13 → ocaml-base-compiler < 4.12.2~
  * Incompatible packages:
    - (invariant) → ocaml-base-compiler = 4.14.2
    - async → core_kernel < v0.13 → ocaml < 4.12.0 → ocaml-system >= 3.09.1
  * Incompatible packages:
    - (invariant) → ocaml-base-compiler = 4.14.2
    - async → core_kernel < v0.13 → ocaml < 4.12.0 → ocaml-variants
  * Incompatible packages:
    - (invariant) → ocaml-base-compiler = 4.14.2
    - async → core_kernel < v0.15 → ppx_sexp_conv >= v0.14 → ppxlib < 0.15.0 → ocaml-migrate-parsetree <
      2.0.0 → ocaml < 4.13 → dkml-base-compiler
  * Missing dependency:
    - async → core_kernel < v0.13 → ocaml < 4.12.0 → ocaml-variants → ocaml-beta
    unmet availability conditions: 'enable-ocaml-beta-repository'
  * Missing dependency:
    - async → core_kernel < v0.13 → ocaml < 4.12.0 → ocaml-variants → system-msvc
    unmet availability conditions: 'os = "win32"'
  * Missing dependency:
    - async → core_kernel < v0.15 → ppx_sexp_conv >= v0.14 → ppxlib < 0.15.0 → ocaml-migrate-parsetree <
      2.0.0 → ocaml-variants (= 4.08.0+beta2 | = 4.08.0+beta3)
    no matching version

Everything is fine on OCaml 5.3.

So it looks like to merge this PR we would need to either:

  • have a release of Async dependencies which supports the new ppxlib on OCaml 4.14.2
  • deprecate rpclib-async
  • merge this PR into a branch that doesn't support OCaml 4.x anymore

Currently the XAPI project is still on OCaml 4.14.2 for production releases (there is an experimental branch for OCaml 5.x), so I wouldn't drop 4.14.2 support just yet.

AFAICT there are no users of rpclib-async in opam, or in the XAPI project (we fully switched to Lwt a while ago).

A compromise could be to make rpclib-async available only on OCaml 5.x, I'll try to see if that makes the CI work.

actions/cache@v2 shows an error that it is deprecated

Signed-off-by: Edwin Török <edwin@etorok.net>
ppx_deriving_rpc now requires ppxlib >= 0.36.0.
It still works on both OCaml 4.14.x and 5.x.

rpclib-async fails to install on OCaml 4.14.x, because dependencies of
Async are not compatible with the new ppxlib.
However on OCaml 5.3 the solver finds a solution, so restrict
rpclib-async to be available only on OCaml 5.3+

Signed-off-by: Edwin Török <edwin@etorok.net>
Copy link
Collaborator

@edwintorok edwintorok left a comment

Choose a reason for hiding this comment

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

CI passes now.

rpclib (except async) retains compatibility with both OCaml 4.14.2 and 5.x.
rpclib-async is restricted to OCaml 5.3+.

@edwintorok edwintorok merged commit bc4edc4 into mirage:master Aug 8, 2025
6 checks passed
@mseri
Copy link
Collaborator

mseri commented Aug 9, 2025

I am away and won’t be able to make a release any time soon, feel free to do it

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