Skip to content

Commit 3b73a8d

Browse files
authored
flambda-backend: Communicate frontend layouts to lambda (#1455)
1 parent f94a067 commit 3b73a8d

Some content is hidden

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

52 files changed

+1134
-731
lines changed

.depend

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,6 @@ parsing/jane_syntax.cmo : \
434434
parsing/parsetree.cmi \
435435
parsing/longident.cmi \
436436
parsing/location.cmi \
437-
utils/language_extension.cmi \
438437
parsing/jane_syntax_parsing.cmi \
439438
parsing/asttypes.cmi \
440439
parsing/ast_helper.cmi \
@@ -443,7 +442,6 @@ parsing/jane_syntax.cmx : \
443442
parsing/parsetree.cmi \
444443
parsing/longident.cmx \
445444
parsing/location.cmx \
446-
utils/language_extension.cmx \
447445
parsing/jane_syntax_parsing.cmx \
448446
parsing/asttypes.cmi \
449447
parsing/ast_helper.cmx \
@@ -1236,19 +1234,22 @@ typing/primitive.cmo : \
12361234
typing/outcometree.cmi \
12371235
utils/misc.cmi \
12381236
parsing/location.cmi \
1237+
typing/layouts.cmi \
12391238
parsing/attr_helper.cmi \
12401239
typing/primitive.cmi
12411240
typing/primitive.cmx : \
12421241
parsing/parsetree.cmi \
12431242
typing/outcometree.cmi \
12441243
utils/misc.cmx \
12451244
parsing/location.cmx \
1245+
typing/layouts.cmx \
12461246
parsing/attr_helper.cmx \
12471247
typing/primitive.cmi
12481248
typing/primitive.cmi : \
12491249
parsing/parsetree.cmi \
12501250
typing/outcometree.cmi \
1251-
parsing/location.cmi
1251+
parsing/location.cmi \
1252+
typing/layouts.cmi
12521253
typing/printpat.cmo : \
12531254
typing/types.cmi \
12541255
typing/typedtree.cmi \
@@ -1980,6 +1981,7 @@ typing/typeopt.cmi : \
19801981
typing/typedtree.cmi \
19811982
typing/path.cmi \
19821983
parsing/location.cmi \
1984+
typing/layouts.cmi \
19831985
lambda/lambda.cmi \
19841986
typing/env.cmi
19851987
typing/types.cmo : \
@@ -3710,6 +3712,7 @@ lambda/lambda.cmo : \
37103712
utils/misc.cmi \
37113713
parsing/longident.cmi \
37123714
parsing/location.cmi \
3715+
typing/layouts.cmi \
37133716
typing/ident.cmi \
37143717
typing/env.cmi \
37153718
lambda/debuginfo.cmi \
@@ -3725,6 +3728,7 @@ lambda/lambda.cmx : \
37253728
utils/misc.cmx \
37263729
parsing/longident.cmx \
37273730
parsing/location.cmx \
3731+
typing/layouts.cmx \
37283732
typing/ident.cmx \
37293733
typing/env.cmx \
37303734
lambda/debuginfo.cmx \
@@ -3739,6 +3743,7 @@ lambda/lambda.cmi : \
37393743
typing/primitive.cmi \
37403744
typing/path.cmi \
37413745
parsing/location.cmi \
3746+
typing/layouts.cmi \
37423747
typing/ident.cmi \
37433748
typing/env.cmi \
37443749
lambda/debuginfo.cmi \
@@ -3793,6 +3798,7 @@ lambda/matching.cmx : \
37933798
lambda/matching.cmi : \
37943799
typing/typedtree.cmi \
37953800
parsing/location.cmi \
3801+
typing/layouts.cmi \
37963802
lambda/lambda.cmi \
37973803
typing/ident.cmi \
37983804
lambda/debuginfo.cmi
@@ -3881,6 +3887,7 @@ lambda/transl_array_comprehension.cmo : \
38813887
typing/predef.cmi \
38823888
utils/misc.cmi \
38833889
lambda/matching.cmi \
3890+
typing/layouts.cmi \
38843891
lambda/lambda.cmi \
38853892
typing/ident.cmi \
38863893
typing/env.cmi \
@@ -3894,6 +3901,7 @@ lambda/transl_array_comprehension.cmx : \
38943901
typing/predef.cmx \
38953902
utils/misc.cmx \
38963903
lambda/matching.cmx \
3904+
typing/layouts.cmx \
38973905
lambda/lambda.cmx \
38983906
typing/ident.cmx \
38993907
typing/env.cmx \
@@ -3902,6 +3910,7 @@ lambda/transl_array_comprehension.cmx : \
39023910
lambda/transl_array_comprehension.cmi
39033911
lambda/transl_array_comprehension.cmi : \
39043912
typing/typedtree.cmi \
3913+
typing/layouts.cmi \
39053914
lambda/lambda.cmi \
39063915
lambda/debuginfo.cmi
39073916
lambda/transl_comprehension_utils.cmo : \
@@ -3923,6 +3932,7 @@ lambda/transl_list_comprehension.cmo : \
39233932
typing/typedtree.cmi \
39243933
lambda/transl_comprehension_utils.cmi \
39253934
lambda/matching.cmi \
3935+
typing/layouts.cmi \
39263936
lambda/lambda.cmi \
39273937
typing/ident.cmi \
39283938
parsing/asttypes.cmi \
@@ -3932,12 +3942,14 @@ lambda/transl_list_comprehension.cmx : \
39323942
typing/typedtree.cmx \
39333943
lambda/transl_comprehension_utils.cmx \
39343944
lambda/matching.cmx \
3945+
typing/layouts.cmx \
39353946
lambda/lambda.cmx \
39363947
typing/ident.cmx \
39373948
parsing/asttypes.cmi \
39383949
lambda/transl_list_comprehension.cmi
39393950
lambda/transl_list_comprehension.cmi : \
39403951
typing/typedtree.cmi \
3952+
typing/layouts.cmi \
39413953
lambda/lambda.cmi \
39423954
lambda/debuginfo.cmi
39433955
lambda/translattribute.cmo : \
@@ -3980,6 +3992,7 @@ lambda/translclass.cmo : \
39803992
typing/path.cmi \
39813993
lambda/matching.cmi \
39823994
parsing/location.cmi \
3995+
typing/layouts.cmi \
39833996
lambda/lambda.cmi \
39843997
typing/ident.cmi \
39853998
typing/env.cmi \
@@ -3997,6 +4010,7 @@ lambda/translclass.cmx : \
39974010
typing/path.cmx \
39984011
lambda/matching.cmx \
39994012
parsing/location.cmx \
4013+
typing/layouts.cmx \
40004014
lambda/lambda.cmx \
40014015
typing/ident.cmx \
40024016
typing/env.cmx \
@@ -4083,6 +4097,7 @@ lambda/translcore.cmx : \
40834097
parsing/asttypes.cmi \
40844098
lambda/translcore.cmi
40854099
lambda/translcore.cmi : \
4100+
typing/types.cmi \
40864101
typing/typedtree.cmi \
40874102
parsing/longident.cmi \
40884103
parsing/location.cmi \
@@ -4204,6 +4219,7 @@ lambda/translprim.cmo : \
42044219
utils/misc.cmi \
42054220
lambda/matching.cmi \
42064221
parsing/location.cmi \
4222+
typing/layouts.cmi \
42074223
lambda/lambda.cmi \
42084224
typing/ident.cmi \
42094225
typing/env.cmi \
@@ -4224,6 +4240,7 @@ lambda/translprim.cmx : \
42244240
utils/misc.cmx \
42254241
lambda/matching.cmx \
42264242
parsing/location.cmx \
4243+
typing/layouts.cmx \
42274244
lambda/lambda.cmx \
42284245
typing/ident.cmx \
42294246
typing/env.cmx \

asmcomp/cmm_helpers.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1579,7 +1579,7 @@ let box_sized size mode dbg exp =
15791579
(* Simplification of some primitives into C calls *)
15801580

15811581
let default_prim name =
1582-
Primitive.simple ~name ~arity:0(*ignored*) ~alloc:true
1582+
Primitive.simple_on_values ~name ~arity:0(*ignored*) ~alloc:true
15831583

15841584

15851585
let int64_native_prim name arity ~alloc =

asmcomp/cmmgen.ml

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ let rec transl env e =
541541
transl_make_array dbg env kind alloc_heap args
542542
| (Pduparray _, [arg]) ->
543543
let prim_obj_dup =
544-
Primitive.simple ~name:"caml_obj_dup" ~arity:1 ~alloc:true
544+
Primitive.simple_on_values ~name:"caml_obj_dup" ~arity:1 ~alloc:true
545545
in
546546
transl_ccall env prim_obj_dup [arg] dbg
547547
| (Pmakearray _, []) ->
@@ -826,9 +826,13 @@ and transl_make_array dbg env kind mode args =
826826

827827
and transl_ccall env prim args dbg =
828828
let transl_arg native_repr arg =
829+
(* CR layouts v2: This match to be extended with
830+
| Same_as_ocaml_repr Float64 -> (XFloat, transl env arg)
831+
in the PR that adds Float64 *)
829832
match native_repr with
830-
| Same_as_ocaml_repr ->
833+
| Same_as_ocaml_repr Value ->
831834
(XInt, transl env arg)
835+
| Same_as_ocaml_repr Void -> assert false
832836
| Unboxed_float ->
833837
(XFloat, transl_unbox_float dbg env arg)
834838
| Unboxed_integer bi ->
@@ -856,7 +860,11 @@ and transl_ccall env prim args dbg =
856860
in
857861
let typ_res, wrap_result =
858862
match prim.prim_native_repr_res with
859-
| _, Same_as_ocaml_repr -> (typ_val, fun x -> x)
863+
(* CR layouts v2: This match to be extended with
864+
| Same_as_ocaml_repr Float64 -> (typ_float, fun x -> x)
865+
in the PR that adds Float64 *)
866+
| _, Same_as_ocaml_repr Value -> (typ_val, fun x -> x)
867+
| _, Same_as_ocaml_repr Void -> assert false
860868
(* TODO: Allow Alloc_local on suitably typed C stubs *)
861869
| _, Unboxed_float -> (typ_float, box_float dbg alloc_heap)
862870
| _, Unboxed_integer Pint64 when size_int = 4 ->

boot/ocamlc

15.1 KB
Binary file not shown.

boot/ocamllex

0 Bytes
Binary file not shown.

bytecomp/bytegen.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ let rec comp_expr env exp sz cont =
797797
comp_expr env (Lprim (Pmakearray (kind, mutability, m), args, loc)) sz cont
798798
| Lprim (Pduparray _, [arg], loc) ->
799799
let prim_obj_dup =
800-
Primitive.simple ~name:"caml_obj_dup" ~arity:1 ~alloc:true
800+
Primitive.simple_on_values ~name:"caml_obj_dup" ~arity:1 ~alloc:true
801801
in
802802
comp_expr env (Lprim (Pccall prim_obj_dup, [arg], loc)) sz cont
803803
| Lprim (Pduparray _, _, _) ->

compilerlibs/Makefile.compilerlibs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,9 @@ PARSING_CMI = \
8080

8181
TYPING = \
8282
typing/path.cmo \
83+
typing/layouts.cmo \
8384
typing/primitive.cmo \
8485
typing/shape.cmo \
85-
typing/layouts.cmo \
8686
typing/types.cmo \
8787
typing/btype.cmo \
8888
typing/oprint.cmo \

dune

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
asttypes parsetree
6969

7070
;; TYPING
71-
ident path primitive shape layouts types btype oprint subst predef datarepr
71+
ident path layouts primitive shape types btype oprint subst predef datarepr
7272
cmi_format persistent_env env errortrace
7373
typedtree printtyped ctype printtyp includeclass mtype envaux includecore
7474
tast_iterator tast_mapper signature_group cmt_format cms_format untypeast
@@ -263,8 +263,8 @@
263263
(parsetree.mli as compiler-libs/parsetree.mli)
264264
(ident.mli as compiler-libs/ident.mli)
265265
(path.mli as compiler-libs/path.mli)
266-
(primitive.mli as compiler-libs/primitive.mli)
267266
(layouts.mli as compiler-libs/layouts.mli)
267+
(primitive.mli as compiler-libs/primitive.mli)
268268
(types.mli as compiler-libs/types.mli)
269269
(btype.mli as compiler-libs/btype.mli)
270270
(binutils.mli as compiler-libs/binutils.mli)

lambda/lambda.ml

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -637,13 +637,14 @@ let layout_class = Pvalue Pgenval
637637
let layout_module = Pvalue Pgenval
638638
let layout_module_field = Pvalue Pgenval
639639
let layout_functor = Pvalue Pgenval
640-
let layout_float = Pvalue Pfloatval
640+
let layout_boxed_float = Pvalue Pfloatval
641641
let layout_string = Pvalue Pgenval
642642
let layout_boxedint bi = Pvalue (Pboxedintval bi)
643643
let layout_lazy = Pvalue Pgenval
644644
let layout_lazy_contents = Pvalue Pgenval
645645
let layout_any_value = Pvalue Pgenval
646646
let layout_letrec = layout_any_value
647+
let layout_probe_arg = Pvalue Pgenval
647648

648649
(* CR ncourant: use [Ptop] or remove this as soon as possible. *)
649650
let layout_top = layout_any_value
@@ -1438,12 +1439,15 @@ let primitive_result_layout (p : primitive) =
14381439
| Pfield _ | Pfield_computed _ -> layout_field
14391440
| Pfloatfield _ | Pfloatofint _ | Pnegfloat _ | Pabsfloat _
14401441
| Paddfloat _ | Psubfloat _ | Pmulfloat _ | Pdivfloat _
1441-
| Pbox_float _ -> layout_float
1442+
| Pbox_float _ -> layout_boxed_float
14421443
| Punbox_float -> Punboxed_float
14431444
| Pccall { prim_native_repr_res = _, Untagged_int; _} -> layout_int
1444-
| Pccall { prim_native_repr_res = _, Unboxed_float; _} -> layout_float
1445-
| Pccall { prim_native_repr_res = _, Same_as_ocaml_repr; _} ->
1446-
layout_any_value
1445+
| Pccall { prim_native_repr_res = _, Unboxed_float; _} -> layout_boxed_float
1446+
| Pccall { prim_native_repr_res = _, Same_as_ocaml_repr s; _} ->
1447+
begin match s with
1448+
| Value -> layout_any_value
1449+
| Void -> assert false
1450+
end
14471451
| Pccall { prim_native_repr_res = _, Unboxed_integer bi; _} ->
14481452
layout_boxedint bi
14491453
| Praise _ -> layout_bottom
@@ -1465,7 +1469,7 @@ let primitive_result_layout (p : primitive) =
14651469
| Parrayrefu array_ref_kind | Parrayrefs array_ref_kind ->
14661470
(match array_ref_kind with
14671471
| Pintarray_ref -> layout_int
1468-
| Pfloatarray_ref _ -> layout_float
1472+
| Pfloatarray_ref _ -> layout_boxed_float
14691473
| Pgenarray_ref _ | Paddrarray_ref -> layout_field)
14701474
| Pbintofint (bi, _) | Pcvtbint (_,bi,_)
14711475
| Pnegbint (bi, _) | Paddbint (bi, _) | Psubbint (bi, _)
@@ -1482,7 +1486,7 @@ let primitive_result_layout (p : primitive) =
14821486
| Pbigarrayref (_, _, kind, _) ->
14831487
begin match kind with
14841488
| Pbigarray_unknown -> layout_any_value
1485-
| Pbigarray_float32 | Pbigarray_float64 -> layout_float
1489+
| Pbigarray_float32 | Pbigarray_float64 -> layout_boxed_float
14861490
| Pbigarray_sint8 | Pbigarray_uint8
14871491
| Pbigarray_sint16 | Pbigarray_uint16
14881492
| Pbigarray_caml_int -> layout_int

lambda/lambda.mli

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ val layout_module : layout
527527
val layout_functor : layout
528528
val layout_module_field : layout
529529
val layout_string : layout
530-
val layout_float : layout
530+
val layout_boxed_float : layout
531531
val layout_boxedint : boxed_integer -> layout
532532
(* A layout that is Pgenval because it is the field of a block *)
533533
val layout_field : layout
@@ -537,6 +537,8 @@ val layout_lazy_contents : layout
537537
val layout_any_value : layout
538538
(* A layout that is Pgenval because it is bound by a letrec *)
539539
val layout_letrec : layout
540+
(* The probe hack: Free vars in probes must have layout value. *)
541+
val layout_probe_arg : layout
540542

541543
val layout_top : layout
542544
val layout_bottom : layout

0 commit comments

Comments
 (0)