@@ -39167,6 +39167,21 @@ let rec parse_native_repr_attributes env core_type ty =
39167
39167
| _ -> ([], Same_as_ocaml_repr)
39168
39168
39169
39169
39170
+ let parse_native_repr_attributes valdecl env core_type ty =
39171
+ match core_type.ptyp_desc, (Ctype.repr ty).desc
39172
+ with
39173
+ | Ptyp_constr ({txt = Ldot(Ldot(Lident "Js", "Fn"),_)}, [{ptyp_desc = Ptyp_arrow (_, _, ct2)}]),
39174
+ Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),[{desc = Tarrow (_, _, t2, _)}],_) ->
39175
+ let is_internal_primitive = match valdecl.pval_prim with
39176
+ | [ s ] -> s <> "" && (s.[0] = '%' || s.[0] = '?')
39177
+ | _ -> false in
39178
+ let repr_args, repr_res = parse_native_repr_attributes env ct2 t2 in
39179
+ let native_repr_args =
39180
+ if is_internal_primitive then
39181
+ Same_as_ocaml_repr :: repr_args (* uncurried primitives treated like curried ones *)
39182
+ else [] (* uncurried externals are treated specially by the back-end *) in
39183
+ (native_repr_args, repr_res)
39184
+ | _ -> parse_native_repr_attributes env core_type ty
39170
39185
39171
39186
(* Translate a value declaration *)
39172
39187
let transl_value_decl env loc valdecl =
@@ -39183,11 +39198,11 @@ let transl_value_decl env loc valdecl =
39183
39198
let native_repr_args, native_repr_res =
39184
39199
let rec scann (attrs : Parsetree.attributes) =
39185
39200
match attrs with
39186
- | ({txt = "internal.arity";_},
39201
+ | ({txt = "internal.arity";_},
39187
39202
PStr [ {pstr_desc = Pstr_eval
39188
39203
(
39189
39204
({pexp_desc = Pexp_constant (Pconst_integer (i,_))} :
39190
- Parsetree.expression) ,_)}]) :: _ ->
39205
+ Parsetree.expression) ,_)}]) :: _ ->
39191
39206
Some (int_of_string i)
39192
39207
| _ :: rest -> scann rest
39193
39208
| [] -> None
@@ -39196,7 +39211,7 @@ let transl_value_decl env loc valdecl =
39196
39211
else Primitive.Same_as_ocaml_repr :: make (n - 1)
39197
39212
in
39198
39213
match scann valdecl.pval_attributes with
39199
- | None -> parse_native_repr_attributes env valdecl.pval_type ty
39214
+ | None -> parse_native_repr_attributes valdecl env valdecl.pval_type ty
39200
39215
| Some x -> make x , Primitive.Same_as_ocaml_repr
39201
39216
in
39202
39217
let prim =
@@ -43686,7 +43701,6 @@ and type_application env funct (sargs : sargs) : targs * Types.type_expr =
43686
43701
Location.prerr_warning sarg1.pexp_loc Warnings.Unused_argument;
43687
43702
unify env ty_fun (newty (Tarrow(l1,t1,t2,Clink(ref Cunknown))));
43688
43703
(t1, t2)
43689
- | Tconstr (Pdot (Pdot(Pident {name = "Js"},"Fn",_),_,_),[{desc=Tarrow (l,t1,t2,_)}],_)
43690
43704
| Tarrow (l,t1,t2,_) when Asttypes.same_arg_label l l1
43691
43705
->
43692
43706
(t1, t2)
0 commit comments