Skip to content

Commit a73784c

Browse files
committed
review comments
1 parent 7789f4f commit a73784c

File tree

1 file changed

+45
-23
lines changed

1 file changed

+45
-23
lines changed

middle_end/flambda2/from_lambda/closure_conversion.ml

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ module Inlining = struct
383383
~result_arity:(Code.result_arity code) ~make_inlined_body)
384384
end
385385

386-
let close_c_call acc env ~loc ~ids_with_kinds
386+
let close_c_call acc env ~loc ~let_bound_ids_with_kinds
387387
({ prim_name;
388388
prim_arity;
389389
prim_alloc;
@@ -394,13 +394,41 @@ let close_c_call acc env ~loc ~ids_with_kinds
394394
prim_native_repr_args;
395395
prim_native_repr_res
396396
} :
397-
Primitive.description) ~(args : Simple.t list) exn_continuation dbg
397+
Primitive.description) ~(args : Simple.t list list) exn_continuation dbg
398398
~current_region (k : Acc.t -> Named.t list -> Expr_with_acc.t) :
399399
Expr_with_acc.t =
400+
let args =
401+
List.map
402+
(function
403+
| [arg] -> arg
404+
| [] | _ :: _ :: _ ->
405+
Misc.fatal_errorf
406+
"close_c_call: expected only singleton arguments for primitive %s, \
407+
but got: [%a]"
408+
prim_name
409+
(Format.pp_print_list ~pp_sep:Format.pp_print_space (fun ppf args ->
410+
Format.fprintf ppf "[%a]"
411+
(Format.pp_print_list ~pp_sep:Format.pp_print_space
412+
Simple.print)
413+
args))
414+
args)
415+
args
416+
in
400417
let env, let_bound_vars =
401418
List.fold_left_map
402419
(fun env (id, kind) -> Env.add_var_like env id Not_user_visible kind)
403-
env ids_with_kinds
420+
env let_bound_ids_with_kinds
421+
in
422+
let let_bound_var =
423+
match let_bound_vars with
424+
| [let_bound_var] -> let_bound_var
425+
| [] | _ :: _ :: _ ->
426+
Misc.fatal_errorf
427+
"close_c_call: expected singleton return for primitive %s, but got: \
428+
[%a]"
429+
prim_name
430+
(Format.pp_print_list ~pp_sep:Format.pp_print_space Variable.print)
431+
let_bound_vars
404432
in
405433
let cost_metrics_of_body, free_names_of_body, acc, body =
406434
Acc.measure_cost_metrics acc ~f:(fun acc ->
@@ -409,13 +437,6 @@ let close_c_call acc env ~loc ~ids_with_kinds
409437
(fun var -> Named.create_simple (Simple.var var))
410438
let_bound_vars))
411439
in
412-
let let_bound_var =
413-
match let_bound_vars with
414-
| [let_bound_var] -> let_bound_var
415-
| [] | _ :: _ :: _ ->
416-
Misc.fatal_error
417-
"close_c_call: unboxed products are currently unsupported"
418-
in
419440
let box_return_value =
420441
match prim_native_repr_res with
421442
| _, Same_as_ocaml_repr -> None
@@ -635,8 +656,9 @@ let close_raise acc env ~raise_kind ~arg ~dbg exn_continuation =
635656
let acc, arg = find_simple acc env arg in
636657
close_raise0 acc env ~raise_kind ~arg ~dbg exn_continuation
637658

638-
let close_primitive acc env ~ids_with_kinds named (prim : Lambda.primitive)
639-
~args loc (exn_continuation : IR.exn_continuation option) ~current_region
659+
let close_primitive acc env ~let_bound_ids_with_kinds named
660+
(prim : Lambda.primitive) ~args loc
661+
(exn_continuation : IR.exn_continuation option) ~current_region
640662
(k : Acc.t -> Named.t list -> Expr_with_acc.t) : Expr_with_acc.t =
641663
let orig_exn_continuation = exn_continuation in
642664
let acc, exn_continuation =
@@ -659,9 +681,8 @@ let close_primitive acc env ~ids_with_kinds named (prim : Lambda.primitive)
659681
IR.print_named named
660682
| Some exn_continuation -> exn_continuation
661683
in
662-
let args = List.flatten args in
663-
close_c_call acc env ~loc ~ids_with_kinds prim ~args exn_continuation dbg
664-
~current_region k
684+
close_c_call acc env ~loc ~let_bound_ids_with_kinds prim ~args
685+
exn_continuation dbg ~current_region k
665686
| Pgetglobal cu, [] ->
666687
if Compilation_unit.equal cu (Env.current_unit env)
667688
then
@@ -747,7 +768,7 @@ let close_trap_action_opt trap_action =
747768
| Pop { exn_handler } -> Pop { exn_handler; raise_kind = None })
748769
trap_action
749770

750-
let close_named acc env ~ids_with_kinds (named : IR.named)
771+
let close_named acc env ~let_bound_ids_with_kinds (named : IR.named)
751772
(k : Acc.t -> Named.t list -> Expr_with_acc.t) : Expr_with_acc.t =
752773
match named with
753774
| Simple (Var id) ->
@@ -783,7 +804,7 @@ let close_named acc env ~ids_with_kinds (named : IR.named)
783804
Lambda_to_flambda_primitives_helpers.bind_recs acc None ~register_const0
784805
[prim] Debuginfo.none k
785806
| Prim { prim; args; loc; exn_continuation; region } ->
786-
close_primitive acc env ~ids_with_kinds named prim ~args loc
807+
close_primitive acc env ~let_bound_ids_with_kinds named prim ~args loc
787808
exn_continuation
788809
~current_region:(fst (Env.find_var env region))
789810
k
@@ -863,14 +884,14 @@ let classify_fields_of_block env fields alloc_mode =
863884
then Computed_static fields
864885
else Constant fields
865886

866-
let close_let acc env ids user_visible defining_expr
887+
let close_let acc env let_bound_ids_with_kinds user_visible defining_expr
867888
~(body : Acc.t -> Env.t -> Expr_with_acc.t) : Expr_with_acc.t =
868-
let rec cont ids env acc (defining_exprs : Named.t list) =
869-
match ids, defining_exprs with
889+
let rec cont ids_with_kinds env acc (defining_exprs : Named.t list) =
890+
match ids_with_kinds, defining_exprs with
870891
| [], [] -> body acc env
871-
| (id, kind) :: ids, defining_expr :: defining_exprs -> (
892+
| (id, kind) :: ids_with_kinds, defining_expr :: defining_exprs -> (
872893
let body_env, var = Env.add_var_like env id user_visible kind in
873-
let body acc env = cont ids env acc defining_exprs in
894+
let body acc env = cont ids_with_kinds env acc defining_exprs in
874895
match defining_expr with
875896
| Simple simple ->
876897
let body_env = Env.add_simple_to_substitute env id simple kind in
@@ -1030,7 +1051,8 @@ let close_let acc env ids user_visible defining_expr
10301051
"CC.close_let: defining_exprs should have the same length as number of \
10311052
variables"
10321053
in
1033-
close_named acc env ~ids_with_kinds:ids defining_expr (cont ids env)
1054+
close_named acc env ~let_bound_ids_with_kinds defining_expr
1055+
(cont let_bound_ids_with_kinds env)
10341056

10351057
let close_let_cont acc env ~name ~is_exn_handler ~params
10361058
~(recursive : Asttypes.rec_flag)

0 commit comments

Comments
 (0)