Skip to content

Commit db77ca4

Browse files
mlassonhhugo
andauthored
Fix Recursive Modules on ocaml < 4.13 (#1485)
* Use caml_alloc_dummy_infix where it is needed * Update changes * Tests: allow to run some test with OCaml 4.12 * Fix caml_update_dummy Co-authored-by: Hugo Heuzard <[email protected]>
1 parent 168d44f commit db77ca4

File tree

6 files changed

+33
-9
lines changed

6 files changed

+33
-9
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Dev (2023-??-??) - ??
22

33
## Bug fixes
4+
* Runtime: Fix recursive modules on ocaml < 4.13 (#1485)
45
* Runtime: fix hashing of NaN (#1475)
56
* Runtime: float rounding should resolve tie away from zero (#1475)
67
* Runtime: fix Gc.stat, Gc.quick_stat, Gc.get (#1475)

compiler/tests-jsoo/dune

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
1+
(library
2+
(name jsoo_testsuite_latest)
3+
(modules test_io test_floats)
4+
(libraries unix compiler-libs.common js_of_ocaml-compiler)
5+
(enabled_if
6+
(>= %{ocaml_version} 4.14))
7+
(inline_tests
8+
(modes js best))
9+
(preprocess
10+
(pps ppx_expect)))
11+
112
(library
213
(name jsoo_testsuite)
3-
(libraries unix compiler-libs.common)
14+
(modules
15+
(:standard \ test_io test_floats))
16+
(libraries unix compiler-libs.common js_of_ocaml-compiler)
417
(foreign_stubs
518
(language c)
619
(names bigarray_stubs flush_stubs))

compiler/tests-jsoo/test_rec_mod.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1818
*)
1919

20+
open Js_of_ocaml_compiler.Stdlib
21+
2022
(* https://github.com/ocaml/ocaml/pull/9497 *)
2123
(* Original test case from the issue: *)
2224

@@ -36,7 +38,9 @@ let%expect_test _ =
3638
ignore (IdSet.mem { id = 1 } basic_set : bool)
3739
(* diverge here *)
3840
with e ->
39-
assert (String.ends_with ~suffix:"Undefined recursive module" (Printexc.to_string e))
41+
if String.is_suffix ~suffix:"Undefined recursive module" (Printexc.to_string e)
42+
then ()
43+
else raise e
4044

4145
(* Looping version *)
4246
module rec M1 : sig

compiler/tests-jsoo/test_time.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@
1717
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1818
*)
1919

20+
open Js_of_ocaml_compiler.Stdlib
21+
2022
let%expect_test _ =
2123
let f = Unix.time () in
22-
let z, _integral = Float.modf f in
24+
let z, _integral = modf f in
2325
match Float.classify_float f, Float.classify_float z with
2426
| FP_normal, FP_zero -> ()
2527
| _ -> assert false
@@ -49,7 +51,7 @@ let%expect_test _ =
4951
assert (
5052
String.length s > 0
5153
&& String.for_all
52-
(function
54+
~f:(function
5355
| '0' .. '9' | ' ' -> true
5456
| _ -> false)
5557
s)

runtime/internalMod.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1919

2020
//Provides: caml_CamlinternalMod_init_mod
21-
//Requires: caml_raise_with_arg, caml_global_data
21+
//Requires: caml_raise_with_arg, caml_global_data, caml_alloc_dummy_infix
2222
//If: !effects
2323
//Version: < 4.13
2424
function caml_CamlinternalMod_init_mod(loc,shape) {
@@ -29,7 +29,9 @@ function caml_CamlinternalMod_init_mod(loc,shape) {
2929
if(typeof shape === "number")
3030
switch(shape){
3131
case 0://function
32-
struct[idx]={fun:undef_module};
32+
var dummy=caml_alloc_dummy_infix();
33+
dummy.fun=undef_module;
34+
struct[idx]=dummy;
3335
break;
3436
case 1://lazy
3537
struct[idx]=[246, undef_module];
@@ -78,7 +80,7 @@ function caml_CamlinternalMod_update_mod(shape,real,x) {
7880
}
7981

8082
//Provides: caml_CamlinternalMod_init_mod
81-
//Requires: caml_raise_with_arg, caml_global_data
83+
//Requires: caml_raise_with_arg, caml_global_data, caml_alloc_dummy_infix
8284
//If: effects
8385
//Version: < 4.13
8486
function caml_CamlinternalMod_init_mod(loc,shape,cont) {
@@ -89,7 +91,9 @@ function caml_CamlinternalMod_init_mod(loc,shape,cont) {
8991
if(typeof shape === "number")
9092
switch(shape){
9193
case 0://function
92-
struct[idx]={fun:undef_module};
94+
var dummy=caml_alloc_dummy_infix();
95+
dummy.fun=undef_module;
96+
struct[idx]=dummy;
9397
break;
9498
case 1://lazy
9599
struct[idx]=[246, undef_module];

runtime/obj.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
//Provides: caml_update_dummy
1919
function caml_update_dummy (x, y) {
20-
if( typeof y==="function" ) { x.fun = y; return 0; }
2120
if( y.fun ) { x.fun = y.fun; return 0; }
21+
if( typeof y==="function" ) { x.fun = y; return 0; }
2222
var i = y.length; while (i--) x[i] = y[i]; return 0;
2323
}
2424

0 commit comments

Comments
 (0)