@@ -733,25 +733,53 @@ and transl_apply ~scopes
733733 sargs)
734734 : Lambda. lambda)
735735
736- and transl_function0
737- ~scopes loc return untuplify_fn max_arity
736+ and transl_curried_function
737+ ~scopes loc return
738+ repr partial (param :Ident.t ) cases =
739+ let max_arity = Lambda. max_arity () in
740+ let rec loop ~scopes loc return ~arity partial (param :Ident.t ) cases =
741+ match cases with
742+ [{c_lhs= pat; c_guard= None ;
743+ c_rhs= {exp_desc =
744+ Texp_function
745+ { arg_label = _; param = param'; cases = cases';
746+ partial = partial'; }; exp_env; exp_type;exp_loc}}]
747+ when arity < max_arity ->
748+ if Parmatch. inactive ~partial pat
749+ then
750+ let kind = value_kind pat.pat_env pat.pat_type in
751+ let return_kind = function_return_value_kind exp_env exp_type in
752+ let ((_, params, return), body) =
753+ loop ~scopes exp_loc return_kind ~arity: (arity + 1 )
754+ partial' param' cases'
755+ in
756+ ((Curried , (param, kind) :: params, return),
757+ Matching. for_function ~scopes loc None (Lvar param)
758+ [pat, body] partial)
759+ else begin
760+ begin match partial with
761+ | Total ->
762+ Location. prerr_warning pat.pat_loc
763+ Match_on_mutable_state_prevent_uncurry
764+ | Partial -> ()
765+ end ;
766+ transl_tupled_function ~scopes ~arity
767+ loc return repr partial param cases
768+ end
769+ | cases ->
770+ transl_tupled_function ~scopes ~arity
771+ loc return repr partial param cases
772+ in
773+ loop ~scopes loc return ~arity: 1 partial param cases
774+
775+ and transl_tupled_function
776+ ~scopes ~arity loc return
738777 repr partial (param :Ident.t ) cases =
739778 match cases with
740- [{c_lhs= pat; c_guard= None ;
741- c_rhs= {exp_desc = Texp_function { arg_label = _; param = param'; cases;
742- partial = partial'; }; exp_env; exp_type} as exp}]
743- when max_arity > 1 && Parmatch. inactive ~partial pat ->
744- let kind = value_kind pat.pat_env pat.pat_type in
745- let return_kind = function_return_value_kind exp_env exp_type in
746- let ((_, params, return), body) =
747- transl_function0 ~scopes exp.exp_loc return_kind false (max_arity - 1 )
748- repr partial' param' cases
749- in
750- ((Curried , (param, kind) :: params, return),
751- Matching. for_function ~scopes loc None (Lvar param)
752- [pat, body] partial)
753779 | {c_lhs= {pat_desc = Tpat_tuple pl}} :: _
754- when untuplify_fn && List. length pl < = max_arity ->
780+ when ! Clflags. native_code
781+ && arity = 1
782+ && List. length pl < = (Lambda. max_arity () ) ->
755783 begin try
756784 let size = List. length pl in
757785 let pats_expr_list =
@@ -783,37 +811,38 @@ and transl_function0
783811 ((Tupled , tparams, return),
784812 Matching. for_tupled_function ~scopes loc params
785813 (transl_tupled_cases ~scopes pats_expr_list) partial)
786- with Matching. Cannot_flatten ->
787- ((Curried , [param, Pgenval ], return),
788- Matching. for_function ~scopes loc repr (Lvar param)
789- (transl_cases ~scopes cases) partial)
814+ with Matching. Cannot_flatten ->
815+ transl_function0 ~scopes loc return repr partial param cases
790816 end
791- | {c_lhs =pat } :: other_cases ->
792- let kind =
817+ | _ -> transl_function0 ~scopes loc return repr partial param cases
818+
819+ and transl_function0
820+ ~scopes loc return
821+ repr partial (param :Ident.t ) cases =
822+ let kind =
823+ match cases with
824+ | [] ->
825+ (* With Camlp4, a pattern matching might be empty *)
826+ Pgenval
827+ | {c_lhs =pat } :: other_cases ->
793828 (* All the patterns might not share the same types. We must take the
794829 union of the patterns types *)
795830 List. fold_left (fun k {c_lhs =pat } ->
796- Typeopt. value_kind_union k
797- (value_kind pat.pat_env pat.pat_type))
831+ Typeopt. value_kind_union k
832+ (value_kind pat.pat_env pat.pat_type))
798833 (value_kind pat.pat_env pat.pat_type) other_cases
799- in
800- ((Curried , [param, kind], return),
801- Matching. for_function ~scopes loc repr (Lvar param)
802- (transl_cases ~scopes cases) partial)
803- | [] ->
804- (* With Camlp4, a pattern matching might be empty *)
805- ((Curried , [param, Pgenval ], return),
806- Matching. for_function ~scopes loc repr (Lvar param)
807- (transl_cases ~scopes cases) partial)
834+ in
835+ ((Curried , [param, kind], return),
836+ Matching. for_function ~scopes loc repr (Lvar param)
837+ (transl_cases ~scopes cases) partial)
808838
809839and transl_function ~scopes e param cases partial =
810840 let ((kind, params, return), body) =
811841 event_function ~scopes e
812842 (function repr ->
813843 let pl = push_defaults e.exp_loc [] cases partial in
814844 let return_kind = function_return_value_kind e.exp_env e.exp_type in
815- transl_function0 ~scopes e.exp_loc return_kind
816- ! Clflags. native_code (Lambda. max_arity() )
845+ transl_curried_function ~scopes e.exp_loc return_kind
817846 repr partial param pl)
818847 in
819848 let attr = default_function_attribute in
@@ -1107,8 +1136,7 @@ and transl_letop ~scopes loc env let_ ands param case partial =
11071136 let (kind, params, return), body =
11081137 event_function ~scopes case.c_rhs
11091138 (function repr ->
1110- transl_function0 ~scopes case.c_rhs.exp_loc return_kind
1111- ! Clflags. native_code (Lambda. max_arity() )
1139+ transl_curried_function ~scopes case.c_rhs.exp_loc return_kind
11121140 repr partial param [case])
11131141 in
11141142 let attr = default_function_attribute in
0 commit comments