Skip to content

Commit 2c45dc0

Browse files
mshinwellEkdohibs
authored andcommitted
Code review
1 parent dd2a983 commit 2c45dc0

23 files changed

+185
-148
lines changed

backend/cmm.mli

+1
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ and operation =
224224
| Copaque (* Sys.opaque_identity *)
225225
| Cbeginregion | Cendregion
226226
| Ctuple_field of int * machtype array
227+
(* the [machtype array] refers to the whole tuple *)
227228

228229
(* This is information used exclusively during construction of cmm terms by
229230
cmmgen, and thus irrelevant for selectgen and flambda2. *)

backend/cmm_helpers.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1078,7 +1078,7 @@ module Extended_machtype = struct
10781078
typ_any_int
10791079
| Pvalue Pintval -> typ_tagged_int
10801080
| Pvalue _ -> typ_val
1081-
| Punboxed_product fields -> Array.concat @@ List.map of_layout fields
1081+
| Punboxed_product fields -> Array.concat (List.map of_layout fields)
10821082
end
10831083

10841084
let machtype_of_layout layout =

backend/selectgen.ml

+5-3
Original file line numberDiff line numberDiff line change
@@ -921,18 +921,20 @@ method emit_expr_aux (env:environment) exp :
921921
ret (self#insert_op_debug env Iopaque dbg rs rs)
922922
end
923923
| Cop(Ctuple_field(field, fields_layout), [arg], dbg) ->
924-
begin match self#emit_expr env arg with
924+
begin match self#emit_expr env arg with
925925
None -> None
926926
| Some loc_exp ->
927-
let flat_size a = Array.fold_left (fun acc t -> acc + Array.length t) 0 a in
927+
let flat_size a =
928+
Array.fold_left (fun acc t -> acc + Array.length t) 0 a
929+
in
928930
assert(Array.length loc_exp = flat_size fields_layout);
929931
let before = Array.sub fields_layout 0 field in
930932
let size_before = flat_size before in
931933
let field_slice =
932934
Array.sub loc_exp size_before (Array.length fields_layout.(field))
933935
in
934936
ret field_slice
935-
end
937+
end
936938
| Cop(op, args, dbg) ->
937939
begin match self#emit_parts_list env args with
938940
None -> None

middle_end/.ocamlformat-enable

+2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1+
clambda_layout.ml
2+
clambda_layout.mli
13
mangling.ml
24
mangling.mli

middle_end/clambda_layout.ml

+45-44
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,43 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Pierre Chambart, OCamlPro *)
6+
(* *)
7+
(* Copyright 2023 OCamlPro SAS *)
8+
(* *)
9+
(* All rights reserved. This file is distributed under the terms of *)
10+
(* the GNU Lesser General Public License version 2.1, with the *)
11+
(* special exception on linking described in the file LICENSE. *)
12+
(* *)
13+
(**************************************************************************)
14+
115
type atom =
216
| Value
317
| Value_int
418
| Unboxed_float
519
| Unboxed_int of Lambda.boxed_integer
620

7-
let rec fold_left_layout (f : 'acc -> 'e -> atom -> 'acc)
8-
(acc : 'acc) (expr : Clambda.ulambda) (layout : Clambda_primitives.layout) : 'acc =
21+
let rec fold_left_layout (f : 'acc -> 'e -> atom -> 'acc) (acc : 'acc)
22+
(expr : Clambda.ulambda) (layout : Clambda_primitives.layout) : 'acc =
923
match layout with
10-
| Ptop ->
11-
Misc.fatal_error "[Ptop] can't be stored in a closure."
24+
| Ptop -> Misc.fatal_error "[Ptop] can't be stored in a closure."
1225
| Pbottom ->
1326
Misc.fatal_error
14-
"[Pbottom] should have been eliminated as dead code \
15-
and not stored in a closure."
27+
"[Pbottom] should have been eliminated as dead code and not stored in a \
28+
closure."
1629
| Punboxed_float -> f acc expr Unboxed_float
1730
| Punboxed_int bi -> f acc expr (Unboxed_int bi)
1831
| Pvalue Pintval -> f acc expr Value_int
1932
| Pvalue _ -> f acc expr Value
2033
| Punboxed_product layouts ->
21-
List.fold_left (fun acc (field, layout) ->
34+
List.fold_left
35+
(fun acc (field, layout) ->
2236
let expr : Clambda.ulambda =
23-
Uprim (Punboxed_product_field (field, layouts), [expr], Debuginfo.none) in
24-
fold_left_layout f acc expr layout) acc
37+
Uprim (Punboxed_product_field (field, layouts), [expr], Debuginfo.none)
38+
in
39+
fold_left_layout f acc expr layout)
40+
acc
2541
(List.mapi (fun i v -> i, v) layouts)
2642

2743
type ('visible, 'invisible) decomposition' =
@@ -30,10 +46,12 @@ type ('visible, 'invisible) decomposition' =
3046
| Product of ('visible, 'invisible) decomposition' array
3147

3248
type decomposition =
33-
| Atom of { offset : int; layout : atom }
49+
| Atom of
50+
{ offset : int;
51+
layout : atom
52+
}
3453
| Product of decomposition array
3554

36-
3755
let print_atom ppf = function
3856
| Value -> Format.fprintf ppf "val"
3957
| Value_int -> Format.fprintf ppf "int"
@@ -42,7 +60,8 @@ let print_atom ppf = function
4260
| Unboxed_int Pint64 -> Format.fprintf ppf "unboxed_int64"
4361
| Unboxed_int Pnativeint -> Format.fprintf ppf "unboxed_nativeint"
4462

45-
let equal_decomposition = (=)
63+
let equal_decomposition = ( = )
64+
4665
let rec print_decomposition ppf dec =
4766
match dec with
4867
| Atom { offset; layout } ->
@@ -54,30 +73,26 @@ let rec print_decomposition ppf dec =
5473

5574
let rec decompose (layout : Lambda.layout) : _ decomposition' =
5675
match layout with
57-
| Ptop ->
58-
Misc.fatal_error "[Ptop] can't be stored in a closure."
76+
| Ptop -> Misc.fatal_error "[Ptop] can't be stored in a closure."
5977
| Pbottom ->
6078
Misc.fatal_error
61-
"[Pbottom] should have been eliminated as dead code \
62-
and not stored in a closure."
79+
"[Pbottom] should have been eliminated as dead code and not stored in a \
80+
closure."
6381
| Punboxed_float -> Gc_invisible ((), Unboxed_float)
6482
| Punboxed_int bi -> Gc_invisible ((), Unboxed_int bi)
6583
| Pvalue Pintval -> Gc_invisible ((), Value_int)
6684
| Pvalue _ -> Gc_visible ((), Value)
67-
| Punboxed_product l ->
68-
Product (Array.of_list (List.map decompose l))
85+
| Punboxed_product l -> Product (Array.of_list (List.map decompose l))
6986

7087
let rec solidify (dec : (int, int) decomposition') : decomposition =
7188
match dec with
7289
| Gc_visible (offset, layout) -> Atom { offset; layout }
7390
| Gc_invisible (offset, layout) -> Atom { offset; layout }
74-
| Product a ->
75-
Product (Array.map solidify a)
91+
| Product a -> Product (Array.map solidify a)
7692

77-
let rec fold_decompose
78-
(f1 : 'acc -> 'a -> atom -> 'acc * 'b) (f2 : 'acc -> 'c -> atom -> 'acc * 'd)
79-
(acc : 'acc) (d : ('a, 'c) decomposition') :
80-
'acc * ('b, 'd) decomposition' =
93+
let rec fold_decompose (f1 : 'acc -> 'a -> atom -> 'acc * 'b)
94+
(f2 : 'acc -> 'c -> atom -> 'acc * 'd) (acc : 'acc)
95+
(d : ('a, 'c) decomposition') : 'acc * ('b, 'd) decomposition' =
8196
match d with
8297
| Gc_visible (v, layout) ->
8398
let acc, v = f1 acc v layout in
@@ -90,36 +105,22 @@ let rec fold_decompose
90105
acc, Product elts
91106

92107
let atom_size (layout : atom) =
93-
match layout with
94-
| Value
95-
| Value_int
96-
| Unboxed_float
97-
| Unboxed_int _ -> 1
108+
match layout with Value | Value_int | Unboxed_float | Unboxed_int _ -> 1
98109

99110
let assign_invisible_offsets init_pos (var, dec) =
100-
let f_visible acc () _layout =
101-
acc, ()
102-
in
103-
let f_invisible acc () layout =
104-
acc + atom_size layout, acc
105-
in
111+
let f_visible acc () _layout = acc, () in
112+
let f_invisible acc () layout = acc + atom_size layout, acc in
106113
let acc, dec = fold_decompose f_visible f_invisible init_pos dec in
107114
acc, (var, dec)
108115

109116
let assign_visible_offsets init_pos (var, dec) =
110-
let f_visible acc () layout =
111-
acc + atom_size layout, acc
112-
in
113-
let f_invisible acc off _layout =
114-
acc, off
115-
in
117+
let f_visible acc () layout = acc + atom_size layout, acc in
118+
let f_invisible acc off _layout = acc, off in
116119
let acc, dec = fold_decompose f_visible f_invisible init_pos dec in
117120
acc, (var, solidify dec)
118121

119122
let decompose_free_vars ~base_offset ~free_vars =
120-
let free_vars =
121-
List.map (fun (var, kind) -> var, decompose kind) free_vars
122-
in
123+
let free_vars = List.map (fun (var, kind) -> var, decompose kind) free_vars in
123124
let base_offset, free_vars =
124125
List.fold_left_map assign_invisible_offsets base_offset free_vars
125126
in

middle_end/clambda_layout.mli

+23-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,35 @@
1+
(**************************************************************************)
2+
(* *)
3+
(* OCaml *)
4+
(* *)
5+
(* Pierre Chambart, OCamlPro *)
6+
(* *)
7+
(* Copyright 2023 OCamlPro SAS *)
8+
(* *)
9+
(* All rights reserved. This file is distributed under the terms of *)
10+
(* the GNU Lesser General Public License version 2.1, with the *)
11+
(* special exception on linking described in the file LICENSE. *)
12+
(* *)
13+
(**************************************************************************)
14+
115
type atom =
216
| Value
317
| Value_int
418
| Unboxed_float
519
| Unboxed_int of Lambda.boxed_integer
620

721
val fold_left_layout :
8-
('acc -> Clambda.ulambda -> atom -> 'acc) -> 'acc -> Clambda.ulambda ->
9-
Clambda_primitives.layout -> 'acc
22+
('acc -> Clambda.ulambda -> atom -> 'acc) ->
23+
'acc ->
24+
Clambda.ulambda ->
25+
Clambda_primitives.layout ->
26+
'acc
1027

1128
type decomposition =
12-
| Atom of { offset : int; layout : atom }
29+
| Atom of
30+
{ offset : int;
31+
layout : atom
32+
}
1333
| Product of decomposition array
1434

1535
val equal_decomposition : decomposition -> decomposition -> bool

middle_end/flambda2/from_lambda/closure_conversion.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -2098,8 +2098,9 @@ let wrap_partial_application acc env apply_continuation (apply : IR.apply)
20982098
~params ~params_arity ~removed_params:Ident.Set.empty
20992099
~return:apply.return_arity ~return_continuation ~exn_continuation
21002100
~my_region:apply.region ~body:fbody ~attr ~loc:apply.loc
2101-
~free_idents_of_body ~closure_alloc_mode ~num_trailing_local_params
2102-
~contains_no_escaping_local_allocs Recursive.Non_recursive ]
2101+
~free_idents_of_body ~closure_alloc_mode
2102+
~num_trailing_complex_local_params ~contains_no_escaping_local_allocs
2103+
Recursive.Non_recursive ]
21032104
in
21042105
let body acc env =
21052106
let arg = find_simple_from_id env wrapper_id in

middle_end/flambda2/from_lambda/lambda_to_flambda.ml

+8-2
Original file line numberDiff line numberDiff line change
@@ -1230,7 +1230,10 @@ let rec cps acc env ccenv (lam : L.lambda) (k : cps_continuation)
12301230
~body:(fun acc env ccenv after_defining_expr ->
12311231
cps_tail acc env ccenv defining_expr after_defining_expr k_exn)
12321232
~handler:(fun acc env ccenv ->
1233-
let kind = Flambda_kind.With_subkind.unsafe_from_lambda value_kind in
1233+
let kind =
1234+
Flambda_kind.With_subkind.from_lambda_values_and_unboxed_numbers_only
1235+
value_kind
1236+
in
12341237
let env, new_id = Env.register_mutable_variable env id kind in
12351238
let body acc ccenv = cps acc env ccenv body k k_exn in
12361239
CC.close_let acc ccenv
@@ -1285,7 +1288,10 @@ let rec cps acc env ccenv (lam : L.lambda) (k : cps_continuation)
12851288
| Ptop | Pbottom ->
12861289
Misc.fatal_error "Cannot bind layout [Ptop] or [Pbottom]"
12871290
| Pvalue _ | Punboxed_int _ | Punboxed_float ->
1288-
env, [id, Flambda_kind.With_subkind.unsafe_from_lambda layout]
1291+
( env,
1292+
[ ( id,
1293+
Flambda_kind.With_subkind
1294+
.from_lambda_values_and_unboxed_numbers_only layout ) ] )
12891295
| Punboxed_product layouts ->
12901296
let arity_component =
12911297
Flambda_arity.Component_for_creation.Unboxed_product

0 commit comments

Comments
 (0)