Skip to content

Commit bb3f249

Browse files
authored
Cleanup uncurried (#6080)
* Clean up uncurried: uncurried.swap and config Rename `@@uncurried` to `@@uncurried.swap` so relegating it to tests only. Also simplify the setting in bsconfig, which now takes just a boolean. * Remove @toUncurried, which is not essential. * Update CHANGELOG.md * Rename `@@uncurried.always` to simply `@@uncurried`. * Move all the uncurried config to module Config. The Config module is used by the compiler, so the `uncurried` setting needs to be reset on each file as tests compile several files on a single command line (actual project builds don't). * Update CHANGELOG.md * Clean up isSwap
1 parent 881b82f commit bb3f249

39 files changed

+82
-183
lines changed

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414

1515
#### :rocket: New Feature
1616

17-
- Introduce experimental uncurried by default mode. Can be turned on mid-file by adding standalone annotation `@@uncurried`. For experimentation only. https://github.com/rescript-lang/rescript-compiler/pull/5796
18-
- Adding `@@toUncurried` to the file and reformat will convert to uncurried syntax https://github.com/rescript-lang/rescript-compiler/pull/5800
17+
- Introduce experimental uncurried by default mode. Can be turned on mid-file by adding standalone annotation `@@uncurried.swap`. For experimentation only. https://github.com/rescript-lang/rescript-compiler/pull/5796
18+
- ~Adding `@@toUncurried` to the file and reformat will convert to uncurried syntax https://github.com/rescript-lang/rescript-compiler/pull/5800~
1919
- Add support for unary uncurried pipe in uncurried mode https://github.com/rescript-lang/rescript-compiler/pull/5804
2020
- Add support for partial application of uncurried functions: with uncurried application one can provide a
2121
subset of the arguments, and return a curried type with the remaining ones https://github.com/rescript-lang/rescript-compiler/pull/5805
@@ -24,10 +24,10 @@ subset of the arguments, and return a curried type with the remaining ones https
2424
- Add support for default arguments in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5835
2525
- Inline uncurried application when it is safe https://github.com/rescript-lang/rescript-compiler/pull/5847
2626
- Support optional named arguments without a final unit in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5907
27-
- 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.
27+
- Add support for uncurried mode: a mode where everything is considered uncurried, whether with or without the `.`. This can be turned on with `@@uncurried` locally in a file. For project-level configuration in `bsconfig.json`, there's a boolean config `"uncurried"`, which propagates to dependencies, to turn on uncurried mode.
2828
Since there's no syntax for partial application in this new mode, introduce `@res.partial foo(x)` to express partial application. This is temporary and will later have some surface syntax.
2929
Use best effort to determine the config when formatting a file.
30-
https://github.com/rescript-lang/rescript-compiler/pull/5968
30+
https://github.com/rescript-lang/rescript-compiler/pull/5968 https://github.com/rescript-lang/rescript-compiler/pull/6080
3131

3232
#### :boom: Breaking Change
3333

docs/docson/build-schema.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,6 @@
359359
"additionalProperties": false,
360360
"required": ["version"]
361361
},
362-
"uncurried-specs": {
363-
"type": "string",
364-
"enum": ["legacy", "default", "always"]
365-
},
366362
"bsc-flags": {
367363
"oneOf": [
368364
{
@@ -445,7 +441,7 @@
445441
"description": "Configuration for the JSX transformation."
446442
},
447443
"uncurried": {
448-
"$ref": "#/definitions/uncurried-specs",
444+
"type": "boolean",
449445
"description": "Configuration for the uncurried mode."
450446
},
451447
"reason": {

jscomp/bsb/bsb_config_parse.ml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,14 +95,13 @@ 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 =
98+
let extract_uncurried (map : json_map) : bool =
9999
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
100+
| None -> false
101+
| Some (True _) -> true
102+
| Some (False _) -> false
104103
| Some config ->
105-
Bsb_exception.config_error config "uncurried expects one of: \"legacy\", \"default\", \"always\"."
104+
Bsb_exception.config_error config "uncurried expects one of: true, false."
106105

107106
let extract_string (map : json_map) (field : string) cb =
108107
match map.?(field) with

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 * Res_uncurried.config * Set_string.t
25+
val deps_from_bsconfig : unit -> Bsb_package_specs.t * Bsb_jsx.t * bool * 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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,5 +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;
67+
uncurried: bool;
6868
}

jscomp/bsb/bsb_ninja_rule.ml

Lines changed: 3 additions & 5 deletions
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) ~(uncurried: Res_uncurried.config) ~(digest : string) ~(package_specs : Bsb_package_specs.t)
94+
~(jsx : Bsb_jsx.t) ~(uncurried: bool) ~(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
@@ -102,10 +102,8 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config)
102102
since the default is already good -- it does not*)
103103
let buf = Ext_buffer.create 100 in
104104
let ns_flag = match namespace with None -> "" | Some n -> " -bs-ns " ^ n in
105-
let add_uncurried_flag = function
106-
| Res_uncurried.Legacy -> ()
107-
| Default -> Ext_buffer.add_string buf " -uncurried default"
108-
| Always -> Ext_buffer.add_string buf " -uncurried always" in
105+
let add_uncurried_flag b =
106+
if b then Ext_buffer.add_string buf " -uncurried" in
109107
let mk_ml_cmj_cmd ~(read_cmi : [ `yes | `is_cmi | `no ]) ~is_dev ~postbuild :
110108
string =
111109
Ext_buffer.clear buf;

jscomp/bsb/bsb_ninja_rule.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +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 ->
75+
uncurried:bool ->
7676
digest:string ->
7777
package_specs:Bsb_package_specs.t ->
7878
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; uncurried : Res_uncurried.config }
25+
type dep_payload = { package_specs : Bsb_package_specs.t; jsx : Bsb_jsx.t; uncurried : bool }
2626

2727
type t =
2828
| Toplevel

jscomp/bsc/rescript_compiler_main.ml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,12 @@ let process_file sourcefile ?(kind ) ppf =
5151
The {!Location.input_name} relies on that we write the binary ast
5252
properly
5353
*)
54+
let uncurried = !Config.uncurried in
5455
let kind =
5556
match kind with
5657
| None -> Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile)
5758
| Some kind -> kind in
58-
match kind with
59+
let res = match kind with
5960
| Ml ->
6061
let sourcefile = set_abs_input_name sourcefile in
6162
setup_compiler_printer `ml;
@@ -103,6 +104,9 @@ let process_file sourcefile ?(kind ) ppf =
103104
Format.pp_print_newline Format.std_formatter ()
104105
| Unknown ->
105106
Bsc_args.bad_arg ("don't know what to do with " ^ sourcefile)
107+
in
108+
Config.uncurried := uncurried;
109+
res
106110
let usage = "Usage: bsc <options> <files>\nOptions are:"
107111

108112
let ppf = Format.err_formatter
@@ -406,13 +410,7 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array =
406410

407411
"-nopervasives", set Clflags.nopervasives,
408412
"*internal*";
409-
"-uncurried", string_call (fun i ->
410-
match i with
411-
| "default" -> Res_uncurried.init := Default
412-
| "always" -> Res_uncurried.init := Always; Config.use_automatic_curried_application := true
413-
| "legacy" -> Res_uncurried.init := Legacy
414-
| _ -> Bsc_args.bad_arg (" Not supported -uncurried option : " ^ i)
415-
),
413+
"-uncurried", unit_call (fun () -> Config.uncurried := Uncurried),
416414
"*internal* Set jsx module";
417415
"-v", unit_call print_version_string,
418416
"Print compiler version and location of standard library and exit";

jscomp/build_tests/uncurried-always/bsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"dir" : "src",
66
"subdirs" : true
77
},
8-
"uncurried": "always"
8+
"uncurried": true
99
}

0 commit comments

Comments
 (0)