From c6eb1a19de099bc20e907cb272940e8d4ee524a3 Mon Sep 17 00:00:00 2001 From: Andrey Popp <8mayday@gmail.com> Date: Wed, 5 Nov 2025 08:42:38 +0100 Subject: [PATCH] Support for OCaml 5.4 --- .github/workflows/main.yml | 3 ++- Makefile | 2 +- mlx/dune | 11 +++++++++- mlx/jsx_helper.ml | 3 +-- mlx/mlx_shim.ml | 21 +++++++++++++++++++ mlx/pp.ml | 3 ++- .../ocaml/preprocess/jsx_helper.ml | 3 +-- 7 files changed, 38 insertions(+), 8 deletions(-) create mode 100644 mlx/mlx_shim.ml diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index a8d4a49..6b5566e 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,7 +19,8 @@ jobs: - "4.14" - "5.1" - "5.2" - - "ocaml-base-compiler.5.3.0~beta2" + - "5.3" + - "5.4" runs-on: ${{ matrix.os }} diff --git a/Makefile b/Makefile index 7d19329..46317bf 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ .PHONY: init init: - opam switch create . 5.3.0 --no-install -y + opam switch create . 5.4.0 --no-install -y opam install . --deps-only -y opam install menhir.20201216 ocamlformat ocaml-lsp-server -y diff --git a/mlx/dune b/mlx/dune index 18f4b37..c495415 100644 --- a/mlx/dune +++ b/mlx/dune @@ -2,8 +2,17 @@ (name pp) (package mlx) (public_name mlx-pp) + (modules :standard \ mlx_shim) (flags - (:standard -w -9-67 -open Astlib.Ast_501)) + (:standard -w -9-67 -open Astlib -open Astlib.Ast_501 -open Mlx_shim)) + (libraries ppxlib ocaml-compiler-libs.shadow mlx_shim)) + +(library + (name mlx_shim) + (package mlx) + (modules mlx_shim) + (flags + (:standard -w -9-67 -open Astlib -open Astlib.Ast_501)) (libraries ppxlib ocaml-compiler-libs.shadow)) (ocamllex lexer) diff --git a/mlx/jsx_helper.ml b/mlx/jsx_helper.ml index bceb76e..674d61c 100644 --- a/mlx/jsx_helper.ml +++ b/mlx/jsx_helper.ml @@ -11,7 +11,6 @@ let make_loc (startpos, endpos) = Location.loc_ghost = false; } -let mkloc txt loc = { Location.txt; loc } let mkexp ~loc d = Exp.mk ~loc:(make_loc loc) d let mkjsxexp ~loc:loc' e = @@ -63,7 +62,7 @@ let make_jsx_element ~raise ~loc:_ ~tag ~end_tag ~props ~children () = in let props = let prop_exp ~loc name = - let id = mkloc (Lident name) (make_loc loc) in + let id = Location.mkloc (Lident name) (make_loc loc) in mkexp ~loc (Pexp_ident id) in List.map diff --git a/mlx/mlx_shim.ml b/mlx/mlx_shim.ml new file mode 100644 index 0000000..d66c794 --- /dev/null +++ b/mlx/mlx_shim.ml @@ -0,0 +1,21 @@ +module Pprintast = struct + include Pprintast + + let tyvar = Compiler_pprintast.tyvar +end + +module Location = struct + include Location + + let mkloc txt loc = { Location.txt; loc } + let mknoloc txt = { Location.txt; loc = Location.none } +end + +module Longident = struct + include Longident + + let last = function + | Lident s -> s + | Ldot (_, s) -> s + | Lapply (_, _) -> Misc.fatal_error "Longident.last" +end diff --git a/mlx/pp.ml b/mlx/pp.ml index 81fc498..ec05ce5 100644 --- a/mlx/pp.ml +++ b/mlx/pp.ml @@ -29,7 +29,8 @@ let () = match str with | Ok str -> let str = Conv.copy_structure str in - if !print_ml then Format.printf "%a@." Pprintast.structure str + if !print_ml then + Format.printf "%a@." Compiler_pprintast.structure str else let oc = stdout in output_string oc diff --git a/ocamlmerlin_mlx/ocaml/preprocess/jsx_helper.ml b/ocamlmerlin_mlx/ocaml/preprocess/jsx_helper.ml index 60875b5..1f94854 100644 --- a/ocamlmerlin_mlx/ocaml/preprocess/jsx_helper.ml +++ b/ocamlmerlin_mlx/ocaml/preprocess/jsx_helper.ml @@ -12,7 +12,6 @@ let make_loc (startpos, endpos) = Location.loc_ghost = false; } -let mkloc txt loc = { Location.txt; loc } let mkexp ~loc d = Exp.mk ~loc:(make_loc loc) d let mkjsxexp ~loc:loc' e = @@ -64,7 +63,7 @@ let make_jsx_element ~raise ~loc:_ ~tag ~end_tag ~props ~children () = in let props = let prop_exp ~loc name = - let id = mkloc (Lident name) (make_loc loc) in + let id = Location.mkloc (Lident name) (make_loc loc) in mkexp ~loc (Pexp_ident id) in List.map