Skip to content

Commit

Permalink
Misc: bump minimum version (#1368)
Browse files Browse the repository at this point in the history
  • Loading branch information
hhugo authored Dec 20, 2022
1 parent 66570ba commit e177d2a
Show file tree
Hide file tree
Showing 28 changed files with 56 additions and 1,759 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ jobs:
os:
- ubuntu-latest
ocaml-compiler:
- 4.04.x
- 4.05.x
- 4.06.x
- 4.07.x
- 4.08.x
- 4.09.x
- 4.10.x
Expand Down
7 changes: 7 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# dev (20??-??) - ??
## Features/Changes
* Misc: bump min ocaml version to 4.08

## Bug fixes


# 5.0.1 (2022-12-20) - Lille
## Features/Changes

Expand Down
5 changes: 1 addition & 4 deletions compiler/lib/base64.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,8 @@ let unsafe_get_uint8 t off = Char.code (String.unsafe_get t off)

let unsafe_set_uint8 t off v = Bytes.unsafe_set t off (Char.chr v)

external unsafe_set_uint16 : bytes -> int -> int -> unit = "%caml_string_set16u"
[@@noalloc] [@@if ocaml_version < (4, 7, 0)]

external unsafe_set_uint16 : bytes -> int -> int -> unit = "%caml_bytes_set16u"
[@@noalloc] [@@if ocaml_version >= (4, 7, 0)]
[@@noalloc]

external unsafe_get_uint16 : string -> int -> int = "%caml_string_get16u" [@@noalloc]

Expand Down
20 changes: 3 additions & 17 deletions compiler/lib/instr.ml
Original file line number Diff line number Diff line change
Expand Up @@ -199,24 +199,10 @@ type desc =
}

let ops =
let if_v407 =
match Ocaml_version.v with
| `V4_04 | `V4_06 -> fun _ -> K_will_not_happen
| `V4_07 | `V4_08 | `V4_09 | `V4_10 | `V4_11 | `V4_12 | `V4_13 | `V4_14 | `V5_00 ->
fun k -> k
in
let if_v500 =
match Ocaml_version.v with
| `V4_04
| `V4_06
| `V4_07
| `V4_08
| `V4_09
| `V4_10
| `V4_11
| `V4_12
| `V4_13
| `V4_14 -> fun _ -> K_will_not_happen
| `V4_08 | `V4_09 | `V4_10 | `V4_11 | `V4_12 | `V4_13 | `V4_14 ->
fun _ -> K_will_not_happen
| `V5_00 -> fun k -> k
in
let instrs =
Expand Down Expand Up @@ -368,7 +354,7 @@ let ops =
; BREAK, K_will_not_happen, "BREAK"
; RERAISE, KStop 0, "RERAISE"
; RAISE_NOTRACE, KStop 0, "RAISE_NOTRACE"
; GETSTRINGCHAR, if_v407 KNullary, "GETSTRINGCHAR"
; GETSTRINGCHAR, KNullary, "GETSTRINGCHAR"
; PERFORM, if_v500 KNullaryCall, "PERFORM"
; RESUME, if_v500 KNullaryCall, "RESUME"
; RESUMETERM, if_v500 (KStop 1), "RESUMETERM"
Expand Down
9 changes: 0 additions & 9 deletions compiler/lib/magic_number.ml
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@ let equal a b = compare a b = 0
let current_exe =
let v =
match Ocaml_version.v with
| `V4_04 -> 11
| `V4_06 -> 11
| `V4_07 -> 23
| `V4_08 -> 25
| `V4_09 -> 26
| `V4_10 -> 27
Expand All @@ -84,9 +81,6 @@ let current_exe =
let current_cmo =
let v =
match Ocaml_version.v with
| `V4_04 -> 11
| `V4_06 -> 22
| `V4_07 -> 23
| `V4_08 -> 25
| `V4_09 -> 26
| `V4_10 -> 27
Expand All @@ -101,9 +95,6 @@ let current_cmo =
let current_cma =
let v =
match Ocaml_version.v with
| `V4_04 -> 12
| `V4_06 -> 22
| `V4_07 -> 23
| `V4_08 -> 25
| `V4_09 -> 26
| `V4_10 -> 27
Expand Down
139 changes: 14 additions & 125 deletions compiler/lib/ocaml_compiler.ml
Original file line number Diff line number Diff line change
Expand Up @@ -34,142 +34,32 @@ let rec constant_of_const : _ -> Code.constant =
| Const_float_array sl ->
let l = List.map ~f:(fun f -> Code.Float (float_of_string f)) sl in
Tuple (Obj.double_array_tag, Array.of_list l, Unknown)
| ((Const_pointer (i, _)) [@if BUCKLESCRIPT]) ->
| ((Const_pointer i) [@if ocaml_version < (4, 12, 0)]) ->
Int (Int32.of_int_warning_on_overflow i)
| ((Const_block (tag, _, l)) [@if BUCKLESCRIPT]) ->
let l = Array.of_list (List.map l ~f:constant_of_const) in
Tuple (tag, l, Unknown)
| ((Const_pointer i) [@ifnot BUCKLESCRIPT] [@if ocaml_version < (4, 12, 0)]) ->
Int (Int32.of_int_warning_on_overflow i)
| ((Const_block (tag, l)) [@ifnot BUCKLESCRIPT]) ->
| Const_block (tag, l) ->
let l = Array.of_list (List.map l ~f:constant_of_const) in
Tuple (tag, l, Unknown)

let rec find_loc_in_summary ident' = function
| Env.Env_empty -> None
| Env.Env_value (_summary, ident, description)
when Poly.(ident = ident') ->
Some description.Types.val_loc
| Env.Env_value (summary,_,_)
| Env.Env_value (_summary, ident, description) when Poly.(ident = ident') ->
Some description.Types.val_loc
| Env.Env_value (summary, _, _)
| Env.Env_type (summary, _, _)
| Env.Env_extension (summary, _, _)
| (Env.Env_module (summary, _, _,_) [@if ocaml_version >= (4,8,0)])
| (Env.Env_module (summary, _, _) [@if ocaml_version < (4,8,0)])
| Env.Env_module (summary, _, _, _)
| Env.Env_modtype (summary, _, _)
| Env.Env_class (summary, _, _)
| Env.Env_cltype (summary, _, _)
| (Env.Env_open (summary, _) [@if ocaml_version >= (4,8,0)])
| (Env.Env_open (summary, _, _) [@if ocaml_version < (4,8,0)] [@if ocaml_version >= (4,7,0)])
| (Env.Env_open (summary, _) [@if ocaml_version < (4,7,0)])
| Env.Env_open (summary, _)
| Env.Env_functor_arg (summary, _)
| (Env.Env_constraints (summary, _) [@if ocaml_version >= (4,4,0)])
| (Env.Env_copy_types (summary, _) [@if ocaml_version >= (4,6,0)] [@if ocaml_version < (4,10,0)])
| (Env.Env_copy_types (summary) [@if ocaml_version >= (4,10,0)])
| (Env.Env_persistent (summary, _) [@if ocaml_version >= (4,8,0)])
| (Env.Env_value_unbound (summary, _, _) [@if ocaml_version >= (4,10,0)])
| (Env.Env_module_unbound (summary, _, _) [@if ocaml_version >= (4,10,0)])
-> find_loc_in_summary ident' summary
[@@ocamlformat "disable"]

(* Copied from ocaml/utils/tbl.ml *)
module Tbl = struct
[@@@ocaml.warning "-unused-field"]

open Poly

type ('a, 'b) t =
| Empty
| Node of ('a, 'b) t * 'a * 'b * ('a, 'b) t * int

let empty = Empty

let height = function
| Empty -> 0
| Node (_, _, _, _, h) -> h

let create l x d r =
let hl = height l and hr = height r in
Node (l, x, d, r, if hl >= hr then hl + 1 else hr + 1)

let bal l x d r =
let hl = height l and hr = height r in
if hl > hr + 1
then
match l with
| Node (ll, lv, ld, lr, _) when height ll >= height lr ->
create ll lv ld (create lr x d r)
| Node (ll, lv, ld, Node (lrl, lrv, lrd, lrr, _), _) ->
create (create ll lv ld lrl) lrv lrd (create lrr x d r)
| _ -> assert false
else if hr > hl + 1
then
match r with
| Node (rl, rv, rd, rr, _) when height rr >= height rl ->
create (create l x d rl) rv rd rr
| Node (Node (rll, rlv, rld, rlr, _), rv, rd, rr, _) ->
create (create l x d rll) rlv rld (create rlr rv rd rr)
| _ -> assert false
else create l x d r

let rec add x data = function
| Empty -> Node (Empty, x, data, Empty, 1)
| Node (l, v, d, r, h) ->
let c = compare x v in
if c = 0
then Node (l, x, data, r, h)
else if c < 0
then bal (add x data l) v d r
else bal l v d (add x data r)

let rec iter f = function
| Empty -> ()
| Node (l, v, d, r, _) ->
iter f l;
f v d;
iter f r

let rec find compare x = function
| Empty -> raise Not_found
| Node (l, v, d, r, _) ->
let c = compare x v in
if c = 0 then d else find compare x (if c < 0 then l else r)

let rec fold f m accu =
match m with
| Empty -> accu
| Node (l, v, d, r, _) -> fold f r (f v d (fold f l accu))
end
[@@if ocaml_version < (4, 8, 0)]

module Symtable = struct
type 'a numtable =
{ num_cnt : int
; num_tbl : ('a, int) Tbl.t
}

module GlobalMap = struct
type t = Ident.t numtable

let filter_global_map (p : Ident.t -> bool) gmap =
let newtbl = ref Tbl.empty in
Tbl.iter (fun id num -> if p id then newtbl := Tbl.add id num !newtbl) gmap.num_tbl;
{ num_cnt = gmap.num_cnt; num_tbl = !newtbl }

let find nn t =
Tbl.find (fun x1 x2 -> String.compare (Ident.name x1) (Ident.name x2)) nn t.num_tbl

let iter nn t = Tbl.iter nn t.num_tbl

let fold f t acc = Tbl.fold f t.num_tbl acc
end

let reloc_ident name =
let buf = Bytes.create 4 in
Symtable.patch_object buf [ Reloc_setglobal (Ident.create_persistent name), 0 ];
let get i = Char.code (Bytes.get buf i) in
get 0 + (get 1 lsl 8) + (get 2 lsl 16) + (get 3 lsl 24)
end
[@@if ocaml_version < (4, 8, 0)]
| Env.Env_constraints (summary, _)
| ((Env.Env_copy_types (summary, _)) [@if ocaml_version < (4, 10, 0)])
| ((Env.Env_copy_types summary) [@if ocaml_version >= (4, 10, 0)])
| Env.Env_persistent (summary, _)
| ((Env.Env_value_unbound (summary, _, _)) [@if ocaml_version >= (4, 10, 0)])
| ((Env.Env_module_unbound (summary, _, _)) [@if ocaml_version >= (4, 10, 0)]) ->
find_loc_in_summary ident' summary

module Symtable = struct
(* Copied from ocaml/bytecomp/symtable.ml *)
Expand Down Expand Up @@ -219,7 +109,6 @@ module Symtable = struct
let get i = Char.code (Bytes.get buf i) in
get 0 + (get 1 lsl 8) + (get 2 lsl 16) + (get 3 lsl 24)
end
[@@if ocaml_version >= (4, 8, 0)]

module Ident = struct
[@@@ocaml.warning "-unused-field"]
Expand Down
5 changes: 1 addition & 4 deletions compiler/lib/ocaml_version.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ let rec compare v v' =

let v =
match current with
| 4 :: (4 | 5) :: _ -> `V4_04
| 4 :: 6 :: _ -> `V4_06
| 4 :: 7 :: _ -> `V4_07
| 4 :: 8 :: _ -> `V4_08
| 4 :: 9 :: _ -> `V4_09
| 4 :: 10 :: _ -> `V4_10
Expand All @@ -79,7 +76,7 @@ let v =
| 5 :: 0 :: _ -> `V5_00
| _ ->
if compare current [ 4; 4 ] < 0
then failwith "OCaml version unsupported. Upgrade to OCaml 4.04 or newer."
then failwith "OCaml version unsupported. Upgrade to OCaml 4.08 or newer."
else (
assert (compare current [ 5; 1 ] >= 0);
failwith "OCaml version unsupported. Upgrade js_of_ocaml.")
5 changes: 1 addition & 4 deletions compiler/lib/ocaml_version.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ val compare : t -> t -> int
val split : string -> t

val v :
[ `V4_04 (* OCaml 4.04 / OCaml 4.05 *)
| `V4_06 (* OCaml 4.06 *)
| `V4_07 (* OCaml 4.07 *)
| `V4_08 (* OCaml 4.08 *)
[ `V4_08 (* OCaml 4.08 *)
| `V4_09 (* OCaml 4.09 *)
| `V4_10 (* OCaml 4.10 *)
| `V4_11 (* OCaml 4.11 *)
Expand Down
4 changes: 2 additions & 2 deletions compiler/lib/parse_bytecode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ let predefined_exceptions =

let new_closure_repr =
match Ocaml_version.v with
| `V4_04 | `V4_06 | `V4_07 | `V4_08 | `V4_09 | `V4_10 | `V4_11 -> false
| `V4_08 | `V4_09 | `V4_10 | `V4_11 -> false
| `V4_12 | `V4_13 | `V4_14 | `V5_00 -> true

(* Read and manipulate debug section *)
Expand Down Expand Up @@ -2241,7 +2241,7 @@ let parse_bytecode code globals debug_data =
let override_global =
match Ocaml_version.v with
| `V4_13 | `V4_14 | `V5_00 -> []
| `V4_04 | `V4_06 | `V4_07 | `V4_08 | `V4_09 | `V4_10 | `V4_11 | `V4_12 ->
| `V4_08 | `V4_09 | `V4_10 | `V4_11 | `V4_12 ->
let jsmodule name func =
Prim (Extern "%overrideMod", [ Pc (NativeString name); Pc (NativeString func) ])
in
Expand Down
2 changes: 1 addition & 1 deletion compiler/ppx/ppx_optcomp_light.ml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
(** Minimal version of ppx_optcomp
It only support the following attribute
{[
[@if ocaml_version < (4,8,0)]
[@if ocaml_version < (4,12,0)]
]}
on module (Pstr_module),
toplevel bindings (Pstr_value, Pstr_primitive)
Expand Down
4 changes: 1 addition & 3 deletions compiler/tests-compiler/getenv.ml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ let%expect_test _ =
compile_and_run
~flags:[ "--setenv"; "D=±" ]
{|
(if Sys.ocaml_version >= "4.07"
then
match Sys.getenv "D" with
(match Sys.getenv "D" with
| "\u{00b1}" -> ()
| _ -> print_endline "BUG")|};
[%expect {||}]
14 changes: 7 additions & 7 deletions 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.04) (< 5.1)))
(ocaml (and (>= 4.08) (< 5.1)))
(num :with-test)
(ppx_expect (and (>= v0.14.2) :with-test))
(ppxlib (>= 0.15.0))
Expand All @@ -41,7 +41,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 (>= 4.04))
(ocaml (>= 4.08))
(js_of_ocaml (= :version))
(js_of_ocaml-ppx (= :version))
(lwt (>= 2.4.4))
Expand All @@ -60,7 +60,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 (>= 4.04))
(ocaml (>= 4.08))
(js_of_ocaml (= :version))
(ppxlib (>= 0.15))
(num :with-test)
Expand All @@ -74,7 +74,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 (>= 4.04))
(ocaml (>= 4.08))
(js_of_ocaml (= :version))
(ppxlib (>= 0.15.0))
(num :with-test)
Expand All @@ -88,7 +88,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 (>= 4.04))
(ocaml (>= 4.08))
(js_of_ocaml-compiler (= :version))
(ocamlfind (>= 1.5.1))
(cohttp-lwt-unix :with-test)
Expand All @@ -105,7 +105,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 (>= 4.04))
(ocaml (>= 4.08))
(js_of_ocaml (= :version))
(js_of_ocaml-ppx (= :version))
(react (>= 1.2.1))
Expand All @@ -123,7 +123,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 (>= 4.04))
(ocaml (>= 4.08))
(js_of_ocaml-compiler (= :version))
(ppxlib (>= 0.15))
(num :with-test)
Expand Down
Loading

0 comments on commit e177d2a

Please sign in to comment.