Skip to content

Commit 5b66756

Browse files
committed
[compiler] recognize internal customized arity
1 parent 50cc24f commit 5b66756

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

vendor/ocaml/typing/typedecl.ml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,20 @@ let transl_exception env sext =
13131313
let newenv = Env.add_extension ~check:true ext.ext_id ext.ext_type env in
13141314
ext, newenv
13151315

1316+
let customize_arity arity pval_attributes =
1317+
let cur_arity = ref arity in
1318+
List.iter (fun (x:Parsetree.attribute) ->
1319+
match x with
1320+
| {txt = "internal.arity";_},
1321+
PStr [ {pstr_desc = Pstr_eval
1322+
(
1323+
({pexp_desc = Pexp_constant (Const_int i)} :
1324+
Parsetree.expression) ,_)}]
1325+
-> if i < !cur_arity then cur_arity := i
1326+
| _ -> ()
1327+
) pval_attributes ;
1328+
!cur_arity
1329+
13161330
(* Translate a value declaration *)
13171331
let transl_value_decl env loc valdecl =
13181332
let cty = Typetexp.transl_type_scheme env valdecl.pval_type in
@@ -1323,7 +1337,7 @@ let transl_value_decl env loc valdecl =
13231337
{ val_type = ty; val_kind = Val_reg; Types.val_loc = loc;
13241338
val_attributes = valdecl.pval_attributes }
13251339
| decl ->
1326-
let arity = Ctype.arity ty in
1340+
let arity = customize_arity (Ctype.arity ty) valdecl.pval_attributes in
13271341
let prim = Primitive.parse_declaration arity decl in
13281342
let prim_native_name = prim.prim_native_name in
13291343
if arity = 0 && not ( String.length prim_native_name > 3 &&

0 commit comments

Comments
 (0)