Skip to content

Commit

Permalink
conditionalize the changes in ocaml/ocaml#13193
Browse files Browse the repository at this point in the history
  • Loading branch information
anmonteiro committed Oct 6, 2024
1 parent 081f4de commit c9ea938
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 6 deletions.
8 changes: 8 additions & 0 deletions jscomp/stdlib/camlinternalMod.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,17 @@ let rec update_mod_field modu i shape n =
| Value _ ->
() (* the value is already there *)
| Class ->
#if OCAML_VERSION >= (5, 3, 0)
assert (Obj.tag n = 0 && Obj.size n = 3);
#else
assert (Obj.tag n = 0 && Obj.size n = 4);
#endif
let cl = Obj.field modu i in
#if OCAML_VERSION >= (5, 3, 0)
for j = 0 to 2 do
#else
for j = 0 to 3 do
#endif
Obj.set_field cl j (Obj.field n j)
done
| Module comps ->
Expand Down
9 changes: 9 additions & 0 deletions jscomp/stdlib/camlinternalOO.cppo.ml
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,12 @@ let init_class table =
table.initializers <- List.rev table.initializers;
resize table (3 + Obj.magic table.methods.(1) * 16 / Sys.word_size)


#if OCAML_VERSION >= (5, 3, 0)
let inherits cla vals virt_meths concr_meths (_, super, env) top =
#else
let inherits cla vals virt_meths concr_meths (_, super, _, env) top =
#endif
narrow cla vals virt_meths concr_meths;
let init =
if top then super cla env else Obj.repr (super cla) in
Expand All @@ -345,7 +350,11 @@ let make_class pub_meths class_init =
let table = create_table pub_meths in
let env_init = class_init table in
init_class table;
#if OCAML_VERSION >= (5, 3, 0)
(env_init (Obj.repr 0), class_init, Obj.repr 0)
#else
(env_init (Obj.repr 0), class_init, env_init, Obj.repr 0)
#endif

type init_table = { mutable env_init: t; mutable class_init: table -> t }
[@@warning "-unused-field"]
Expand Down
8 changes: 8 additions & 0 deletions jscomp/stdlib/camlinternalOO.cppo.mli
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,18 @@ val create_table : string array -> table
val init_class : table -> unit
val inherits :
table -> string array -> string array -> string array ->
#if OCAML_VERSION >= (5, 3, 0)
(t * (table -> obj -> Obj.t) * obj) -> bool -> Obj.t array
#else
(t * (table -> obj -> Obj.t) * t * obj) -> bool -> Obj.t array
#endif
val make_class :
string array -> (table -> Obj.t -> t) ->
#if OCAML_VERSION >= (5, 3, 0)
(t * (table -> Obj.t -> t) * Obj.t)
#else
(t * (table -> Obj.t -> t) * (Obj.t -> t) * Obj.t)
#endif
type init_table
val make_class_store :
string array -> (table -> t) -> init_table -> unit
Expand Down
30 changes: 27 additions & 3 deletions jscomp/stdlib/dune
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@
(deps camlinternalMod.cppo.ml)
(target camlinternalMod.ml)
(action
(run cppo -D=BS %{env:CPPO_FLAGS=} %{deps} -o %{target})))
(run
cppo
-D=BS
-V
OCAML:%{ocaml_version}
%{env:CPPO_FLAGS=}
%{deps}
-o
%{target})))

(rule
(deps camlinternalMod.cppo.mli)
Expand All @@ -83,13 +91,29 @@
(deps camlinternalOO.cppo.ml)
(target camlinternalOO.ml)
(action
(run cppo -D=BS %{env:CPPO_FLAGS=} %{deps} -o %{target})))
(run
cppo
-D=BS
-V
OCAML:%{ocaml_version}
%{env:CPPO_FLAGS=}
%{deps}
-o
%{target})))

(rule
(deps camlinternalOO.cppo.mli)
(target camlinternalOO.mli)
(action
(run cppo -D=BS %{env:CPPO_FLAGS=} %{deps} -o %{target})))
(run
cppo
-D=BS
-V
OCAML:%{ocaml_version}
%{env:CPPO_FLAGS=}
%{deps}
-o
%{target})))

(rule
(deps float.cppo.ml)
Expand Down
6 changes: 3 additions & 3 deletions test/blackbox-tests/mel-as-variants-lists.t
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
> type (_, _) x =
> | [] : ('a, 'a) x
> | ( :: ) : 'a * ('ty, 'v) x -> ('a -> 'ty, 'v) x
> let rec f : type a b. (a, string ref) x -> string =
> let rec f : type a. (a, string ref) x -> string =
> fun x -> match x with [] -> "empty" | _ :: xs -> f xs
> EOF
Expand Down Expand Up @@ -47,7 +47,7 @@
>
> let x : _ x = []
>
> let rec f : type a b. (a, string ref) x -> string =
> let rec f : type a. (a, string ref) x -> string =
> fun x -> match x with [] -> "empty" | _ :: xs -> f xs
> EOF
Expand Down Expand Up @@ -82,7 +82,7 @@
> let x : _ x = []
> let y : _ x = [ 2 ]
>
> let rec f : type a b. (a, string ref) x -> string =
> let rec f : type a. (a, string ref) x -> string =
> fun x -> match x with [] -> "empty" | _ :: xs -> f xs
> EOF
Expand Down

0 comments on commit c9ea938

Please sign in to comment.