@@ -885,6 +885,12 @@ let rec cps acc env ccenv (lam : L.lambda) (k : cps_continuation)
885
885
[new_id, value_kind]
886
886
User_visible (Simple new_value) ~body )
887
887
k_exn
888
+ | Llet ((Strict | Alias | StrictOpt ), _layout, id, defining_expr, Lvar id')
889
+ when Ident. same id id' ->
890
+ (* Simplif already simplifies such bindings, but we can generate new ones
891
+ when translating primitives (see the Lprim case below). *)
892
+ (* This case must not be moved above the case for let-bound primitives. *)
893
+ cps acc env ccenv defining_expr k k_exn
888
894
| Llet ((Strict | Alias | StrictOpt ), layout , id , defining_expr , body ) ->
889
895
let_cont_nonrecursive_with_extra_params acc env ccenv ~is_exn_handler: false
890
896
~params: [id, is_user_visible env id, layout]
@@ -936,6 +942,12 @@ let rec cps acc env ccenv (lam : L.lambda) (k : cps_continuation)
936
942
Misc. fatal_errorf " Wrong number of arguments for Lraise: %a"
937
943
Printlambda. primitive prim)
938
944
| _ ->
945
+ (* The code for translating primitives needs a let binding, so we
946
+ introduce such a binding explicitly. *)
947
+ (* For primitives like [Psequand], which are transformed instead, this
948
+ binding is useless and can move calls out of tail position, so we rely
949
+ on a special case above that removes such bindings when the bound
950
+ expression isn't a primitive. *)
939
951
let name = Printlambda. name_of_primitive prim in
940
952
let id = Ident. create_local name in
941
953
let result_layout = L. primitive_result_layout prim in
0 commit comments