Skip to content

Commit 22bc07c

Browse files
cristianoccknitt
authored andcommitted
Avoid generating calls to Curry when adjusting arity of uncurried functions.
A function such as this one: ``` let t4 = ({contents: x0}, {contents: x1}, {contents: x2}, {contents: x3}) => (x0, x1, x2, x3) ``` is 4 nested functions each one extracting the `contents` field. In uncurried mode, the arity is adjusted to be 4, by putting a wrapper on top. The wrapper was added by applying all the new args at once, which requires `Curry` runtime.
1 parent 3ce98db commit 22bc07c

File tree

3 files changed

+22
-17
lines changed

3 files changed

+22
-17
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
- Fix Deno compatibility issues on Windows. https://github.com/rescript-lang/rescript-compiler/pull/6850
1919
- Fix issue with infinite loops with type errors on recursive types. https://github.com/rescript-lang/rescript-compiler/pull/6867
2020
- Ignore `@uncurry` attribute in uncurried mode, to avoid generating calls to `Curry` at runtime. https://github.com/rescript-lang/rescript-compiler/pull/6869
21+
- Avoid generating calls to Curry when adjusting arity of uncurried functions. https://github.com/rescript-lang/rescript-compiler/pull/6870
2122

2223
# 11.1.3-rc.1
2324

jscomp/core/lam_eta_conversion.ml

+5-1
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,13 @@ let unsafe_adjust_to_arity loc ~(to_ : int) ?(from : int option) (fn : Lam.t) :
163163
let extra_args =
164164
Ext_list.init (to_ - from) (fun _ -> Ident.create Literals.param)
165165
in
166+
let rec mk_apply body vars = match vars with
167+
| [] -> body
168+
| var :: vars ->
169+
mk_apply (Lam.apply body [var] ap_info) vars in
166170
Lam.function_ ~attr:Lambda.default_function_attribute ~arity:to_
167171
~params:(Ext_list.append params extra_args)
168-
~body:(Lam.apply body (Ext_list.map extra_args Lam.var) ap_info)
172+
~body:(mk_apply body (Ext_list.map extra_args Lam.var))
169173
| _ -> (
170174
let arity = to_ in
171175
let extra_args =

jscomp/test/mutable_uncurry_test.js

+16-16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)