Skip to content

Commit

Permalink
Add support for OCaml 5.1 (#428)
Browse files Browse the repository at this point in the history
* Update trunk AST for pvb_constraint
* Add migration from 501 to 500
* Bump the 501 AST magic numbers
* Binary AST reader: use latest possible AST version

When the magic numbers aren't unique, before this commit, the binary
AST reader would read into the first AST version matching the magic
number. With this commit, it takes the last such version. That's important
for trunk support.

* Fix inline tests' dependency on OCaml version

Done by making the expected output also dependent on the OCaml version

* Add a add tests to test both round-trips as well as a test comparing
parsing on 5.0.0 with parsing on 5.1.0 and then down migrating. This last
test will need to be updated when bumping the AST.

Signed-off-by: Thibaut Mattio <[email protected]>
Co-authored-by: Samuel Hym <[email protected]>
Co-authored-by: Florian Angeletti <[email protected]>
Co-authored-by: Sonja Heinze <[email protected]>
Co-authored-by: Paul-Elliot <[email protected]>
  • Loading branch information
5 people authored Jun 20, 2023
1 parent 137d607 commit f0320c4
Show file tree
Hide file tree
Showing 34 changed files with 5,966 additions and 16 deletions.
7 changes: 7 additions & 0 deletions .ocamlformat-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ astlib/ast_411.ml
astlib/ast_412.ml
astlib/ast_413.ml
astlib/ast_414.ml
astlib/ast_501.ml

# Files that use cinaps to generate bode blocks from other code blocks work well,
# but files that inject freely formatted code via cinaps must be excluded
Expand All @@ -25,18 +26,24 @@ ast/versions.mli
# Currently our expect-test lexer is too strict for our expect tests to
# work well with ocamlformat
test/base/test.ml
test/base/test_510.ml
test/code_path/test.ml
test/code_path/test_510.ml
test/deriving/test.ml
test/deriving/test_510.ml
test/driver/attributes/test.ml
test/driver/attributes/test_510.ml
test/driver/instrument/test.ml
test/driver/non-compressible-suffix/test.ml
test/driver/transformations/test.ml
test/expand-header-and-footer/test.ml
test/expansion_helpers/mangle/test.ml
test/expansion_inside_payloads/test.ml
test/extensions_and_deriving/test.ml
test/extensions_and_deriving/test_510.ml
test/location/exception/test.ml
test/metaquot/test.ml
test/metaquot/test_510.ml
test/ppx_import_support/test.ml
test/quoter/test.ml
test/traverse/test.ml
Expand Down
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ unreleased
- Update description to reflect that `ppxlib` contains more than a library
(#422, @pitag-ha)

- Add support for OCaml 5.1, excluding OCaml `5.1.0~alpha1` (#428, @shym, @Octachron , @pitag-ha, @panglesd)
- Driver: Fix `-locations-check` option for coercions with ground (#428, @Octachron)

0.29.1 (14/02/2023)
------------------

Expand Down
1 change: 1 addition & 0 deletions ast/supported_version/supported_version.ml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ let all =
(4, 13);
(4, 14);
(5, 0);
(5, 1);
]

let to_string (a, b) =
Expand Down
22 changes: 16 additions & 6 deletions ast/versions.ml
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,13 @@ module OCaml_500 = struct
let string_version = "5.0"
end
let ocaml_500 : OCaml_500.types ocaml_version = (module OCaml_500)
module OCaml_501 = struct
module Ast = Astlib.Ast_501
include Make_witness(Astlib.Ast_501)
let version = 501
let string_version = "5.1"
end
let ocaml_501 : OCaml_501.types ocaml_version = (module OCaml_501)
(*$*)

let all_versions : (module OCaml_version) list = [
Expand All @@ -525,6 +532,7 @@ let all_versions : (module OCaml_version) list = [
(module OCaml_413 : OCaml_version);
(module OCaml_414 : OCaml_version);
(module OCaml_500 : OCaml_version);
(module OCaml_501 : OCaml_version);
(*$*)
]

Expand Down Expand Up @@ -559,6 +567,8 @@ include Register_migration(OCaml_413)(OCaml_414)
(Astlib.Migrate_413_414)(Astlib.Migrate_414_413)
include Register_migration(OCaml_414)(OCaml_500)
(Astlib.Migrate_414_500)(Astlib.Migrate_500_414)
include Register_migration(OCaml_500)(OCaml_501)
(Astlib.Migrate_500_501)(Astlib.Migrate_501_500)
(*$*)

module OCaml_current = OCaml_OCAML_VERSION
Expand All @@ -577,10 +587,10 @@ module Find_version = struct
else
loop tail
in
(* First check whether it could be the current version, probably
the most common use case.
This bias towards the current version also provides a way to
choose wisely between, say, `trunk` and the latest stable
release, for which the magic numbers are not distinguished *)
loop @@ ((module OCaml_current : OCaml_version) :: all_versions)
(* Traverse the versions from last to first:
if the magic numbers aren't unique among versions,
we want the latest version with a magic number match.
The situation in mind is trunk support. *)
let all_versions_top_down = List.rev all_versions in
loop all_versions_top_down
end
1 change: 1 addition & 0 deletions ast/versions.mli
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ module OCaml_412 : OCaml_version with module Ast = Astlib.Ast_412
module OCaml_413 : OCaml_version with module Ast = Astlib.Ast_413
module OCaml_414 : OCaml_version with module Ast = Astlib.Ast_414
module OCaml_500 : OCaml_version with module Ast = Astlib.Ast_500
module OCaml_501 : OCaml_version with module Ast = Astlib.Ast_501
(*$*)

(* An alias to the current compiler version *)
Expand Down
Loading

0 comments on commit f0320c4

Please sign in to comment.