Skip to content

Commit f4075a4

Browse files
authored
flambda-backend: Add a float64 layout and float# type. (#1528)
1 parent 43f02af commit f4075a4

Some content is hidden

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

66 files changed

+2250
-378
lines changed

asmcomp/cmm_helpers.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ let send_function (arity, result, mode) =
22102210
let fun_name = send_function_name arity result mode in
22112211
let fun_args =
22122212
[obj, typ_val; tag, typ_int; cache, typ_addr]
2213-
@ List.map (fun id -> (id, typ_val)) (List.tl args) in
2213+
@ List.combine (List.tl args) arity in
22142214
let fun_dbg = placeholder_fun_dbg ~human_name:fun_name in
22152215
Cfunction
22162216
{fun_name;

asmcomp/cmmgen.ml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,21 @@ let join_unboxed_number_kind ~strict k1 k2 =
334334
k
335335
| _, _ -> No_unboxing
336336

337+
(* [exttype_of_sort] and [machtype_of_sort] should be kept in sync with
338+
[Typeopt.layout_of_const_sort]. *)
339+
(* CR layouts v5: Void case should probably be typ_void *)
340+
let exttype_of_sort (s : Layouts.Sort.const) =
341+
match s with
342+
| Value -> XInt
343+
| Float64 -> XFloat
344+
| Void -> Misc.fatal_error "Cmmgen.exttype_of_sort: void encountered"
345+
346+
let machtype_of_sort (s : Layouts.Sort.const) =
347+
match s with
348+
| Value -> typ_val
349+
| Float64 -> typ_float
350+
| Void -> Misc.fatal_error "Cmmgen.machtype_of_sort: void encountered"
351+
337352
let is_unboxed_number_cmm ~strict cmm =
338353
let r = ref No_result in
339354
let notify k =
@@ -828,13 +843,8 @@ and transl_make_array dbg env kind mode args =
828843

829844
and transl_ccall env prim args dbg =
830845
let transl_arg native_repr arg =
831-
(* CR layouts v2: This match to be extended with
832-
| Same_as_ocaml_repr Float64 -> (XFloat, transl env arg)
833-
in the PR that adds Float64 *)
834846
match native_repr with
835-
| Same_as_ocaml_repr Value ->
836-
(XInt, transl env arg)
837-
| Same_as_ocaml_repr Void -> assert false
847+
| Same_as_ocaml_repr sort -> (exttype_of_sort sort, transl env arg)
838848
| Unboxed_float ->
839849
(XFloat, transl_unbox_float dbg env arg)
840850
| Unboxed_integer bi ->
@@ -864,11 +874,7 @@ and transl_ccall env prim args dbg =
864874
in
865875
let typ_res, wrap_result =
866876
match prim.prim_native_repr_res with
867-
(* CR layouts v2: This match to be extended with
868-
| Same_as_ocaml_repr Float64 -> (typ_float, fun x -> x)
869-
in the PR that adds Float64 *)
870-
| _, Same_as_ocaml_repr Value -> (typ_val, fun x -> x)
871-
| _, Same_as_ocaml_repr Void -> assert false
877+
| _, Same_as_ocaml_repr sort -> (machtype_of_sort sort, fun x -> x)
872878
(* TODO: Allow Alloc_local on suitably typed C stubs *)
873879
| _, Unboxed_float -> (typ_float, box_float dbg alloc_heap)
874880
| _, Unboxed_integer Pint64 when size_int = 4 ->

boot/menhir/parser.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,15 +980,15 @@ let mk_directive ~loc name arg =
980980
let check_layout loc id =
981981
begin
982982
match id with
983-
| ("any" | "value" | "void" | "immediate64" | "immediate") -> ()
983+
| ("any" | "value" | "void" | "immediate64" | "immediate" | "float64") -> ()
984984
| _ -> expecting loc "layout"
985985
end;
986986
let loc = make_loc loc in
987987
Attr.mk ~loc (mkloc id loc) (PStr [])
988988

989989
(* Unboxed literals *)
990990

991-
(* CR layouts v2: The [unboxed_*] functions will both be improved and lose
991+
(* CR layouts v2.5: The [unboxed_*] functions will both be improved and lose
992992
their explicit assert once we have real unboxed literals in Jane syntax; they
993993
may also get re-inlined at that point *)
994994
let unboxed_literals_extension = Language_extension.Layouts

boot/ocamlc

7.4 KB
Binary file not shown.

boot/ocamllex

0 Bytes
Binary file not shown.

lambda/lambda.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ let layout_module = Pvalue Pgenval
648648
let layout_module_field = Pvalue Pgenval
649649
let layout_functor = Pvalue Pgenval
650650
let layout_boxed_float = Pvalue Pfloatval
651+
let layout_unboxed_float = Punboxed_float
651652
let layout_string = Pvalue Pgenval
652653
let layout_boxedint bi = Pvalue (Pboxedintval bi)
653654

@@ -1459,6 +1460,7 @@ let primitive_result_layout (p : primitive) =
14591460
| Pccall { prim_native_repr_res = _, Same_as_ocaml_repr s; _} ->
14601461
begin match s with
14611462
| Value -> layout_any_value
1463+
| Float64 -> layout_unboxed_float
14621464
| Void -> assert false
14631465
end
14641466
| Pccall { prim_native_repr_res = _, Unboxed_integer bi; _} ->

lambda/lambda.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,7 @@ val layout_functor : layout
535535
val layout_module_field : layout
536536
val layout_string : layout
537537
val layout_boxed_float : layout
538+
val layout_unboxed_float : layout
538539
val layout_boxedint : boxed_integer -> layout
539540
(* A layout that is Pgenval because it is the field of a block *)
540541
val layout_field : layout

lambda/matching.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ exception Error of Location.t * error
106106

107107
let dbg = false
108108

109-
(* CR layouts v2: When we're ready to allow non-values, these can be deleted or
109+
(* CR layouts v5: When we're ready to allow non-values, these can be deleted or
110110
changed to check for void. *)
111111
let layout_must_be_value loc layout =
112112
match Layout.(sub layout (value ~why:V1_safety_check)) with
@@ -1772,7 +1772,7 @@ let get_pat_args_constr p rem =
17721772
List.iteri
17731773
(fun i arg -> layout_must_be_value arg.pat_loc cstr_arg_layouts.(i))
17741774
args;
1775-
(* CR layouts v2: This sanity check will have to go (or be replaced with a
1775+
(* CR layouts v5: This sanity check will have to go (or be replaced with a
17761776
void-specific check) when we have other non-value sorts *)
17771777
args @ rem
17781778
| _ -> assert false
@@ -1784,7 +1784,7 @@ let get_expr_args_constr ~scopes head (arg, _mut, sort, layout) rem =
17841784
| _ -> fatal_error "Matching.get_expr_args_constr"
17851785
in
17861786
let loc = head_loc ~scopes head in
1787-
(* CR layouts v2: This sanity check should be removed or changed to
1787+
(* CR layouts v5: This sanity check should be removed or changed to
17881788
specifically check for void when we add other non-value sorts. *)
17891789
Array.iter (fun layout -> layout_must_be_value head.pat_loc layout)
17901790
cstr.cstr_arg_layouts;
@@ -3999,7 +3999,7 @@ let for_multiple_match ~scopes ~return_layout loc paraml mode pat_act_list parti
39993999
partial)
40004000

40014001
(* Error report *)
4002-
(* CR layouts v2: This file didn't use to have the report_error infrastructure -
4002+
(* CR layouts v5: This file didn't use to have the report_error infrastructure -
40034003
I added it only for the void sanity checking in this module, which I'm not
40044004
sure is even needed. Reevaluate. *)
40054005
open Format

lambda/transl_array_comprehension.ml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,6 @@ end
445445
446446
This function returns both a pair of said CPSed Lambda term and the let
447447
bindings generated by this term (as an [Iterator_bindings.t], which see). *)
448-
(* CR layouts v2: the value that is passed to this function for [transl_exp]
449-
(and all the other [~transl_exp] parameters in this file) must only be called
450-
on expressions whose types have sort value. Probably [transl_exp] will have
451-
been updated to allow other sorts by the time we allow array elements other
452-
than value, but check that. *)
453448
let iterator ~transl_exp ~scopes ~loc
454449
: comprehension_iterator -> (lambda -> lambda) * Iterator_bindings.t
455450
= function
@@ -832,6 +827,8 @@ let comprehension
832827
~array_sizing
833828
~array
834829
~index
830+
(* CR layouts v4: Ensure that the [transl_exp] here can cope
831+
with non-values. *)
835832
~body:(transl_exp ~scopes Sort.for_array_element comp_body)),
836833
(* If it was dynamically grown, cut it down to size *)
837834
match array_sizing with

lambda/translcore.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ let layout_must_be_value loc layout =
4343
| Ok _ -> ()
4444
| Error e -> raise (Error (loc, Non_value_layout e))
4545

46-
(* CR layouts v2: In the places where this is used, we will want to allow
47-
#float, but not void yet (e.g., the left of a semicolon and loop bodies). we
46+
(* CR layouts v7: In the places where this is used, we will want to allow
47+
float#, but not void yet (e.g., the left of a semicolon and loop bodies). we
4848
still default to value before checking for void, to allow for sort variables
4949
arising in situations like
5050
@@ -860,7 +860,7 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
860860
| _ ->
861861
let oid = Ident.create_local "open" in
862862
let body, _ =
863-
(* CR layouts v2: Currently we only allow values at the top of a
863+
(* CR layouts v5: Currently we only allow values at the top of a
864864
module. When that changes, some adjustments may be needed
865865
here. *)
866866
List.fold_left (fun (body, pos) id ->
@@ -900,7 +900,7 @@ and transl_exp0 ~in_new_scope ~scopes sort e =
900900
(We could probably calculate the layouts of these variables here
901901
rather than requiring them all to be value, but that would be even
902902
more hacky.) *)
903-
(* CR layouts v2: if we get close to releasing other layout somebody
903+
(* CR layouts v2.5: if we get close to releasing other layout somebody
904904
actually might put in a probe, check with the middle-end team about
905905
the status of fixing this. *)
906906
let path = Path.Pident id in
@@ -1411,7 +1411,7 @@ and transl_record ~scopes loc env mode fields repres opt_init_expr =
14111411
then begin
14121412
(* Allocate new record with given fields (and remaining fields
14131413
taken from init_expr if any *)
1414-
(* CR layouts v2: currently we raise if a non-value field is detected.
1414+
(* CR layouts v5: currently we raise if a non-value field is detected.
14151415
relax that. *)
14161416
let init_id = Ident.create_local "init" in
14171417
let lv =
@@ -1498,7 +1498,7 @@ and transl_record ~scopes loc env mode fields repres opt_init_expr =
14981498
of the copy *)
14991499
let copy_id = Ident.create_local "newrecord" in
15001500
let update_field cont (lbl, definition) =
1501-
(* CR layouts v2: remove this check to allow non-value fields. Even
1501+
(* CR layouts v5: remove this check to allow non-value fields. Even
15021502
in the current version we can reasonably skip it because if we built
15031503
the init record, we must have already checked for void. *)
15041504
layout_must_be_value lbl.lbl_loc lbl.lbl_layout;

0 commit comments

Comments
 (0)