Skip to content

Commit 9ad29cd

Browse files
committed
Fix issues with the arity of externals.
Fixes #6880
1 parent 101f90a commit 9ad29cd

15 files changed

+104
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- Allow free vars in types for type coercion `e :> t`. https://github.com/rescript-lang/rescript-compiler/pull/6828
2121
- Allow `private` in with constraints. https://github.com/rescript-lang/rescript-compiler/pull/6843
2222
- Add regex literals as syntax sugar for `@bs.re`. https://github.com/rescript-lang/rescript-compiler/pull/6776
23-
- Improved mechanism to determine arity of externals, which is consistent however the type is written. https://github.com/rescript-lang/rescript-compiler/pull/6874
23+
- Improved mechanism to determine arity of externals, which is consistent however the type is written. https://github.com/rescript-lang/rescript-compiler/pull/6874 https://github.com/rescript-lang/rescript-compiler/pull/6881
2424

2525
#### :boom: Breaking Change
2626

jscomp/core/lam_compile_external_call.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ let translate_ffi (cxt : Lam_compile_context.t) arg_types
365365
2. support [@@scope "window"]
366366
we need know whether we should call [add_js_module] or not
367367
*)
368-
translate_scoped_module_val external_module_name name scopes ~dynamic_import
368+
let e = translate_scoped_module_val external_module_name name scopes ~dynamic_import in
369+
if args = [] then e
370+
else E.call ~info:{ arity = Full; call_info = Call_na } e args
369371
| Js_module_as_class module_name ->
370372
let fn = external_var module_name ~dynamic_import in
371373
let args, eff = assemble_args_no_splice arg_types args in

jscomp/frontend/external_ffi_types.ml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,13 @@ let from_string s : t =
240240

241241
let () =
242242
Primitive.coerce :=
243-
fun ({prim_name; prim_arity; prim_native_name; prim_alloc = _} :
243+
fun ({
244+
prim_name;
245+
prim_arity;
246+
prim_native_name;
247+
prim_alloc = _;
248+
prim_from_constructor = _;
249+
} :
244250
Primitive.description) (p2 : Primitive.description) ->
245251
let p2_native = p2.prim_native_name in
246252
prim_name = p2.prim_name && prim_arity = p2.prim_arity

jscomp/gentype_tests/typescript-react-example/src/ImportHookDefault.res.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/gentype_tests/typescript-react-example/src/ImportHooks.res.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/gentype_tests/typescript-react-example/src/ImportIndex.res.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/gentype_tests/typescript-react-example/src/JSXV4.res.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/gentype_tests/typescript-react-example/src/MyInput.res.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jscomp/ml/primitive.ml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type description =
2525
prim_arity: int; (* Number of arguments *)
2626
prim_alloc: bool; (* Does it allocates or raise? *)
2727
prim_native_name: string; (* Name of C function for the nat. code gen. *)
28+
prim_from_constructor: bool; (* Is it from a type constructor instead of a concrete function type? *)
2829
}
2930

3031
let coerce : (description -> description -> bool) ref =
@@ -37,15 +38,17 @@ let simple ~name ~arity ~alloc =
3738
{prim_name = name;
3839
prim_arity = arity;
3940
prim_alloc = alloc;
40-
prim_native_name = "";}
41+
prim_native_name = "";
42+
prim_from_constructor = false;}
4143

4244
let make ~name ~alloc ~native_name ~arity =
4345
{prim_name = name;
4446
prim_arity = arity;
4547
prim_alloc = alloc;
46-
prim_native_name = native_name;}
48+
prim_native_name = native_name;
49+
prim_from_constructor = false;}
4750

48-
let parse_declaration valdecl ~arity =
51+
let parse_declaration valdecl ~arity ~from_constructor =
4952
let name, native_name =
5053
match valdecl.pval_prim with
5154
| name :: name2 :: _ -> (name, name2)
@@ -56,7 +59,8 @@ let parse_declaration valdecl ~arity =
5659
{prim_name = name;
5760
prim_arity = arity;
5861
prim_alloc = true;
59-
prim_native_name = native_name;}
62+
prim_native_name = native_name;
63+
prim_from_constructor = from_constructor}
6064

6165
open Outcometree
6266

jscomp/ml/primitive.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ type description = private
2222
prim_arity: int; (* Number of arguments *)
2323
prim_alloc: bool; (* Does it allocates or raise? *)
2424
prim_native_name: string; (* Name of C function for the nat. code gen. *)
25+
prim_from_constructor: bool; (* Is it from a type constructor instead of a concrete function type? *)
2526
}
2627

2728
(* Invariant [List.length d.prim_native_repr_args = d.prim_arity] *)
@@ -42,6 +43,7 @@ val make
4243
val parse_declaration
4344
: Parsetree.value_description
4445
-> arity: int
46+
-> from_constructor: bool
4547
-> description
4648

4749
val print

0 commit comments

Comments
 (0)