Skip to content

Commit c550944

Browse files
committed
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 a164042 commit c550944

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
- Make tests ready for uncurried mode. https://github.com/rescript-lang/rescript-compiler/pull/6862
5959
- Make gentype tests uncurried. https://github.com/rescript-lang/rescript-compiler/pull/6866
6060
- Ignore `@uncurry` attribute in uncurried mode, to avoid generating calls to `Curry` at runtime. https://github.com/rescript-lang/rescript-compiler/pull/6869
61+
- Avoid generating calls to Curry when adjusting arity of uncurried functions. https://github.com/rescript-lang/rescript-compiler/pull/6870
6162

6263
#### :nail_care: Polish
6364

jscomp/core/lam_eta_conversion.ml

Lines changed: 5 additions & 1 deletion
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

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

0 commit comments

Comments
 (0)