Skip to content

Commit 8578c97

Browse files
authored
Successful build with --enable-runtime5 (#2017)
* Install runtime/caml headers Updates the dune build system to install the runtime5 headers. Covers #77 * Add CAML_RUNTIME_5 macro to runtime. This allows code using the runtime (particularly otherlibs/) to condition on 4 vs. 5. Alternatively, otherlibs/ could be duplicated between 4 and 5, but only minimal changes were necessary. * unix/fork.c conditionals When building with runtime5, fork needs to use runtime_events instead of eventlog. * unix/signals.c conditionals Runtime5 removes caml_sigmask_hook, so the code should use pthread_sigmask directly. See CR for discussion - the upstream unix/signals.c uses sigprocmask, which seems incorrect. * Upstream build system fixes - Fixes unquoted 'yes' call - Fixes unsubstituted runtime_suffix generator - Disables stack allocation when runtime5 is enabled - Regenerates configure script * Add runtime5 compile-time constant Implements "%runtime5" primitive for checking whether we're configured with runtime5 at compile time. In the compiler, it just returns the config bool. In runtime/ it returns true; in runtime4/ false. Also implements caml_sys_const_naked_pointers_checked in runtime/. * Runtime5 global symbol seperator Runtime5 renames global symbols to 'caml_module.name' instead of 'caml_module__name'. The backend now cases on the configured runtime. * Forward port caml_flambda2_invalid Implements caml_flambda2_invalid runtime diagonstic. See #530 * Forward port caml_obj_make_forward Runtime/ did not include this function, so the implementation is copied from runtime4. The same code works with the new OCaml 5 lazy implementation. * With_async_exns conditional Uses the runtime5 compile-time constant to conditionally implement with_async_exns as a try/catch block. Future work will implement with_async_exns properly in runtime5, at which point this should be removed. * Bootstrap 4 compiler
1 parent 17078bf commit 8578c97

File tree

27 files changed

+176
-28
lines changed

27 files changed

+176
-28
lines changed

middle_end/closure/closure.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,7 @@ let rec close ({ backend; fenv; cenv ; mutable_vars; kinds; catch_env } as env)
13421342
| Ostype_cygwin -> make_const_bool (Sys.os_type = "Cygwin")
13431343
| Backend_type ->
13441344
make_const_int 0 (* tag 0 is the same as Native here *)
1345+
| Runtime5 -> make_const_bool Config.runtime5
13451346
in
13461347
let arg, _approx = close env arg in
13471348
let id = Ident.create_local "dummy" in

middle_end/flambda/closure_conversion.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ let rec close t env (lam : Lambda.lambda) : Flambda.t =
456456
| Ostype_cygwin -> lambda_const_bool (String.equal Sys.os_type "Cygwin")
457457
| Backend_type ->
458458
Lambda.const_int 0 (* tag 0 is the same as Native *)
459+
| Runtime5 -> lambda_const_bool Config.runtime5
459460
end
460461
in
461462
close t env

middle_end/flambda2/from_lambda/lambda_to_flambda_primitives.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,8 @@ let convert_lprim ~big_endian (prim : L.primitive) (args : Simple.t list list)
12411241
| Ostype_win32 -> [Simple (Simple.const_bool (Sys.os_type = "Win32"))]
12421242
| Ostype_cygwin -> [Simple (Simple.const_bool (Sys.os_type = "Cygwin"))]
12431243
| Backend_type ->
1244-
[Simple Simple.const_zero] (* constructor 0 is the same as Native here *))
1244+
[Simple Simple.const_zero] (* constructor 0 is the same as Native here *)
1245+
| Runtime5 -> [Simple (Simple.const_bool Config.runtime5)])
12451246
| Pbswap16, [[arg]] ->
12461247
[ tag_int
12471248
(Unary (Int_arith (Naked_immediate, Swap_byte_endianness), untag_int arg))

ocaml/boot/ocamlc

278 Bytes
Binary file not shown.

ocaml/boot/ocamllex

100 Bytes
Binary file not shown.

ocaml/bytecomp/bytegen.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,8 @@ let comp_primitive stack_info p sz args =
508508
| Ostype_unix -> "ostype_unix"
509509
| Ostype_win32 -> "ostype_win32"
510510
| Ostype_cygwin -> "ostype_cygwin"
511-
| Backend_type -> "backend_type" in
511+
| Backend_type -> "backend_type"
512+
| Runtime5 -> "runtime5" in
512513
Kccall(Printf.sprintf "caml_sys_const_%s" const_name, 1)
513514
| Pisint _ -> Kisint
514515
| Pisout -> Kisout

ocaml/configure

Lines changed: 10 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ocaml/configure.ac

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,8 +2118,10 @@ AS_CASE([$host],
21182118

21192119
## Activate the systhread library
21202120

2121-
if [ "$enable_runtime5" = "yes" ]; then
2121+
if [[ x"$enable_runtime5" = x"yes" ]]; then
21222122
runtime_suffix=
2123+
# CR ocaml 5 runtime: forward port locals
2124+
enable_stack_allocation="no"
21232125
else
21242126
runtime_suffix=4
21252127
fi
@@ -2132,7 +2134,8 @@ AS_CASE([$enable_systhreads,$enable_unix_lib],
21322134
[systhread_support=false
21332135
AC_MSG_NOTICE([the threads library is disabled])],
21342136
[systhread_support=true
2135-
AC_CONFIG_FILES([otherlibs/systhreads${runtime_suffix}/META])
2137+
AC_CONFIG_FILES([otherlibs/systhreads/META])
2138+
AC_CONFIG_FILES([otherlibs/systhreads4/META])
21362139
otherlibraries="$otherlibraries systhreads${runtime_suffix}"
21372140
lib_systhreads=true
21382141
lib_systhreads_path="systhreads${runtime_suffix}"

ocaml/lambda/lambda.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type compile_time_constant =
2727
| Ostype_win32
2828
| Ostype_cygwin
2929
| Backend_type
30+
| Runtime5
3031

3132
type immediate_or_pointer =
3233
| Immediate
@@ -1624,7 +1625,7 @@ let primitive_result_layout (p : primitive) =
16241625
end
16251626
| Pctconst (
16261627
Big_endian | Word_size | Int_size | Max_wosize
1627-
| Ostype_unix | Ostype_cygwin | Ostype_win32 | Backend_type
1628+
| Ostype_unix | Ostype_cygwin | Ostype_win32 | Backend_type | Runtime5
16281629
) ->
16291630
(* Compile-time constants only ever return ints for now,
16301631
enumerate them all to be sure to modify this if it becomes wrong. *)

ocaml/lambda/lambda.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ type compile_time_constant =
2929
| Ostype_win32
3030
| Ostype_cygwin
3131
| Backend_type
32+
| Runtime5
3233

3334
type immediate_or_pointer =
3435
| Immediate

ocaml/lambda/printlambda.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ let primitive ppf = function
432432
| Ostype_unix -> "ostype_unix"
433433
| Ostype_win32 -> "ostype_win32"
434434
| Ostype_cygwin -> "ostype_cygwin"
435-
| Backend_type -> "backend_type" in
435+
| Backend_type -> "backend_type"
436+
| Runtime5 -> "runtime5" in
436437
fprintf ppf "sys.constant_%s" const_name
437438
| Pisint { variant_only } ->
438439
fprintf ppf (if variant_only then "isint" else "obj_is_int")

ocaml/lambda/translprim.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ let lookup_primitive loc poly pos p =
186186
| "%ostype_unix" -> Primitive ((Pctconst Ostype_unix), 1)
187187
| "%ostype_win32" -> Primitive ((Pctconst Ostype_win32), 1)
188188
| "%ostype_cygwin" -> Primitive ((Pctconst Ostype_cygwin), 1)
189+
| "%runtime5" -> Primitive ((Pctconst Runtime5), 1)
189190
| "%frame_pointers" -> Frame_pointers
190191
| "%negint" -> Primitive (Pnegint, 1)
191192
| "%succint" -> Primitive ((Poffsetint 1), 1)

ocaml/middle_end/closure/closure.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1305,6 +1305,7 @@ let rec close ({ backend; fenv; cenv ; mutable_vars; kinds; catch_env } as env)
13051305
| Ostype_cygwin -> make_const_bool (Sys.os_type = "Cygwin")
13061306
| Backend_type ->
13071307
make_const_int 0 (* tag 0 is the same as Native here *)
1308+
| Runtime5 -> make_const_bool Config.runtime5
13081309
in
13091310
let arg, _approx = close env arg in
13101311
let id = Ident.create_local "dummy" in

ocaml/middle_end/flambda/closure_conversion.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,7 @@ let rec close t env (lam : Lambda.lambda) : Flambda.t =
451451
| Ostype_cygwin -> lambda_const_bool (String.equal Sys.os_type "Cygwin")
452452
| Backend_type ->
453453
Lambda.const_int 0 (* tag 0 is the same as Native *)
454+
| Runtime5 -> lambda_const_bool Config.runtime5
454455
end
455456
in
456457
close t env

ocaml/otherlibs/unix/fork.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@
1717

1818
#include <caml/mlvalues.h>
1919
#include <caml/debugger.h>
20-
#if 0 /* BACKPORT BEGIN */
20+
#ifdef CAML_RUNTIME_5
2121
#include <caml/runtime_events.h>
22-
#endif
22+
#else
2323
#include <caml/eventlog.h>
24-
/* BACKPORT END */
24+
#endif
2525
#include "unixsupport.h"
2626
#include <caml/domain.h>
2727
#include <caml/fail.h>
2828

29-
#if 0 /* BACKPORT */
29+
#ifdef CAML_RUNTIME_5
3030
/* Post-fork tasks to be carried out in the parent */
3131
void caml_atfork_parent(pid_t child_pid) {
3232
CAML_EV_LIFECYCLE(EV_FORK_PARENT, child_pid);
@@ -42,35 +42,34 @@ void caml_atfork_child(void) {
4242
CAMLprim value caml_unix_fork(value unit)
4343
{
4444
int ret;
45-
/* BACKPORT
45+
46+
#ifdef CAML_RUNTIME_5
4647
if (caml_domain_is_multicore()) {
4748
caml_failwith
4849
("Unix.fork may not be called while other domains were created");
4950
}
50-
*/
51-
52-
/* BACKPORT BEGIN */
51+
#else
5352
CAML_EV_FLUSH();
54-
/* BACKPORT END */
53+
#endif
5554

5655
ret = fork();
5756

5857
if (ret == -1) caml_uerror("fork", Nothing);
5958

60-
#if 0 /* BACKPORT BEGIN */
59+
#ifdef CAML_RUNTIME_5
6160
if (ret == 0) {
6261
caml_atfork_child();
6362
/* the following hook can be redefined in other places */
6463
caml_atfork_hook();
6564
} else {
6665
caml_atfork_parent(ret);
6766
}
68-
#endif
67+
#else
6968
CAML_EVENTLOG_DO({
7069
if (ret == 0)
7170
caml_eventlog_disable();
7271
});
73-
/* BACKPORT END */
72+
#endif
7473

7574
if (caml_debugger_in_use)
7675
if ((caml_debugger_fork_mode && ret == 0) ||

ocaml/otherlibs/unix/signals.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,16 @@ CAMLprim value caml_unix_sigprocmask(value vaction, value vset)
7474
how = sigprocmask_cmd[Int_val(vaction)];
7575
decode_sigset(vset, &set);
7676
caml_enter_blocking_section();
77+
#ifdef CAML_RUNTIME_5
78+
// CR ocaml 5 runtime: the upstream 5.0 unix lib uses sigprocmask here,
79+
// which seems wrong? Previously, there was a global caml_sigmask_hook wrapper
80+
// that got installed as sigprocmask or pthread_sigmask based on whether
81+
// systhreads was enabled. The 5 runtime is now multithreaded, so always
82+
// links pthread, so should always use pthread_sigmask.
83+
retcode = pthread_sigmask(how, &set, &oldset);
84+
#else
7785
retcode = caml_sigmask_hook(how, &set, &oldset);
86+
#endif
7887
caml_leave_blocking_section();
7988
/* Run any handlers for just-unmasked pending signals */
8089
caml_process_pending_actions();

ocaml/runtime/amd64nt.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,8 @@ caml_ml_array_bound_error:
427427
caml_system__code_end:
428428

429429
.DATA
430-
PUBLIC caml_system__frametable
431-
caml_system__frametable LABEL QWORD
430+
PUBLIC caml_system.frametable
431+
caml_system.frametable LABEL QWORD
432432
QWORD 1 ; one descriptor
433433
QWORD L107 ; return address into callback
434434
WORD -1 ; negative frame size => use callback link

ocaml/runtime/callback.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ CAMLexport value caml_callbackN (value closure, int narg, value args[])
309309
return caml_raise_if_exception(caml_callbackN_exn(closure, narg, args));
310310
}
311311

312+
CAMLprim value caml_with_async_exns(value body_callback)
313+
{
314+
caml_failwith("Called caml_with_async_exns in runtime5: not implemented.");
315+
}
316+
312317
/* Naming of OCaml values */
313318

314319
struct named_value {

ocaml/runtime/caml/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#ifndef CAML_CONFIG_H
1717
#define CAML_CONFIG_H
1818

19+
#define CAML_RUNTIME_5
20+
1921
/* CAML_NAME_SPACE was introduced in OCaml 3.08 to declare compatibility with
2022
the newly caml_-prefixed names of C runtime functions and to disable the
2123
definition of compatibility macros for the un-prefixed names. The

ocaml/runtime/caml/dune

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,74 @@
2727
(action
2828
(with-stdout-to %{targets}
2929
(run %{dep:../../tools/make-version-header.sh} %{dep:../../VERSION}))))
30+
31+
(install
32+
(files
33+
(address_class.h as caml/address_class.h)
34+
(addrmap.h as caml/addrmap.h)
35+
(alloc.h as caml/alloc.h)
36+
(atomic_refcount.h as caml/atomic_refcount.h)
37+
(backtrace_prim.h as caml/backtrace_prim.h)
38+
(backtrace.h as caml/backtrace.h)
39+
(bigarray.h as caml/bigarray.h)
40+
(callback.h as caml/callback.h)
41+
(camlatomic.h as caml/camlatomic.h)
42+
(codefrag.h as caml/codefrag.h)
43+
(compact.h as caml/compact.h)
44+
(compare.h as caml/compare.h)
45+
(config.h as caml/config.h)
46+
(custom.h as caml/custom.h)
47+
(debugger.h as caml/debugger.h)
48+
(domain_state.h as caml/domain_state.h)
49+
(domain_state.tbl as caml/domain_state.tbl)
50+
(domain.h as caml/domain.h)
51+
(dynlink.h as caml/dynlink.h)
52+
(exec.h as caml/exec.h)
53+
(fail.h as caml/fail.h)
54+
(fiber.h as caml/fiber.h)
55+
(finalise.h as caml/finalise.h)
56+
(fix_code.h as caml/fix_code.h)
57+
(frame_descriptors.h as caml/frame_descriptors.h)
58+
(gc_ctrl.h as caml/gc_ctrl.h)
59+
(gc_stats.h as caml/gc_stats.h)
60+
(gc.h as caml/gc.h)
61+
(globroots.h as caml/globroots.h)
62+
(hash.h as caml/hash.h)
63+
(hooks.h as caml/hooks.h)
64+
(instrtrace.h as caml/instrtrace.h)
65+
(instruct.h as caml/instruct.h)
66+
(interp.h as caml/interp.h)
67+
(intext.h as caml/intext.h)
68+
(io.h as caml/io.h)
69+
(lf_skiplist.h as caml/lf_skiplist.h)
70+
(m.h as caml/m.h)
71+
(major_gc.h as caml/major_gc.h)
72+
(md5.h as caml/md5.h)
73+
(memory.h as caml/memory.h)
74+
(memprof.h as caml/memprof.h)
75+
(minor_gc.h as caml/minor_gc.h)
76+
(misc.h as caml/misc.h)
77+
(mlvalues.h as caml/mlvalues.h)
78+
(osdeps.h as caml/osdeps.h)
79+
(platform.h as caml/platform.h)
80+
(prims.h as caml/prims.h)
81+
(printexc.h as caml/printexc.h)
82+
(reverse.h as caml/reverse.h)
83+
(roots.h as caml/roots.h)
84+
(runtime_events.h as caml/runtime_events.h)
85+
(s.h as caml/s.h)
86+
(shared_heap.h as caml/shared_heap.h)
87+
(signals.h as caml/signals.h)
88+
(sizeclasses.h as caml/sizeclasses.h)
89+
(skiplist.h as caml/skiplist.h)
90+
(stack.h as caml/stack.h)
91+
(startup_aux.h as caml/startup_aux.h)
92+
(startup.h as caml/startup.h)
93+
(sync.h as caml/sync.h)
94+
(sys.h as caml/sys.h)
95+
(version.h as caml/version.h)
96+
(weak.h as caml/weak.h)
97+
(winsupport.h as caml/winsupport.h)
98+
)
99+
(section lib)
100+
(package ocaml_runtime_stdlib))

ocaml/runtime/misc.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,18 @@ void caml_bad_caml_state(void)
250250
{
251251
caml_fatal_error("no domain lock held");
252252
}
253+
254+
/* Flambda 2 invalid term markers */
255+
256+
CAMLnoreturn_start
257+
void caml_flambda2_invalid (value message)
258+
CAMLnoreturn_end;
259+
260+
void caml_flambda2_invalid (value message)
261+
{
262+
fprintf (stderr, "[ocaml] [flambda2] Invalid code:\n%s\n\n",
263+
String_val(message));
264+
fprintf (stderr, "This might have arisen from a wrong use of [Obj.magic].\n");
265+
fprintf (stderr, "Consider using [Sys.opaque_identity].\n");
266+
abort ();
267+
}

ocaml/runtime/obj.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,13 @@ CAMLprim value caml_obj_set_raw_field(value arg, value pos, value bits)
6666
return Val_unit;
6767
}
6868

69+
CAMLprim value caml_obj_make_forward(value blk, value fwd)
70+
{
71+
caml_modify(&Field(blk, 0), fwd);
72+
Tag_val (blk) = Forward_tag;
73+
return Val_unit;
74+
}
75+
6976
/* [size] is a value encoding a number of blocks */
7077
CAMLprim value caml_obj_block(value tag, value size)
7178
{

0 commit comments

Comments
 (0)