Skip to content

Commit 4ee15a8

Browse files
committed
Add support for uncurried-always
Add support for uncurried-always: a mode where everything is considered uncurried, whether with or without the `.`. This can be turned on with `@@uncurriedAlways` locally in a file. Added a project config `"uncurried"`, which propagates to dependencies, and takes the values: `"legacy"` which changes nothing, or `"default"` for uncurried by default, or `"always"` for uncurried-always.
1 parent fca615f commit 4ee15a8

27 files changed

+209
-33
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ subset of the arguments, and return a curried type with the remaining ones https
2525
- Inline uncurried application when it is safe https://github.com/rescript-lang/rescript-compiler/pull/5847
2626
- Add support for toplevel `await` https://github.com/rescript-lang/rescript-compiler/pull/5940
2727
- Support optional named arguments without a final unit in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5907
28+
- Add support for uncurried-always: a mode where everything is considered uncurried, whether with or without the `.`. This can be turned on with `@@uncurriedAlways` locally in a file. Added a project config `"uncurried"`, which propagates to dependencies, and takes the values: `"legacy"` which changes nothing, or `"default"` for uncurried by default, or `"always"` for uncurried-always. https://github.com/rescript-lang/rescript-compiler/pull/5968
2829

2930
#### :boom: Breaking Change
3031

docs/docson/build-schema.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@
359359
"additionalProperties": false,
360360
"required": ["version"]
361361
},
362+
"uncurried-specs": {
363+
"type": "string",
364+
"enum": ["legacy", "default", "always"]
365+
},
362366
"bsc-flags": {
363367
"oneOf": [
364368
{
@@ -440,6 +444,10 @@
440444
"$ref": "#/definitions/jsx-specs",
441445
"description": "Configuration for the JSX transformation."
442446
},
447+
"uncurried": {
448+
"$ref": "#/definitions/uncurried-specs",
449+
"description": "Configuration for the uncurried mode."
450+
},
443451
"reason": {
444452
"$ref": "#/definitions/reason-specs",
445453
"description": "ReScript comes with [Reason](http://reasonml.github.io/) by default. Specific configurations here."

jscomp/bsb/bsb_build_schemas.ml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,3 +79,5 @@ let gentypeconfig = "gentypeconfig"
7979
let language = "language"
8080
let path = "path"
8181
let ignored_dirs = "ignored-dirs"
82+
83+
let uncurried = "uncurried"

jscomp/bsb/bsb_clean.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ let clean_bs_garbage proj_dir =
5151
Bsb_log.warn "@{<warning>Failed@} to clean due to %s" (Printexc.to_string e)
5252

5353
let clean_bs_deps proj_dir =
54-
let _, _, pinned_dependencies = Bsb_config_parse.deps_from_bsconfig () in
54+
let _, _, _, pinned_dependencies = Bsb_config_parse.deps_from_bsconfig () in
5555
let queue = Bsb_build_util.walk_all_deps proj_dir ~pinned_dependencies in
5656
Queue.iter
5757
(fun (pkg_cxt : Bsb_build_util.package_context) ->

jscomp/bsb/bsb_config_parse.ml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,15 @@ let extract_gentype_config (map : json_map) : Bsb_config_types.gentype_config =
9595
| Some config ->
9696
Bsb_exception.config_error config "gentypeconfig expect an object"
9797

98+
let extract_uncurried (map : json_map) : Res_uncurried.config =
99+
match map.?(Bsb_build_schemas.uncurried) with
100+
| None -> Legacy
101+
| Some (Str { str = "legacy" }) -> Legacy
102+
| Some (Str { str = "default" }) -> Default
103+
| Some (Str { str = "always" }) -> Always
104+
| Some config ->
105+
Bsb_exception.config_error config "uncurried expects one of: \"legacy\", \"default\", \"always\"."
106+
98107
let extract_string (map : json_map) (field : string) cb =
99108
match map.?(field) with
100109
| None -> None
@@ -337,6 +346,10 @@ let interpret_json ~(package_kind : Bsb_package_kind.t) ~(per_proj_dir : string)
337346
jsx;
338347
generators = extract_generators map;
339348
cut_generators;
349+
uncurried =
350+
(match package_kind with
351+
| Toplevel -> extract_uncurried map
352+
| Pinned_dependency x | Dependency x -> x.uncurried);
340353
}
341354
| None ->
342355
Bsb_exception.invalid_spec "no sources specified in bsconfig.json")
@@ -348,5 +361,6 @@ let deps_from_bsconfig () =
348361
| Obj { map } ->
349362
( Bsb_package_specs.from_map ~cwd:Bsb_global_paths.cwd map,
350363
Bsb_jsx.from_map map,
364+
extract_uncurried map,
351365
Bsb_build_util.extract_pinned_dependencies map )
352366
| _ -> assert false

jscomp/bsb/bsb_config_parse.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
val deps_from_bsconfig : unit -> Bsb_package_specs.t * Bsb_jsx.t * Set_string.t
25+
val deps_from_bsconfig : unit -> Bsb_package_specs.t * Bsb_jsx.t * Res_uncurried.config * Set_string.t
2626

2727
val interpret_json :
2828
package_kind:Bsb_package_kind.t -> per_proj_dir:string -> Bsb_config_types.t

jscomp/bsb/bsb_config_types.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,5 @@ type t = {
6464
cut_generators : bool;
6565
(* note when used as a dev mode, we will always ignore it *)
6666
gentype_config : gentype_config;
67+
uncurried: Res_uncurried.config;
6768
}

jscomp/bsb/bsb_ninja_gen.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ let output_ninja_and_namespace_map ~per_proj_dir ~package_kind
159159
built_in_dependency;
160160
reason_react_jsx;
161161
jsx;
162+
uncurried;
162163
generators;
163164
namespace;
164165
warning;
@@ -205,7 +206,7 @@ let output_ninja_and_namespace_map ~per_proj_dir ~package_kind
205206
let rules : Bsb_ninja_rule.builtin =
206207
Bsb_ninja_rule.make_custom_rules ~gentype_config
207208
~has_postbuild:js_post_build_cmd ~pp_file ~has_builtin:built_in_dependency
208-
~reason_react_jsx ~jsx ~package_specs ~namespace ~digest ~package_name
209+
~reason_react_jsx ~jsx ~uncurried ~package_specs ~namespace ~digest ~package_name
209210
~warnings ~ppx_files ~bsc_flags ~dpkg_incls (* dev dependencies *)
210211
~lib_incls (* its own libs *)
211212
~dev_incls (* its own devs *)

jscomp/bsb/bsb_ninja_rule.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config)
9191
~(has_postbuild : string option) ~(pp_file : string option)
9292
~(has_builtin : bool)
9393
~(reason_react_jsx : Bsb_config_types.reason_react_jsx option)
94-
~(jsx : Bsb_jsx.t) ~(digest : string) ~(package_specs : Bsb_package_specs.t)
94+
~(jsx : Bsb_jsx.t) ~(uncurried: Res_uncurried.config) ~(digest : string) ~(package_specs : Bsb_package_specs.t)
9595
~(namespace : string option) ~package_name ~warnings
9696
~(ppx_files : Bsb_config_types.ppx list) ~bsc_flags ~(dpkg_incls : string)
9797
~(lib_incls : string) ~(dev_incls : string) ~bs_dependencies
@@ -171,6 +171,10 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config)
171171
| None -> ()
172172
| Some Classic -> Ext_buffer.add_string buf " -bs-jsx-mode classic"
173173
| Some Automatic -> Ext_buffer.add_string buf " -bs-jsx-mode automatic");
174+
(match uncurried with
175+
| Legacy -> ()
176+
| Default -> Ext_buffer.add_string buf " -uncurried default"
177+
| Always -> Ext_buffer.add_string buf " -uncurried always");
174178

175179
Ext_buffer.add_char_string buf ' ' bsc_flags;
176180
Ext_buffer.add_string buf " -absname -bs-ast -o $out $i";

jscomp/bsb/bsb_ninja_rule.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ val make_custom_rules :
7272
has_builtin:bool ->
7373
reason_react_jsx:Bsb_config_types.reason_react_jsx option ->
7474
jsx:Bsb_jsx.t ->
75+
uncurried:Res_uncurried.config ->
7576
digest:string ->
7677
package_specs:Bsb_package_specs.t ->
7778
namespace:string option ->

jscomp/bsb/bsb_package_kind.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
type dep_payload = { package_specs : Bsb_package_specs.t; jsx : Bsb_jsx.t }
25+
type dep_payload = { package_specs : Bsb_package_specs.t; jsx : Bsb_jsx.t; uncurried : Res_uncurried.config }
2626

2727
type t =
2828
| Toplevel

jscomp/bsb/bsb_world.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ let vendor_ninja = Bsb_global_paths.vendor_ninja
2727

2828
let make_world_deps cwd (config : Bsb_config_types.t option)
2929
(ninja_args : string array) =
30-
let package_specs, jsx, pinned_dependencies =
30+
let package_specs, jsx, uncurried, pinned_dependencies =
3131
match config with
3232
| None ->
3333
(* When this running bsb does not read bsconfig.json,
@@ -36,7 +36,7 @@ let make_world_deps cwd (config : Bsb_config_types.t option)
3636
*)
3737
Bsb_config_parse.deps_from_bsconfig ()
3838
| Some config ->
39-
(config.package_specs, config.jsx, config.pinned_dependencies)
39+
(config.package_specs, config.jsx, config.uncurried, config.pinned_dependencies)
4040
in
4141
let args =
4242
if Ext_array.is_empty ninja_args then [| vendor_ninja |]
@@ -67,8 +67,8 @@ let make_world_deps cwd (config : Bsb_config_types.t option)
6767
let _config : _ option =
6868
Bsb_ninja_regen.regenerate_ninja
6969
~package_kind:
70-
(if is_pinned then Pinned_dependency { package_specs; jsx }
71-
else Dependency { package_specs; jsx })
70+
(if is_pinned then Pinned_dependency { package_specs; jsx; uncurried }
71+
else Dependency { package_specs; jsx; uncurried })
7272
~per_proj_dir:proj_dir ~forced:false
7373
in
7474
let command =

jscomp/bsc/rescript_compiler_main.ml

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let setup_compiler_printer (syntax_kind : [ syntax_kind | `default])=
2424
(match syntax_kind with
2525
| `default -> ()
2626
| #syntax_kind as k -> Config.syntax_kind := k);
27-
let syntax_kind = !Config.syntax_kind in
27+
let syntax_kind = !Config.syntax_kind in
2828
if syntax_kind = `rescript then begin
2929
Lazy.force Super_main.setup;
3030
Lazy.force Res_outcome_printer.setup
@@ -245,20 +245,17 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
245245

246246
"-bs-jsx", string_call (fun i ->
247247
(if i <> "3" && i <> "4" then Bsc_args.bad_arg (" Not supported jsx version : " ^ i));
248-
let open Js_config in
249-
jsx_version := jsx_version_of_int @@ int_of_string i),
248+
Js_config.jsx_version := Js_config.jsx_version_of_int @@ int_of_string i),
250249
"*internal* Set jsx version";
251250

252251
"-bs-jsx-module", string_call (fun i ->
253252
(if i <> "react" then Bsc_args.bad_arg (" Not supported jsx-module : " ^ i));
254-
let open Js_config in
255-
Js_config.jsx_module := jsx_module_of_string i),
253+
Js_config.jsx_module := Js_config.jsx_module_of_string i),
256254
"*internal* Set jsx module";
257255

258256
"-bs-jsx-mode", string_call (fun i ->
259257
(if i <> "classic" && i <> "automatic" then Bsc_args.bad_arg (" Not supported jsx-mode : " ^ i));
260-
let open Js_config in
261-
Js_config.jsx_mode := jsx_mode_of_string i),
258+
Js_config.jsx_mode := Js_config.jsx_mode_of_string i),
262259
"*internal* Set jsx mode";
263260

264261
"-bs-package-output", string_call Js_packages_state.update_npm_package_path,
@@ -406,8 +403,14 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
406403

407404
"-nopervasives", set Clflags.nopervasives,
408405
"*internal*";
409-
"-bs-uncurry", set Config.default_uncurry,
410-
"*internal" ;
406+
"-uncurried", string_call (fun i ->
407+
match i with
408+
| "default" -> Res_uncurried.init := Default
409+
| "always" -> Res_uncurried.init := Always
410+
| "legacy" -> Res_uncurried.init := Legacy
411+
| _ -> Bsc_args.bad_arg (" Not supported -uncurried option : " ^ i)
412+
),
413+
"*internal* Set jsx module";
411414
"-v", unit_call print_version_string,
412415
"Print compiler version and location of standard library and exit";
413416

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
*.exe
2+
*.obj
3+
*.out
4+
*.compile
5+
*.native
6+
*.byte
7+
*.cmo
8+
*.annot
9+
*.cmi
10+
*.cmx
11+
*.cmt
12+
*.cmti
13+
*.cma
14+
*.a
15+
*.cmxa
16+
*.obj
17+
*~
18+
*.annot
19+
*.cmj
20+
*.bak
21+
lib/bs
22+
*.mlast
23+
*.mliast
24+
.vscode
25+
.merlin
26+
.bsb.lock
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "uncurried",
3+
"version": "0.1.0",
4+
"sources": {
5+
"dir" : "src",
6+
"subdirs" : true
7+
},
8+
"uncurried": "always"
9+
}

jscomp/build_tests/uncurried/input.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//@ts-check
2+
const cp = require("child_process");
3+
const assert = require("assert");
4+
const fs = require('fs')
5+
const path = require('path')
6+
var rescript_exe = require("../../../scripts/bin_path").rescript_exe
7+
8+
cp.execSync(`${rescript_exe} clean -with-deps`, { cwd: __dirname, });
9+
cp.execSync(`${rescript_exe}`, { cwd: __dirname, });

jscomp/build_tests/uncurried/package-lock.json

Lines changed: 44 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "uncurried",
3+
"version": "0.1.0",
4+
"scripts": {
5+
"clean": "rescript clean",
6+
"build": "rescript build",
7+
"watch": "rescript build -w"
8+
},
9+
"keywords": [
10+
"ReScript"
11+
],
12+
"author": "",
13+
"license": "MIT",
14+
"devDependencies": {
15+
"rescript": "^10.0.0"
16+
}
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
let foo = (x, y) => x + y
2+
3+
let z = foo(. 3, 4)
4+
5+
let bar = (. x, y) => x + y
6+
7+
let b = bar(3, 4)
8+
9+
let w = 3->foo(4)
10+
11+
let a = 3->foo(. 4)

jscomp/ext/config.ml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ let interface_suffix = ref ".mli"
2929
separately because it can differ when we're in the middle of a
3030
bootstrapping phase. *)
3131

32-
let default_uncurry = ref false
33-
3432
let print_config oc =
3533
let p name valu = Printf.fprintf oc "%s: %s\n" name valu in
3634
p "version" version;

jscomp/ext/config.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,4 @@ val ast_impl_magic_number : string
4545
val cmt_magic_number : string
4646
(* Magic number for compiled interface files *)
4747

48-
val default_uncurry : bool ref
49-
5048
val print_config : out_channel -> unit

res_syntax/src/res_core.ml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6410,6 +6410,9 @@ and parseStandaloneAttribute p =
64106410
| "uncurried" ->
64116411
p.uncurried_config <- Res_uncurried.Default;
64126412
attrId
6413+
| "uncurriedAlways" ->
6414+
p.uncurried_config <- Res_uncurried.Always;
6415+
attrId
64136416
| "toUncurried" -> {attrId with txt = "uncurried"}
64146417
| _ -> attrId
64156418
in

res_syntax/src/res_parser.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ let make ?(mode = ParseForTypeChecker) src filename =
122122
diagnostics = [];
123123
comments = [];
124124
regions = [ref Report];
125-
uncurried_config = Res_uncurried.init;
125+
uncurried_config = !Res_uncurried.init;
126126
}
127127
in
128128
parserState.scanner.err <-

0 commit comments

Comments
 (0)