diff --git a/CHANGELOG.md b/CHANGELOG.md index 7365413ff1..47921d5c87 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,7 @@ These are only breaking changes for unformatted code. - Remove method application via operator `##`, which does not exist in `.res` syntax https://github.com/rescript-lang/rescript-compiler/pull/5844 - Treat `@meth` annotation as making the type uncurried for backwards compatibitly with some examples https://github.com/rescript-lang/rescript-compiler/pull/5845 - Process `@set` annotation for field update as generating an uncurried function https://github.com/rescript-lang/rescript-compiler/pull/5846 +- Treat uncurried application of primitives like curried application, which produces better output https://github.com/rescript-lang/rescript-compiler/pull/5851 # 10.1.0-rc.6 diff --git a/jscomp/ml/typecore.ml b/jscomp/ml/typecore.ml index 62e5cd9f6b..47b5d1735a 100644 --- a/jscomp/ml/typecore.ml +++ b/jscomp/ml/typecore.ml @@ -2041,7 +2041,11 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected = exp_attributes = sexp.pexp_attributes; exp_env = env } in - if fully_applied then + let is_primitive = match funct.exp_desc with + | Texp_ident (_, _, {val_kind = Val_prim _}) -> true + | _ -> false in + + if fully_applied && not is_primitive then rue (apply_internal "opaqueFullApply" (mk_apply (apply_internal "opaque" funct) args)) else rue (mk_apply funct args) diff --git a/jscomp/test/UncurriedExternals.js b/jscomp/test/UncurriedExternals.js index 0f0aa5bfe4..6a3cbf9c40 100644 --- a/jscomp/test/UncurriedExternals.js +++ b/jscomp/test/UncurriedExternals.js @@ -26,11 +26,9 @@ function tg(arr) { var tc = Object.assign({}, "abc"); -var te = (function (prim) { - return prim; - })({ - RE_EXN_ID: "Not_found" - }); +var te = { + RE_EXN_ID: "Not_found" +}; var tcr = {}; @@ -87,11 +85,9 @@ function tg$1(arr) { var tc$1 = Object.assign({}, "abc"); -var te$1 = (function (prim) { - return prim; - })({ - RE_EXN_ID: "Not_found" - }); +var te$1 = { + RE_EXN_ID: "Not_found" +}; var tcr$1 = {}; diff --git a/jscomp/test/bs_splice_partial.js b/jscomp/test/bs_splice_partial.js index b8189340b6..de4887587f 100644 --- a/jscomp/test/bs_splice_partial.js +++ b/jscomp/test/bs_splice_partial.js @@ -32,7 +32,7 @@ function test_cb(x) { } function f(x) { - v(x); + Curry._1(v, x); } function testUndefined(param) { diff --git a/lib/4.06.1/unstable/js_compiler.ml b/lib/4.06.1/unstable/js_compiler.ml index 8caaab84f9..c16a1390ac 100644 --- a/lib/4.06.1/unstable/js_compiler.ml +++ b/lib/4.06.1/unstable/js_compiler.ml @@ -42771,7 +42771,11 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected = exp_attributes = sexp.pexp_attributes; exp_env = env } in - if fully_applied then + let is_primitive = match funct.exp_desc with + | Texp_ident (_, _, {val_kind = Val_prim _}) -> true + | _ -> false in + + if fully_applied && not is_primitive then rue (apply_internal "opaqueFullApply" (mk_apply (apply_internal "opaque" funct) args)) else rue (mk_apply funct args) diff --git a/lib/4.06.1/unstable/js_playground_compiler.ml b/lib/4.06.1/unstable/js_playground_compiler.ml index f0eb935612..65ef64ec87 100644 --- a/lib/4.06.1/unstable/js_playground_compiler.ml +++ b/lib/4.06.1/unstable/js_playground_compiler.ml @@ -42771,7 +42771,11 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected = exp_attributes = sexp.pexp_attributes; exp_env = env } in - if fully_applied then + let is_primitive = match funct.exp_desc with + | Texp_ident (_, _, {val_kind = Val_prim _}) -> true + | _ -> false in + + if fully_applied && not is_primitive then rue (apply_internal "opaqueFullApply" (mk_apply (apply_internal "opaque" funct) args)) else rue (mk_apply funct args) diff --git a/lib/4.06.1/whole_compiler.ml b/lib/4.06.1/whole_compiler.ml index 4bd0071deb..5c7f94a9b2 100644 --- a/lib/4.06.1/whole_compiler.ml +++ b/lib/4.06.1/whole_compiler.ml @@ -97765,7 +97765,11 @@ and type_expect_ ?in_function ?(recarg=Rejected) env sexp ty_expected = exp_attributes = sexp.pexp_attributes; exp_env = env } in - if fully_applied then + let is_primitive = match funct.exp_desc with + | Texp_ident (_, _, {val_kind = Val_prim _}) -> true + | _ -> false in + + if fully_applied && not is_primitive then rue (apply_internal "opaqueFullApply" (mk_apply (apply_internal "opaque" funct) args)) else rue (mk_apply funct args)