Skip to content

Commit

Permalink
OCaml 5.3 support (#2800)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro authored Nov 3, 2024
1 parent ffe5118 commit 4b5f460
Show file tree
Hide file tree
Showing 27 changed files with 1,661 additions and 70 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/nix-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- 5_0
- 5_1
- 5_2
- 5_3

runs-on: ubuntu-latest
steps:
Expand All @@ -44,6 +45,7 @@ jobs:
- {ocaml-version: '5_2', os: macos-13}
- {ocaml-version: '4_14', os: macos-14}
- {ocaml-version: '5_2', os: macos-14}
- {ocaml-version: '5_3', os: macos-14}
runs-on: ${{ matrix.setup.os }}
steps:
- uses: actions/checkout@v4
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/opam-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ jobs:
- {ocaml-compiler: '4.10.x', os: ubuntu-latest}
- {ocaml-compiler: '4.12.x', os: ubuntu-latest}
- {ocaml-compiler: '4.14.x', os: ubuntu-latest}
- {ocaml-compiler: 'ocaml-base-compiler.5.3.0~alpha1', os: ubuntu-latest}
- {ocaml-compiler: '4.06.x', os: macos-13}
- {ocaml-compiler: '4.10.x', os: macos-13}
- {ocaml-compiler: '4.12.x', os: macos-13}
- {ocaml-compiler: '4.14.x', os: macos-13}
- {ocaml-compiler: 'ocaml-base-compiler.5.3.0~alpha1', os: macos-13}
# looks like setup-ocaml@v3 can only run actions on windows for
# OCaml >= 4.13
# https://github.com/ocaml/setup-ocaml/issues/822#issuecomment-2215525942
Expand Down Expand Up @@ -58,6 +60,10 @@ jobs:
path: _opam
key: opam-${{ matrix.setup.os }}-${{ matrix.setup.ocaml-compiler }}-${{ hashFiles('**.opam') }}

- name: Pin utop for OCaml 5.3
if: ${{ matrix.setup.ocaml-compiler == 'ocaml-base-compiler.5.3.0~alpha1' }}
run: opam pin add utop --dev-repo

- name: Install dependencies
run: opam install . --deps-only

Expand Down
6 changes: 3 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@
(ocaml
(and
(>= "4.06")
(< "5.3")))
(< "5.4")))
(ocamlfind :build)
(dune-build-info
(>= 2.9.3))
(menhir
(>= "20180523"))
(merlin-extend
(>= "0.6"))
(>= "0.6.2"))
fix
ppx_derivers
cppo
Expand All @@ -57,7 +57,7 @@
(ocaml
(and
(>= "4.06")
(< "5.3")))
(< "5.4")))
(reason
(= :version))
(utop
Expand Down
20 changes: 10 additions & 10 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages."${system}".extend (self: super: {
ocamlPackages = super.ocaml-ng.ocamlPackages_5_2;
ocamlPackages = super.ocaml-ng.ocamlPackages_5_3;
});
packages = pkgs.callPackage ./nix { nix-filter = nix-filter.lib; };
in
Expand Down
7 changes: 6 additions & 1 deletion nix/shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@

mkShell {
inputsFrom = [ reason ];
nativeBuildInputs = with ocamlPackages; [ utop merlin odoc ocamlformat ];
nativeBuildInputs = with ocamlPackages; [
utop
merlin
odoc
ocamlformat
];
buildInputs =
with ocamlPackages; (if release-mode then [ cacert curl dune-release git ] else [ ]);
}
4 changes: 2 additions & 2 deletions reason.opam
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ homepage: "https://reasonml.github.io/"
bug-reports: "https://github.com/reasonml/reason/issues"
depends: [
"dune" {>= "2.9"}
"ocaml" {>= "4.06" & < "5.3"}
"ocaml" {>= "4.06" & < "5.4"}
"ocamlfind" {build}
"dune-build-info" {>= "2.9.3"}
"menhir" {>= "20180523"}
"merlin-extend" {>= "0.6"}
"merlin-extend" {>= "0.6.2"}
"fix"
"ppx_derivers"
"cppo"
Expand Down
2 changes: 1 addition & 1 deletion rtop.opam
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ homepage: "https://reasonml.github.io/"
bug-reports: "https://github.com/reasonml/reason/issues"
depends: [
"dune" {>= "2.9"}
"ocaml" {>= "4.06" & < "5.3"}
"ocaml" {>= "4.06" & < "5.4"}
"reason" {= version}
"utop" {>= "2.0"}
"cppo"
Expand Down
6 changes: 6 additions & 0 deletions rtop/dune
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
(action
(run cppo -V OCAML:%{ocaml_version} %{deps} -o %{targets})))

(rule
(targets reason_utop.ml)
(deps reason_utop.cppo.ml)
(action
(run cppo -V OCAML:%{ocaml_version} %{deps} -o %{targets})))

(executable
(name rtop)
(public_name rtop)
Expand Down
3 changes: 3 additions & 0 deletions rtop/reason_toploop.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ let main () =
List.exists ((=) "camlp4r") !Topfind.predicates then
print_endline "Reason is incompatible with camlp4!"
else begin
#if OCAML_VERSION >= (5,3,0)
if not (Toploop.prepare Format.err_formatter ()) then raise (Compenv.Exit_with_status 2);
#endif
Toploop.parse_toplevel_phrase := (fun t ->
if !Reason_utop.current_top = UTop then
default_parse_toplevel_phrase t
Expand Down
28 changes: 20 additions & 8 deletions rtop/reason_utop.ml → rtop/reason_utop.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,31 @@ let init_reason () =

(* Printing in Reason syntax *)
let open Reason_toolchain.From_current in
let wrap f g fmt x = g fmt (f x) in
let wrap f g fmt x =
g fmt (f x)
in
#if OCAML_VERSION >= (5,3,0)
let wrap_doc f g fmt x =
let doc_f =
Format_doc.deprecated_printer (fun fmt -> Format.fprintf fmt "%a" g (f x))
in
doc_f fmt
#else
let wrap_doc = wrap
#endif
in
Toploop.print_out_value := wrap copy_out_value Reason_oprint.print_out_value;
Toploop.print_out_type := wrap copy_out_type Reason_oprint.print_out_type;
Toploop.print_out_type := wrap_doc copy_out_type Reason_oprint.print_out_type;
Toploop.print_out_class_type :=
wrap copy_out_class_type Reason_oprint.print_out_class_type;
wrap_doc copy_out_class_type Reason_oprint.print_out_class_type;
Toploop.print_out_module_type :=
wrap copy_out_module_type Reason_oprint.print_out_module_type;
wrap_doc copy_out_module_type Reason_oprint.print_out_module_type;
Toploop.print_out_type_extension :=
wrap copy_out_type_extension Reason_oprint.print_out_type_extension;
wrap_doc copy_out_type_extension Reason_oprint.print_out_type_extension;
Toploop.print_out_sig_item :=
wrap copy_out_sig_item Reason_oprint.print_out_sig_item;
wrap_doc copy_out_sig_item Reason_oprint.print_out_sig_item;
Toploop.print_out_signature :=
wrap (List.map copy_out_sig_item) Reason_oprint.print_out_signature;
wrap_doc (List.map copy_out_sig_item) Reason_oprint.print_out_signature;
Toploop.print_out_phrase :=
wrap copy_out_phrase Reason_oprint.print_out_phrase;
let current_show_fn =
Expand Down Expand Up @@ -122,7 +134,7 @@ let init_ocaml () =
let toggle_syntax () =
match !current_top with RTop -> init_ocaml () | UTop -> init_reason ()

let _ =
let () =
Hashtbl.add
(Toploop.directive_table [@ocaml.warning "-3"])
"toggle_syntax"
Expand Down
12 changes: 11 additions & 1 deletion src/reason-parser/ocaml_util.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,17 @@ let print_loc ppf loc =


let print_error loc f ppf x =
#if OCAML_VERSION >= (4,8,0)
#if OCAML_VERSION >= (5,3,0)
let error =
let f (fmt: Format_doc.formatter) err =
let doc_f =
Format_doc.deprecated_printer (fun fmt -> Format.fprintf fmt "%a" f err)
in
doc_f fmt
in
Location.error_of_printer ~loc f x in
Location.print_report ppf error
#elif OCAML_VERSION >= (4,8,0)
let error = Location.error_of_printer ~loc f x in
Location.print_report ppf error
#else
Expand Down
Loading

0 comments on commit 4b5f460

Please sign in to comment.