Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for ocaml 5.2 #1553

Merged
merged 7 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ocamlformat
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ break-separators=before
dock-collection-brackets=false
margin=90
module-item-spacing=sparse
version=0.26.0
version=0.26.1
ocaml-version=4.08.0
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# dev - ???

## Features/Changes
* Mics: fix support for OCaml 5.2

# 5.6.0 (2024-01-02) - Lille

## Features/Changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ let runtime =
; effect
; zstd
; runtime_events
; blake2
]

include Files
2 changes: 2 additions & 0 deletions compiler/lib-runtime-files/tests/all.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ let%expect_test _ =
+backtrace.js
+bigarray.js
+bigstring.js
+blake2.js
+compare.js
+domain.js
+dynlink.js
Expand Down Expand Up @@ -59,6 +60,7 @@ let%expect_test _ =
+backtrace.js
+bigarray.js
+bigstring.js
+blake2.js
+compare.js
+domain.js
+effect.js
Expand Down
47 changes: 25 additions & 22 deletions compiler/lib/parse_bytecode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ let resize_globals g size =
module State = struct
type elt =
| Var of Var.t * loc
| Dummy
| Dummy of string
| Unset

let elt_to_var e =
Expand All @@ -569,7 +569,7 @@ module State = struct
let print_elt f v =
match v with
| Var (x, _) -> Format.fprintf f "%a" Var.print x
| Dummy -> Format.fprintf f "٭"
| Dummy _ -> Format.fprintf f "٭"
| Unset -> Format.fprintf f "∅"

type handler =
Expand Down Expand Up @@ -619,7 +619,7 @@ module State = struct
{ st with
stack =
(match st.accu with
| Dummy -> Dummy
| Dummy x -> Dummy x
| Unset -> Unset
| Var (x, _) -> Var (x, loc))
:: st.stack
Expand All @@ -634,7 +634,7 @@ module State = struct
{ st with
accu =
(match List.nth st.stack n with
| Dummy -> Dummy
| Dummy x -> Dummy x
| Unset -> Unset
| Var (x, _) -> Var (x, loc))
}
Expand All @@ -647,7 +647,7 @@ module State = struct
List.fold_left (st.accu :: st.stack) ~init:[] ~f:(fun l e ->
match e with
| Var (x, _) -> x :: l
| Dummy | Unset -> l)
| Dummy _ | Unset -> l)

let set_accu st x loc = { st with accu = Var (x, loc) }

Expand All @@ -671,15 +671,15 @@ module State = struct
let stack =
List.fold_right state.stack ~init:[] ~f:(fun e stack ->
match e with
| Dummy -> Dummy :: stack
| Dummy x -> Dummy x :: stack
| Unset -> Unset :: stack
| Var (x, l) ->
let y = Var.fork x in
Var (y, l) :: stack)
in
let state = { state with stack; current_pc } in
match state.accu with
| Dummy | Unset -> state
| Dummy _ | Unset -> state
| Var (x, loc) ->
let y, state = fresh_var state loc in
Var.propagate_name x y;
Expand Down Expand Up @@ -866,22 +866,22 @@ let rec compile_block blocks debug_data code pc state =
let rec check (xs : State.elt list) (ys : State.elt list) =
match xs, ys with
| Var _ :: xs, Var _ :: ys -> check xs ys
| Dummy :: xs, Dummy :: ys -> check xs ys
| Dummy _ :: xs, Dummy _ :: ys -> check xs ys
| Unset :: _, _ -> assert false
| _, Unset :: _ -> assert false
| [], [] -> ()
| Var _ :: _, Dummy :: _ -> assert false
| Dummy :: _, Var _ :: _ -> assert false
| Var _ :: _, Dummy _ :: _ -> assert false
| Dummy _ :: _, Var _ :: _ -> assert false
| _ :: _, [] -> assert false
| [], _ :: _ -> assert false
in
check old_state.State.stack state.State.stack;
match old_state.State.accu, state.State.accu with
| Dummy, Dummy -> ()
| Dummy _, Dummy _ -> ()
| Var _, Var _ -> ()
| Unset, Unset -> ()
| Var _, Dummy -> assert false
| Dummy, Var _ -> assert false
| Var _, Dummy _ -> assert false
| Dummy _, Var _ -> assert false
| Unset, _ | _, Unset -> assert false)
| None -> (
let limit = Blocks.next blocks pc in
Expand Down Expand Up @@ -1086,7 +1086,10 @@ and compile infos pc state instrs =
{ state with
State.stack =
(* See interp.c *)
State.Dummy :: State.Dummy :: State.Dummy :: state.State.stack
State.Dummy "push_retaddr(retaddr)"
:: State.Dummy "push_retaddr(env)"
:: State.Dummy "push_retaddr(extra_args)"
:: state.State.stack
}
instrs
| APPLY ->
Expand Down Expand Up @@ -1246,8 +1249,8 @@ and compile infos pc state instrs =
let x, state = State.fresh_var state loc in
let env = List.map vals ~f:(fun (x, loc) -> State.Var (x, loc)) in
let env =
let code = State.Dummy in
let closure_info = State.Dummy in
let code = State.Dummy "closure(code)" in
let closure_info = State.Dummy "closure(info)" in
if new_closure_repr then code :: closure_info :: env else code :: env
in
let env = Array.of_list env in
Expand Down Expand Up @@ -1294,13 +1297,13 @@ and compile infos pc state instrs =
let env = ref (List.map vals ~f:(fun (x, loc) -> State.Var (x, loc))) in
List.iter !vars ~f:(fun (i, x) ->
let code = State.Var (x, noloc) in
let closure_info = State.Dummy in
let closure_info = State.Dummy "closurerec(info)" in
if new_closure_repr
then env := code :: closure_info :: !env
else env := code :: !env;
if i > 0
then
let infix_tag = State.Dummy in
let infix_tag = State.Dummy "closurerec(infix_tag)" in
env := infix_tag :: !env);
let env = Array.of_list !env in
let state = !state in
Expand Down Expand Up @@ -1794,10 +1797,10 @@ and compile infos pc state instrs =
{ (State.push_handler handler_ctx_state) with
State.stack =
(* See interp.c *)
State.Dummy
:: State.Dummy
:: State.Dummy
:: State.Dummy
State.Dummy "pushtrap(pc)"
:: State.Dummy "pushtrap(sp_off)"
:: State.Dummy "pushtrap(env)"
:: State.Dummy "pushtrap(extra_args)"
:: state.State.stack
};
instrs, (Branch (interm_addr, []), loc), state
Expand Down
76 changes: 76 additions & 0 deletions compiler/tests-ocaml/lib-digest/digests.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
(* TEST
*)

module Test(H: Digest.S) = struct

let string (msg, hh) =
if not ( (H.(equal (string msg) (of_hex hh))))
then (
Printf.printf "Expecting %S\
\nGot %S\n" hh (H.to_hex (H.string msg)); assert false)

let file wlen rlen =
let data = String.init wlen Char.unsafe_chr in
Out_channel.with_open_bin "data.tmp"
(fun oc -> Out_channel.output_string oc data);
let h1 = H.file "data.tmp" in
assert (H.equal h1 (H.string data));
let h2 =
In_channel.with_open_bin "data.tmp"
(fun ic -> H.channel ic rlen) in
assert (H.equal h2 (H.substring data 0 rlen));
Sys.remove "data.tmp"

let run_tests tests =
List.iter string tests;
file 100 99;
file 100_000 10_000
end

(* Test inputs *)

let in1 = ""
let in2 = "a"
let in3 = "abc"
let in4 = "abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno\
ijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu"
let in5 = String.make 100_000 'a'

(* Test vectors *)

module TestMD5 = Test(Digest.MD5)
let _ = TestMD5.run_tests
[in1, "d41d8cd98f00b204e9800998ecf8427e";
in2, "0cc175b9c0f1b6a831c399e269772661";
in3, "900150983cd24fb0d6963f7d28e17f72";
in4, "03dd8807a93175fb062dfb55dc7d359c";
in5, "1af6d6f2f682f76f80e606aeaaee1680"]

module TestBLAKE512 = Test(Digest.BLAKE512)
let _ = TestBLAKE512.run_tests
[in1, "786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419\
d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce";
in2, "333fcb4ee1aa7c115355ec66ceac917c8bfd815bf7587d325aec1864edd24e34\
d5abe2c6b1b5ee3face62fed78dbef802f2a85cb91d455a8f5249d330853cb3c";
in3, "ba80a53f981c4d0d6a2797b69f12f6e94c212f14685ac4b74b12bb6fdbffa2d1\
7d87c5392aab792dc252d5de4533cc9518d38aa8dbf1925ab92386edd4009923";
in4, "ce741ac5930fe346811175c5227bb7bfcd47f42612fae46c0809514f9e0e3a11\
ee1773287147cdeaeedff50709aa716341fe65240f4ad6777d6bfaf9726e5e52";
in5, "fe89a110a412012e7cc5c0e05b03b48a6b9d0ba108187826c5ac82ce7aa45e7e\
31b054979ec8ca5acd0bcc85f379d848f90f9d1593358cba8d88c7cd94ea8eee"]

module TestBLAKE256 = Test(Digest.BLAKE256)
let _ = TestBLAKE256.run_tests
[in1, "0e5751c026e543b2e8ab2eb06099daa1d1e5df47778f7787faab45cdf12fe3a8";
in2, "8928aae63c84d87ea098564d1e03ad813f107add474e56aedd286349c0c03ea4";
in3, "bddd813c634239723171ef3fee98579b94964e3bb1cb3e427262c8c068d52319";
in4, "90a0bcf5e5a67ac1578c2754617994cfc248109275a809a0721feebd1e918738";
in5, "b717c86cf745507ec5373f12f21350eb8550039b4263f7ba6e8df9030b5673c6"]

module TestBLAKE128 = Test(Digest.BLAKE128)
let _ = TestBLAKE128.run_tests
[in1, "cae66941d9efbd404e4d88758ea67670";
in2, "27c35e6e9373877f29e562464e46497e";
in3, "cf4ab791c62b8d2b2109c90275287816";
in4, "8fa81cd08c10a6e4dd94583e6fb48c2f";
in5, "5c4b4b762807b3290e7eee0aa9b18655"]
17 changes: 17 additions & 0 deletions compiler/tests-ocaml/lib-digest/dune
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(executables
(names md5)
(libraries)
(modules md5)
(modes js))

(rule
Expand All @@ -16,3 +17,19 @@
(deps md5.reference md5.referencejs)
(action
(diff md5.reference md5.referencejs)))

(executables
(names digests)
(libraries)
(enabled_if
(>= %{ocaml_version} 5.2))
(modules digests)
(modes js))

(rule
(alias runtest)
(deps digests.bc.js)
(enabled_if
(>= %{ocaml_version} 5.2))
(action
(run node ./digests.bc.js)))
2 changes: 1 addition & 1 deletion dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
(description
"Js_of_ocaml is a compiler from OCaml bytecode to JavaScript. It makes it possible to run pure OCaml programs in JavaScript environment like browsers and Node.js")
(depends
(ocaml (and (>= 4.08) (< 5.2)))
(ocaml (and (>= 4.08) (< 5.3)))
(num :with-test)
(ppx_expect (and (>= v0.14.2) :with-test))
(ppxlib (>= 0.15.0))
Expand Down
2 changes: 1 addition & 1 deletion js_of_ocaml-compiler.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ doc: "https://ocsigen.org/js_of_ocaml/latest/manual/overview"
bug-reports: "https://github.com/ocsigen/js_of_ocaml/issues"
depends: [
"dune" {>= "3.7"}
"ocaml" {>= "4.08" & < "5.2"}
"ocaml" {>= "4.08" & < "5.3"}
"num" {with-test}
"ppx_expect" {>= "v0.14.2" & with-test}
"ppxlib" {>= "0.15.0"}
Expand Down
Loading
Loading