Skip to content

Commit 07e7372

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 f03259a commit 07e7372

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 ->

0 commit comments

Comments
 (0)