Skip to content

Commit 70007b2

Browse files
committed
Merge flambda-backend changes
This has been committed with conflicts: both modified: asmcomp/cmmgen.ml both modified: bytecomp/bytegen.ml deleted by us: compilerlibs/Makefile.compilerlibs both modified: dune both modified: lambda/lambda.ml both modified: lambda/lambda.mli both modified: lambda/translprim.ml both modified: ocamltest/dune both modified: ocamltest/main.ml both modified: otherlibs/systhreads/st_stubs.c both modified: stdlib/stdlib.ml both modified: stdlib/stdlib.mli both modified: testsuite/tests/basic/patmatch_for_multiple.ml both modified: testsuite/tests/lazy/minor_major_force.ml both modified: testsuite/tests/lf_skiplist/test.ml both modified: testsuite/tests/lib-runtime-events/test_caml.ml both modified: testsuite/tests/shape-index/index_aliases.reference both modified: testsuite/tests/statmemprof/callstacks.ml both modified: testsuite/tests/typing-immediate/immediate.ml both modified: tools/objinfo.ml both modified: typing/env.ml both modified: typing/env.mli both modified: typing/oprint.ml both modified: typing/persistent_env.ml both modified: typing/typedtree.mli both modified: typing/typemod.ml
2 parents 8b2c8a0 + bb081b4 commit 70007b2

File tree

261 files changed

+22711
-12522
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+22711
-12522
lines changed

Makefile.common-jst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ boot_targets = \
6060
$(boot_ocamlopt) \
6161
$(boot_ocamlmklib) \
6262
$(boot_ocamldep) \
63-
$(boot_ocamlobjinfo)
63+
$(boot_ocamlobjinfo) \
64+
ocaml/ocamltest/ocamltest.byte
6465

6566
boot-compiler: _build/_bootinstall
6667
RUNTIME_DIR=$(RUNTIME_DIR) $(dune) build $(ws_boot) $(coverage_dune_flags) $(boot_targets)

asmcomp/cmmgen.ml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,11 +1097,19 @@ and transl_prim_1 env p arg dbg =
10971097
box_int dbg Pnativeint m (get_header (transl env arg) dbg)
10981098
| Pperform ->
10991099
<<<<<<< HEAD
1100+
<<<<<<< HEAD
1101+
Misc.fatal_error "Effects-related primitives not yet supported"
1102+
(* CR mshinwell: use [Runtimetags] once available
1103+
||||||| 2572783060
11001104
Misc.fatal_error "Effects-related primitives not yet supported"
11011105
(* CR mshinwell: use [Runtimetags] once available
1106+
=======
1107+
>>>>>>> ocaml-jst/flambda-patches
11021108
let cont =
1103-
make_alloc dbg cont_tag [int_const dbg 0] ~mode:Lambda.alloc_heap
1109+
make_alloc dbg Runtimetags.cont_tag [int_const dbg 0]
1110+
~mode:Lambda.alloc_heap
11041111
in
1112+
<<<<<<< HEAD
11051113
(* CR mshinwell: Rc_normal may be wrong, but this code is unlikely
11061114
to be in production by then *)
11071115
Cop(Capply (typ_val, Rc_normal),
@@ -1114,9 +1122,17 @@ and transl_prim_1 env p arg dbg =
11141122
in
11151123
Cop(Capply typ_val,
11161124
>>>>>>> 5.2.0
1125+
||||||| 2572783060
1126+
(* CR mshinwell: Rc_normal may be wrong, but this code is unlikely
1127+
to be in production by then *)
1128+
Cop(Capply (typ_val, Rc_normal),
1129+
=======
1130+
(* Rc_normal means "allow tailcalls". Preventing them here by using
1131+
Rc_nontail improves backtraces of paused fibers. *)
1132+
Cop(Capply (typ_val, Rc_nontail),
1133+
>>>>>>> ocaml-jst/flambda-patches
11171134
[Cconst_symbol ("caml_perform", dbg); transl env arg; cont],
11181135
dbg)
1119-
*)
11201136
| Pdls_get ->
11211137
Cop(Cdls_get, [transl env arg], dbg)
11221138
| Patomic_load {immediate_or_pointer = Immediate} ->
@@ -1416,14 +1432,14 @@ and transl_prim_3 env p arg1 arg2 arg3 dbg =
14161432
(* Effects *)
14171433
<<<<<<< HEAD
14181434
| Presume ->
1419-
Misc.fatal_error "Effects-related primitives not yet supported"
1420-
(*
1421-
(* CR mshinwell: Rc_normal may be wrong, but this code is unlikely
1422-
to be in production by then *)
1435+
(* Rc_normal is required here, because there are some usages of effects
1436+
with repeated resumes, and these should consume O(1) stack space by
1437+
tail-calling caml_resume. *)
14231438
Cop (Capply (typ_val, Rc_normal),
14241439
[Cconst_symbol ("caml_resume", dbg);
14251440
transl env arg1; transl env arg2; transl env arg3],
14261441
dbg)
1442+
<<<<<<< HEAD
14271443
*)
14281444
||||||| 121bedcfd2
14291445
| Presume ->
@@ -1435,26 +1451,25 @@ and transl_prim_3 env p arg1 arg2 arg3 dbg =
14351451
=======
14361452
14371453
>>>>>>> 5.2.0
1454+
||||||| 2572783060
1455+
*)
1456+
=======
1457+
>>>>>>> ocaml-jst/flambda-patches
14381458
| Prunstack ->
1439-
Misc.fatal_error "Effects-related primitives not yet supported"
1440-
(*
1441-
(* CR mshinwell: Rc_normal may be wrong, but this code is unlikely
1442-
to be in production by then *)
1443-
Cop (Capply (typ_val, Rc_normal),
1459+
(* Rc_normal is fine here but unlikely to ever be a tail call (usages
1460+
of this primitive shouldn't be generated in tail position), so
1461+
we use Rc_nontail for clarity. *)
1462+
Cop (Capply (typ_val, Rc_nontail),
14441463
[Cconst_symbol ("caml_runstack", dbg);
14451464
transl env arg1; transl env arg2; transl env arg3],
14461465
dbg)
1447-
*)
14481466
| Preperform ->
1449-
Misc.fatal_error "Effects-related primitives not yet supported"
1450-
(*
1451-
(* CR mshinwell: Rc_normal may be wrong, but this code is unlikely
1452-
to be in production by then *)
1467+
(* Rc_normal is required here, this is used in tail position and should
1468+
tail call. *)
14531469
Cop (Capply (typ_val, Rc_normal),
14541470
[Cconst_symbol ("caml_reperform", dbg);
14551471
transl env arg1; transl env arg2; transl env arg3],
14561472
dbg)
1457-
*)
14581473

14591474
| Pperform | Pdls_get | Presume
14601475
| Patomic_exchange | Patomic_fetch_add | Patomic_load _

bytecomp/bytegen.ml

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -173,22 +173,29 @@ let preserve_tailcall_for_prim = function
173173
| Pmodbint _ | Pandbint _ | Porbint _ | Pxorbint _ | Plslbint _ | Plsrbint _
174174
| Pasrbint _ | Pbintcomp _ | Punboxed_int_comp _
175175
| Pbigarrayref _ | Pbigarrayset _ | Pbigarraydim _
176-
| Pstring_load_16 _ | Pstring_load_32 _ | Pstring_load_64 _ | Pstring_load_128 _
177-
| Pbytes_load_16 _ | Pbytes_load_32 _ | Pbytes_load_64 _ | Pbytes_load_128 _
178-
| Pbytes_set_16 _ | Pbytes_set_32 _ | Pbytes_set_64 _ | Pbytes_set_128 _
179-
| Pbigstring_load_16 _ | Pbigstring_load_32 _ | Pbigstring_load_64 _
180-
| Pbigstring_load_128 _ | Pbigstring_set_16 _ | Pbigstring_set_32 _
176+
| Pstring_load_16 _ | Pstring_load_32 _ | Pstring_load_f32 _
177+
| Pstring_load_64 _ | Pstring_load_128 _
178+
| Pbytes_load_16 _ | Pbytes_load_32 _ | Pbytes_load_f32 _
179+
| Pbytes_load_64 _ | Pbytes_load_128 _
180+
| Pbytes_set_16 _ | Pbytes_set_32 _ | Pbytes_set_f32 _
181+
| Pbytes_set_64 _ | Pbytes_set_128 _
182+
| Pbigstring_load_16 _ | Pbigstring_load_32 _ | Pbigstring_load_f32 _
183+
| Pbigstring_load_64 _ | Pbigstring_load_128 _
184+
| Pbigstring_set_16 _ | Pbigstring_set_32 _ | Pbigstring_set_f32 _
181185
| Pfloatarray_load_128 _ | Pfloat_array_load_128 _ | Pint_array_load_128 _
182-
| Punboxed_float_array_load_128 _ | Punboxed_int32_array_load_128 _
183-
| Punboxed_int64_array_load_128 _ | Punboxed_nativeint_array_load_128 _
186+
| Punboxed_float_array_load_128 _ | Punboxed_float32_array_load_128 _
187+
| Punboxed_int32_array_load_128 _ | Punboxed_int64_array_load_128 _
188+
| Punboxed_nativeint_array_load_128 _
184189
| Pfloatarray_set_128 _ | Pfloat_array_set_128 _ | Pint_array_set_128 _
185-
| Punboxed_float_array_set_128 _ | Punboxed_int32_array_set_128 _
186-
| Punboxed_int64_array_set_128 _ | Punboxed_nativeint_array_set_128 _
190+
| Punboxed_float_array_set_128 _ | Punboxed_float32_array_set_128 _
191+
| Punboxed_int32_array_set_128 _ | Punboxed_int64_array_set_128 _
192+
| Punboxed_nativeint_array_set_128 _
187193
| Pbigstring_set_64 _ | Pbigstring_set_128 _
188194
| Pprobe_is_enabled _ | Pobj_dup
189195
| Pctconst _ | Pbswap16 | Pbbswap _ | Pint_as_pointer _
190196
| Patomic_exchange | Patomic_cas | Patomic_fetch_add | Patomic_load _
191-
| Pdls_get ->
197+
| Pdls_get | Preinterpret_tagged_int63_as_unboxed_int64
198+
| Preinterpret_unboxed_int64_as_tagged_int63 ->
192199
false
193200

194201
(* Add a Kpop N instruction in front of a continuation *)
@@ -471,12 +478,15 @@ let comp_primitive stack_info p sz args =
471478
| Pbytessetu -> Ksetbyteschar
472479
| Pstring_load_16(_) -> Kccall("caml_string_get16", 2)
473480
| Pstring_load_32(_) -> Kccall("caml_string_get32", 2)
481+
| Pstring_load_f32(_) -> Kccall("caml_string_getf32", 2)
474482
| Pstring_load_64(_) -> Kccall("caml_string_get64", 2)
475483
| Pbytes_set_16(_) -> Kccall("caml_bytes_set16", 3)
476484
| Pbytes_set_32(_) -> Kccall("caml_bytes_set32", 3)
485+
| Pbytes_set_f32(_) -> Kccall("caml_bytes_setf32", 3)
477486
| Pbytes_set_64(_) -> Kccall("caml_bytes_set64", 3)
478487
| Pbytes_load_16(_) -> Kccall("caml_bytes_get16", 2)
479488
| Pbytes_load_32(_) -> Kccall("caml_bytes_get32", 2)
489+
| Pbytes_load_f32(_) -> Kccall("caml_bytes_getf32", 2)
480490
| Pbytes_load_64(_) -> Kccall("caml_bytes_get64", 2)
481491
| Parraylength _ -> Kvectlength
482492
(* In bytecode, nothing is ever actually stack-allocated, so we ignore the
@@ -566,14 +576,18 @@ let comp_primitive stack_info p sz args =
566576
| Pbintcomp(_, Cgt) | Punboxed_int_comp(_, Cgt) -> Kccall("caml_greaterthan", 2)
567577
| Pbintcomp(_, Cle) | Punboxed_int_comp(_, Cle) -> Kccall("caml_lessequal", 2)
568578
| Pbintcomp(_, Cge) | Punboxed_int_comp(_, Cge) -> Kccall("caml_greaterequal", 2)
579+
| Pbigarrayref(_, n, Pbigarray_float32_t, _) -> Kccall("caml_ba_float32_get_" ^ Int.to_string n, n + 1)
580+
| Pbigarrayset(_, n, Pbigarray_float32_t, _) -> Kccall("caml_ba_float32_set_" ^ Int.to_string n, n + 2)
569581
| Pbigarrayref(_, n, _, _) -> Kccall("caml_ba_get_" ^ Int.to_string n, n + 1)
570582
| Pbigarrayset(_, n, _, _) -> Kccall("caml_ba_set_" ^ Int.to_string n, n + 2)
571583
| Pbigarraydim(n) -> Kccall("caml_ba_dim_" ^ Int.to_string n, 1)
572584
| Pbigstring_load_16(_) -> Kccall("caml_ba_uint8_get16", 2)
573585
| Pbigstring_load_32(_) -> Kccall("caml_ba_uint8_get32", 2)
586+
| Pbigstring_load_f32(_) -> Kccall("caml_ba_uint8_getf32", 2)
574587
| Pbigstring_load_64(_) -> Kccall("caml_ba_uint8_get64", 2)
575588
| Pbigstring_set_16(_) -> Kccall("caml_ba_uint8_set16", 3)
576589
| Pbigstring_set_32(_) -> Kccall("caml_ba_uint8_set32", 3)
590+
| Pbigstring_set_f32(_) -> Kccall("caml_ba_uint8_setf32", 3)
577591
| Pbigstring_set_64(_) -> Kccall("caml_ba_uint8_set64", 3)
578592
| Pbswap16 -> Kccall("caml_bswap16", 1)
579593
| Pbbswap(bi,_) -> comp_bint_primitive bi "bswap" args
@@ -592,12 +606,28 @@ let comp_primitive stack_info p sz args =
592606
| Pstring_load_128 _ | Pbytes_load_128 _ | Pbytes_set_128 _
593607
| Pbigstring_load_128 _ | Pbigstring_set_128 _
594608
| Pfloatarray_load_128 _ | Pfloat_array_load_128 _ | Pint_array_load_128 _
595-
| Punboxed_float_array_load_128 _ | Punboxed_int32_array_load_128 _
596-
| Punboxed_int64_array_load_128 _ | Punboxed_nativeint_array_load_128 _
609+
| Punboxed_float_array_load_128 _ | Punboxed_float32_array_load_128 _
610+
| Punboxed_int32_array_load_128 _ | Punboxed_int64_array_load_128 _
611+
| Punboxed_nativeint_array_load_128 _
597612
| Pfloatarray_set_128 _ | Pfloat_array_set_128 _ | Pint_array_set_128 _
598-
| Punboxed_float_array_set_128 _ | Punboxed_int32_array_set_128 _
599-
| Punboxed_int64_array_set_128 _ | Punboxed_nativeint_array_set_128 _ ->
613+
| Punboxed_float_array_set_128 _ | Punboxed_float32_array_set_128 _
614+
| Punboxed_int32_array_set_128 _ | Punboxed_int64_array_set_128 _
615+
| Punboxed_nativeint_array_set_128 _ ->
600616
fatal_error "128-bit load/store is not supported in bytecode mode."
617+
| Preinterpret_tagged_int63_as_unboxed_int64 ->
618+
if not (Target_system.is_64_bit ())
619+
then
620+
Misc.fatal_error
621+
"Preinterpret_tagged_int63_as_unboxed_int64 can only be used on 64-bit \
622+
targets";
623+
Kccall("caml_reinterpret_tagged_int63_as_unboxed_int64", 1)
624+
| Preinterpret_unboxed_int64_as_tagged_int63 ->
625+
if not (Target_system.is_64_bit ())
626+
then
627+
Misc.fatal_error
628+
"Preinterpret_unboxed_int64_as_tagged_int63 can only be used on 64-bit \
629+
targets";
630+
Kccall("caml_reinterpret_unboxed_int64_as_tagged_int63", 1)
601631
(* The cases below are handled in [comp_expr] before the [comp_primitive] call
602632
(in the order in which they appear below),
603633
so they should never be reached in this function. *)
@@ -1265,4 +1295,19 @@ let compile_implementation modulename expr =
12651295
fst (compile_gen ~modulename ~init_stack:0 expr)
12661296

12671297
let compile_phrase expr =
1298+
<<<<<<< HEAD
12681299
compile_gen ~init_stack:1 expr
1300+
||||||| 2572783060
1301+
reset ();
1302+
Fun.protect ~finally:reset (fun () ->
1303+
let init_code = comp_block empty_env expr 1 [Kreturn 1] in
1304+
let fun_code = comp_remainder [] in
1305+
(init_code, fun_code))
1306+
=======
1307+
reset ();
1308+
Fun.protect ~finally:reset (fun () ->
1309+
let init_code = comp_block empty_env expr 1 [Kreturn 1] in
1310+
let fun_code = comp_remainder [] in
1311+
(init_code, fun_code))
1312+
1313+
>>>>>>> ocaml-jst/flambda-patches

bytecomp/emitcode.ml

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,10 @@ and emit_branch_comp = function
212212
| Clt -> out opBLTINT | Cle -> out opBLEINT
213213
| Cgt -> out opBGTINT | Cge -> out opBGEINT
214214

215+
let runtime5_only () =
216+
if not Config.runtime5 then
217+
Misc.fatal_error "Effect primitives are only supported on runtime5"
218+
215219
let emit_instr = function
216220
Klabel lbl -> define_label lbl
217221
| Kacc n ->
@@ -319,17 +323,11 @@ let emit_instr = function
319323
| Kgetpubmet tag -> out opGETPUBMET; out_int tag; out_int 0
320324
| Kgetdynmet -> out opGETDYNMET
321325
| Kevent ev -> record_event ev
322-
(* CR mshinwell: enable for effects support
323-
| Kperform -> out opPERFORM
324-
| Kresume -> out opRESUME
325-
| Kresumeterm n -> out opRESUMETERM; out_int n
326-
| Kreperformterm n -> out opREPERFORMTERM; out_int n
327-
| Kstop -> out opSTOP *)
328-
| Kperform
329-
| Kresume
330-
| Kresumeterm _
331-
| Kreperformterm _
332-
| Kstop -> Misc.fatal_error "No effects support provided yet"
326+
| Kperform -> runtime5_only (); out opPERFORM
327+
| Kresume -> runtime5_only (); out opRESUME
328+
| Kresumeterm n -> runtime5_only (); out opRESUMETERM; out_int n
329+
| Kreperformterm n -> runtime5_only (); out opREPERFORMTERM; out_int n
330+
| Kstop -> out opSTOP
333331

334332
(* Emission of a list of instructions. Include some peephole optimization. *)
335333

bytecomp/symtable.ml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,12 @@ let rec transl_const = function
214214
in
215215
List.iteri transl_field fields;
216216
block
217+
| Const_mixed_block _ ->
218+
(* CR layouts v5.9: Support constant mixed blocks in bytecode, either by
219+
dynamically allocating them once at top-level, or by supporting
220+
marshaling into the cmo format for mixed blocks in bytecode.
221+
*)
222+
Misc.fatal_error "[Const_mixed_block] not supported in bytecode."
217223
| Const_float_block fields | Const_float_array fields ->
218224
let res = Array.Floatarray.create (List.length fields) in
219225
List.iteri (fun i f -> Array.Floatarray.set res i (float_of_string f))

0 commit comments

Comments
 (0)