Commit 7a53982
committed
New mechanism to determine arity of externals.
The arity of external declarations is currently determined just based on the untyped parse tree.
This is probably because the "real" arity is ambiguous in curried mode, and the convention is that an explicit type of the form `t1 => t2 => t3` determines arity 2, but type aliases are ignored.
Here's an example:
https://rescript-lang.org/try?version=v11.1.2&code=C4TwDgpgBArlC8UAUBLAdsANFdwCUCAfDhgFAACAbgIYA2UEAHsBAE5p1SUCMAXLAigAiSkKgB6cVGqsUoKADNWAewC2AlAGccqsLRQBjORRr0mLdp0oAmfqgzZcBeMVyCRYydNnytDRnqGxqS0EMCK3IKMRFzcSIyYjHghYYrWUTE28YnJQA
In the example
```res
type u = (int, int) => int
@Val external v1: u = "v" // arity from u is implicit
@Val external v2: (int, int) => int = "v" // arity is explicit
let f1 = x => v1(x,x)
let f2 = x => v2(x,x)
```
we have that `v2` is determined to have arity 2, but the arity of `v1` is not determined.
As a consequence, the code generated for `f1` uses runtime `Curry`, both in curried an uncurried mode.
This PR uses the actual type coming from the type checker when in uncurried mode, as that does not suffer from ambiguity.
The consequences are that the external behaves the same however the type is defined, and in the example, no `Curry` runtime is generated.1 parent 94ac53e commit 7a53982
File tree
16 files changed
+79
-98
lines changed- jscomp
- build_tests/react_ppx/src
- frontend
- gentype_tests/typescript-react-example/src
- ml
- test
16 files changed
+79
-98
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
240 | 240 | | |
241 | 241 | | |
242 | 242 | | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
250 | | - | |
| 243 | + | |
251 | 244 | | |
252 | 245 | | |
253 | 246 | | |
| |||
Lines changed: 7 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 4 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | 23 | | |
27 | 24 | | |
28 | 25 | | |
29 | 26 | | |
30 | 27 | | |
31 | | - | |
32 | | - | |
| 28 | + | |
33 | 29 | | |
34 | 30 | | |
35 | 31 | | |
36 | 32 | | |
37 | 33 | | |
38 | 34 | | |
39 | 35 | | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | 36 | | |
49 | 37 | | |
50 | 38 | | |
51 | 39 | | |
52 | | - | |
53 | | - | |
54 | | - | |
| 40 | + | |
55 | 41 | | |
56 | | - | |
| 42 | + | |
57 | 43 | | |
58 | | - | |
| 44 | + | |
59 | 45 | | |
60 | | - | |
61 | | - | |
62 | | - | |
| 46 | + | |
63 | 47 | | |
64 | | - | |
65 | | - | |
| 48 | + | |
66 | 49 | | |
67 | 50 | | |
68 | 51 | | |
| |||
73 | 56 | | |
74 | 57 | | |
75 | 58 | | |
76 | | - | |
77 | | - | |
78 | | - | |
| 59 | + | |
79 | 60 | | |
80 | 61 | | |
81 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | 20 | | |
26 | 21 | | |
27 | 22 | | |
28 | 23 | | |
29 | 24 | | |
30 | | - | |
31 | | - | |
| 25 | + | |
32 | 26 | | |
33 | 27 | | |
34 | 28 | | |
| |||
42 | 36 | | |
43 | 37 | | |
44 | 38 | | |
45 | | - | |
46 | | - | |
| 39 | + | |
47 | 40 | | |
48 | 41 | | |
49 | 42 | | |
50 | 43 | | |
51 | | - | |
52 | | - | |
| 44 | + | |
53 | 45 | | |
54 | 46 | | |
55 | 47 | | |
| |||
0 commit comments