@@ -383,7 +383,7 @@ module Inlining = struct
383
383
~result_arity: (Code. result_arity code) ~make_inlined_body )
384
384
end
385
385
386
- let close_c_call acc env ~loc ~ids_with_kinds
386
+ let close_c_call acc env ~loc ~let_bound_ids_with_kinds
387
387
({ prim_name;
388
388
prim_arity;
389
389
prim_alloc;
@@ -394,13 +394,41 @@ let close_c_call acc env ~loc ~ids_with_kinds
394
394
prim_native_repr_args;
395
395
prim_native_repr_res
396
396
} :
397
- Primitive. description ) ~(args : Simple.t list ) exn_continuation dbg
397
+ Primitive. description ) ~(args : Simple.t list list ) exn_continuation dbg
398
398
~current_region (k : Acc.t -> Named.t list -> Expr_with_acc.t ) :
399
399
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
400
417
let env, let_bound_vars =
401
418
List. fold_left_map
402
419
(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
404
432
in
405
433
let cost_metrics_of_body, free_names_of_body, acc, body =
406
434
Acc. measure_cost_metrics acc ~f: (fun acc ->
@@ -409,13 +437,6 @@ let close_c_call acc env ~loc ~ids_with_kinds
409
437
(fun var -> Named. create_simple (Simple. var var))
410
438
let_bound_vars))
411
439
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
419
440
let box_return_value =
420
441
match prim_native_repr_res with
421
442
| _ , Same_as_ocaml_repr -> None
@@ -635,8 +656,9 @@ let close_raise acc env ~raise_kind ~arg ~dbg exn_continuation =
635
656
let acc, arg = find_simple acc env arg in
636
657
close_raise0 acc env ~raise_kind ~arg ~dbg exn_continuation
637
658
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
640
662
(k : Acc.t -> Named.t list -> Expr_with_acc.t ) : Expr_with_acc.t =
641
663
let orig_exn_continuation = exn_continuation in
642
664
let acc, exn_continuation =
@@ -659,9 +681,8 @@ let close_primitive acc env ~ids_with_kinds named (prim : Lambda.primitive)
659
681
IR. print_named named
660
682
| Some exn_continuation -> exn_continuation
661
683
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
665
686
| Pgetglobal cu , [] ->
666
687
if Compilation_unit. equal cu (Env. current_unit env)
667
688
then
@@ -747,7 +768,7 @@ let close_trap_action_opt trap_action =
747
768
| Pop { exn_handler } -> Pop { exn_handler; raise_kind = None })
748
769
trap_action
749
770
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 )
751
772
(k : Acc.t -> Named.t list -> Expr_with_acc.t ) : Expr_with_acc.t =
752
773
match named with
753
774
| Simple (Var id ) ->
@@ -783,7 +804,7 @@ let close_named acc env ~ids_with_kinds (named : IR.named)
783
804
Lambda_to_flambda_primitives_helpers. bind_recs acc None ~register_const0
784
805
[prim] Debuginfo. none k
785
806
| 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
787
808
exn_continuation
788
809
~current_region: (fst (Env. find_var env region))
789
810
k
@@ -863,14 +884,14 @@ let classify_fields_of_block env fields alloc_mode =
863
884
then Computed_static fields
864
885
else Constant fields
865
886
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
867
888
~(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
870
891
| [] , [] -> body acc env
871
- | (id , kind ) :: ids , defining_expr :: defining_exprs -> (
892
+ | (id , kind ) :: ids_with_kinds , defining_expr :: defining_exprs -> (
872
893
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
874
895
match defining_expr with
875
896
| Simple simple ->
876
897
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
1030
1051
" CC.close_let: defining_exprs should have the same length as number of \
1031
1052
variables"
1032
1053
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)
1034
1056
1035
1057
let close_let_cont acc env ~name ~is_exn_handler ~params
1036
1058
~(recursive : Asttypes.rec_flag )
0 commit comments