Skip to content

Comments

Support OCaml 5.4.0#570

Merged
NathanReb merged 5 commits intoocaml-ppx:mainfrom
patricoferris:ci
May 12, 2025
Merged

Support OCaml 5.4.0#570
NathanReb merged 5 commits intoocaml-ppx:mainfrom
patricoferris:ci

Conversation

@patricoferris
Copy link
Collaborator

@patricoferris patricoferris commented Apr 4, 2025

We now have a dune 3.18.0 with 5.4.0 support (afaict). See the conversation in #566

@patricoferris patricoferris added the no changelog Use this label to disable the changelog check github action label Apr 4, 2025
@NathanReb
Copy link
Collaborator

There are a few missing promotions it seems!

@patricoferris patricoferris changed the title Bump trunk CI build to 5.4.0+trunk Support OCaml 5.4.0 Apr 19, 2025
@patricoferris
Copy link
Collaborator Author

I think we're just waiting for the magic numbers to be bumped in OCaml.

@patricoferris patricoferris removed the no changelog Use this label to disable the changelog check github action label Apr 19, 2025
@NathanReb
Copy link
Collaborator

I think we're just waiting for the magic numbers to be bumped in OCaml

I thought they were bumped on the development branch now.

It also seems the dune version we're using for the trunk CI build does not build.

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.

Looks great! Thanks for taking the time to work on this.

From the top of your head, do you know which functions in the migration need to be reviewed?

Comment on lines 17 to 20
type t = (*IF_AT_LEAST 504 Ocaml_common.Longident.t = *)
Lident of string
| Ldot of t loc * string loc
| Lapply of t loc * t loc
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should have a Longident module in ast_504 similar to what we have for Asttypes. That way if the type is further modified, it'll be treated as a regular AST change.

I think we should still have a Longident module in astlib but it should only provide the utility functions on Longidents from the compiler, same as the Parse, or Pprintast modules do for other moving Ast types.

Since Astlib is supposed to provide the stable layer on top of the compiler-libs that's necessary for ppxlib, we should maybe make it provide the exact set of functions we need and nothing more.

What would you think about the following:

  • Make Legacy_longident define only the type
  • Make Longident provide the functions we use, conditionnally compiled to work with the current compiler
  • Have a Longident module in Ppxlib that expose the functions corresponding to our internal AST.

As I write this I wonder if, in fact, we don't need any compiler functions on longidents but simply need the ones for our internal AST. Making a compat layer for functions unnecessary as we can simply have a local copy of the correct version.

@kit-ty-kate
Copy link
Contributor

the magic numbers have been bumped

@patricoferris
Copy link
Collaborator Author

Thanks for the review @NathanReb -- I think I followed what you were suggesting and applied the changes. To reiterate:

  • We know version Longident in the AST itself for 504
  • Our Internal AST Longident is still that from 502 so nothing else needs changed there

And everything just works.

Presumably when we bump the internal AST to 504 we will have to almost invert this in order to migrate from below to 504.

@patricoferris
Copy link
Collaborator Author

Also, we're waiting on a new version of dune that support 5.4.0 too.

@kit-ty-kate
Copy link
Contributor

the dune PR has been merged in opam-repository

This also updates the easier parts of ppxlib to be compatible with 5.4.0.
We will need to version the Location module.

Signed-off-by: Patrick Ferris <patrick@sirref.org>
Adds support for the OCaml 5.4, mainly versioning the Longident
module and handling migrations of tuples with and without labels.

Signed-off-by: Patrick Ferris <patrick@sirref.org>
Signed-off-by: Patrick Ferris <patrick@sirref.org>
Signed-off-by: Patrick Ferris <patrick@sirref.org>
Signed-off-by: Patrick Ferris <patrick@sirref.org>
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.

Trunk build's green and the ocaml-ci failures seem out of our control, let's merge!

I'll backport these changes to a separate 0.37.0 branch so we can cut a release with it that's not dependent on the 5.3 AST bump.

@NathanReb NathanReb merged commit 31e5638 into ocaml-ppx:main May 12, 2025
7 of 8 checks passed
@NathanReb NathanReb mentioned this pull request May 12, 2025
NathanReb pushed a commit to NathanReb/opam-repository that referenced this pull request Oct 10, 2025
CHANGES:

### 5.4 Support

- Add initial OCaml 5.4 support (ocaml-ppx/ppxlib#570, @patricoferris, @NathanReb)

### Other Changes

- Add `Longident.to/of_compiler` to astlib to simplify maintenance
  of ppx-es that interacts with other parts of the compiler-libs such
  as the type checker. (ocaml-ppx/ppxlib#603, @NathanReb)

- Fix a bug where some infix operators such as `mod` would be printed as
  raw identifiers by our `Pprintast`. (ocaml-ppx/ppxlib#601, @NathanReb)

- Fix 5.2 -> 5.3 migration of constants. Those used to always have a `none`
  location which can lead to unhelpful error messages.
  (ocaml-ppx/ppxlib#569, @NathanReb)

- Add a new context-free rule type that replaces AST nodes that have the registered
  attributes attached to them. (ocaml-ppx/ppxlib#574, @Skepfyr)

- Allow users to derive code from module bindings and module declarations
  (ocaml-ppx/ppxlib#576, @patricoferris)

- Expose `Ppxlib.Location.Error.t = Astlib.Location.Error.t` (ocaml-ppx/ppxlib#593, @ceastlund)

- Add `@@@ppxlib.inline.end`, deprecate `@@@deriving.end`. (ocaml-ppx/ppxlib#594, @ceastlund)

- Clean the AST of any ppxlib migration attributes whenever printing using
  Pretty_print mode and the use_compiler_pp flag. (ocaml-ppx/ppxlib#598, @patricoferris)

- Add custom printer support to `pp_ast` functions via the `?printer` config
  parameter. (ocaml-ppx/ppxlib#526, @pedrobslisboa)
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.

3 participants