From 38512ae077aa421ed8af7e449a9badff11ab913a Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 25 Nov 2022 11:05:17 +0100 Subject: [PATCH 1/2] Inline uncurried application when it is safe --- CHANGELOG.md | 2 +- jscomp/core/lam_pass_remove_alias.ml | 58 +++++++++++++- jscomp/test/arity_deopt.js | 5 +- jscomp/test/attr_test.js | 6 +- jscomp/test/bs_rest_test.js | 4 +- jscomp/test/internal_unused_test.js | 6 +- jscomp/test/ppx_apply_test.js | 2 +- jscomp/test/uncurried_cast.js | 18 +++-- jscomp/test/uncurried_pipe.js | 20 ++--- jscomp/test/uncurry_glob_test.js | 6 +- jscomp/test/uncurry_test.js | 76 ++++++++++++++----- lib/4.06.1/unstable/js_compiler.ml | 58 +++++++++++++- lib/4.06.1/unstable/js_playground_compiler.ml | 58 +++++++++++++- lib/4.06.1/whole_compiler.ml | 58 +++++++++++++- 14 files changed, 307 insertions(+), 70 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10341bd8f5..fdd32c9e47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ subset of the arguments, and return a curried type with the remaining ones https - Add support for uncurried externals https://github.com/rescript-lang/rescript-compiler/pull/5815 https://github.com/rescript-lang/rescript-compiler/pull/5819 https://github.com/rescript-lang/rescript-compiler/pull/5830 - Parser/Printer: unify uncurried functions of arity 0, and of arity 1 taking unit. There's now only arity 1 in the source language. https://github.com/rescript-lang/rescript-compiler/pull/5825 - Add support for default arguments in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5835 - +- Inline uncurried application when it is safe #### :boom: Breaking Change diff --git a/jscomp/core/lam_pass_remove_alias.ml b/jscomp/core/lam_pass_remove_alias.ml index f7e4253932..fe459f6bfc 100644 --- a/jscomp/core/lam_pass_remove_alias.ml +++ b/jscomp/core/lam_pass_remove_alias.ml @@ -64,6 +64,49 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = | Some (OptionalBlock (l, _)) -> l | _ -> if p = Pval_from_option_not_nest then lvar else x) | Lglobal_module _ -> lam + | Lprim { primitive = Pfull_apply; args = Lvar v :: ap_args as args; loc } + -> ( + (* Inline uncurried application when safe *) + let normal () = + Lam.prim ~primitive:Pfull_apply ~args:(Ext_list.map args simpl) loc + in + let ap_args = Ext_list.map ap_args simpl in + match Hash_ident.find_opt meta.ident_tbl v with + | Some + (FunctionId + { + lambda = + Some + ( Lfunction + ({ params; body; attr = { is_a_functor = false } } as m), + rec_flag ); + }) + when Ext_list.same_length ap_args params + && Lam_analysis.lfunction_can_be_beta_reduced m + && Lam_analysis.ok_to_inline_fun_when_app m ap_args -> ( + let param_map = + Lam_closure.is_closed_with_map meta.export_idents params body + in + let is_export_id = Set_ident.mem meta.export_idents v in + match (is_export_id, param_map) with + | false, (_, param_map) | true, (true, param_map) -> ( + match rec_flag with + | Lam_rec -> + Lam_beta_reduce.propagate_beta_reduce_with_map meta + param_map params body ap_args + | Lam_self_rec -> normal () + | Lam_non_rec -> + if + Ext_list.exists ap_args (fun lam -> + Lam_hit.hit_variable v lam) + (*avoid nontermination, e.g, `g(g)`*) + then normal () + else + simpl + (Lam_beta_reduce.propagate_beta_reduce_with_map meta + param_map params body ap_args)) + | _ -> normal ()) + | _ -> normal ()) | Lprim { primitive; args; loc } -> Lam.prim ~primitive ~args:(Ext_list.map args simpl) loc | Lifthenelse @@ -160,8 +203,9 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = Some ( Lfunction ({ params; body; attr = { is_a_functor } } as m), rec_flag ); - }) when Lam_analysis.lfunction_can_be_beta_reduced m -> - if Ext_list.same_length ap_args params (* && false *) then + }) + when Lam_analysis.lfunction_can_be_beta_reduced m -> + if Ext_list.same_length ap_args params then if is_a_functor (* && (Set_ident.mem v meta.export_idents) && false *) @@ -211,8 +255,14 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = else normal () else normal () | Some _ | None -> normal ()) - | Lapply { ap_func = Lfunction ({ params; body } as lfunction); ap_args = args; _ } - when Ext_list.same_length params args && Lam_analysis.lfunction_can_be_beta_reduced lfunction -> + | Lapply + { + ap_func = Lfunction ({ params; body } as lfunction); + ap_args = args; + _; + } + when Ext_list.same_length params args + && Lam_analysis.lfunction_can_be_beta_reduced lfunction -> simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args) (* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *) (* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *) diff --git a/jscomp/test/arity_deopt.js b/jscomp/test/arity_deopt.js index dd033cbd32..e8ab98f4ce 100644 --- a/jscomp/test/arity_deopt.js +++ b/jscomp/test/arity_deopt.js @@ -1,7 +1,6 @@ 'use strict'; var Mt = require("./mt.js"); -var Curry = require("../../lib/js/curry.js"); var suites = { contents: /* [] */0 @@ -50,13 +49,13 @@ function f3(x) { }; } -eq("File \"arity_deopt.ml\", line 45, characters 7-14", 6, f0(1, 2, 3)); +eq("File \"arity_deopt.ml\", line 45, characters 7-14", 6, 6); eq("File \"arity_deopt.ml\", line 46, characters 11-18", 6, (function (y, z) { return (1 + y | 0) + z | 0; })(2, 3)); -eq("File \"arity_deopt.ml\", line 47, characters 15-22", 6, Curry._1(f2(1, 2), 3)); +eq("File \"arity_deopt.ml\", line 47, characters 15-22", 6, 6); eq("File \"arity_deopt.ml\", line 48, characters 15-22", 6, (function (y, z) { return (1 + y | 0) + z | 0; diff --git a/jscomp/test/attr_test.js b/jscomp/test/attr_test.js index 6cc9a4cd9c..16b3145f94 100644 --- a/jscomp/test/attr_test.js +++ b/jscomp/test/attr_test.js @@ -5,13 +5,13 @@ function u(x, y) { return x + y | 0; } -var h = u(1, 2); +var h = 3; function max2(x, y) { return x + y; } -var hh = max2(1, 2); +var hh = 1 + 2; function f(x) { des(x, (function () { @@ -24,4 +24,4 @@ exports.h = h; exports.max2 = max2; exports.hh = hh; exports.f = f; -/* h Not a pure module */ +/* No side effect */ diff --git a/jscomp/test/bs_rest_test.js b/jscomp/test/bs_rest_test.js index 8692d0540b..45e51b726e 100644 --- a/jscomp/test/bs_rest_test.js +++ b/jscomp/test/bs_rest_test.js @@ -12,9 +12,9 @@ function xxx(prim) { return x(prim); } -var u = xxx(3); +var u = x(3); -var xx = xxx("3"); +var xx = x("3"); exports.v = v; exports.xxx = xxx; diff --git a/jscomp/test/internal_unused_test.js b/jscomp/test/internal_unused_test.js index dd9a22dff9..72ed996233 100644 --- a/jscomp/test/internal_unused_test.js +++ b/jscomp/test/internal_unused_test.js @@ -15,10 +15,6 @@ function f(param) { var c = 5; -function h(a, b) { - return a + b | 0; -} - var h1 = 2; var h2 = h1 + 1 | 0; @@ -39,7 +35,7 @@ console.log(h2); console.log(c); -console.log(h(1, 2)); +console.log(3); function H($star) { return {}; diff --git a/jscomp/test/ppx_apply_test.js b/jscomp/test/ppx_apply_test.js index 78d10e39ea..dcf4df309c 100644 --- a/jscomp/test/ppx_apply_test.js +++ b/jscomp/test/ppx_apply_test.js @@ -37,7 +37,7 @@ function unary(a) { return a + 3 | 0; } -var xx = unary(3); +var xx = 6; eq("File \"ppx_apply_test.ml\", line 17, characters 5-12", u, 3); diff --git a/jscomp/test/uncurried_cast.js b/jscomp/test/uncurried_cast.js index db82191d3e..0205d44de9 100644 --- a/jscomp/test/uncurried_cast.js +++ b/jscomp/test/uncurried_cast.js @@ -22,12 +22,13 @@ var Uncurried = { var E = /* @__PURE__ */Caml_exceptions.create("Uncurried_cast.E"); function testRaise(param) { - return raise({ - RE_EXN_ID: E - }); + throw { + RE_EXN_ID: E, + Error: new Error() + }; } -var l = map({ +var l = Belt_List.mapU({ hd: 1, tl: { hd: 2, @@ -76,12 +77,13 @@ var StandardNotation = { }; function testRaise$1(param) { - return raise({ - RE_EXN_ID: E - }); + throw { + RE_EXN_ID: E, + Error: new Error() + }; } -var l$1 = map({ +var l$1 = Belt_List.mapU({ hd: 1, tl: { hd: 2, diff --git a/jscomp/test/uncurried_pipe.js b/jscomp/test/uncurried_pipe.js index 419c08ca24..486c57243d 100644 --- a/jscomp/test/uncurried_pipe.js +++ b/jscomp/test/uncurried_pipe.js @@ -9,13 +9,13 @@ function addC(x, y) { return x + y | 0; } -var v7 = add(3, 4); +var v7 = 7; -var v17 = add(10, add(3, 4)); +var v17 = 17; -var v27 = add(20, 7); +var v27 = 27; -var v37 = 30 + add(3, 4) | 0; +var v37 = 37; function unary(x) { return x + 1 | 0; @@ -31,15 +31,15 @@ var StandardNotation = { unary: unary }; -var v7$1 = add(3, 4); +var v7$1 = 7; -var v17$1 = add(10, add(3, 4)); +var v17$1 = 17; -var v27$1 = add(20, 7); +var v27$1 = 27; -var v37$1 = 30 + add(3, 4) | 0; +var v37$1 = 37; -var v100 = unary(99); +var v100 = 100; exports.StandardNotation = StandardNotation; exports.v7 = v7$1; @@ -47,4 +47,4 @@ exports.v17 = v17$1; exports.v27 = v27$1; exports.v37 = v37$1; exports.v100 = v100; -/* v7 Not a pure module */ +/* No side effect */ diff --git a/jscomp/test/uncurry_glob_test.js b/jscomp/test/uncurry_glob_test.js index 6f8d68f4de..8006c02677 100644 --- a/jscomp/test/uncurry_glob_test.js +++ b/jscomp/test/uncurry_glob_test.js @@ -12,18 +12,16 @@ function f(param) { return 3; } -f(undefined); - function $plus$great(a, h) { return h(a); } function u(h) { - return $plus$great(3, h); + return h(3); } exports.M = M; exports.f = f; exports.$plus$great = $plus$great; exports.u = u; -/* Not a pure module */ +/* No side effect */ diff --git a/jscomp/test/uncurry_test.js b/jscomp/test/uncurry_test.js index 9cab4c5c23..758e829b92 100644 --- a/jscomp/test/uncurry_test.js +++ b/jscomp/test/uncurry_test.js @@ -366,23 +366,65 @@ function f22(a0, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a1 ]; } -console.log(f0(undefined)); - -console.log(f1(0)); - -console.log(f2(0, 1)); - -console.log(f3(0, 1, 2)); - -console.log(f4(0, 1, 2, 3)); - -console.log(f5(0, 1, 2, 3, 4)); - -console.log(f6(0, 1, 2, 3, 4, 5)); - -console.log(f7(0, 1, 2, 3, 4, 5, 6)); - -console.log(f8(0, 1, 2, 3, 4, 5, 6, 7)); +console.log(0); + +console.log(0); + +console.log([ + 0, + 1 + ]); + +console.log([ + 0, + 1, + 2 + ]); + +console.log([ + 0, + 1, + 2, + 3 + ]); + +console.log([ + 0, + 1, + 2, + 3, + 4 + ]); + +console.log([ + 0, + 1, + 2, + 3, + 4, + 5 + ]); + +console.log([ + 0, + 1, + 2, + 3, + 4, + 5, + 6 + ]); + +console.log([ + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7 + ]); console.log(f9(0, 1, 2, 3, 4, 5, 6, 7, 8)); diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 5ea519f11d..4a8661df36 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -139371,6 +139371,49 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = | Some (OptionalBlock (l, _)) -> l | _ -> if p = Pval_from_option_not_nest then lvar else x) | Lglobal_module _ -> lam + | Lprim { primitive = Pfull_apply; args = Lvar v :: ap_args as args; loc } + -> ( + (* Inline uncurried application when safe *) + let normal () = + Lam.prim ~primitive:Pfull_apply ~args:(Ext_list.map args simpl) loc + in + let ap_args = Ext_list.map ap_args simpl in + match Hash_ident.find_opt meta.ident_tbl v with + | Some + (FunctionId + { + lambda = + Some + ( Lfunction + ({ params; body; attr = { is_a_functor = false } } as m), + rec_flag ); + }) + when Ext_list.same_length ap_args params + && Lam_analysis.lfunction_can_be_beta_reduced m + && Lam_analysis.ok_to_inline_fun_when_app m ap_args -> ( + let param_map = + Lam_closure.is_closed_with_map meta.export_idents params body + in + let is_export_id = Set_ident.mem meta.export_idents v in + match (is_export_id, param_map) with + | false, (_, param_map) | true, (true, param_map) -> ( + match rec_flag with + | Lam_rec -> + Lam_beta_reduce.propagate_beta_reduce_with_map meta + param_map params body ap_args + | Lam_self_rec -> normal () + | Lam_non_rec -> + if + Ext_list.exists ap_args (fun lam -> + Lam_hit.hit_variable v lam) + (*avoid nontermination, e.g, `g(g)`*) + then normal () + else + simpl + (Lam_beta_reduce.propagate_beta_reduce_with_map meta + param_map params body ap_args)) + | _ -> normal ()) + | _ -> normal ()) | Lprim { primitive; args; loc } -> Lam.prim ~primitive ~args:(Ext_list.map args simpl) loc | Lifthenelse @@ -139467,8 +139510,9 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = Some ( Lfunction ({ params; body; attr = { is_a_functor } } as m), rec_flag ); - }) when Lam_analysis.lfunction_can_be_beta_reduced m -> - if Ext_list.same_length ap_args params (* && false *) then + }) + when Lam_analysis.lfunction_can_be_beta_reduced m -> + if Ext_list.same_length ap_args params then if is_a_functor (* && (Set_ident.mem v meta.export_idents) && false *) @@ -139518,8 +139562,14 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = else normal () else normal () | Some _ | None -> normal ()) - | Lapply { ap_func = Lfunction ({ params; body } as lfunction); ap_args = args; _ } - when Ext_list.same_length params args && Lam_analysis.lfunction_can_be_beta_reduced lfunction -> + | Lapply + { + ap_func = Lfunction ({ params; body } as lfunction); + ap_args = args; + _; + } + when Ext_list.same_length params args + && Lam_analysis.lfunction_can_be_beta_reduced lfunction -> simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args) (* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *) (* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *) diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index 85d05a2658..4e61120664 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -139371,6 +139371,49 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = | Some (OptionalBlock (l, _)) -> l | _ -> if p = Pval_from_option_not_nest then lvar else x) | Lglobal_module _ -> lam + | Lprim { primitive = Pfull_apply; args = Lvar v :: ap_args as args; loc } + -> ( + (* Inline uncurried application when safe *) + let normal () = + Lam.prim ~primitive:Pfull_apply ~args:(Ext_list.map args simpl) loc + in + let ap_args = Ext_list.map ap_args simpl in + match Hash_ident.find_opt meta.ident_tbl v with + | Some + (FunctionId + { + lambda = + Some + ( Lfunction + ({ params; body; attr = { is_a_functor = false } } as m), + rec_flag ); + }) + when Ext_list.same_length ap_args params + && Lam_analysis.lfunction_can_be_beta_reduced m + && Lam_analysis.ok_to_inline_fun_when_app m ap_args -> ( + let param_map = + Lam_closure.is_closed_with_map meta.export_idents params body + in + let is_export_id = Set_ident.mem meta.export_idents v in + match (is_export_id, param_map) with + | false, (_, param_map) | true, (true, param_map) -> ( + match rec_flag with + | Lam_rec -> + Lam_beta_reduce.propagate_beta_reduce_with_map meta + param_map params body ap_args + | Lam_self_rec -> normal () + | Lam_non_rec -> + if + Ext_list.exists ap_args (fun lam -> + Lam_hit.hit_variable v lam) + (*avoid nontermination, e.g, `g(g)`*) + then normal () + else + simpl + (Lam_beta_reduce.propagate_beta_reduce_with_map meta + param_map params body ap_args)) + | _ -> normal ()) + | _ -> normal ()) | Lprim { primitive; args; loc } -> Lam.prim ~primitive ~args:(Ext_list.map args simpl) loc | Lifthenelse @@ -139467,8 +139510,9 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = Some ( Lfunction ({ params; body; attr = { is_a_functor } } as m), rec_flag ); - }) when Lam_analysis.lfunction_can_be_beta_reduced m -> - if Ext_list.same_length ap_args params (* && false *) then + }) + when Lam_analysis.lfunction_can_be_beta_reduced m -> + if Ext_list.same_length ap_args params then if is_a_functor (* && (Set_ident.mem v meta.export_idents) && false *) @@ -139518,8 +139562,14 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = else normal () else normal () | Some _ | None -> normal ()) - | Lapply { ap_func = Lfunction ({ params; body } as lfunction); ap_args = args; _ } - when Ext_list.same_length params args && Lam_analysis.lfunction_can_be_beta_reduced lfunction -> + | Lapply + { + ap_func = Lfunction ({ params; body } as lfunction); + ap_args = args; + _; + } + when Ext_list.same_length params args + && Lam_analysis.lfunction_can_be_beta_reduced lfunction -> simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args) (* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *) (* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *) diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index feb242c2f1..6ca99951ef 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -154541,6 +154541,49 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = | Some (OptionalBlock (l, _)) -> l | _ -> if p = Pval_from_option_not_nest then lvar else x) | Lglobal_module _ -> lam + | Lprim { primitive = Pfull_apply; args = Lvar v :: ap_args as args; loc } + -> ( + (* Inline uncurried application when safe *) + let normal () = + Lam.prim ~primitive:Pfull_apply ~args:(Ext_list.map args simpl) loc + in + let ap_args = Ext_list.map ap_args simpl in + match Hash_ident.find_opt meta.ident_tbl v with + | Some + (FunctionId + { + lambda = + Some + ( Lfunction + ({ params; body; attr = { is_a_functor = false } } as m), + rec_flag ); + }) + when Ext_list.same_length ap_args params + && Lam_analysis.lfunction_can_be_beta_reduced m + && Lam_analysis.ok_to_inline_fun_when_app m ap_args -> ( + let param_map = + Lam_closure.is_closed_with_map meta.export_idents params body + in + let is_export_id = Set_ident.mem meta.export_idents v in + match (is_export_id, param_map) with + | false, (_, param_map) | true, (true, param_map) -> ( + match rec_flag with + | Lam_rec -> + Lam_beta_reduce.propagate_beta_reduce_with_map meta + param_map params body ap_args + | Lam_self_rec -> normal () + | Lam_non_rec -> + if + Ext_list.exists ap_args (fun lam -> + Lam_hit.hit_variable v lam) + (*avoid nontermination, e.g, `g(g)`*) + then normal () + else + simpl + (Lam_beta_reduce.propagate_beta_reduce_with_map meta + param_map params body ap_args)) + | _ -> normal ()) + | _ -> normal ()) | Lprim { primitive; args; loc } -> Lam.prim ~primitive ~args:(Ext_list.map args simpl) loc | Lifthenelse @@ -154637,8 +154680,9 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = Some ( Lfunction ({ params; body; attr = { is_a_functor } } as m), rec_flag ); - }) when Lam_analysis.lfunction_can_be_beta_reduced m -> - if Ext_list.same_length ap_args params (* && false *) then + }) + when Lam_analysis.lfunction_can_be_beta_reduced m -> + if Ext_list.same_length ap_args params then if is_a_functor (* && (Set_ident.mem v meta.export_idents) && false *) @@ -154688,8 +154732,14 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = else normal () else normal () | Some _ | None -> normal ()) - | Lapply { ap_func = Lfunction ({ params; body } as lfunction); ap_args = args; _ } - when Ext_list.same_length params args && Lam_analysis.lfunction_can_be_beta_reduced lfunction -> + | Lapply + { + ap_func = Lfunction ({ params; body } as lfunction); + ap_args = args; + _; + } + when Ext_list.same_length params args + && Lam_analysis.lfunction_can_be_beta_reduced lfunction -> simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args) (* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *) (* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *) From 17f66b66aa0510265702200d4877e6fa05b95014 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 25 Nov 2022 11:10:31 +0100 Subject: [PATCH 2/2] Add inlining tests for curried/uncurried normal/async functions. --- CHANGELOG.md | 2 +- jscomp/test/async_inline.js | 32 ++++++++++++++++++++++++++++++++ jscomp/test/async_inline.res | 10 ++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fdd32c9e47..209e577af8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,7 +22,7 @@ subset of the arguments, and return a curried type with the remaining ones https - Add support for uncurried externals https://github.com/rescript-lang/rescript-compiler/pull/5815 https://github.com/rescript-lang/rescript-compiler/pull/5819 https://github.com/rescript-lang/rescript-compiler/pull/5830 - Parser/Printer: unify uncurried functions of arity 0, and of arity 1 taking unit. There's now only arity 1 in the source language. https://github.com/rescript-lang/rescript-compiler/pull/5825 - Add support for default arguments in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5835 -- Inline uncurried application when it is safe +- Inline uncurried application when it is safe https://github.com/rescript-lang/rescript-compiler/pull/5847 #### :boom: Breaking Change diff --git a/jscomp/test/async_inline.js b/jscomp/test/async_inline.js index f9b240b196..150cc10a3f 100644 --- a/jscomp/test/async_inline.js +++ b/jscomp/test/async_inline.js @@ -31,9 +31,41 @@ async function broken$1(someAsyncFunction) { var broken$2 = broken$1; +function curriedId(x) { + return x; +} + +async function curriedIdAsync(x) { + return x; +} + +function uncurriedId(x) { + return x; +} + +async function uncurriedIdAsync(x) { + return x; +} + +var tcia = curriedIdAsync(3); + +var tui = 3; + +var tuia = uncurriedIdAsync(3); + +var tci = 3; + exports.willBeInlined = willBeInlined; exports.inlined = inlined; exports.wrapSomethingAsync = wrapSomethingAsync; exports.M = M; exports.broken = broken$2; +exports.curriedId = curriedId; +exports.curriedIdAsync = curriedIdAsync; +exports.uncurriedId = uncurriedId; +exports.uncurriedIdAsync = uncurriedIdAsync; +exports.tci = tci; +exports.tcia = tcia; +exports.tui = tui; +exports.tuia = tuia; /* inlined Not a pure module */ diff --git a/jscomp/test/async_inline.res b/jscomp/test/async_inline.res index f8dd74a9a2..98c6ba14d3 100644 --- a/jscomp/test/async_inline.res +++ b/jscomp/test/async_inline.res @@ -26,3 +26,13 @@ let broken = async (someAsyncFunction) => { } let broken = someAsyncFunction => broken(someAsyncFunction) + +let curriedId = x => x +let curriedIdAsync = async x => x +let uncurriedId = (.x ) => x +let uncurriedIdAsync = async (.x ) => x + +let tci = curriedId(3) +let tcia = curriedIdAsync(3) +let tui = uncurriedId(. 3) +let tuia = uncurriedIdAsync(. 3) \ No newline at end of file