Skip to content

Commit f458733

Browse files
committed
flambda-backend: fix things after merge
1 parent 9f604aa commit f458733

9 files changed

+256
-433
lines changed

boot/ocamlc

43 KB
Binary file not shown.

boot/ocamllex

72 Bytes
Binary file not shown.

lambda/transl_array_comprehension.ml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ end = struct
231231
let y = y.Let_binding.var in
232232
let open (val Lambda_utils.int_ops ~loc) in
233233
let product =
234-
Let_binding.make (Immutable Alias) Pintval "product" (x * y)
234+
Let_binding.make (Immutable Alias) (Pvalue Pintval) "product" (x * y)
235235
in
236236
(* [x * y] is safe, for strictly positive [x] and [y], iff you can undo the
237237
multiplication: [(x * y)/y = x]. We assume the inputs are values, so we
@@ -240,7 +240,7 @@ end = struct
240240
(Lifthenelse(product.var / y = x,
241241
product.var,
242242
raise_overflow_exn ~loc,
243-
Pintval))
243+
Pvalue Pintval))
244244

245245
(** [safe_product_pos_vals ~loc xs] generates the lambda expression that
246246
computes the product of all the lambda values in [xs] assuming they are
@@ -260,7 +260,7 @@ end = struct
260260
variables, but we assume the optimizer can deal with that case nicely. *)
261261
let safe_product_pos ?(variable_name = "x") ~loc factors =
262262
let factors =
263-
List.map (Let_binding.make (Immutable Strict) Pintval
263+
List.map (Let_binding.make (Immutable Strict) (Pvalue Pintval)
264264
variable_name) factors
265265
in
266266
Let_binding.let_all factors (safe_product_pos_vals ~loc factors)
@@ -366,7 +366,7 @@ module Iterator_bindings = struct
366366
(* We can assume that the range is nonempty, but computing its size
367367
still might overflow *)
368368
let range_size =
369-
Let_binding.make (Immutable Alias) Pintval
369+
Let_binding.make (Immutable Alias) (Pvalue Pintval)
370370
"range_size" (high - low + l1)
371371
in
372372
Let_binding.let_one range_size
@@ -375,7 +375,7 @@ module Iterator_bindings = struct
375375
(Lifthenelse(range_size.var > l0,
376376
range_size.var,
377377
Precompute_array_size.raise_overflow_exn ~loc,
378-
Pintval))
378+
Pvalue Pintval))
379379
| Array { iter_arr = _; iter_len } ->
380380
iter_len.var
381381

@@ -445,7 +445,7 @@ let iterator ~transl_exp ~scopes ~loc
445445
= function
446446
| Texp_comp_range { ident; pattern = _; start; stop; direction } ->
447447
let bound name value =
448-
Let_binding.make (Immutable Strict) Pintval
448+
Let_binding.make (Immutable Strict) (Pvalue Pintval)
449449
name (transl_exp ~scopes value)
450450
in
451451
let start = bound "start" start in
@@ -463,14 +463,14 @@ let iterator ~transl_exp ~scopes ~loc
463463
; direction }
464464
| Texp_comp_in { pattern; sequence = iter_arr_exp } ->
465465
let iter_arr =
466-
Let_binding.make (Immutable Strict) Pgenval
466+
Let_binding.make (Immutable Strict) (Pvalue Pgenval)
467467
"iter_arr" (transl_exp ~scopes iter_arr_exp)
468468
in
469469
let iter_arr_kind = Typeopt.array_kind iter_arr_exp in
470470
let iter_len =
471471
(* Extra let-binding if we're not in the fixed-size array case; the
472472
middle-end will simplify this for us *)
473-
Let_binding.make (Immutable Alias) Pintval
473+
Let_binding.make (Immutable Alias) (Pvalue Pintval)
474474
"iter_len"
475475
(Lprim(Parraylength iter_arr_kind, [iter_arr.var], loc))
476476
in
@@ -491,7 +491,7 @@ let iterator ~transl_exp ~scopes ~loc
491491
[iter_arr.var; Lvar iter_ix],
492492
loc))
493493
pattern
494-
Pintval
494+
(Pvalue Pintval)
495495
body
496496
}
497497
in
@@ -542,7 +542,7 @@ let clause ~transl_exp ~scopes ~loc = function
542542
fun body -> Lifthenelse(transl_exp ~scopes cond,
543543
body,
544544
lambda_unit,
545-
Pintval (* [unit] is immediate *))
545+
(Pvalue Pintval) (* [unit] is immediate *))
546546

547547
(** The [array_sizing] type describes whether an array comprehension has been
548548
translated using the fixed-size array optimization ([Fixed_size]), or it has
@@ -614,7 +614,7 @@ let clauses ~transl_exp ~scopes ~loc = function
614614
for_and_clause ~transl_exp ~loc ~scopes bindings
615615
in
616616
let array_size =
617-
Let_binding.make (Immutable Alias) Pintval
617+
Let_binding.make (Immutable Alias) (Pvalue Pintval)
618618
"array_size"
619619
(Iterator_bindings.Fixed_size_array.total_size_nonempty
620620
~loc var_bindings)
@@ -625,7 +625,7 @@ let clauses ~transl_exp ~scopes ~loc = function
625625
}
626626
| clauses ->
627627
let array_size =
628-
Let_binding.make Mutable Pintval
628+
Let_binding.make Mutable (Pvalue Pintval)
629629
"array_size" (int Resizable_array.starting_size)
630630
in
631631
let make_comprehension =
@@ -696,7 +696,7 @@ let initial_array ~loc ~array_kind ~array_size ~array_sizing =
696696
| Dynamic_size, Pfloatarray ->
697697
Mutable, Resizable_array.make ~loc array_kind (float 0.)
698698
in
699-
Let_binding.make array_let_kind Pgenval "array" array_value
699+
Let_binding.make array_let_kind (Pvalue Pgenval) "array" array_value
700700

701701
(** Generate the code for the body of an array comprehension. This involves
702702
translating the body expression (a [Typedtree.expression], which is the
@@ -763,14 +763,14 @@ let body
763763
Lassign(array_size.id, i 2 * array_size.var),
764764
Lassign(array.id,
765765
Resizable_array.double ~loc array.var)),
766-
Pintval (* [unit] is immediate *)),
766+
(Pvalue Pintval) (* [unit] is immediate *)),
767767
(* ...and then set the element now that the array is big enough *)
768768
set_element_raw elt)
769769
in
770770
let set_element_known_kind_in_bounds = match array_kind with
771771
| Pgenarray ->
772772
let is_first_iteration = (index.var = l0) in
773-
let elt = Let_binding.make (Immutable Strict) Pgenval "elt" body in
773+
let elt = Let_binding.make (Immutable Strict) (Pvalue Pgenval) "elt" body in
774774
let make_array = match array_sizing with
775775
| Fixed_size ->
776776
make_vect ~loc ~length:array_size.var ~init:elt.var
@@ -781,7 +781,7 @@ let body
781781
(Lifthenelse(is_first_iteration,
782782
Lassign(array.id, make_array),
783783
set_element_in_bounds elt.var,
784-
Pintval (* [unit] is immediate *)))
784+
(Pvalue Pintval) (* [unit] is immediate *)))
785785
| Pintarray | Paddrarray | Pfloatarray ->
786786
set_element_in_bounds body
787787
in
@@ -801,7 +801,7 @@ let comprehension
801801
let array =
802802
initial_array ~loc ~array_kind ~array_size ~array_sizing
803803
in
804-
let index = Let_binding.make Mutable Pintval "index" (int 0) in
804+
let index = Let_binding.make Mutable (Pvalue Pintval) "index" (int 0) in
805805
(* The core of the comprehension: the array, the index, and the iteration that
806806
fills everything in. The translation of the clauses will produce a check
807807
to see if we can avoid doing the hard work of growing the array, which is
@@ -848,6 +848,6 @@ let comprehension
848848
can use [Pgenarray] to create the empty array above but still
849849
use [array_kind] here. Is that right? *)
850850
(* (And the result has the [value_kind] of the array) *)
851-
Parrayval array_kind))
851+
(Pvalue (Parrayval array_kind))))
852852
| Dynamic_size_info ->
853853
comprehension

lambda/transl_comprehension_utils.ml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ module Let_binding = struct
99

1010
type t =
1111
{ let_kind : Let_kind.t
12-
; value_kind : value_kind
12+
; layout : layout
1313
; id : Ident.t
1414
; init : lambda
1515
; var : lambda }
1616

17-
let make (let_kind : Let_kind.t) value_kind name init =
17+
let make (let_kind : Let_kind.t) layout name init =
1818
let id = Ident.create_local name in
1919
let var = match let_kind with
2020
| Mutable -> Lmutvar id
2121
| Immutable _ -> Lvar id
2222
in
23-
{let_kind; value_kind; id; init; var}
23+
{let_kind; layout; id; init; var}
2424

25-
let let_one {let_kind; value_kind; id; init} body =
25+
let let_one {let_kind; layout; id; init} body =
2626
match let_kind with
27-
| Immutable let_kind -> Llet(let_kind, value_kind, id, init, body)
28-
| Mutable -> Lmutlet(value_kind, id, init, body)
27+
| Immutable let_kind -> Llet(let_kind, layout, id, init, body)
28+
| Mutable -> Lmutlet(layout, id, init, body)
2929

3030
let let_all = List.fold_right let_one
3131
end
@@ -43,7 +43,9 @@ module Lambda_utils = struct
4343
~loc
4444
~mode
4545
func
46-
args =
46+
args
47+
~result_layout
48+
=
4749
(* These defaultscould be promoted to optional arguments if they were more
4850
widely used *)
4951
let region_close = Rc_normal in
@@ -60,6 +62,7 @@ module Lambda_utils = struct
6062
; ap_inlined = inlined
6163
; ap_specialised = specialised
6264
; ap_probe = probe
65+
; ap_result_layout = result_layout
6366
}
6467

6568
module type Int_ops = sig

lambda/transl_comprehension_utils.mli

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ module Let_binding : sig
2727
(** The first-class (in OCaml) type of let bindings. *)
2828
type t = private
2929
{ let_kind : Let_kind.t
30-
; value_kind : value_kind
30+
; layout : layout
3131
; id : Ident.t
3232
; init : lambda (* initial value *)
3333
; var : lambda (* occurrence of this variable *)
3434
}
3535

3636
(** Create a fresh local identifier (with name as given by the string
3737
argument) to bind to an initial value given by the lambda argument. *)
38-
val make : Let_kind.t -> value_kind -> string -> lambda -> t
38+
val make : Let_kind.t -> layout -> string -> lambda -> t
3939

4040
(** Create a Lambda let-binding (with [Llet]) from a first-class let
4141
binding, providing the body. *)
@@ -65,7 +65,8 @@ module Lambda_utils : sig
6565
(** Apply a Lambda function to some Lambda values, at a location; all the
6666
other information needed by [Lapply] is set to some default value. *)
6767
val apply :
68-
loc:scoped_location -> mode:alloc_mode -> lambda -> lambda list -> lambda
68+
loc:scoped_location -> mode:alloc_mode -> lambda -> lambda list ->
69+
result_layout:layout -> lambda
6970

7071
(** Nicer OCaml syntax for constructing Lambda ASTs that operate on integers;
7172
created by [int_ops], which includes the necessary location in all the

lambda/transl_list_comprehension.ml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ type translated_iterator =
149149
(** The name given to the values we're iterating over; needs to be a fresh
150150
name for [for]-[in] iterators in case the user specifies a complex
151151
pattern. *)
152-
; element_kind : value_kind
153-
(** The [value_kind] of the values we're iterating over. *)
152+
; element_kind : layout
153+
(** The [layout] of the values we're iterating over. *)
154154
; add_bindings : lambda -> lambda
155155
(** Any extra bindings that should be present in the body of this iterator,
156156
for use by nested pieces of the translation; used if the user specifies a
@@ -169,7 +169,7 @@ let iterator ~transl_exp ~scopes = function
169169
correct (i.e., left-to-right) order *)
170170
let transl_bound var bound =
171171
Let_binding.make
172-
(Immutable Strict) Pintval
172+
(Immutable Strict) (Pvalue Pintval)
173173
var (transl_exp ~scopes bound)
174174
in
175175
let start = transl_bound "start" start in
@@ -179,25 +179,25 @@ let iterator ~transl_exp ~scopes = function
179179
| Downto -> rev_dlist_concat_iterate_down)
180180
; arg_lets = [start; stop]
181181
; element = ident
182-
; element_kind = Pintval
182+
; element_kind = Pvalue Pintval
183183
; add_bindings = Fun.id
184184
}
185185
| Texp_comp_in { pattern; sequence } ->
186186
let iter_list =
187-
Let_binding.make (Immutable Strict) Pgenval
187+
Let_binding.make (Immutable Strict) (Pvalue Pgenval)
188188
"iter_list" (transl_exp ~scopes sequence)
189189
in
190190
(* Create a fresh variable to use as the function argument *)
191191
let element = Ident.create_local "element" in
192192
{ builder = rev_dlist_concat_map
193193
; arg_lets = [iter_list]
194194
; element
195-
; element_kind = Typeopt.value_kind pattern.pat_env pattern.pat_type
195+
; element_kind = Typeopt.layout pattern.pat_env pattern.pat_type
196196
; add_bindings =
197197
(* CR aspectorzabusky: This has to be at [value_kind] [Pgenval],
198198
right, since we don't know more specifically? *)
199199
Matching.for_let
200-
~scopes pattern.pat_loc (Lvar element) pattern Pgenval
200+
~scopes pattern.pat_loc (Lvar element) pattern (Pvalue Pgenval)
201201
}
202202

203203
(** Translates a list comprehension binding
@@ -238,8 +238,8 @@ let rec translate_bindings
238238
~kind:(Curried { nlocal = 2 })
239239
(* Only the accumulator is local, but since the function itself is
240240
local, [nlocal] has to be equal to the number of parameters *)
241-
~params:[element, element_kind; inner_acc, Pgenval]
242-
~return:Pgenval
241+
~params:[element, element_kind; inner_acc, Pvalue Pgenval]
242+
~return:(Pvalue Pgenval)
243243
~attr:default_function_attribute
244244
~loc
245245
~mode:alloc_local
@@ -253,6 +253,7 @@ let rec translate_bindings
253253
(Lazy.force builder)
254254
(List.map (fun Let_binding.{id; _} -> Lvar id) arg_lets @
255255
[body_func; accumulator])
256+
~result_layout:(Pvalue Pgenval)
256257
in
257258
arg_lets @ body_arg_lets, result
258259
| [] ->
@@ -283,7 +284,7 @@ let rec translate_clauses
283284
Lifthenelse(transl_exp ~scopes cond,
284285
body ~accumulator,
285286
accumulator,
286-
Pgenval (* [list]s have the standard representation *))
287+
(Pvalue Pgenval) (* [list]s have the standard representation *))
287288
end
288289
| [] ->
289290
comprehension_body ~accumulator
@@ -304,3 +305,4 @@ let comprehension ~transl_exp ~scopes ~loc { comp_body; comp_clauses } =
304305
~mode:alloc_heap
305306
(Lazy.force rev_list_to_list)
306307
[rev_comprehension]
308+
~result_layout:(Pvalue Pgenval)

0 commit comments

Comments
 (0)