From 3690efc83a147fcac4f278c25122118686682b27 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 16 Mar 2023 17:43:43 +0100 Subject: [PATCH 1/7] 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. --- docs/docson/build-schema.json | 6 +----- jscomp/bsb/bsb_config_parse.ml | 11 +++++----- jscomp/bsb/bsb_config_parse.mli | 2 +- jscomp/bsb/bsb_config_types.ml | 2 +- jscomp/bsb/bsb_ninja_rule.ml | 8 +++---- jscomp/bsb/bsb_ninja_rule.mli | 2 +- jscomp/bsb/bsb_package_kind.ml | 2 +- jscomp/bsc/rescript_compiler_main.ml | 8 +------ .../uncurried-always/bsconfig.json | 2 +- jscomp/test/UncurriedExternals.res | 2 +- jscomp/test/async_await.res | 2 +- jscomp/test/uncurried_cast.res | 2 +- jscomp/test/uncurried_default.args.res | 2 +- jscomp/test/uncurried_pipe.res | 2 +- res_syntax/src/res_core.ml | 21 +++++++++---------- res_syntax/src/res_multi_printer.ml | 2 +- res_syntax/src/res_printer.ml | 8 +++---- res_syntax/src/res_uncurried.ml | 10 ++++----- .../expressions/UncurriedByDefault.res | 2 +- .../expected/UncurriedByDefault.res.txt | 2 +- .../tests/printer/expr/UncurriedByDefault.res | 2 +- .../printer/expr/expected/ToUncurried.res.txt | 2 +- .../expr/expected/UncurriedByDefault.res.txt | 2 +- 23 files changed, 45 insertions(+), 59 deletions(-) diff --git a/docs/docson/build-schema.json b/docs/docson/build-schema.json index 3ccbd9705e..7f24e3e02d 100644 --- a/docs/docson/build-schema.json +++ b/docs/docson/build-schema.json @@ -359,10 +359,6 @@ "additionalProperties": false, "required": ["version"] }, - "uncurried-specs": { - "type": "string", - "enum": ["legacy", "default", "always"] - }, "bsc-flags": { "oneOf": [ { @@ -445,7 +441,7 @@ "description": "Configuration for the JSX transformation." }, "uncurried": { - "$ref": "#/definitions/uncurried-specs", + "type": "boolean", "description": "Configuration for the uncurried mode." }, "reason": { diff --git a/jscomp/bsb/bsb_config_parse.ml b/jscomp/bsb/bsb_config_parse.ml index 9863e55631..2ea53deb4c 100644 --- a/jscomp/bsb/bsb_config_parse.ml +++ b/jscomp/bsb/bsb_config_parse.ml @@ -95,14 +95,13 @@ let extract_gentype_config (map : json_map) : Bsb_config_types.gentype_config = | Some config -> Bsb_exception.config_error config "gentypeconfig expect an object" -let extract_uncurried (map : json_map) : Res_uncurried.config = +let extract_uncurried (map : json_map) : bool = match map.?(Bsb_build_schemas.uncurried) with - | None -> Legacy - | Some (Str { str = "legacy" }) -> Legacy - | Some (Str { str = "default" }) -> Default - | Some (Str { str = "always" }) -> Always + | None -> false + | Some (True _) -> true + | Some (False _) -> false | Some config -> - Bsb_exception.config_error config "uncurried expects one of: \"legacy\", \"default\", \"always\"." + Bsb_exception.config_error config "uncurried expects one of: true, false." let extract_string (map : json_map) (field : string) cb = match map.?(field) with diff --git a/jscomp/bsb/bsb_config_parse.mli b/jscomp/bsb/bsb_config_parse.mli index fa6c3fc041..3ce5d5e166 100644 --- a/jscomp/bsb/bsb_config_parse.mli +++ b/jscomp/bsb/bsb_config_parse.mli @@ -22,7 +22,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -val deps_from_bsconfig : unit -> Bsb_package_specs.t * Bsb_jsx.t * Res_uncurried.config * Set_string.t +val deps_from_bsconfig : unit -> Bsb_package_specs.t * Bsb_jsx.t * bool * Set_string.t val interpret_json : package_kind:Bsb_package_kind.t -> per_proj_dir:string -> Bsb_config_types.t diff --git a/jscomp/bsb/bsb_config_types.ml b/jscomp/bsb/bsb_config_types.ml index 6c51306b57..4404ad727d 100644 --- a/jscomp/bsb/bsb_config_types.ml +++ b/jscomp/bsb/bsb_config_types.ml @@ -64,5 +64,5 @@ type t = { cut_generators : bool; (* note when used as a dev mode, we will always ignore it *) gentype_config : gentype_config; - uncurried: Res_uncurried.config; + uncurried: bool; } diff --git a/jscomp/bsb/bsb_ninja_rule.ml b/jscomp/bsb/bsb_ninja_rule.ml index 9388923651..829a8f5bfe 100644 --- a/jscomp/bsb/bsb_ninja_rule.ml +++ b/jscomp/bsb/bsb_ninja_rule.ml @@ -91,7 +91,7 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config) ~(has_postbuild : string option) ~(pp_file : string option) ~(has_builtin : bool) ~(reason_react_jsx : Bsb_config_types.reason_react_jsx option) - ~(jsx : Bsb_jsx.t) ~(uncurried: Res_uncurried.config) ~(digest : string) ~(package_specs : Bsb_package_specs.t) + ~(jsx : Bsb_jsx.t) ~(uncurried: bool) ~(digest : string) ~(package_specs : Bsb_package_specs.t) ~(namespace : string option) ~package_name ~warnings ~(ppx_files : Bsb_config_types.ppx list) ~bsc_flags ~(dpkg_incls : string) ~(lib_incls : string) ~(dev_incls : string) ~bs_dependencies @@ -102,10 +102,8 @@ let make_custom_rules ~(gentype_config : Bsb_config_types.gentype_config) since the default is already good -- it does not*) let buf = Ext_buffer.create 100 in let ns_flag = match namespace with None -> "" | Some n -> " -bs-ns " ^ n in - let add_uncurried_flag = function - | Res_uncurried.Legacy -> () - | Default -> Ext_buffer.add_string buf " -uncurried default" - | Always -> Ext_buffer.add_string buf " -uncurried always" in + let add_uncurried_flag b = + if b then Ext_buffer.add_string buf " -uncurried" in let mk_ml_cmj_cmd ~(read_cmi : [ `yes | `is_cmi | `no ]) ~is_dev ~postbuild : string = Ext_buffer.clear buf; diff --git a/jscomp/bsb/bsb_ninja_rule.mli b/jscomp/bsb/bsb_ninja_rule.mli index 0fc6ac0edc..5760ed8940 100644 --- a/jscomp/bsb/bsb_ninja_rule.mli +++ b/jscomp/bsb/bsb_ninja_rule.mli @@ -72,7 +72,7 @@ val make_custom_rules : has_builtin:bool -> reason_react_jsx:Bsb_config_types.reason_react_jsx option -> jsx:Bsb_jsx.t -> - uncurried:Res_uncurried.config -> + uncurried:bool -> digest:string -> package_specs:Bsb_package_specs.t -> namespace:string option -> diff --git a/jscomp/bsb/bsb_package_kind.ml b/jscomp/bsb/bsb_package_kind.ml index 5173395496..22c196260f 100644 --- a/jscomp/bsb/bsb_package_kind.ml +++ b/jscomp/bsb/bsb_package_kind.ml @@ -22,7 +22,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -type dep_payload = { package_specs : Bsb_package_specs.t; jsx : Bsb_jsx.t; uncurried : Res_uncurried.config } +type dep_payload = { package_specs : Bsb_package_specs.t; jsx : Bsb_jsx.t; uncurried : bool } type t = | Toplevel diff --git a/jscomp/bsc/rescript_compiler_main.ml b/jscomp/bsc/rescript_compiler_main.ml index e7888bcc0d..224b3268fb 100644 --- a/jscomp/bsc/rescript_compiler_main.ml +++ b/jscomp/bsc/rescript_compiler_main.ml @@ -406,13 +406,7 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array = "-nopervasives", set Clflags.nopervasives, "*internal*"; - "-uncurried", string_call (fun i -> - match i with - | "default" -> Res_uncurried.init := Default - | "always" -> Res_uncurried.init := Always; Config.use_automatic_curried_application := true - | "legacy" -> Res_uncurried.init := Legacy - | _ -> Bsc_args.bad_arg (" Not supported -uncurried option : " ^ i) - ), + "-uncurried", unit_call (fun () -> Res_uncurried.init := Swap; Config.use_automatic_curried_application := true), "*internal* Set jsx module"; "-v", unit_call print_version_string, "Print compiler version and location of standard library and exit"; diff --git a/jscomp/build_tests/uncurried-always/bsconfig.json b/jscomp/build_tests/uncurried-always/bsconfig.json index da0a38fd3e..bfbf9db2bf 100644 --- a/jscomp/build_tests/uncurried-always/bsconfig.json +++ b/jscomp/build_tests/uncurried-always/bsconfig.json @@ -5,5 +5,5 @@ "dir" : "src", "subdirs" : true }, - "uncurried": "always" + "uncurried": true } diff --git a/jscomp/test/UncurriedExternals.res b/jscomp/test/UncurriedExternals.res index 5a9b875453..7cea6830a1 100644 --- a/jscomp/test/UncurriedExternals.res +++ b/jscomp/test/UncurriedExternals.res @@ -39,7 +39,7 @@ module StandardNotation = { let (get, set) = useState(() => 3) } -@@uncurried +@@uncurried.swap external raise: exn => 'a = "%raise" let dd = (. ()) => raise(Not_found) diff --git a/jscomp/test/async_await.res b/jscomp/test/async_await.res index 5a3de28f5b..fd7bf92f34 100644 --- a/jscomp/test/async_await.res +++ b/jscomp/test/async_await.res @@ -1,4 +1,4 @@ -@@uncurried +@@uncurried.swap let next = n => n + 1 let useNext = async () => next(3) diff --git a/jscomp/test/uncurried_cast.res b/jscomp/test/uncurried_cast.res index 112fc86d7d..4a4684ffd7 100644 --- a/jscomp/test/uncurried_cast.res +++ b/jscomp/test/uncurried_cast.res @@ -23,7 +23,7 @@ module StandardNotation = { let anInt = still2Args(~z=3)(. 5) } -@@uncurried +@@uncurried.swap open Uncurried diff --git a/jscomp/test/uncurried_default.args.res b/jscomp/test/uncurried_default.args.res index 4d8209947a..386e4269c9 100644 --- a/jscomp/test/uncurried_default.args.res +++ b/jscomp/test/uncurried_default.args.res @@ -14,7 +14,7 @@ module StandardNotation = { let r3 = foo3(. ) } -@@uncurried +@@uncurried.swap open StandardNotation diff --git a/jscomp/test/uncurried_pipe.res b/jscomp/test/uncurried_pipe.res index 3cd23ee883..3bc4f179b9 100644 --- a/jscomp/test/uncurried_pipe.res +++ b/jscomp/test/uncurried_pipe.res @@ -10,7 +10,7 @@ module StandardNotation = { let unary = (. x) => x + 1 } -@@uncurried +@@uncurried.swap open StandardNotation diff --git a/res_syntax/src/res_core.ml b/res_syntax/src/res_core.ml index c5eb333e9a..3d83e7355b 100644 --- a/res_syntax/src/res_core.ml +++ b/res_syntax/src/res_core.ml @@ -386,7 +386,7 @@ let buildLongident words = let makeInfixOperator (p : Parser.t) token startPos endPos = let stringifiedToken = if token = Token.MinusGreater then - if p.uncurried_config |> Res_uncurried.isDefault then "|.u" else "|." + if p.uncurried_config |> Res_uncurried.isSwap then "|.u" else "|." else if token = Token.PlusPlus then "^" else if token = Token.BangEqual then "<>" else if token = Token.BangEqualEqual then "!=" @@ -1559,7 +1559,7 @@ and parseEs6ArrowExpression ?(arrowAttrs = []) ?(arrowStartPos = None) ?context when p.uncurried_config |> Res_uncurried.fromDotted ~dotted && isFun -> true | TermParameter _ :: rest - when (not (p.uncurried_config |> Res_uncurried.isDefault)) && isFun -> + when (not (p.uncurried_config |> Res_uncurried.isSwap)) && isFun -> rest |> List.exists (function | TermParameter {dotted} -> dotted @@ -1597,7 +1597,7 @@ and parseEs6ArrowExpression ?(arrowAttrs = []) ?(arrowStartPos = None) ?context if uncurried && (termParamNum = 1 - || not (p.uncurried_config |> Res_uncurried.isDefault)) + || not (p.uncurried_config |> Res_uncurried.isSwap)) then (termParamNum - 1, Ast_uncurried.uncurriedFun ~loc ~arity funExpr, 1) else (termParamNum - 1, funExpr, arity + 1) @@ -3922,7 +3922,7 @@ and parsePolyTypeExpr p = let returnType = parseTypExpr ~alias:false p in let loc = mkLoc typ.Parsetree.ptyp_loc.loc_start p.prevEndPos in let tFun = Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType in - if p.uncurried_config |> Res_uncurried.isDefault then + if p.uncurried_config |> Res_uncurried.isSwap then Ast_uncurried.uncurriedType ~loc ~arity:1 tFun else tFun | _ -> Ast_helper.Typ.var ~loc:var.loc var.txt) @@ -4252,7 +4252,7 @@ and parseEs6ArrowType ~attrs p = let endPos = p.prevEndPos in let returnTypeArity = match parameters with - | _ when p.uncurried_config |> Res_uncurried.isDefault -> 0 + | _ when p.uncurried_config |> Res_uncurried.isSwap -> 0 | _ -> if parameters |> List.exists (function {dotted; typ = _} -> dotted) then 0 @@ -4268,8 +4268,7 @@ and parseEs6ArrowType ~attrs p = in if uncurried - && (paramNum = 1 - || not (p.uncurried_config |> Res_uncurried.isDefault)) + && (paramNum = 1 || not (p.uncurried_config |> Res_uncurried.isSwap)) then let loc = mkLoc startPos endPos in let tArg = Ast_helper.Typ.arrow ~loc ~attrs argLbl typ t in @@ -4335,7 +4334,7 @@ and parseArrowTypeRest ~es6Arrow ~startPos typ p = let returnType = parseTypExpr ~alias:false p in let loc = mkLoc startPos p.prevEndPos in let arrowTyp = Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType in - if p.uncurried_config |> Res_uncurried.isDefault then + if p.uncurried_config |> Res_uncurried.isSwap then Ast_uncurried.uncurriedType ~loc ~arity:1 arrowTyp else arrowTyp | _ -> typ @@ -6409,13 +6408,13 @@ and parseStandaloneAttribute p = let attrId = parseAttributeId ~startPos p in let attrId = match attrId.txt with - | "uncurried" -> - p.uncurried_config <- Res_uncurried.Default; + | "uncurried.swap" -> + p.uncurried_config <- Res_uncurried.Swap; attrId | "uncurriedAlways" -> p.uncurried_config <- Res_uncurried.Always; attrId - | "toUncurried" -> {attrId with txt = "uncurried"} + | "toUncurried" -> {attrId with txt = "uncurried.swap"} | _ -> attrId in let payload = parsePayload p in diff --git a/res_syntax/src/res_multi_printer.ml b/res_syntax/src/res_multi_printer.ml index 74d5ca639e..eef59576e3 100644 --- a/res_syntax/src/res_multi_printer.ml +++ b/res_syntax/src/res_multi_printer.ml @@ -43,7 +43,7 @@ let getUncurriedAlwaysFromBsconfig ~filename = |> List.exists (fun line -> let words = line |> String.split_on_char '\"' in words |> List.exists (fun word -> word = "uncurried") - && words |> List.exists (fun word -> word = "always")) + && words |> List.exists (fun word -> word = "true")) in if uncurriedAlways then Res_uncurried.init := Always diff --git a/res_syntax/src/res_printer.ml b/res_syntax/src/res_printer.ml index c3f8b66d79..fe66f737d6 100644 --- a/res_syntax/src/res_printer.ml +++ b/res_syntax/src/res_printer.ml @@ -5276,15 +5276,15 @@ and printAttribute ?(standalone = false) ~state | _ -> let id = match id.txt with - | "uncurried" -> - state.uncurried_config <- Res_uncurried.Default; + | "uncurried.swap" -> + state.uncurried_config <- Res_uncurried.Swap; id | "uncurriedAlways" -> state.uncurried_config <- Res_uncurried.Always; id | "toUncurried" -> - state.uncurried_config <- Res_uncurried.Default; - {id with txt = "uncurried"} + state.uncurried_config <- Res_uncurried.Swap; + {id with txt = "uncurried.swap"} | _ -> id in ( Doc.group diff --git a/res_syntax/src/res_uncurried.ml b/res_syntax/src/res_uncurried.ml index ae56178b84..7a5f0f75b9 100644 --- a/res_syntax/src/res_uncurried.ml +++ b/res_syntax/src/res_uncurried.ml @@ -1,20 +1,20 @@ -type config = Legacy | Default | Always +type config = Legacy | Swap | Always let init = ref Legacy -let isDefault = function +let isSwap = function | Legacy -> false - | Default -> true + | Swap -> true | Always -> true (* For parsing *) let fromDotted ~dotted = function | Legacy -> dotted - | Default -> not dotted + | Swap -> not dotted | Always -> true (* For printing *) let getDotted ~uncurried = function | Legacy -> uncurried - | Default -> not uncurried + | Swap -> not uncurried | Always -> false diff --git a/res_syntax/tests/parsing/grammar/expressions/UncurriedByDefault.res b/res_syntax/tests/parsing/grammar/expressions/UncurriedByDefault.res index 797a2fc43b..8af116782b 100644 --- a/res_syntax/tests/parsing/grammar/expressions/UncurriedByDefault.res +++ b/res_syntax/tests/parsing/grammar/expressions/UncurriedByDefault.res @@ -50,7 +50,7 @@ let t4 = (. type a b) => (l: list, x: a) => list{x, ...l} let t5 = (type a b) => (. l: list, x: a) => list{x, ...l} let t6 = (. type a b) => (. l: list, x: a) => list{x, ...l} -@@uncurried +@@uncurried.swap let cApp = foo(. 3) let uApp = foo(3) diff --git a/res_syntax/tests/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt b/res_syntax/tests/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt index f1d09f99ef..d473af11a6 100644 --- a/res_syntax/tests/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt +++ b/res_syntax/tests/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt @@ -76,7 +76,7 @@ let t5 (type a) (type b) = ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) let t6 (type a) (type b) = ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) -[@@@uncurried ] +[@@@uncurried.swap ] let cApp = foo 3 let uApp = ((foo 3)[@res.uapp ]) let cFun x = 3 diff --git a/res_syntax/tests/printer/expr/UncurriedByDefault.res b/res_syntax/tests/printer/expr/UncurriedByDefault.res index 5fff9ed943..9b7e7b1e4f 100644 --- a/res_syntax/tests/printer/expr/UncurriedByDefault.res +++ b/res_syntax/tests/printer/expr/UncurriedByDefault.res @@ -57,7 +57,7 @@ let t4 = (. type a b) => (l: list, x: a) => list{x, ...l} let t5 = (type a b) => (. l: list, x: a) => list{x, ...l} let t6 = (. type a b) => (. l: list, x: a) => list{x, ...l} -@@uncurried +@@uncurried.swap let cApp = foo(. 3) let uApp = foo(3) diff --git a/res_syntax/tests/printer/expr/expected/ToUncurried.res.txt b/res_syntax/tests/printer/expr/expected/ToUncurried.res.txt index b11293a008..8a84eef5e4 100644 --- a/res_syntax/tests/printer/expr/expected/ToUncurried.res.txt +++ b/res_syntax/tests/printer/expr/expected/ToUncurried.res.txt @@ -15,7 +15,7 @@ type bTyp = (. string) => string => int type cTyp2 = (string, string) => int type uTyp2 = (. string, string) => int -@@uncurried +@@uncurried.swap let cApp = foo(. 3) let uApp = foo(3) diff --git a/res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt b/res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt index a6b95d53a4..15c4e15836 100644 --- a/res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt +++ b/res_syntax/tests/printer/expr/expected/UncurriedByDefault.res.txt @@ -57,7 +57,7 @@ let t4 = (type a b, l: list, x: a) => list{x, ...l} let t5 = (. type a b, l: list, x: a) => list{x, ...l} let t6 = (. type a b, l: list, x: a) => list{x, ...l} -@@uncurried +@@uncurried.swap let cApp = foo(. 3) let uApp = foo(3) From 335811bf460c7c6fa2f60c5eb96d766b0bc1c115 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 16 Mar 2023 17:45:40 +0100 Subject: [PATCH 2/7] Remove @toUncurried, which is not essential. --- CHANGELOG.md | 2 +- res_syntax/src/res_core.ml | 1 - res_syntax/src/res_printer.ml | 3 -- res_syntax/tests/printer/expr/ToUncurried.res | 35 ------------------- .../printer/expr/expected/ToUncurried.res.txt | 35 ------------------- 5 files changed, 1 insertion(+), 75 deletions(-) delete mode 100644 res_syntax/tests/printer/expr/ToUncurried.res delete mode 100644 res_syntax/tests/printer/expr/expected/ToUncurried.res.txt diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a1bf3c39d..84fb5dc380 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ #### :rocket: New Feature - 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 -- Adding `@@toUncurried` to the file and reformat will convert to uncurried syntax https://github.com/rescript-lang/rescript-compiler/pull/5800 +- ~Adding `@@toUncurried` to the file and reformat will convert to uncurried syntax https://github.com/rescript-lang/rescript-compiler/pull/5800~ - Add support for unary uncurried pipe in uncurried mode https://github.com/rescript-lang/rescript-compiler/pull/5804 - Add support for partial application of uncurried functions: with uncurried application one can provide a subset of the arguments, and return a curried type with the remaining ones https://github.com/rescript-lang/rescript-compiler/pull/5805 diff --git a/res_syntax/src/res_core.ml b/res_syntax/src/res_core.ml index 3d83e7355b..6908af68cc 100644 --- a/res_syntax/src/res_core.ml +++ b/res_syntax/src/res_core.ml @@ -6414,7 +6414,6 @@ and parseStandaloneAttribute p = | "uncurriedAlways" -> p.uncurried_config <- Res_uncurried.Always; attrId - | "toUncurried" -> {attrId with txt = "uncurried.swap"} | _ -> attrId in let payload = parsePayload p in diff --git a/res_syntax/src/res_printer.ml b/res_syntax/src/res_printer.ml index fe66f737d6..e881021a6b 100644 --- a/res_syntax/src/res_printer.ml +++ b/res_syntax/src/res_printer.ml @@ -5282,9 +5282,6 @@ and printAttribute ?(standalone = false) ~state | "uncurriedAlways" -> state.uncurried_config <- Res_uncurried.Always; id - | "toUncurried" -> - state.uncurried_config <- Res_uncurried.Swap; - {id with txt = "uncurried.swap"} | _ -> id in ( Doc.group diff --git a/res_syntax/tests/printer/expr/ToUncurried.res b/res_syntax/tests/printer/expr/ToUncurried.res deleted file mode 100644 index 0b704a150e..0000000000 --- a/res_syntax/tests/printer/expr/ToUncurried.res +++ /dev/null @@ -1,35 +0,0 @@ -let cApp = foo(3) -let uApp = foo(. 3) - -let cFun = x => 3 -let uFun = (.x) => 3 -let mixFun = (a, .b, c) => (d, e, f) => (g, .h) => 4 -let bracesFun = (. x) => y => x+y -let cFun2 = (x, y) => 3 -let uFun2 = (. x, y) => 3 - -type cTyp = string => int -type uTyp = (. string) => int -type mixTyp = (string, .string, string) => (string, string, string) => (string, .string) => int -type bTyp = (. string) => string => int -type cTyp2 = (string, string) => int -type uTyp2 = (.string, string) => int - -@@toUncurried - -let cApp = foo(3) -let uApp = foo(. 3) - -let cFun = x => 3 -let uFun = (.x) => 3 -let mixFun = (a, .b, c) => (d, e, f) => (g, .h) => 4 -let bracesFun = (. x) => y => x+y -let cFun2 = (x, y) => 3 -let uFun2 = (. x, y) => 3 - -type cTyp = string => int -type uTyp = (. string) => int -type mixTyp = (string, .string, string) => (string, string, string) => (string, .string) => int -type bTyp = (. string) => string => int -type cTyp2 = (string, string) => int -type uTyp2 = (.string, string) => int diff --git a/res_syntax/tests/printer/expr/expected/ToUncurried.res.txt b/res_syntax/tests/printer/expr/expected/ToUncurried.res.txt deleted file mode 100644 index 8a84eef5e4..0000000000 --- a/res_syntax/tests/printer/expr/expected/ToUncurried.res.txt +++ /dev/null @@ -1,35 +0,0 @@ -let cApp = foo(3) -let uApp = foo(. 3) - -let cFun = x => 3 -let uFun = (. x) => 3 -let mixFun = a => (. b, c) => {(d, e, f, g) => (. h) => 4} -let bracesFun = (. x) => {y => x + y} -let cFun2 = (x, y) => 3 -let uFun2 = (. x, y) => 3 - -type cTyp = string => int -type uTyp = (. string) => int -type mixTyp = string => (. string, string) => (string, string, string, string) => (. string) => int -type bTyp = (. string) => string => int -type cTyp2 = (string, string) => int -type uTyp2 = (. string, string) => int - -@@uncurried.swap - -let cApp = foo(. 3) -let uApp = foo(3) - -let cFun = (. x) => 3 -let uFun = x => 3 -let mixFun = (. a) => (b, c) => {(. d, e, f, g) => h => 4} -let bracesFun = x => {(. y) => x + y} -let cFun2 = (. x, y) => 3 -let uFun2 = (x, y) => 3 - -type cTyp = (. string) => int -type uTyp = string => int -type mixTyp = (. string) => (string, string) => (. string, string, string, string) => string => int -type bTyp = string => (. string) => int -type cTyp2 = (. string, string) => int -type uTyp2 = (string, string) => int From 3c634f4d511706b678a8305f8b1b7e7dc270001d Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 16 Mar 2023 17:48:04 +0100 Subject: [PATCH 3/7] Update CHANGELOG.md --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 84fb5dc380..286b981f9e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,7 +14,7 @@ #### :rocket: New Feature -- 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 +- 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 - ~Adding `@@toUncurried` to the file and reformat will convert to uncurried syntax https://github.com/rescript-lang/rescript-compiler/pull/5800~ - Add support for unary uncurried pipe in uncurried mode https://github.com/rescript-lang/rescript-compiler/pull/5804 - Add support for partial application of uncurried functions: with uncurried application one can provide a @@ -24,7 +24,7 @@ subset of the arguments, and return a curried type with the remaining ones https - Add support for default arguments in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5835 - Inline uncurried application when it is safe https://github.com/rescript-lang/rescript-compiler/pull/5847 - Support optional named arguments without a final unit in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5907 -- 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. +- 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 boolean project config `"uncurried"`, which propagates to dependencies, to turn on uncurried mode. 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. Use best effort to determine the config when formatting a file. https://github.com/rescript-lang/rescript-compiler/pull/5968 From a296670652f26dd3711f6fc9fe5e59305722ca2c Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 16 Mar 2023 17:54:47 +0100 Subject: [PATCH 4/7] Rename `@@uncurried.always` to simply `@@uncurried`. --- CHANGELOG.md | 2 +- jscomp/frontend/ast_config.ml | 2 +- jscomp/stdlib-406/pervasivesU.res | 2 +- jscomp/stdlib-406/pervasivesU.resi | 2 +- jscomp/test/UncurriedAlways.res | 2 +- jscomp/test/UncurriedPervasives.res | 2 +- res_syntax/src/res_core.ml | 4 ++-- res_syntax/src/res_multi_printer.ml | 12 ++++++------ res_syntax/src/res_printer.ml | 4 ++-- res_syntax/src/res_uncurried.ml | 8 ++++---- .../parsing/grammar/expressions/UncurriedAlways.res | 2 +- .../expressions/expected/UncurriedAlways.res.txt | 2 +- 12 files changed, 22 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 286b981f9e..5cddcd6feb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,7 +24,7 @@ subset of the arguments, and return a curried type with the remaining ones https - Add support for default arguments in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5835 - Inline uncurried application when it is safe https://github.com/rescript-lang/rescript-compiler/pull/5847 - Support optional named arguments without a final unit in uncurried functions https://github.com/rescript-lang/rescript-compiler/pull/5907 -- 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 boolean project config `"uncurried"`, which propagates to dependencies, to turn on uncurried mode. +- 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. 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. Use best effort to determine the config when formatting a file. https://github.com/rescript-lang/rescript-compiler/pull/5968 diff --git a/jscomp/frontend/ast_config.ml b/jscomp/frontend/ast_config.ml index 053ed4d079..40e9bf6b83 100644 --- a/jscomp/frontend/ast_config.ml +++ b/jscomp/frontend/ast_config.ml @@ -44,7 +44,7 @@ let process_directives str = | Pstr_attribute ({ txt = "directive" }, PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) -> Js_config.directives := !Js_config.directives @ [d] - | Pstr_attribute ({txt = "uncurriedAlways"}, _) -> Config.use_automatic_curried_application := true + | Pstr_attribute ({txt = "uncurried"}, _) -> Config.use_automatic_curried_application := true | _ -> ()) let rec iter_on_bs_config_str (x : Parsetree.structure) = diff --git a/jscomp/stdlib-406/pervasivesU.res b/jscomp/stdlib-406/pervasivesU.res index 38648bd2dc..314c9f08a4 100644 --- a/jscomp/stdlib-406/pervasivesU.res +++ b/jscomp/stdlib-406/pervasivesU.res @@ -13,7 +13,7 @@ /* */ /* ************************************************************************ */ -@@uncurriedAlways +@@uncurried /* Internal */ external __unsafe_cast: 'a => 'b = "%identity" diff --git a/jscomp/stdlib-406/pervasivesU.resi b/jscomp/stdlib-406/pervasivesU.resi index 37466a4842..948cb486ab 100644 --- a/jscomp/stdlib-406/pervasivesU.resi +++ b/jscomp/stdlib-406/pervasivesU.resi @@ -13,7 +13,7 @@ /* */ /* ************************************************************************ */ -@@uncurriedAlways +@@uncurried " The initially opened module. diff --git a/jscomp/test/UncurriedAlways.res b/jscomp/test/UncurriedAlways.res index 289dd96fe9..63d8e25899 100644 --- a/jscomp/test/UncurriedAlways.res +++ b/jscomp/test/UncurriedAlways.res @@ -1,4 +1,4 @@ -@@uncurriedAlways +@@uncurried let foo = (x, y) => x + y diff --git a/jscomp/test/UncurriedPervasives.res b/jscomp/test/UncurriedPervasives.res index 95abc78a9c..5edc7ad770 100644 --- a/jscomp/test/UncurriedPervasives.res +++ b/jscomp/test/UncurriedPervasives.res @@ -1,2 +1,2 @@ -@@uncurriedAlways +@@uncurried let n : _ => unit = ignore // Check that we're pulling in uncurried pervasives diff --git a/res_syntax/src/res_core.ml b/res_syntax/src/res_core.ml index 6908af68cc..ab0b39c2e3 100644 --- a/res_syntax/src/res_core.ml +++ b/res_syntax/src/res_core.ml @@ -6411,8 +6411,8 @@ and parseStandaloneAttribute p = | "uncurried.swap" -> p.uncurried_config <- Res_uncurried.Swap; attrId - | "uncurriedAlways" -> - p.uncurried_config <- Res_uncurried.Always; + | "uncurried" -> + p.uncurried_config <- Res_uncurried.Uncurried; attrId | _ -> attrId in diff --git a/res_syntax/src/res_multi_printer.ml b/res_syntax/src/res_multi_printer.ml index eef59576e3..2736c2ed61 100644 --- a/res_syntax/src/res_multi_printer.ml +++ b/res_syntax/src/res_multi_printer.ml @@ -1,8 +1,8 @@ let defaultPrintWidth = 100 -(* Determine if the file is in uncurried-always mode by looking for - the fist ancestor .bsconfig and see if it contains "uncurry": "default" *) -let getUncurriedAlwaysFromBsconfig ~filename = +(* Determine if the file is in uncurried mode by looking for + the fist ancestor .bsconfig and see if it contains "uncurried": "true" *) +let getUncurriedFromBsconfig ~filename = let rec findBsconfig ~dir = let bsconfig = Filename.concat dir "bsconfig.json" in if Sys.file_exists bsconfig then Some (Res_io.readFile ~filename:bsconfig) @@ -38,18 +38,18 @@ let getUncurriedAlwaysFromBsconfig ~filename = | None -> () | Some bsconfig -> let lines = bsconfig |> String.split_on_char '\n' in - let uncurriedAlways = + let uncurried = lines |> List.exists (fun line -> let words = line |> String.split_on_char '\"' in words |> List.exists (fun word -> word = "uncurried") && words |> List.exists (fun word -> word = "true")) in - if uncurriedAlways then Res_uncurried.init := Always + if uncurried then Res_uncurried.init := Uncurried (* print res files to res syntax *) let printRes ~ignoreParseErrors ~isInterface ~filename = - getUncurriedAlwaysFromBsconfig ~filename; + getUncurriedFromBsconfig ~filename; if isInterface then ( let parseResult = Res_driver.parsingEngine.parseInterface ~forPrinter:true ~filename diff --git a/res_syntax/src/res_printer.ml b/res_syntax/src/res_printer.ml index e881021a6b..034e8a9143 100644 --- a/res_syntax/src/res_printer.ml +++ b/res_syntax/src/res_printer.ml @@ -5279,8 +5279,8 @@ and printAttribute ?(standalone = false) ~state | "uncurried.swap" -> state.uncurried_config <- Res_uncurried.Swap; id - | "uncurriedAlways" -> - state.uncurried_config <- Res_uncurried.Always; + | "uncurried" -> + state.uncurried_config <- Res_uncurried.Uncurried; id | _ -> id in diff --git a/res_syntax/src/res_uncurried.ml b/res_syntax/src/res_uncurried.ml index 7a5f0f75b9..5239f1cd0c 100644 --- a/res_syntax/src/res_uncurried.ml +++ b/res_syntax/src/res_uncurried.ml @@ -1,20 +1,20 @@ -type config = Legacy | Swap | Always +type config = Legacy | Swap | Uncurried let init = ref Legacy let isSwap = function | Legacy -> false | Swap -> true - | Always -> true + | Uncurried -> true (* For parsing *) let fromDotted ~dotted = function | Legacy -> dotted | Swap -> not dotted - | Always -> true + | Uncurried -> true (* For printing *) let getDotted ~uncurried = function | Legacy -> uncurried | Swap -> not uncurried - | Always -> false + | Uncurried -> false diff --git a/res_syntax/tests/parsing/grammar/expressions/UncurriedAlways.res b/res_syntax/tests/parsing/grammar/expressions/UncurriedAlways.res index b11e027327..9ddd985431 100644 --- a/res_syntax/tests/parsing/grammar/expressions/UncurriedAlways.res +++ b/res_syntax/tests/parsing/grammar/expressions/UncurriedAlways.res @@ -1,4 +1,4 @@ -@@uncurriedAlways +@@uncurried let foo = (x, y) => x + y diff --git a/res_syntax/tests/parsing/grammar/expressions/expected/UncurriedAlways.res.txt b/res_syntax/tests/parsing/grammar/expressions/expected/UncurriedAlways.res.txt index a7778c95ed..da666964db 100644 --- a/res_syntax/tests/parsing/grammar/expressions/expected/UncurriedAlways.res.txt +++ b/res_syntax/tests/parsing/grammar/expressions/expected/UncurriedAlways.res.txt @@ -1,4 +1,4 @@ -[@@@uncurriedAlways ] +[@@@uncurried ] let foo = ((Function$ (fun x -> fun y -> x + y))[@res.arity 2]) let z = ((foo 3 4)[@res.uapp ]) let bar = ((Function$ (fun x -> fun y -> x + y))[@res.arity 2]) From 254b5da034657cb6a7e601ec0ac2d0f600ea362e Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 16 Mar 2023 20:28:29 +0100 Subject: [PATCH 5/7] 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). --- jscomp/bsc/rescript_compiler_main.ml | 8 ++++++-- jscomp/core/res_compmisc.ml | 2 +- jscomp/ext/config.ml | 3 ++- jscomp/ext/config.mli | 3 ++- jscomp/frontend/ast_config.ml | 2 +- jscomp/ml/ctype.ml | 2 +- jscomp/ml/typecore.ml | 2 +- res_syntax/src/res_core.ml | 4 ++-- res_syntax/src/res_multi_printer.ml | 2 +- res_syntax/src/res_parser.ml | 4 ++-- res_syntax/src/res_parser.mli | 2 +- res_syntax/src/res_printer.ml | 8 ++++---- res_syntax/src/res_uncurried.ml | 10 +++------- 13 files changed, 27 insertions(+), 25 deletions(-) diff --git a/jscomp/bsc/rescript_compiler_main.ml b/jscomp/bsc/rescript_compiler_main.ml index 224b3268fb..4df293ca7a 100644 --- a/jscomp/bsc/rescript_compiler_main.ml +++ b/jscomp/bsc/rescript_compiler_main.ml @@ -51,11 +51,12 @@ let process_file sourcefile ?(kind ) ppf = The {!Location.input_name} relies on that we write the binary ast properly *) + let uncurried = !Config.uncurried in let kind = match kind with | None -> Ext_file_extensions.classify_input (Ext_filename.get_extension_maybe sourcefile) | Some kind -> kind in - match kind with + let res = match kind with | Ml -> let sourcefile = set_abs_input_name sourcefile in setup_compiler_printer `ml; @@ -103,6 +104,9 @@ let process_file sourcefile ?(kind ) ppf = Format.pp_print_newline Format.std_formatter () | Unknown -> Bsc_args.bad_arg ("don't know what to do with " ^ sourcefile) + in + Config.uncurried := uncurried; + res let usage = "Usage: bsc \nOptions are:" let ppf = Format.err_formatter @@ -406,7 +410,7 @@ let buckle_script_flags : (string * Bsc_args.spec * string) array = "-nopervasives", set Clflags.nopervasives, "*internal*"; - "-uncurried", unit_call (fun () -> Res_uncurried.init := Swap; Config.use_automatic_curried_application := true), + "-uncurried", unit_call (fun () -> Config.uncurried := Uncurried), "*internal* Set jsx module"; "-v", unit_call print_version_string, "Print compiler version and location of standard library and exit"; diff --git a/jscomp/core/res_compmisc.ml b/jscomp/core/res_compmisc.ml index 24e447ee27..a4ea829f23 100644 --- a/jscomp/core/res_compmisc.ml +++ b/jscomp/core/res_compmisc.ml @@ -46,7 +46,7 @@ let initial_env () = let initial = Env.initial_safe_string in let env = if !Clflags.nopervasives then initial - else open_implicit_module (if !Config.use_automatic_curried_application then "PervasivesU" else "Pervasives") initial + else open_implicit_module (if !Config.uncurried = Uncurried then "PervasivesU" else "Pervasives") initial in List.fold_left (fun env m -> open_implicit_module m env) diff --git a/jscomp/ext/config.ml b/jscomp/ext/config.ml index 2b181a608f..35040eaa5a 100644 --- a/jscomp/ext/config.ml +++ b/jscomp/ext/config.ml @@ -13,7 +13,8 @@ let bs_only = ref true let unsafe_empty_array = ref false -let use_automatic_curried_application = ref false +type uncurried = Legacy | Uncurried | Swap +let uncurried = ref Legacy and cmi_magic_number = "Caml1999I022" diff --git a/jscomp/ext/config.mli b/jscomp/ext/config.mli index 3c3a78fd64..d409fe0b60 100644 --- a/jscomp/ext/config.mli +++ b/jscomp/ext/config.mli @@ -47,4 +47,5 @@ val cmt_magic_number : string val print_config : out_channel -> unit -val use_automatic_curried_application : bool ref \ No newline at end of file +type uncurried = Legacy | Uncurried | Swap +val uncurried : uncurried ref \ No newline at end of file diff --git a/jscomp/frontend/ast_config.ml b/jscomp/frontend/ast_config.ml index 40e9bf6b83..8dea9688ec 100644 --- a/jscomp/frontend/ast_config.ml +++ b/jscomp/frontend/ast_config.ml @@ -44,7 +44,7 @@ let process_directives str = | Pstr_attribute ({ txt = "directive" }, PStr [ { pstr_desc = Pstr_eval ({ pexp_desc = Pexp_constant (Pconst_string (d, _)) }, _) } ]) -> Js_config.directives := !Js_config.directives @ [d] - | Pstr_attribute ({txt = "uncurried"}, _) -> Config.use_automatic_curried_application := true + | Pstr_attribute ({txt = "uncurried"}, _) -> Config.uncurried := Uncurried | _ -> ()) let rec iter_on_bs_config_str (x : Parsetree.structure) = diff --git a/jscomp/ml/ctype.ml b/jscomp/ml/ctype.ml index c74fa9f57b..dbe6a27efc 100644 --- a/jscomp/ml/ctype.ml +++ b/jscomp/ml/ctype.ml @@ -2341,7 +2341,7 @@ let rec unify (env:Env.t ref) t1 t2 = with Cannot_expand -> unify2 env t1 t2 end - | (Tconstr (Pident {name="function$"}, [tFun; _], _), Tarrow _) when !Config.use_automatic_curried_application -> + | (Tconstr (Pident {name="function$"}, [tFun; _], _), Tarrow _) when !Config.uncurried = Uncurried -> (* subtype: an uncurried function is cast to a curried one *) unify2 env tFun t2 | _ -> diff --git a/jscomp/ml/typecore.ml b/jscomp/ml/typecore.ml index c0cd6e1312..e9aea7c5ff 100644 --- a/jscomp/ml/typecore.ml +++ b/jscomp/ml/typecore.ml @@ -2980,7 +2980,7 @@ and type_argument ?recarg env sarg ty_expected' ty_expected = texp and is_automatic_curried_application env funct = (* When a curried function is used with uncurried application, treat it as a curried application *) - !Config.use_automatic_curried_application && + !Config.uncurried = Uncurried && match (expand_head env funct.exp_type).desc with | Tarrow _ -> true | _ -> false diff --git a/res_syntax/src/res_core.ml b/res_syntax/src/res_core.ml index ab0b39c2e3..0669e3571a 100644 --- a/res_syntax/src/res_core.ml +++ b/res_syntax/src/res_core.ml @@ -6409,10 +6409,10 @@ and parseStandaloneAttribute p = let attrId = match attrId.txt with | "uncurried.swap" -> - p.uncurried_config <- Res_uncurried.Swap; + p.uncurried_config <- Config.Swap; attrId | "uncurried" -> - p.uncurried_config <- Res_uncurried.Uncurried; + p.uncurried_config <- Config.Uncurried; attrId | _ -> attrId in diff --git a/res_syntax/src/res_multi_printer.ml b/res_syntax/src/res_multi_printer.ml index 2736c2ed61..58314749fe 100644 --- a/res_syntax/src/res_multi_printer.ml +++ b/res_syntax/src/res_multi_printer.ml @@ -45,7 +45,7 @@ let getUncurriedFromBsconfig ~filename = words |> List.exists (fun word -> word = "uncurried") && words |> List.exists (fun word -> word = "true")) in - if uncurried then Res_uncurried.init := Uncurried + if uncurried then Config.uncurried := Uncurried (* print res files to res syntax *) let printRes ~ignoreParseErrors ~isInterface ~filename = diff --git a/res_syntax/src/res_parser.ml b/res_syntax/src/res_parser.ml index ec9a392a9c..ca39cfcf84 100644 --- a/res_syntax/src/res_parser.ml +++ b/res_syntax/src/res_parser.ml @@ -22,7 +22,7 @@ type t = { mutable diagnostics: Diagnostics.t list; mutable comments: Comment.t list; mutable regions: regionStatus ref list; - mutable uncurried_config: Res_uncurried.config; + mutable uncurried_config: Config.uncurried; } let err ?startPos ?endPos p error = @@ -122,7 +122,7 @@ let make ?(mode = ParseForTypeChecker) src filename = diagnostics = []; comments = []; regions = [ref Report]; - uncurried_config = !Res_uncurried.init; + uncurried_config = !Config.uncurried; } in parserState.scanner.err <- diff --git a/res_syntax/src/res_parser.mli b/res_syntax/src/res_parser.mli index 8a00c722e2..9544a7cc28 100644 --- a/res_syntax/src/res_parser.mli +++ b/res_syntax/src/res_parser.mli @@ -21,7 +21,7 @@ type t = { mutable diagnostics: Diagnostics.t list; mutable comments: Comment.t list; mutable regions: regionStatus ref list; - mutable uncurried_config: Res_uncurried.config; + mutable uncurried_config: Config.uncurried; } val make : ?mode:mode -> string -> string -> t diff --git a/res_syntax/src/res_printer.ml b/res_syntax/src/res_printer.ml index 034e8a9143..93a6bd9023 100644 --- a/res_syntax/src/res_printer.ml +++ b/res_syntax/src/res_printer.ml @@ -575,9 +575,9 @@ let printOptionalLabel attrs = module State = struct let customLayoutThreshold = 2 - type t = {customLayout: int; mutable uncurried_config: Res_uncurried.config} + type t = {customLayout: int; mutable uncurried_config: Config.uncurried} - let init () = {customLayout = 0; uncurried_config = !Res_uncurried.init} + let init () = {customLayout = 0; uncurried_config = !Config.uncurried} let nextCustomLayout t = {t with customLayout = t.customLayout + 1} @@ -5277,10 +5277,10 @@ and printAttribute ?(standalone = false) ~state let id = match id.txt with | "uncurried.swap" -> - state.uncurried_config <- Res_uncurried.Swap; + state.uncurried_config <- Config.Swap; id | "uncurried" -> - state.uncurried_config <- Res_uncurried.Uncurried; + state.uncurried_config <- Config.Uncurried; id | _ -> id in diff --git a/res_syntax/src/res_uncurried.ml b/res_syntax/src/res_uncurried.ml index 5239f1cd0c..0af31b1fda 100644 --- a/res_syntax/src/res_uncurried.ml +++ b/res_syntax/src/res_uncurried.ml @@ -1,20 +1,16 @@ -type config = Legacy | Swap | Uncurried - -let init = ref Legacy - let isSwap = function - | Legacy -> false + | Config.Legacy -> false | Swap -> true | Uncurried -> true (* For parsing *) let fromDotted ~dotted = function - | Legacy -> dotted + | Config.Legacy -> dotted | Swap -> not dotted | Uncurried -> true (* For printing *) let getDotted ~uncurried = function - | Legacy -> uncurried + | Config.Legacy -> uncurried | Swap -> not uncurried | Uncurried -> false From 1aaae745f9ec51a72d527791137a69a55b7457c0 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Thu, 16 Mar 2023 20:39:42 +0100 Subject: [PATCH 6/7] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5cddcd6feb..bc6c641e3d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ subset of the arguments, and return a curried type with the remaining ones https - 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. 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. Use best effort to determine the config when formatting a file. -https://github.com/rescript-lang/rescript-compiler/pull/5968 +https://github.com/rescript-lang/rescript-compiler/pull/5968 https://github.com/rescript-lang/rescript-compiler/pull/6080 #### :boom: Breaking Change From 04f2c2ce892d16ff1b64b1c94af7325ee0566422 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Fri, 17 Mar 2023 07:45:35 +0100 Subject: [PATCH 7/7] Clean up isSwap --- res_syntax/src/res_core.ml | 28 +++++++++------------------- res_syntax/src/res_uncurried.ml | 5 ----- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/res_syntax/src/res_core.ml b/res_syntax/src/res_core.ml index 0669e3571a..ca3dc4275e 100644 --- a/res_syntax/src/res_core.ml +++ b/res_syntax/src/res_core.ml @@ -386,7 +386,7 @@ let buildLongident words = let makeInfixOperator (p : Parser.t) token startPos endPos = let stringifiedToken = if token = Token.MinusGreater then - if p.uncurried_config |> Res_uncurried.isSwap then "|.u" else "|." + if p.uncurried_config = Legacy then "|." else "|.u" else if token = Token.PlusPlus then "^" else if token = Token.BangEqual then "<>" else if token = Token.BangEqualEqual then "!=" @@ -1558,8 +1558,7 @@ and parseEs6ArrowExpression ?(arrowAttrs = []) ?(arrowStartPos = None) ?context | TermParameter {dotted} :: _ when p.uncurried_config |> Res_uncurried.fromDotted ~dotted && isFun -> true - | TermParameter _ :: rest - when (not (p.uncurried_config |> Res_uncurried.isSwap)) && isFun -> + | TermParameter _ :: rest when p.uncurried_config = Legacy && isFun -> rest |> List.exists (function | TermParameter {dotted} -> dotted @@ -1594,11 +1593,7 @@ and parseEs6ArrowExpression ?(arrowAttrs = []) ?(arrowStartPos = None) ?context let uncurried = p.uncurried_config |> Res_uncurried.fromDotted ~dotted in - if - uncurried - && (termParamNum = 1 - || not (p.uncurried_config |> Res_uncurried.isSwap)) - then + if uncurried && (termParamNum = 1 || p.uncurried_config = Legacy) then (termParamNum - 1, Ast_uncurried.uncurriedFun ~loc ~arity funExpr, 1) else (termParamNum - 1, funExpr, arity + 1) | TypeParameter {dotted = _; attrs; locs = newtypes; pos = startPos} -> @@ -3922,9 +3917,8 @@ and parsePolyTypeExpr p = let returnType = parseTypExpr ~alias:false p in let loc = mkLoc typ.Parsetree.ptyp_loc.loc_start p.prevEndPos in let tFun = Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType in - if p.uncurried_config |> Res_uncurried.isSwap then - Ast_uncurried.uncurriedType ~loc ~arity:1 tFun - else tFun + if p.uncurried_config = Legacy then tFun + else Ast_uncurried.uncurriedType ~loc ~arity:1 tFun | _ -> Ast_helper.Typ.var ~loc:var.loc var.txt) | _ -> assert false) | _ -> parseTypExpr p @@ -4252,7 +4246,7 @@ and parseEs6ArrowType ~attrs p = let endPos = p.prevEndPos in let returnTypeArity = match parameters with - | _ when p.uncurried_config |> Res_uncurried.isSwap -> 0 + | _ when p.uncurried_config <> Legacy -> 0 | _ -> if parameters |> List.exists (function {dotted; typ = _} -> dotted) then 0 @@ -4266,10 +4260,7 @@ and parseEs6ArrowType ~attrs p = let uncurried = p.uncurried_config |> Res_uncurried.fromDotted ~dotted in - if - uncurried - && (paramNum = 1 || not (p.uncurried_config |> Res_uncurried.isSwap)) - then + if uncurried && (paramNum = 1 || p.uncurried_config = Legacy) then let loc = mkLoc startPos endPos in let tArg = Ast_helper.Typ.arrow ~loc ~attrs argLbl typ t in (paramNum - 1, Ast_uncurried.uncurriedType ~loc ~arity tArg, 1) @@ -4334,9 +4325,8 @@ and parseArrowTypeRest ~es6Arrow ~startPos typ p = let returnType = parseTypExpr ~alias:false p in let loc = mkLoc startPos p.prevEndPos in let arrowTyp = Ast_helper.Typ.arrow ~loc Asttypes.Nolabel typ returnType in - if p.uncurried_config |> Res_uncurried.isSwap then - Ast_uncurried.uncurriedType ~loc ~arity:1 arrowTyp - else arrowTyp + if p.uncurried_config = Legacy then arrowTyp + else Ast_uncurried.uncurriedType ~loc ~arity:1 arrowTyp | _ -> typ and parseTypExprRegion p = diff --git a/res_syntax/src/res_uncurried.ml b/res_syntax/src/res_uncurried.ml index 0af31b1fda..1a777e1599 100644 --- a/res_syntax/src/res_uncurried.ml +++ b/res_syntax/src/res_uncurried.ml @@ -1,8 +1,3 @@ -let isSwap = function - | Config.Legacy -> false - | Swap -> true - | Uncurried -> true - (* For parsing *) let fromDotted ~dotted = function | Config.Legacy -> dotted