@@ -674,7 +674,7 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
674674 | Texp_constant cst -> Lconst (Const_base cst)
675675 | Texp_let (rec_flag , pat_expr_list , body ) ->
676676 transl_let rec_flag pat_expr_list (transl_exp body)
677- | Texp_function {arg_label = _ ; param; case; partial} ->
677+ | Texp_function {arg_label = _ ; arity; param; case; partial} -> (
678678 let async = has_async_attribute e in
679679 let directive =
680680 match extract_directive_for_fn e with
@@ -695,7 +695,22 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
695695 }
696696 in
697697 let loc = e.exp_loc in
698- Lfunction {params; body; attr; loc}
698+ let lambda = Lfunction {params; body; attr; loc} in
699+ match arity with
700+ | Some arity ->
701+ let prim =
702+ match (Ctype. expand_head e.exp_env e.exp_type).desc with
703+ | Tarrow (Nolabel, t , _ , _ ) -> (
704+ match (Ctype. expand_head e.exp_env t).desc with
705+ | Tconstr (Pident {name = "unit" } , [] , _ ) -> Pjs_fn_make_unit
706+ | _ -> Pjs_fn_make arity)
707+ | _ -> Pjs_fn_make arity
708+ in
709+ Lprim
710+ ( prim (* could be replaced with Opaque in the future except arity 0*) ,
711+ [lambda],
712+ loc )
713+ | None -> lambda)
699714 | Texp_apply
700715 ( ({
701716 exp_desc = Texp_ident (_, _, {val_kind = Val_prim p});
@@ -781,27 +796,6 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda =
781796 with Not_constant -> Lprim (Pmakeblock Blk_tuple , ll, e.exp_loc))
782797 | Texp_construct ({txt = Lident "false" } , _ , [] ) -> Lconst Const_false
783798 | Texp_construct ({txt = Lident "true" } , _ , [] ) -> Lconst Const_true
784- | Texp_construct
785- ({txt = Lident " Function$" }, _, [({exp_desc = Texp_function _} as expr)])
786- ->
787- (* ReScript uncurried encoding *)
788- let loc = expr.exp_loc in
789- let lambda = transl_exp expr in
790- let arity =
791- Ast_uncurried. uncurried_type_get_arity ~env: e.exp_env e.exp_type
792- in
793- let prim =
794- match (Ctype. expand_head expr.exp_env expr.exp_type).desc with
795- | Tarrow (Nolabel, t , _ , _ ) -> (
796- match (Ctype. expand_head expr.exp_env t).desc with
797- | Tconstr (Pident {name = "unit" } , [] , _ ) -> Pjs_fn_make_unit
798- | _ -> Pjs_fn_make arity)
799- | _ -> Pjs_fn_make arity
800- in
801- Lprim
802- ( prim (* could be replaced with Opaque in the future except arity 0*) ,
803- [lambda],
804- loc )
805799 | Texp_construct (lid , cstr , args ) -> (
806800 let ll = transl_list args in
807801 if cstr.cstr_inlined <> None then
0 commit comments