From 8ff4713bcf124f891932ca25d8b4c02cff712c60 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 10 Dec 2024 09:03:32 +0100 Subject: [PATCH 1/6] Represent the arity of uncurried function definitions directly in the AST. --- analysis/src/CompletionFrontEnd.ml | 2 +- analysis/src/DumpAst.ml | 2 +- analysis/src/Xform.ml | 6 +- compiler/frontend/ast_compatible.ml | 4 +- compiler/frontend/ast_compatible.mli | 7 +- compiler/frontend/ast_derive_js_mapper.ml | 6 +- compiler/frontend/ast_derive_projector.ml | 6 +- compiler/frontend/ast_pat.ml | 4 +- compiler/frontend/ast_uncurry_gen.ml | 4 +- compiler/frontend/bs_ast_mapper.ml | 4 +- compiler/frontend/bs_builtin_ppx.ml | 4 +- compiler/ml/ast_async.ml | 6 +- compiler/ml/ast_helper.ml | 3 +- compiler/ml/ast_helper.mli | 1 + compiler/ml/ast_iterator.ml | 2 +- compiler/ml/ast_mapper.ml | 4 +- compiler/ml/ast_mapper_from0.ml | 40 +- compiler/ml/ast_mapper_to0.ml | 29 +- compiler/ml/ast_uncurried.ml | 42 +- compiler/ml/depend.ml | 2 +- compiler/ml/parsetree.ml | 3 +- compiler/ml/pprintast.ml | 22 +- compiler/ml/printast.ml | 7 +- compiler/ml/typecore.ml | 13 +- compiler/ml/untypeast.ml | 7 +- compiler/syntax/src/jsx_v4.ml | 53 +- compiler/syntax/src/res_ast_debugger.ml | 2 +- compiler/syntax/src/res_comments_table.ml | 14 +- compiler/syntax/src/res_core.ml | 11 +- compiler/syntax/src/res_parsetree_viewer.ml | 25 +- compiler/syntax/src/res_printer.ml | 6 +- scripts/test_syntax.sh | 2 +- .../errors/expressions/expected/array.res.txt | 3 +- .../errors/expressions/expected/arrow.res.txt | 8 +- .../errors/expressions/expected/block.res.txt | 39 +- .../expressions/expected/consecutive.res.txt | 6 +- .../expressions/expected/emptyBlock.res.txt | 2 +- .../expected/implementation.res.txt | 5 +- .../other/expected/labelledParameters.res.txt | 14 +- .../errors/structure/expected/gh16B.res.txt | 26 +- .../structure/expected/letBinding.res.txt | 4 +- .../typeDef/expected/inlineRecord.res.txt | 15 +- .../typexpr/expected/objectSpread.res.txt | 2 +- .../expected/UncurriedAlways.res.txt | 4 +- .../expected/UncurriedByDefault.res.txt | 113 ++- .../expressions/expected/apply.res.txt | 17 +- .../expressions/expected/argument.res.txt | 14 +- .../expressions/expected/arrow.res.txt | 239 +++--- .../expressions/expected/async.res.txt | 42 +- .../expressions/expected/await.res.txt | 20 +- .../expressions/expected/binary.res.txt | 3 +- .../expected/binaryNoEs6Arrow.res.txt | 7 +- .../expressions/expected/block.res.txt | 90 +-- .../expected/bracedOrRecord.res.txt | 22 +- .../expressions/expected/coerce.res.txt | 4 +- .../expressions/expected/extension.res.txt | 2 +- .../expected/firstClassModule.res.txt | 93 ++- .../grammar/expressions/expected/jsx.res.txt | 207 ++--- .../expected/locallyAbstractTypes.res.txt | 40 +- .../expressions/expected/record.res.txt | 8 +- .../expected/tupleVsDivision.res.txt | 7 +- .../expressions/expected/uncurried.res.txt | 50 +- .../expected/underscoreApply.res.txt | 52 +- .../grammar/modexpr/expected/apply.res.txt | 7 +- .../expected/firstClassModules.res.txt | 22 +- .../grammar/modexpr/expected/functor.res.txt | 19 +- .../grammar/pattern/expected/any.res.txt | 14 +- .../grammar/pattern/expected/array.res.txt | 10 +- .../grammar/pattern/expected/constant.res.txt | 45 +- .../pattern/expected/constructor.res.txt | 37 +- .../grammar/pattern/expected/dict.res.txt | 45 +- .../pattern/expected/exception.res.txt | 16 +- .../pattern/expected/extension.res.txt | 17 +- .../expected/firstClassModules.res.txt | 32 +- .../grammar/pattern/expected/list.res.txt | 34 +- .../pattern/expected/polyvariants.res.txt | 65 +- .../grammar/pattern/expected/record.res.txt | 40 +- .../grammar/pattern/expected/tuple.res.txt | 17 +- .../grammar/pattern/expected/unit.res.txt | 20 +- .../pattern/expected/variantSpreads.res.txt | 91 +-- .../grammar/pattern/expected/variants.res.txt | 34 +- .../signature/expected/itemExtension.res.txt | 2 +- .../expected/standAloneAttribute.res.txt | 2 +- .../structure/expected/itemExtension.res.txt | 2 +- .../structure/expected/letBinding.res.txt | 14 +- .../expected/modExprExtension.res.txt | 3 +- .../expected/moduleTypeExtension.res.txt | 2 +- .../expected/standaloneAttribute.res.txt | 2 +- .../expected/polyvariant.res.txt | 2 +- .../expected/objectTypeSpreading.res.txt | 29 +- .../typexpr/expected/typeconstr.res.txt | 2 +- .../grammar/typexpr/expected/unit.res.txt | 14 +- .../expected/equalAfterBinaryExpr.res.txt | 285 ++++--- .../expected/nonRecTypes.res.txt | 739 +++++++++--------- .../expected/templateEof.res.txt | 7 +- .../expression/expected/emptyBlock.res.txt | 2 +- .../recovery/expression/expected/list.res.txt | 19 +- .../expr/expected/underscoreApply.res.txt | 2 +- tests/tools_tests/ppx/TestPpx.res | 6 + .../src/expected/TestPpx.res.jsout | 17 + 100 files changed, 1616 insertions(+), 1601 deletions(-) diff --git a/analysis/src/CompletionFrontEnd.ml b/analysis/src/CompletionFrontEnd.ml index 8cae05d0ca..6337c0b5bb 100644 --- a/analysis/src/CompletionFrontEnd.ml +++ b/analysis/src/CompletionFrontEnd.ml @@ -1318,7 +1318,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor match exprToContextPath lhs with | Some contextPath -> setResult (Cpath (CPObj (contextPath, label))) | None -> ()) - | Pexp_fun (lbl, defaultExpOpt, pat, e) -> + | Pexp_fun (lbl, defaultExpOpt, pat, e, _) -> let oldScope = !scope in (match (!processingFun, !currentCtxPath) with | None, Some ctxPath -> processingFun := Some (ctxPath, 0) diff --git a/analysis/src/DumpAst.ml b/analysis/src/DumpAst.ml index 8e21853308..b7ad602f32 100644 --- a/analysis/src/DumpAst.ml +++ b/analysis/src/DumpAst.ml @@ -213,7 +213,7 @@ and printExprItem expr ~pos ~indentation = | None -> "" | Some expr -> "," ^ printExprItem expr ~pos ~indentation) ^ ")" - | Pexp_fun (arg, _maybeDefaultArgExpr, pattern, nextExpr) -> + | Pexp_fun (arg, _maybeDefaultArgExpr, pattern, nextExpr, _) -> "Pexp_fun(\n" ^ addIndentation (indentation + 1) ^ "arg: " diff --git a/analysis/src/Xform.ml b/analysis/src/Xform.ml index b765e511c9..f2a91382b9 100644 --- a/analysis/src/Xform.ml +++ b/analysis/src/Xform.ml @@ -261,7 +261,7 @@ module AddBracesToFn = struct | _ -> false in (match e.pexp_desc with - | Pexp_fun (_, _, _, bodyExpr) + | Pexp_fun (_, _, _, bodyExpr, _) when Loc.hasPos ~pos bodyExpr.pexp_loc && isBracedExpr bodyExpr = false && isFunction bodyExpr = false -> @@ -303,10 +303,10 @@ module AddTypeAnnotation = struct in let rec processFunction ~argNum (e : Parsetree.expression) = match e.pexp_desc with - | Pexp_fun (argLabel, _, pat, e) + | Pexp_fun (argLabel, _, pat, e, _) | Pexp_construct ( {txt = Lident "Function$"}, - Some {pexp_desc = Pexp_fun (argLabel, _, pat, e)} ) -> + Some {pexp_desc = Pexp_fun (argLabel, _, pat, e, _)} ) -> let isUnlabeledOnlyArg = argNum = 1 && argLabel = Nolabel && diff --git a/compiler/frontend/ast_compatible.ml b/compiler/frontend/ast_compatible.ml index 338a66acc1..94170e4e40 100644 --- a/compiler/frontend/ast_compatible.ml +++ b/compiler/frontend/ast_compatible.ml @@ -63,11 +63,11 @@ let app3 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 arg3 : expression = Pexp_apply (fn, [(Nolabel, arg1); (Nolabel, arg2); (Nolabel, arg3)]); } -let fun_ ?(loc = default_loc) ?(attrs = []) pat exp = +let fun_ ?(loc = default_loc) ?(attrs = []) ~arity pat exp = { pexp_loc = loc; pexp_attributes = attrs; - pexp_desc = Pexp_fun (Nolabel, None, pat, exp); + pexp_desc = Pexp_fun (Nolabel, None, pat, exp, arity); } let const_exp_string ?(loc = default_loc) ?(attrs = []) ?delimiter (s : string) diff --git a/compiler/frontend/ast_compatible.mli b/compiler/frontend/ast_compatible.mli index 8bda0e0275..e2b68f601e 100644 --- a/compiler/frontend/ast_compatible.mli +++ b/compiler/frontend/ast_compatible.mli @@ -72,7 +72,12 @@ val apply_labels : *) val fun_ : - ?loc:Location.t -> ?attrs:attrs -> pattern -> expression -> expression + ?loc:Location.t -> + ?attrs:attrs -> + arity:int option -> + pattern -> + expression -> + expression (* val opt_label : string -> Asttypes.arg_label *) diff --git a/compiler/frontend/ast_derive_js_mapper.ml b/compiler/frontend/ast_derive_js_mapper.ml index b845c43749..70f4babb77 100644 --- a/compiler/frontend/ast_derive_js_mapper.ml +++ b/compiler/frontend/ast_derive_js_mapper.ml @@ -167,7 +167,7 @@ let init () = in let to_js_body body = Ast_comb.single_non_rec_value pat_to_js - (Ast_compatible.fun_ + (Ast_compatible.fun_ ~arity:None (Pat.constraint_ (Pat.var pat_param) core_type) body) in @@ -211,7 +211,7 @@ let init () = in let from_js = Ast_comb.single_non_rec_value pat_from_js - (Ast_compatible.fun_ (Pat.var pat_param) + (Ast_compatible.fun_ ~arity:None (Pat.var pat_param) (if create_type then Exp.let_ Nonrecursive [Vb.mk (Pat.var pat_param) (exp_param +: new_type)] @@ -253,7 +253,7 @@ let init () = app2 unsafe_index_get_exp exp_map exp_param else app1 erase_type_exp exp_param); Ast_comb.single_non_rec_value pat_from_js - (Ast_compatible.fun_ (Pat.var pat_param) + (Ast_compatible.fun_ ~arity:None (Pat.var pat_param) (let result = app2 unsafe_index_get_exp rev_exp_map exp_param in diff --git a/compiler/frontend/ast_derive_projector.ml b/compiler/frontend/ast_derive_projector.ml index c84e935e92..6884dbe497 100644 --- a/compiler/frontend/ast_derive_projector.ml +++ b/compiler/frontend/ast_derive_projector.ml @@ -46,7 +46,7 @@ let init () = -> let txt = "param" in Ast_comb.single_non_rec_value ?attrs:gentype_attrs pld_name - (Ast_compatible.fun_ + (Ast_compatible.fun_ ~arity:None (Pat.constraint_ (Pat.var {txt; loc}) core_type) (Exp.field (Exp.ident {txt = Lident txt; loc}) @@ -108,7 +108,9 @@ let init () = annotate_type in Ext_list.fold_right vars exp (fun var b -> - Ast_compatible.fun_ (Pat.var {loc; txt = var}) b) + Ast_compatible.fun_ ~arity:None + (Pat.var {loc; txt = var}) + b) |> handle_uncurried_accessor_tranform ~loc ~arity)) | Ptype_abstract | Ptype_open -> Ast_derive_util.not_applicable tdcl.ptype_loc deriving_name; diff --git a/compiler/frontend/ast_pat.ml b/compiler/frontend/ast_pat.ml index b3789d8e35..91a099c33f 100644 --- a/compiler/frontend/ast_pat.ml +++ b/compiler/frontend/ast_pat.ml @@ -35,7 +35,7 @@ let is_unit_cont ~yes ~no (p : t) = let arity_of_fun (pat : Parsetree.pattern) (e : Parsetree.expression) = let rec aux (e : Parsetree.expression) = match e.pexp_desc with - | Pexp_fun (_, _, _, e) -> 1 + aux e (*FIXME error on optional*) + | Pexp_fun (_, _, _, e, _) -> 1 + aux e (*FIXME error on optional*) (* | Pexp_fun _ -> Location.raise_errorf ~loc:e.pexp_loc "Label is not allowed in JS object" *) @@ -45,7 +45,7 @@ let arity_of_fun (pat : Parsetree.pattern) (e : Parsetree.expression) = let rec labels_of_fun (e : Parsetree.expression) = match e.pexp_desc with - | Pexp_fun (l, _, _, e) -> l :: labels_of_fun e + | Pexp_fun (l, _, _, e, _) -> l :: labels_of_fun e | _ -> [] let rec is_single_variable_pattern_conservative (p : t) = diff --git a/compiler/frontend/ast_uncurry_gen.ml b/compiler/frontend/ast_uncurry_gen.ml index f0eef18c5b..364ff66633 100644 --- a/compiler/frontend/ast_uncurry_gen.ml +++ b/compiler/frontend/ast_uncurry_gen.ml @@ -36,7 +36,7 @@ let to_method_callback loc (self : Bs_ast_mapper.mapper) label match Ast_attributes.process_attributes_rev body.pexp_attributes with | Nothing, attrs -> ( match body.pexp_desc with - | Pexp_fun (arg_label, _, arg, body) -> + | Pexp_fun (arg_label, _, arg, body, _) -> Bs_syntaxerr.optional_err loc arg_label; aux ((arg_label, self.pat self arg, attrs) :: acc) body | _ -> (self.expr self body, acc)) @@ -45,7 +45,7 @@ let to_method_callback loc (self : Bs_ast_mapper.mapper) label let result, rev_extra_args = aux [(label, self_pat, [])] body in let body = Ext_list.fold_left rev_extra_args result (fun e (label, p, attrs) -> - Ast_helper.Exp.fun_ ~loc ~attrs label None p e) + Ast_helper.Exp.fun_ ~loc ~attrs ~arity:None label None p e) in let arity = List.length rev_extra_args in let arity_s = string_of_int arity in diff --git a/compiler/frontend/bs_ast_mapper.ml b/compiler/frontend/bs_ast_mapper.ml index 2fda74cbab..f63531e6b2 100644 --- a/compiler/frontend/bs_ast_mapper.ml +++ b/compiler/frontend/bs_ast_mapper.ml @@ -315,8 +315,8 @@ module E = struct sub vbs) (sub.expr sub e) (* #end *) - | Pexp_fun (lab, def, p, e) -> - fun_ ~loc ~attrs lab + | Pexp_fun (lab, def, p, e, arity) -> + fun_ ~loc ~attrs ~arity lab (map_opt (sub.expr sub) def) (sub.pat sub p) (sub.expr sub e) | Pexp_function pel -> function_ ~loc ~attrs (sub.cases sub pel) diff --git a/compiler/frontend/bs_builtin_ppx.ml b/compiler/frontend/bs_builtin_ppx.ml index 02ec4b1c90..5a0c31d22d 100644 --- a/compiler/frontend/bs_builtin_ppx.ml +++ b/compiler/frontend/bs_builtin_ppx.ml @@ -130,7 +130,7 @@ let expr_mapper ~async_context ~in_function_def (self : mapper) let body = Ast_async.add_async_attribute ~async body in let res = self.expr self body in {e with pexp_desc = Pexp_newtype (s, res)} - | Pexp_fun (label, _, pat, body) -> ( + | Pexp_fun (label, _, pat, body, _arity) -> ( let async = Ast_attributes.has_async_payload e.pexp_attributes <> None in match Ast_attributes.process_attributes_rev e.pexp_attributes with | Nothing, _ -> @@ -594,7 +594,7 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t) | Pexp_ifthenelse (_, then_expr, Some else_expr) -> aux then_expr @ aux else_expr | Pexp_construct (_, Some expr) -> aux expr - | Pexp_fun (_, _, _, expr) | Pexp_newtype (_, expr) -> aux expr + | Pexp_fun (_, _, _, expr, _) | Pexp_newtype (_, expr) -> aux expr | _ -> acc in aux pvb_expr @ spelunk_vbs acc tl diff --git a/compiler/ml/ast_async.ml b/compiler/ml/ast_async.ml index e8ed63a736..b6b4e46b3d 100644 --- a/compiler/ml/ast_async.ml +++ b/compiler/ml/ast_async.ml @@ -40,14 +40,14 @@ let add_async_attribute ~async (body : Parsetree.expression) = let rec add_promise_to_result ~loc (e : Parsetree.expression) = match e.pexp_desc with - | Pexp_fun (label, eo, pat, body) -> + | Pexp_fun (label, eo, pat, body, arity) -> let body = add_promise_to_result ~loc body in - {e with pexp_desc = Pexp_fun (label, eo, pat, body)} + {e with pexp_desc = Pexp_fun (label, eo, pat, body, arity)} | _ -> add_promise_type ~loc ~async:true e let make_function_async ~async (e : Parsetree.expression) = if async then match e.pexp_desc with - | Pexp_fun (_, _, {ppat_loc}, _) -> add_promise_to_result ~loc:ppat_loc e + | Pexp_fun (_, _, {ppat_loc}, _, _) -> add_promise_to_result ~loc:ppat_loc e | _ -> assert false else e diff --git a/compiler/ml/ast_helper.ml b/compiler/ml/ast_helper.ml index 52aa1719ff..01c5ea0e13 100644 --- a/compiler/ml/ast_helper.ml +++ b/compiler/ml/ast_helper.ml @@ -150,7 +150,8 @@ module Exp = struct let ident ?loc ?attrs a = mk ?loc ?attrs (Pexp_ident a) let constant ?loc ?attrs a = mk ?loc ?attrs (Pexp_constant a) let let_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_let (a, b, c)) - let fun_ ?loc ?attrs a b c d = mk ?loc ?attrs (Pexp_fun (a, b, c, d)) + let fun_ ?loc ?attrs ~arity a b c d = + mk ?loc ?attrs (Pexp_fun (a, b, c, d, arity)) let function_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_function a) let apply ?loc ?attrs a b = mk ?loc ?attrs (Pexp_apply (a, b)) let match_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_match (a, b)) diff --git a/compiler/ml/ast_helper.mli b/compiler/ml/ast_helper.mli index 856b35abb9..cfb761485d 100644 --- a/compiler/ml/ast_helper.mli +++ b/compiler/ml/ast_helper.mli @@ -132,6 +132,7 @@ module Exp : sig val fun_ : ?loc:loc -> ?attrs:attrs -> + arity:int option -> arg_label -> expression option -> pattern -> diff --git a/compiler/ml/ast_iterator.ml b/compiler/ml/ast_iterator.ml index b524431edf..6f20cd9650 100644 --- a/compiler/ml/ast_iterator.ml +++ b/compiler/ml/ast_iterator.ml @@ -282,7 +282,7 @@ module E = struct | Pexp_let (_r, vbs, e) -> List.iter (sub.value_binding sub) vbs; sub.expr sub e - | Pexp_fun (_lab, def, p, e) -> + | Pexp_fun (_lab, def, p, e, _) -> iter_opt (sub.expr sub) def; sub.pat sub p; sub.expr sub e diff --git a/compiler/ml/ast_mapper.ml b/compiler/ml/ast_mapper.ml index 4b1d4dca22..83fb0c0e56 100644 --- a/compiler/ml/ast_mapper.ml +++ b/compiler/ml/ast_mapper.ml @@ -278,8 +278,8 @@ module E = struct | Pexp_constant x -> constant ~loc ~attrs x | Pexp_let (r, vbs, e) -> let_ ~loc ~attrs r (List.map (sub.value_binding sub) vbs) (sub.expr sub e) - | Pexp_fun (lab, def, p, e) -> - fun_ ~loc ~attrs lab + | Pexp_fun (lab, def, p, e, arity) -> + fun_ ~loc ~attrs ~arity lab (map_opt (sub.expr sub) def) (sub.pat sub p) (sub.expr sub e) | Pexp_function pel -> function_ ~loc ~attrs (sub.cases sub pel) diff --git a/compiler/ml/ast_mapper_from0.ml b/compiler/ml/ast_mapper_from0.ml index 76ba9e5392..036ecb3755 100644 --- a/compiler/ml/ast_mapper_from0.ml +++ b/compiler/ml/ast_mapper_from0.ml @@ -285,7 +285,7 @@ module E = struct | Pexp_let (r, vbs, e) -> let_ ~loc ~attrs r (List.map (sub.value_binding sub) vbs) (sub.expr sub e) | Pexp_fun (lab, def, p, e) -> - fun_ ~loc ~attrs lab + fun_ ~loc ~attrs ~arity:None lab (map_opt (sub.expr sub) def) (sub.pat sub p) (sub.expr sub e) | Pexp_function pel -> function_ ~loc ~attrs (sub.cases sub pel) @@ -295,8 +295,42 @@ module E = struct match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel) | Pexp_try (e, pel) -> try_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel) | Pexp_tuple el -> tuple ~loc ~attrs (List.map (sub.expr sub) el) - | Pexp_construct (lid, arg) -> - construct ~loc ~attrs (map_loc sub lid) (map_opt (sub.expr sub) arg) + | Pexp_construct (lid, arg) -> ( + let lid1 = map_loc sub lid in + let arg1 = map_opt (sub.expr sub) arg in + let exp1 = construct ~loc ~attrs lid1 arg1 in + match lid.txt with + | Lident "Function$" -> ( + let rec attributes_to_arity (attrs : Parsetree.attributes) = + match attrs with + | ( {txt = "res.arity"}, + PStr + [ + { + pstr_desc = + Pstr_eval + ( {pexp_desc = Pexp_constant (Pconst_integer (arity, _))}, + _ ); + }; + ] ) + :: _ -> + int_of_string arity + | _ :: rest -> attributes_to_arity rest + | [] -> assert false + in + match arg1 with + | Some ({pexp_desc = Pexp_fun (l, eo, p, e, _)} as e1) -> + let arity = attributes_to_arity attrs in + { + e1 with + pexp_desc = + Pexp_construct + ( lid1, + Some {e with pexp_desc = Pexp_fun (l, eo, p, e, Some arity)} + ); + } + | _ -> exp1) + | _ -> exp1) | Pexp_variant (lab, eo) -> variant ~loc ~attrs lab (map_opt (sub.expr sub) eo) | Pexp_record (l, eo) -> diff --git a/compiler/ml/ast_mapper_to0.ml b/compiler/ml/ast_mapper_to0.ml index 2ad44c96b2..260b0de940 100644 --- a/compiler/ml/ast_mapper_to0.ml +++ b/compiler/ml/ast_mapper_to0.ml @@ -283,7 +283,7 @@ module E = struct | Pexp_constant x -> constant ~loc ~attrs (map_constant x) | Pexp_let (r, vbs, e) -> let_ ~loc ~attrs r (List.map (sub.value_binding sub) vbs) (sub.expr sub e) - | Pexp_fun (lab, def, p, e) -> + | Pexp_fun (lab, def, p, e, _) -> fun_ ~loc ~attrs lab (map_opt (sub.expr sub) def) (sub.pat sub p) (sub.expr sub e) @@ -294,8 +294,31 @@ module E = struct match_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel) | Pexp_try (e, pel) -> try_ ~loc ~attrs (sub.expr sub e) (sub.cases sub pel) | Pexp_tuple el -> tuple ~loc ~attrs (List.map (sub.expr sub) el) - | Pexp_construct (lid, arg) -> - construct ~loc ~attrs (map_loc sub lid) (map_opt (sub.expr sub) arg) + | Pexp_construct (lid, arg) -> ( + let exp0 = + construct ~loc ~attrs (map_loc sub lid) (map_opt (sub.expr sub) arg) + in + match lid.txt with + | Lident "Function$" -> ( + match arg with + | Some {pexp_desc = Pexp_fun (_, _, _, _, Some arity)} -> + let arity_to_attributes arity = + [ + ( Location.mknoloc "res.arity", + Parsetree0.PStr + [ + Ast_helper0.Str.eval + (Ast_helper0.Exp.constant + (Pconst_integer (string_of_int arity, None))); + ] ); + ] + in + { + exp0 with + pexp_attributes = arity_to_attributes arity @ exp0.pexp_attributes; + } + | _ -> assert false) + | _ -> exp0) | Pexp_variant (lab, eo) -> variant ~loc ~attrs lab (map_opt (sub.expr sub) eo) | Pexp_record (l, eo) -> diff --git a/compiler/ml/ast_uncurried.ml b/compiler/ml/ast_uncurried.ml index 3d36fcc656..883a8d7ded 100644 --- a/compiler/ml/ast_uncurried.ml +++ b/compiler/ml/ast_uncurried.ml @@ -19,36 +19,14 @@ let uncurried_type ~loc ~arity t_arg = let t_arity = arity_type ~loc arity in Ast_helper.Typ.constr ~loc {txt = Lident "function$"; loc} [t_arg; t_arity] -let arity_to_attributes arity = - [ - ( Location.mknoloc "res.arity", - Parsetree.PStr - [ - Ast_helper.Str.eval - (Ast_helper.Exp.constant - (Pconst_integer (string_of_int arity, None))); - ] ); - ] - -let rec attributes_to_arity (attrs : Parsetree.attributes) = - match attrs with - | ( {txt = "res.arity"}, - PStr - [ - { - pstr_desc = - Pstr_eval - ({pexp_desc = Pexp_constant (Pconst_integer (arity, _))}, _); - }; - ] ) - :: _ -> - int_of_string arity - | _ :: rest -> attributes_to_arity rest - | _ -> assert false - let uncurried_fun ~loc ~arity fun_expr = + let fun_expr = + match fun_expr.Parsetree.pexp_desc with + | Pexp_fun (l, eo, p, e, _) -> + {fun_expr with pexp_desc = Pexp_fun (l, eo, p, e, Some arity)} + | _ -> assert false + in Ast_helper.Exp.construct ~loc - ~attrs:(arity_to_attributes arity) (Location.mknoloc (Longident.Lident "Function$")) (Some fun_expr) @@ -59,7 +37,13 @@ let expr_is_uncurried_fun (expr : Parsetree.expression) = let expr_extract_uncurried_fun (expr : Parsetree.expression) = match expr.pexp_desc with - | Pexp_construct ({txt = Lident "Function$"}, Some e) -> e + | Pexp_construct ({txt = Lident "Function$"}, Some e) -> + let () = + match e.pexp_desc with + | Pexp_fun (_, _, _, _, Some _arity) -> () + | _ -> assert false + in + e | _ -> assert false let core_type_is_uncurried_fun (typ : Parsetree.core_type) = diff --git a/compiler/ml/depend.ml b/compiler/ml/depend.ml index bf4da4cfde..a2c4e04b40 100644 --- a/compiler/ml/depend.ml +++ b/compiler/ml/depend.ml @@ -218,7 +218,7 @@ let rec add_expr bv exp = | Pexp_let (rf, pel, e) -> let bv = add_bindings rf bv pel in add_expr bv e - | Pexp_fun (_, opte, p, e) -> + | Pexp_fun (_, opte, p, e, _) -> add_opt add_expr bv opte; add_expr (add_pattern bv p) e | Pexp_function pel -> add_cases bv pel diff --git a/compiler/ml/parsetree.ml b/compiler/ml/parsetree.ml index 3da8d64769..060f9cf5b4 100644 --- a/compiler/ml/parsetree.ml +++ b/compiler/ml/parsetree.ml @@ -225,7 +225,8 @@ and expression_desc = let rec P1 = E1 and ... and Pn = EN in E (flag = Recursive) *) | Pexp_function of case list (* function P1 -> E1 | ... | Pn -> En *) - | Pexp_fun of arg_label * expression option * pattern * expression + | Pexp_fun of + arg_label * expression option * pattern * expression * int option (* fun P -> E1 (Simple, None) fun ~l:P -> E1 (Labelled l, None) fun ?l:P -> E1 (Optional l, None) diff --git a/compiler/ml/pprintast.ml b/compiler/ml/pprintast.ml index 56eab619d6..a360d3dfe6 100644 --- a/compiler/ml/pprintast.ml +++ b/compiler/ml/pprintast.ml @@ -543,9 +543,13 @@ and expression ctxt f x = | Pexp_let _ | Pexp_letmodule _ | Pexp_open _ | Pexp_letexception _ when ctxt.semi -> paren true (expression reset_ctxt) f x - | Pexp_fun (l, e0, p, e) -> - pp f "@[<2>fun@;%a->@;%a@]" - (label_exp ctxt) (l, e0, p) + | Pexp_fun (l, e0, p, e, arity) -> + let arity_str = match arity with + | None -> "" + | Some arity -> "[arity:" ^ string_of_int arity ^ "]" + in + pp f "@[<2>fun@;%s%a->@;%a@]" + arity_str (label_exp ctxt) (l, e0, p) (expression ctxt) e | Pexp_function l -> pp f "@[function%a@]" (case_list ctxt) l @@ -949,12 +953,16 @@ and binding ctxt f {pvb_pat=p; pvb_expr=x; _} = let rec pp_print_pexp_function f x = if x.pexp_attributes <> [] then pp f "=@;%a" (expression ctxt) x else match x.pexp_desc with - | Pexp_fun (label, eo, p, e) -> + | Pexp_fun (label, eo, p, e, arity) -> + let arity_str = match arity with + | None -> "" + | Some arity -> "arity:" ^ string_of_int arity + in if label=Nolabel then - pp f "%a@ %a" (simple_pattern ctxt) p pp_print_pexp_function e + pp f "%s%a@ %a" arity_str (simple_pattern ctxt) p pp_print_pexp_function e else - pp f "%a@ %a" - (label_exp ctxt) (label,eo,p) pp_print_pexp_function e + pp f "%s%a@ %a" + arity_str (label_exp ctxt) (label,eo,p) pp_print_pexp_function e | Pexp_newtype (str,e) -> pp f "(type@ %s)@ %a" str.txt pp_print_pexp_function e | _ -> pp f "=@;%a" (expression ctxt) x diff --git a/compiler/ml/printast.ml b/compiler/ml/printast.ml index 0977e7f8a2..a635fc0498 100644 --- a/compiler/ml/printast.ml +++ b/compiler/ml/printast.ml @@ -236,8 +236,13 @@ and expression i ppf x = | Pexp_function l -> line i ppf "Pexp_function\n"; list i case ppf l - | Pexp_fun (l, eo, p, e) -> + | Pexp_fun (l, eo, p, e, arity) -> line i ppf "Pexp_fun\n"; + let () = + match arity with + | None -> () + | Some arity -> line i ppf "arity:%d\n" arity + in arg_label i ppf l; option i expression ppf eo; pattern i ppf p; diff --git a/compiler/ml/typecore.ml b/compiler/ml/typecore.ml index f9085caaa4..fba16114be 100644 --- a/compiler/ml/typecore.ml +++ b/compiler/ml/typecore.ml @@ -138,7 +138,7 @@ let iter_expression f e = | Pexp_ident _ | Pexp_new _ | Pexp_constant _ -> () | Pexp_function pel -> List.iter case pel - | Pexp_fun (_, eo, _, e) -> + | Pexp_fun (_, eo, _, e, _) -> may expr eo; expr e | Pexp_apply (e, lel) -> @@ -1914,7 +1914,7 @@ let rec approx_type env sty = let rec type_approx env sexp = match sexp.pexp_desc with | Pexp_let (_, _, e) -> type_approx env e - | Pexp_fun (p, _, _, e) -> + | Pexp_fun (p, _, _, e, _arity) -> let ty = if is_optional p then type_option (newvar ()) else newvar () in newty (Tarrow (p, ty, type_approx env e, Cok)) | Pexp_function ({pc_rhs = e} :: _) -> @@ -2374,7 +2374,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp exp_attributes = sexp.pexp_attributes; exp_env = env; } - | Pexp_fun (l, Some default, spat, sbody) -> + | Pexp_fun (l, Some default, spat, sbody, _arity) -> assert (is_optional l); (* default allowed only with optional argument *) let open Ast_helper in @@ -2414,7 +2414,7 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp in type_function ?in_function loc sexp.pexp_attributes env ty_expected l [Exp.case pat body] - | Pexp_fun (l, None, spat, sbody) -> + | Pexp_fun (l, None, spat, sbody, _arity) -> type_function ?in_function loc sexp.pexp_attributes env ty_expected l [Ast_helper.Exp.case spat sbody] | Pexp_function caselist -> @@ -2531,9 +2531,10 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp exp_attributes = sexp.pexp_attributes; exp_env = env; } - | Pexp_construct (({txt = Lident "Function$"} as lid), sarg) -> + | Pexp_construct + ( ({txt = Lident "Function$"} as lid), + (Some {pexp_desc = Pexp_fun (_, _, _, _, Some arity)} as sarg) ) -> let state = Warnings.backup () in - let arity = Ast_uncurried.attributes_to_arity sexp.pexp_attributes in let uncurried_typ = Ast_uncurried.make_uncurried_type ~env ~arity (newvar ()) in diff --git a/compiler/ml/untypeast.ml b/compiler/ml/untypeast.ml index 0812bc88f7..da064d8d77 100644 --- a/compiler/ml/untypeast.ml +++ b/compiler/ml/untypeast.ml @@ -312,7 +312,8 @@ let expression sub exp = (* One case, no guard: It's a fun. *) | Texp_function {arg_label; cases = [{c_lhs = p; c_guard = None; c_rhs = e}]; _} -> - Pexp_fun (arg_label, None, sub.pat sub p, sub.expr sub e) + let arity = assert false in + Pexp_fun (arg_label, None, sub.pat sub p, sub.expr sub e, arity) (* No label: it's a function. *) | Texp_function {arg_label = Nolabel; cases; _} -> Pexp_function (sub.cases sub cases) @@ -320,13 +321,15 @@ let expression sub exp = | Texp_function {arg_label = (Labelled s | Optional s) as label; cases; _} -> let name = fresh_name s exp.exp_env in + let arity = assert false in Pexp_fun ( label, None, Pat.var ~loc {loc; txt = name}, Exp.match_ ~loc (Exp.ident ~loc {loc; txt = Lident name}) - (sub.cases sub cases) ) + (sub.cases sub cases), + arity ) | Texp_apply (exp, list) -> Pexp_apply ( sub.expr sub exp, diff --git a/compiler/syntax/src/jsx_v4.ml b/compiler/syntax/src/jsx_v4.ml index d80ff12f5c..e8fe6defd4 100644 --- a/compiler/syntax/src/jsx_v4.ml +++ b/compiler/syntax/src/jsx_v4.ml @@ -642,15 +642,17 @@ let transform_lowercase_call3 ~config mapper jsx_expr_loc call_expr_loc attrs let rec recursively_transform_named_args_for_make expr args newtypes core_type = match expr.pexp_desc with (* TODO: make this show up with a loc. *) - | Pexp_fun (Labelled "key", _, _, _) | Pexp_fun (Optional "key", _, _, _) -> + | Pexp_fun (Labelled "key", _, _, _, _) | Pexp_fun (Optional "key", _, _, _, _) + -> Jsx_common.raise_error ~loc:expr.pexp_loc "Key cannot be accessed inside of a component. Don't worry - you can \ always key a component from its parent!" - | Pexp_fun (Labelled "ref", _, _, _) | Pexp_fun (Optional "ref", _, _, _) -> + | Pexp_fun (Labelled "ref", _, _, _, _) | Pexp_fun (Optional "ref", _, _, _, _) + -> Jsx_common.raise_error ~loc:expr.pexp_loc "Ref cannot be passed as a normal prop. Please use `forwardRef` API \ instead." - | Pexp_fun (arg, default, pattern, expression) + | Pexp_fun (arg, default, pattern, expression, _arity) when is_optional arg || is_labelled arg -> let () = match (is_optional arg, pattern, default) with @@ -700,7 +702,8 @@ let rec recursively_transform_named_args_for_make expr args newtypes core_type = ( Nolabel, _, {ppat_desc = Ppat_construct ({txt = Lident "()"}, _) | Ppat_any}, - _expression ) -> + _expression, + _arity ) -> (args, newtypes, core_type) | Pexp_fun ( Nolabel, @@ -709,7 +712,8 @@ let rec recursively_transform_named_args_for_make expr args newtypes core_type = ppat_desc = Ppat_var {txt} | Ppat_constraint ({ppat_desc = Ppat_var {txt}}, _); } as pattern), - _expression ) -> + _expression, + _arity ) -> if txt = "ref" then let type_ = match pattern with @@ -721,7 +725,7 @@ let rec recursively_transform_named_args_for_make expr args newtypes core_type = newtypes, core_type ) else (args, newtypes, core_type) - | Pexp_fun (Nolabel, _, pattern, _expression) -> + | Pexp_fun (Nolabel, _, pattern, _expression, _arity) -> Location.raise_errorf ~loc:pattern.ppat_loc "React: react.component refs only support plain arguments and type \ annotations." @@ -824,14 +828,18 @@ let modified_binding ~binding_loc ~binding_pat_loc ~fn_name binding = ( ((Labelled _ | Optional _) as label), default, pattern, - ({pexp_desc = Pexp_fun _} as internal_expression) ); + ({pexp_desc = Pexp_fun _} as internal_expression), + arity ); } -> let wrap, has_forward_ref, exp = spelunk_for_fun_expression internal_expression in ( wrap, has_forward_ref, - {expression with pexp_desc = Pexp_fun (label, default, pattern, exp)} ) + { + expression with + pexp_desc = Pexp_fun (label, default, pattern, exp, arity); + } ) (* let make = (()) => ... *) (* let make = (_) => ... *) | { @@ -840,19 +848,26 @@ let modified_binding ~binding_loc ~binding_pat_loc ~fn_name binding = ( Nolabel, _default, {ppat_desc = Ppat_construct ({txt = Lident "()"}, _) | Ppat_any}, - _internalExpression ); + _internalExpression, + _arity ); } -> ((fun a -> a), false, expression) (* let make = (~prop) => ... *) | { pexp_desc = Pexp_fun - ((Labelled _ | Optional _), _default, _pattern, _internalExpression); + ( (Labelled _ | Optional _), + _default, + _pattern, + _internalExpression, + _arity ); } -> ((fun a -> a), false, expression) (* let make = (prop) => ... *) - | {pexp_desc = Pexp_fun (_nolabel, _default, pattern, _internalExpression)} - -> + | { + pexp_desc = + Pexp_fun (_nolabel, _default, pattern, _internalExpression, _arity); + } -> if !has_application then ((fun a -> a), false, expression) else Location.raise_errorf ~loc:pattern.ppat_loc @@ -1001,12 +1016,12 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding = (* let make = React.forwardRef({ let \"App" = (props, ref) => make({...props, ref: @optional (Js.Nullabel.toOption(ref))}) })*) - Exp.fun_ nolabel None + Exp.fun_ ~arity:None nolabel None (match core_type_of_attr with | None -> make_props_pattern named_type_list | Some _ -> make_props_pattern typ_vars_of_core_type) (if has_forward_ref then - Exp.fun_ nolabel None + Exp.fun_ ~arity:None nolabel None (Pat.var @@ Location.mknoloc "ref") inner_expression else inner_expression) @@ -1055,9 +1070,11 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding = ( _arg_label, _default, {ppat_desc = Ppat_construct ({txt = Lident "()"}, _)}, - expr ) -> + expr, + _arity ) -> (patterns_with_label, patterns_with_nolabel, expr) - | Pexp_fun (arg_label, default, ({ppat_loc; ppat_desc} as pattern), expr) + | Pexp_fun + (arg_label, default, ({ppat_loc; ppat_desc} as pattern), expr, _arity) -> ( let pattern_without_constraint = strip_constraint_unpack ~label:(get_label arg_label) pattern @@ -1117,7 +1134,7 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding = Pat.constraint_ pattern (ref_type Location.none) | _ -> pattern in - Exp.fun_ Nolabel None pattern expr) + Exp.fun_ ~arity:None Nolabel None pattern expr) expression patterns_with_nolabel in (* ({a, b, _}: props<'a, 'b>) *) @@ -1127,7 +1144,7 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding = | _ -> Pat.record (List.rev patterns_with_label) Open in let expression = - Exp.fun_ Nolabel None + Exp.fun_ ~arity:None Nolabel None (Pat.constraint_ record_pattern (Typ.constr ~loc:empty_loc {txt = Lident "props"; loc = empty_loc} diff --git a/compiler/syntax/src/res_ast_debugger.ml b/compiler/syntax/src/res_ast_debugger.ml index e3bd7f7bf7..0a6cf69a12 100644 --- a/compiler/syntax/src/res_ast_debugger.ml +++ b/compiler/syntax/src/res_ast_debugger.ml @@ -561,7 +561,7 @@ module SexpAst = struct | Pexp_function cases -> Sexp.list [Sexp.atom "Pexp_function"; Sexp.list (map_empty ~f:case cases)] - | Pexp_fun (arg_lbl, expr_opt, pat, expr) -> + | Pexp_fun (arg_lbl, expr_opt, pat, expr, _) -> Sexp.list [ Sexp.atom "Pexp_fun"; diff --git a/compiler/syntax/src/res_comments_table.ml b/compiler/syntax/src/res_comments_table.ml index 50ce987b1f..ac168be7fb 100644 --- a/compiler/syntax/src/res_comments_table.ml +++ b/compiler/syntax/src/res_comments_table.ml @@ -264,7 +264,7 @@ let fun_expr expr = let rec collect attrs_before acc expr = match expr with | { - pexp_desc = Pexp_fun (lbl, default_expr, pattern, return_expr); + pexp_desc = Pexp_fun (lbl, default_expr, pattern, return_expr, _); pexp_attributes = []; } -> let parameter = ([], lbl, default_expr, pattern) in @@ -279,7 +279,7 @@ let fun_expr expr = in collect attrs_before (parameter :: acc) return_expr | { - pexp_desc = Pexp_fun (lbl, default_expr, pattern, return_expr); + pexp_desc = Pexp_fun (lbl, default_expr, pattern, return_expr, _); pexp_attributes = [({txt = "bs"}, _)] as attrs; } -> let parameter = (attrs, lbl, default_expr, pattern) in @@ -287,7 +287,11 @@ let fun_expr expr = | { pexp_desc = Pexp_fun - (((Labelled _ | Optional _) as lbl), default_expr, pattern, return_expr); + ( ((Labelled _ | Optional _) as lbl), + default_expr, + pattern, + return_expr, + _ ); pexp_attributes = attrs; } -> let parameter = (attrs, lbl, default_expr, pattern) in @@ -296,7 +300,7 @@ let fun_expr expr = in match expr with | { - pexp_desc = Pexp_fun (Nolabel, _defaultExpr, _pattern, _returnExpr); + pexp_desc = Pexp_fun (Nolabel, _defaultExpr, _pattern, _returnExpr, _); pexp_attributes = attrs; } as expr -> collect attrs [] {expr with pexp_attributes = []} @@ -1406,7 +1410,7 @@ and walk_expression expr t comments = in attach t.trailing call_expr.pexp_loc after_expr; walk_list (arguments |> List.map (fun (_, e) -> ExprArgument e)) t rest - | Pexp_fun (_, _, _, _) | Pexp_newtype _ -> ( + | Pexp_fun (_, _, _, _, _) | Pexp_newtype _ -> ( let _, parameters, return_expr = fun_expr expr in let comments = visit_list_but_continue_with_remaining_comments ~newline_delimited:false diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index dbd79c7852..610a37b734 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -525,7 +525,9 @@ let process_underscore_application args = (Ppat_var (Location.mkloc hidden_var loc)) ~loc:Location.none in - let fun_expr = Ast_helper.Exp.fun_ ~loc Nolabel None pattern exp_apply in + let fun_expr = + Ast_helper.Exp.fun_ ~loc ~arity:(Some 1) Nolabel None pattern exp_apply + in Ast_uncurried.uncurried_fun ~loc ~arity:1 fun_expr | None -> exp_apply in @@ -1594,7 +1596,8 @@ and parse_es6_arrow_expression ?(arrow_attrs = []) ?(arrow_start_pos = None) {attrs; label = lbl; expr = default_expr; pat; pos = start_pos} -> let loc = mk_loc start_pos end_pos in let fun_expr = - Ast_helper.Exp.fun_ ~loc ~attrs lbl default_expr pat expr + Ast_helper.Exp.fun_ ~loc ~attrs ~arity:(Some arity) lbl default_expr + pat expr in if term_param_num = 1 then ( term_param_num - 1, @@ -2407,13 +2410,13 @@ and over_parse_constrained_or_coerced_or_arrow_expression p expr = let arrow1 = Ast_helper.Exp.fun_ ~loc:(mk_loc expr.pexp_loc.loc_start body.pexp_loc.loc_end) - Asttypes.Nolabel None pat + ~arity:None Asttypes.Nolabel None pat (Ast_helper.Exp.constraint_ body typ) in let arrow2 = Ast_helper.Exp.fun_ ~loc:(mk_loc expr.pexp_loc.loc_start body.pexp_loc.loc_end) - Asttypes.Nolabel None + ~arity:None Asttypes.Nolabel None (Ast_helper.Pat.constraint_ pat typ) body in diff --git a/compiler/syntax/src/res_parsetree_viewer.ml b/compiler/syntax/src/res_parsetree_viewer.ml index 038f19f06b..aa74b0992b 100644 --- a/compiler/syntax/src/res_parsetree_viewer.ml +++ b/compiler/syntax/src/res_parsetree_viewer.ml @@ -140,7 +140,8 @@ let rewrite_underscore_apply expr = ( Nolabel, None, {ppat_desc = Ppat_var {txt = "__x"}}, - ({pexp_desc = Pexp_apply (call_expr, args)} as e) ) -> + ({pexp_desc = Pexp_apply (call_expr, args)} as e), + _ ) -> let new_args = List.map (fun arg -> @@ -185,7 +186,8 @@ let fun_expr expr = ( Nolabel, None, {ppat_desc = Ppat_var {txt = "__x"}}, - {pexp_desc = Pexp_apply _} ); + {pexp_desc = Pexp_apply _}, + _ ); } -> (uncurried, attrs_before, List.rev acc, rewrite_underscore_apply expr) | {pexp_desc = Pexp_newtype (string_loc, rest); pexp_attributes = attrs} -> @@ -193,7 +195,7 @@ let fun_expr expr = let param = NewTypes {attrs; locs = string_locs} in collect ~uncurried ~n_fun attrs_before (param :: acc) return_expr | { - pexp_desc = Pexp_fun (lbl, default_expr, pattern, return_expr); + pexp_desc = Pexp_fun (lbl, default_expr, pattern, return_expr, _); pexp_attributes = []; } -> let parameter = @@ -231,9 +233,9 @@ let filter_parsing_attrs attrs = match attr with | ( { Location.txt = - ( "res.arity" | "res.braces" | "ns.braces" | "res.iflet" - | "res.namedArgLoc" | "res.ternary" | "res.async" | "res.await" - | "res.template" | "res.taggedTemplate" | "res.patVariantSpread" + ( "res.braces" | "ns.braces" | "res.iflet" | "res.namedArgLoc" + | "res.ternary" | "res.async" | "res.await" | "res.template" + | "res.taggedTemplate" | "res.patVariantSpread" | "res.dictPattern" ); }, _ ) -> @@ -382,8 +384,8 @@ let has_attributes attrs = match attr with | ( { Location.txt = - ( "res.arity" | "res.braces" | "ns.braces" | "res.iflet" - | "res.ternary" | "res.async" | "res.await" | "res.template" ); + ( "res.braces" | "ns.braces" | "res.iflet" | "res.ternary" + | "res.async" | "res.await" | "res.template" ); }, _ ) -> false @@ -566,8 +568,8 @@ let is_printable_attribute attr = match attr with | ( { Location.txt = - ( "res.arity" | "res.iflet" | "res.braces" | "ns.braces" | "JSX" - | "res.async" | "res.await" | "res.template" | "res.ternary" ); + ( "res.iflet" | "res.braces" | "ns.braces" | "JSX" | "res.async" + | "res.await" | "res.template" | "res.ternary" ); }, _ ) -> false @@ -744,7 +746,8 @@ let is_underscore_apply_sugar expr = ( Nolabel, None, {ppat_desc = Ppat_var {txt = "__x"}}, - {pexp_desc = Pexp_apply _} ) -> + {pexp_desc = Pexp_apply _}, + _ ) -> true | _ -> false diff --git a/compiler/syntax/src/res_printer.ml b/compiler/syntax/src/res_printer.ml index 6fdb675b7e..a5fde5b0ae 100644 --- a/compiler/syntax/src/res_printer.ml +++ b/compiler/syntax/src/res_printer.ml @@ -2792,7 +2792,8 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl = ( Nolabel, None, {ppat_desc = Ppat_var {txt = "__x"}}, - {pexp_desc = Pexp_apply _} ) + {pexp_desc = Pexp_apply _}, + _ ) | Pexp_construct ( {txt = Lident "Function$"}, Some @@ -2802,7 +2803,8 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl = ( Nolabel, None, {ppat_desc = Ppat_var {txt = "__x"}}, - {pexp_desc = Pexp_apply _} ); + {pexp_desc = Pexp_apply _}, + _ ); } ) -> (* (__x) => f(a, __x, c) -----> f(a, _, c) *) print_expression_with_comments ~state diff --git a/scripts/test_syntax.sh b/scripts/test_syntax.sh index 3e13b719ff..080a9e64a6 100755 --- a/scripts/test_syntax.sh +++ b/scripts/test_syntax.sh @@ -54,7 +54,7 @@ warningYellow='\033[0;33m' successGreen='\033[0;32m' reset='\033[0m' -git diff --ignore-cr-at-eol $(find tests -name expected) >temp/diff.txt +git diff --ignore-cr-at-eol $(find syntax_tests -name expected) >temp/diff.txt diff=$(cat temp/diff.txt) if [[ $diff = "" ]]; then printf "${successGreen}✅ No unstaged tests difference.${reset}\n" diff --git a/tests/syntax_tests/data/parsing/errors/expressions/expected/array.res.txt b/tests/syntax_tests/data/parsing/errors/expressions/expected/array.res.txt index e155f0f9d9..31dbf702e0 100644 --- a/tests/syntax_tests/data/parsing/errors/expressions/expected/array.res.txt +++ b/tests/syntax_tests/data/parsing/errors/expressions/expected/array.res.txt @@ -8,5 +8,4 @@ Did you forget a `]` here? -let xs = - x.map ((Function$ (fun key -> [|key;(predicates.(key))|]))[@res.arity 1]) \ No newline at end of file +let xs = x.map (Function$ (fun [arity:1]key -> [|key;(predicates.(key))|])) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/expressions/expected/arrow.res.txt b/tests/syntax_tests/data/parsing/errors/expressions/expected/arrow.res.txt index 07356025b6..921b269614 100644 --- a/tests/syntax_tests/data/parsing/errors/expressions/expected/arrow.res.txt +++ b/tests/syntax_tests/data/parsing/errors/expressions/expected/arrow.res.txt @@ -9,7 +9,7 @@ Did you forget a `,` here? ;;(Object.keys providers).reduce - ((Function$ - (fun elements -> - fun providerId -> ((let x = 1 in let b = 2 in x + b) - [@res.braces ])))[@res.arity 2]) \ No newline at end of file + (Function$ + (fun [arity:2]elements -> + fun [arity:1]providerId -> ((let x = 1 in let b = 2 in x + b) + [@res.braces ]))) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt b/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt index c360a4c9c0..636937df30 100644 --- a/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt +++ b/tests/syntax_tests/data/parsing/errors/expressions/expected/block.res.txt @@ -64,26 +64,25 @@ Looks like there might be an expression missing here let findThreadByIdLinearScan = - ((Function$ - (fun ~threads:((threads)[@res.namedArgLoc ]) -> - fun ~id:((id)[@res.namedArgLoc ]) -> - ((Js.Array2.findi ThreadsModel.threads - ((Function$ - (fun thread -> - fun i -> - ((let thisId = - match thread with - | ServerData.OneToOne - { otherPersonIDWhichIsAlsoThreadID } -> - otherPersonIDWhichIsAlsoThreadID - | Group { id } -> id - | Unknown { id } -> - (unknown.id |.u Js.String.make) |.u - FBID.ofStringUnsafe in - thisId == id) - [@res.braces ])))[@res.arity 2])) - [@res.braces ]))) - [@res.arity 2]) + Function$ + (fun [arity:2]~threads:((threads)[@res.namedArgLoc ]) -> + fun [arity:1]~id:((id)[@res.namedArgLoc ]) -> + ((Js.Array2.findi ThreadsModel.threads + (Function$ + (fun [arity:2]thread -> + fun [arity:1]i -> + ((let thisId = + match thread with + | ServerData.OneToOne + { otherPersonIDWhichIsAlsoThreadID } -> + otherPersonIDWhichIsAlsoThreadID + | Group { id } -> id + | Unknown { id } -> + (unknown.id |.u Js.String.make) |.u + FBID.ofStringUnsafe in + thisId == id) + [@res.braces ])))) + [@res.braces ])) let x = ((loop 0 (Nil |.u (push doc)))[@res.braces ]) ;;match stack with | Empty -> [%rescript.exprhole ] diff --git a/tests/syntax_tests/data/parsing/errors/expressions/expected/consecutive.res.txt b/tests/syntax_tests/data/parsing/errors/expressions/expected/consecutive.res.txt index 1fe6364746..9d12fcc36f 100644 --- a/tests/syntax_tests/data/parsing/errors/expressions/expected/consecutive.res.txt +++ b/tests/syntax_tests/data/parsing/errors/expressions/expected/consecutive.res.txt @@ -44,9 +44,9 @@ consecutive expressions on a line must be separated by ';' or a newline -let f = ((Function$ (fun a -> fun b -> a + 3))[@res.arity 2]) +let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> a + 3) ;;b -let f = ((Function$ (fun g -> fun h -> ((a + 3; b)[@res.braces ]))) - [@res.arity 2]) +let f = + Function$ (fun [arity:2]g -> fun [arity:1]h -> ((a + 3; b)[@res.braces ])) let () = ((sideEffect1 (); sideEffect2 ())[@res.braces ]) let () = ((let open Foo in let exception End in x ())[@res.braces ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/expressions/expected/emptyBlock.res.txt b/tests/syntax_tests/data/parsing/errors/expressions/expected/emptyBlock.res.txt index 545f257b92..b08fdd7412 100644 --- a/tests/syntax_tests/data/parsing/errors/expressions/expected/emptyBlock.res.txt +++ b/tests/syntax_tests/data/parsing/errors/expressions/expected/emptyBlock.res.txt @@ -1,2 +1,2 @@ let x = { } -let f = ((Function$ (fun a -> fun b -> { }))[@res.arity 2]) \ No newline at end of file +let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> { }) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/expressions/expected/implementation.res.txt b/tests/syntax_tests/data/parsing/errors/expressions/expected/implementation.res.txt index 38fd3ae420..cb8406f831 100644 --- a/tests/syntax_tests/data/parsing/errors/expressions/expected/implementation.res.txt +++ b/tests/syntax_tests/data/parsing/errors/expressions/expected/implementation.res.txt @@ -13,7 +13,8 @@ module InstallerDownload = struct let make = - ((Function$ (fun () -> ((div ~children:[] ())[@res.braces ][@JSX ]))) - [@res.arity 1])[@@react.component ] + Function$ + (fun [arity:1]() -> ((div ~children:[] ())[@res.braces ][@JSX ])) + [@@react.component ] end module LicenseList = struct end \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/other/expected/labelledParameters.res.txt b/tests/syntax_tests/data/parsing/errors/other/expected/labelledParameters.res.txt index 5ffc6661b8..ad41ffd983 100644 --- a/tests/syntax_tests/data/parsing/errors/other/expected/labelledParameters.res.txt +++ b/tests/syntax_tests/data/parsing/errors/other/expected/labelledParameters.res.txt @@ -31,12 +31,12 @@ A labeled parameter starts with a `~`. Did you mean: `~x`? -let f = ((Function$ (fun x -> fun ?(y= 2) -> fun z -> (x + y) + z)) - [@res.arity 3]) +let f = + Function$ + (fun [arity:3]x -> fun [arity:2]?(y= 2) -> fun [arity:1]z -> (x + y) + z) let g = - ((Function$ - (fun ~x:((x)[@res.namedArgLoc ]) -> - fun ?y:(((y)[@res.namedArgLoc ])= 2) -> - fun ~z:((z)[@res.namedArgLoc ]) -> (x + y) + z)) - [@res.arity 3]) + Function$ + (fun [arity:3]~x:((x)[@res.namedArgLoc ]) -> + fun [arity:2]?y:(((y)[@res.namedArgLoc ])= 2) -> + fun [arity:1]~z:((z)[@res.namedArgLoc ]) -> (x + y) + z) type nonrec f = (x:int -> y:int -> int, [ `Has_arity2 ]) function$ \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt b/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt index 0c13bcdc3e..278e3ab31b 100644 --- a/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt +++ b/tests/syntax_tests/data/parsing/errors/structure/expected/gh16B.res.txt @@ -15,12 +15,11 @@ open Ws let wss = Server.make { port = 82 } let address = wss |.u Server.address let log = - ((Function$ - (fun msg -> - Js.log - (((((({js|> Server: |js})[@res.template ]) ^ msg)[@res.template ]) - ^ (({js||js})[@res.template ]))[@res.template ]))) - [@res.arity 1]) + Function$ + (fun [arity:1]msg -> + Js.log + (((((({js|> Server: |js})[@res.template ]) ^ msg)[@res.template ]) ^ + (({js||js})[@res.template ]))[@res.template ])) ;;log (((((((((((((({js|Running on: |js})[@res.template ]) ^ address.address) [@res.template ]) ^ (({js|:|js})[@res.template ])) @@ -34,14 +33,13 @@ module ClientSet = (Belt.Id.MakeComparable)(struct type nonrec t = Client.t let cmp = - ((Function$ - (fun a -> - fun b -> - ((compare - (a |.u Client.getUniqueId) - (b |.u Client.getUniqueId)) - [@res.braces ]))) - [@res.arity 2]) + Function$ + (fun [arity:2]a -> + fun [arity:1]b -> + ((compare + (a |.u Client.getUniqueId) + (b |.u Client.getUniqueId)) + [@res.braces ])) end) let empty = Belt.Set.make ~id:(((module T))[@res.namedArgLoc ]) end diff --git a/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt b/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt index 6be6d414bf..6d99a83fc5 100644 --- a/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt +++ b/tests/syntax_tests/data/parsing/errors/structure/expected/letBinding.res.txt @@ -99,8 +99,8 @@ let rightResource = (ur.resources).find - ((Function$ (fun r -> r.account_id == ((connection.left).account).id)) - [@res.arity 1]) + (Function$ + (fun [arity:1]r -> r.account_id == ((connection.left).account).id)) let x = ((let field = p |.u parseFieldDeclaration in field)[@res.braces ]) let t = ((let (_, _, token) = scanner |.u scan in token)[@res.braces ]) let (keyTable : int Belt.Map.String.t) = [%rescript.exprhole ] diff --git a/tests/syntax_tests/data/parsing/errors/typeDef/expected/inlineRecord.res.txt b/tests/syntax_tests/data/parsing/errors/typeDef/expected/inlineRecord.res.txt index 3847940a87..85834693c6 100644 --- a/tests/syntax_tests/data/parsing/errors/typeDef/expected/inlineRecord.res.txt +++ b/tests/syntax_tests/data/parsing/errors/typeDef/expected/inlineRecord.res.txt @@ -44,11 +44,10 @@ type nonrec user = name: string ; address: < street: string ;country: string > } let make = - ((Function$ - (fun - (props : - < - handleClick: (Click.t -> unit, [ `Has_arity1 ]) function$ ; - value: string > ) - -> render props)) - [@res.arity 1]) \ No newline at end of file + Function$ + (fun + [arity:1](props : + < + handleClick: (Click.t -> unit, [ `Has_arity1 ]) function$ + ;value: string > ) + -> render props) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/errors/typexpr/expected/objectSpread.res.txt b/tests/syntax_tests/data/parsing/errors/typexpr/expected/objectSpread.res.txt index f49d8f0df5..d429e17985 100644 --- a/tests/syntax_tests/data/parsing/errors/typexpr/expected/objectSpread.res.txt +++ b/tests/syntax_tests/data/parsing/errors/typexpr/expected/objectSpread.res.txt @@ -30,4 +30,4 @@ type nonrec u = private { type nonrec x = | Type of < a ;u: int > type nonrec u = < a ;u: int ;v: int > -let f = ((Function$ (fun (x : < a: int ;b: int > ) -> ()))[@res.arity 1]) \ No newline at end of file +let f = Function$ (fun [arity:1](x : < a: int ;b: int > ) -> ()) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt index ffd40ac996..8e6a52419c 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedAlways.res.txt @@ -1,7 +1,7 @@ [@@@uncurried ] -let foo = ((Function$ (fun x -> fun y -> x + y))[@res.arity 2]) +let foo = Function$ (fun [arity:2]x -> fun [arity:1]y -> x + y) let z = foo 3 4 -let bar = ((Function$ (fun x -> fun y -> x + y))[@res.arity 2]) +let bar = Function$ (fun [arity:2]x -> fun [arity:1]y -> x + y) let b = bar 3 4 let w = 3 |.u (foo 4) let a = 3 |.u (foo 4) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt index ee062011ea..4d86f16622 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/UncurriedByDefault.res.txt @@ -1,24 +1,21 @@ let cApp = foo 3 let uApp = foo 3 -let cFun = ((Function$ (fun x -> 3))[@res.arity 1]) -let uFun = ((Function$ (fun x -> 3))[@res.arity 1]) +let cFun = Function$ (fun [arity:1]x -> 3) +let uFun = Function$ (fun [arity:1]x -> 3) let mixFun = - ((Function$ - (fun a -> - fun b -> - fun c -> - ((Function$ - (fun d -> - fun e -> - fun f -> ((Function$ (fun g -> fun h -> 4)) - [@res.arity 2]))) - [@res.arity 3]))) - [@res.arity 3]) + Function$ + (fun [arity:3]a -> + fun [arity:2]b -> + fun [arity:1]c -> + Function$ + (fun [arity:3]d -> + fun [arity:2]e -> + fun [arity:1]f -> + Function$ (fun [arity:2]g -> fun [arity:1]h -> 4))) let bracesFun = - ((Function$ (fun x -> ((Function$ (fun y -> x + y))[@res.arity 1]))) - [@res.arity 1]) -let cFun2 = ((Function$ (fun x -> fun y -> 3))[@res.arity 2]) -let uFun2 = ((Function$ (fun x -> fun y -> 3))[@res.arity 2]) + Function$ (fun [arity:1]x -> Function$ (fun [arity:1]y -> x + y)) +let cFun2 = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3) +let uFun2 = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3) type nonrec cTyp = (string -> int, [ `Has_arity1 ]) function$ type nonrec uTyp = (string -> int, [ `Has_arity1 ]) function$ type nonrec mixTyp = @@ -75,26 +72,24 @@ type nonrec unested = function$ let (uannpoly : ('a -> string, [ `Has_arity1 ]) function$) = xx let (uannint : (int -> string, [ `Has_arity1 ]) function$) = xx -let _ = ((Function$ ((fun x -> 34)[@att ]))[@res.arity 1]) -let _ = ((Function$ ((fun x -> 34)[@res.async ][@att ]))[@res.arity 1]) -let _ = preserveAttr ((Function$ ((fun x -> 34)[@att ]))[@res.arity 1]) -let _ = - preserveAttr ((Function$ ((fun x -> 34)[@res.async ][@att ])) - [@res.arity 1]) +let _ = Function$ ((fun [arity:1]x -> 34)[@att ]) +let _ = Function$ ((fun [arity:1]x -> 34)[@res.async ][@att ]) +let _ = preserveAttr (Function$ ((fun [arity:1]x -> 34)[@att ])) +let _ = preserveAttr (Function$ ((fun [arity:1]x -> 34)[@res.async ][@att ])) let t0 (type a) (type b) = - ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) + Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l) let t1 (type a) (type b) = - ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) + Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l) let t2 (type a) (type b) = - ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) + Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l) let t3 (type a) (type b) = - ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) + Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l) let t4 (type a) (type b) = - ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) + Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l) let t5 (type a) (type b) = - ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) + Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l) let t6 (type a) (type b) = - ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) + Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l) type nonrec arrowPath1 = (int -> string, [ `Has_arity1 ]) function$ type nonrec arrowPath2 = (I.t -> string, [ `Has_arity1 ]) function$ type nonrec arrowPath3 = (int -> string, [ `Has_arity1 ]) function$ @@ -107,31 +102,25 @@ type nonrec callback3 = (ReactEvent.Mouse.t -> unit, [ `Has_arity1 ]) function$ as 'callback let cApp = foo 3 let uApp = foo 3 -let cFun = ((Function$ (fun x -> 3))[@res.arity 1]) -let uFun = ((Function$ (fun x -> 3))[@res.arity 1]) +let cFun = Function$ (fun [arity:1]x -> 3) +let uFun = Function$ (fun [arity:1]x -> 3) let mixFun = - ((Function$ - (fun a -> - ((Function$ - (fun b -> - fun c -> - ((Function$ - (fun d -> - fun e -> - fun f -> - ((Function$ - (fun g -> ((Function$ (fun h -> 4)) - [@res.arity 1]))) - [@res.arity 1]))) - [@res.arity 3]))) - [@res.arity 2]))) - [@res.arity 1]) + Function$ + (fun [arity:1]a -> + Function$ + (fun [arity:2]b -> + fun [arity:1]c -> + Function$ + (fun [arity:3]d -> + fun [arity:2]e -> + fun [arity:1]f -> + Function$ + (fun [arity:1]g -> Function$ (fun [arity:1]h -> 4))))) let bracesFun = - ((Function$ (fun x -> ((Function$ (fun y -> x + y))[@res.arity 1]))) - [@res.arity 1]) -let cFun2 = ((Function$ (fun x -> fun y -> 3))[@res.arity 2]) -let uFun2 = ((Function$ (fun x -> fun y -> 3))[@res.arity 2]) -let cFun2Dots = ((Function$ (fun x -> fun y -> 3))[@res.arity 2]) + Function$ (fun [arity:1]x -> Function$ (fun [arity:1]y -> x + y)) +let cFun2 = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3) +let uFun2 = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3) +let cFun2Dots = Function$ (fun [arity:2]x -> fun [arity:1]y -> 3) type nonrec cTyp = (string -> int, [ `Has_arity1 ]) function$ type nonrec uTyp = (string -> int, [ `Has_arity1 ]) function$ type nonrec mixTyp = @@ -190,20 +179,18 @@ type nonrec unested = let pipe1 = 3 |.u f let (uannpoly : ('a -> string, [ `Has_arity1 ]) function$) = xx let (uannint : (int -> string, [ `Has_arity1 ]) function$) = xx -let _ = ((Function$ ((fun x -> 34)[@att ]))[@res.arity 1]) -let _ = ((Function$ ((fun x -> 34)[@res.async ][@att ]))[@res.arity 1]) -let _ = preserveAttr ((Function$ ((fun x -> 34)[@att ]))[@res.arity 1]) -let _ = - preserveAttr ((Function$ ((fun x -> 34)[@res.async ][@att ])) - [@res.arity 1]) +let _ = Function$ ((fun [arity:1]x -> 34)[@att ]) +let _ = Function$ ((fun [arity:1]x -> 34)[@res.async ][@att ]) +let _ = preserveAttr (Function$ ((fun [arity:1]x -> 34)[@att ])) +let _ = preserveAttr (Function$ ((fun [arity:1]x -> 34)[@res.async ][@att ])) let t0 (type a) (type b) = - ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) + Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l) let t1 (type a) (type b) = - ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) + Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l) let t2 (type a) (type b) = - ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) + Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l) let t3 (type a) (type b) = - ((Function$ (fun (l : a list) -> fun (x : a) -> x :: l))[@res.arity 2]) + Function$ (fun [arity:2](l : a list) -> fun [arity:1](x : a) -> x :: l) type nonrec arrowPath1 = (int -> string, [ `Has_arity1 ]) function$ type nonrec arrowPath2 = (I.t -> string, [ `Has_arity1 ]) function$ type nonrec arrowPath3 = (int -> string, [ `Has_arity1 ]) function$ diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/apply.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/apply.res.txt index 7170c39226..a08df40ebd 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/apply.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/apply.res.txt @@ -1,10 +1,11 @@ -;;foo ((Function$ (fun _ -> bla))[@res.arity 1]) blaz -;;foo ((Function$ (fun _ -> bla))[@res.arity 1]) blaz -;;foo ((Function$ (fun _ -> bla))[@res.arity 1]) blaz -;;foo ((Function$ (fun _ -> bla))[@res.arity 1]) ((Function$ (fun _ -> blaz)) - [@res.arity 1]) -;;List.map ((Function$ (fun x -> x + 1))[@res.arity 1]) myList -;;List.reduce ((Function$ (fun acc -> fun curr -> acc + curr))[@res.arity 2]) - 0 myList +;;foo (Function$ (fun [arity:1]_ -> bla)) blaz +;;foo (Function$ (fun [arity:1]_ -> bla)) blaz +;;foo (Function$ (fun [arity:1]_ -> bla)) blaz +;;foo (Function$ (fun [arity:1]_ -> bla)) + (Function$ (fun [arity:1]_ -> blaz)) +;;List.map (Function$ (fun [arity:1]x -> x + 1)) myList +;;List.reduce + (Function$ (fun [arity:2]acc -> fun [arity:1]curr -> acc + curr)) 0 + myList let unitUncurried = apply () ;;call ~a:(((((a)[@res.namedArgLoc ]) : int))[@res.namedArgLoc ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/argument.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/argument.res.txt index a8e3f5e200..267d3cb084 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/argument.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/argument.res.txt @@ -1,15 +1,15 @@ let foo = - ((Function$ - (fun ~a:((a)[@res.namedArgLoc ]) -> - (a (let __res_unit = () in __res_unit)) +. 1.)) - [@res.arity 1]) -let a = ((Function$ (fun () -> 2))[@res.arity 1]) + Function$ + (fun [arity:1]~a:((a)[@res.namedArgLoc ]) -> + (a (let __res_unit = () in __res_unit)) +. 1.) +let a = Function$ (fun [arity:1]() -> 2) let bar = foo ~a:((a)[@res.namedArgLoc ]) let comparisonResult = compare currentNode.value ~targetValue:((targetValue)[@res.namedArgLoc ]) ;;callback firstNode ~y:((y)[@res.namedArgLoc ]) ;;document.createElementWithOptions {js|div|js} - (elementProps ~onClick:((Function$ (fun _ -> Js.log {js|hello world|js})) - [@res.namedArgLoc ][@res.arity 1])) + (elementProps + ~onClick:((Function$ (fun [arity:1]_ -> Js.log {js|hello world|js})) + [@res.namedArgLoc ])) ;;resolve () ;;resolve (let __res_unit = () in __res_unit) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt index 9dfddce397..9060aa6494 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/arrow.res.txt @@ -1,103 +1,102 @@ -let f = ((Function$ (fun x -> x + 1))[@res.arity 1]) -let f = ((Function$ (fun _ -> Js.log {js|test|js}))[@res.arity 1]) -let f = ((Function$ (fun () -> Js.log {js|unit|js}))[@res.arity 1]) -let f = ((Function$ (fun (Reducer (inst, comp)) -> inst.render comp)) - [@res.arity 1]) -let f = ((Function$ (fun (Instance) -> ()))[@res.arity 1]) -let f = ((Function$ (fun a -> fun b -> a + b))[@res.arity 2]) -let f = ((Function$ (fun 1 -> fun 2 -> ()))[@res.arity 2]) -let f = ((Function$ (fun {js|stringPattern|js} -> ()))[@res.arity 1]) -let f = - ((Function$ (fun {js|stringPattern|js} -> fun {js|stringPattern|js} -> ())) - [@res.arity 2]) -let f = ((Function$ (fun () -> ()))[@res.arity 1]) -let f = ((Function$ (fun (a : int) -> fun (b : int) -> a + b))[@res.arity 2]) -let f = ((Function$ (fun _ -> fun _ -> ()))[@res.arity 2]) -let f = ((Function$ (fun [|a;b|] -> fun [|c;d|] -> ((a + b) + c) + d)) - [@res.arity 2]) -let f = ((Function$ (fun { a } -> a + 1))[@res.arity 1]) -let f = ((Function$ (fun { a; b } -> fun { c; d } -> ((a + b) + c) + d)) - [@res.arity 2]) -let f = ((Function$ (fun (a, b) -> a + b))[@res.arity 1]) -let f = ((Function$ (fun (a, b) -> fun (c, d) -> ((a + b) + c) + d)) - [@res.arity 2]) -let f = ((Function$ (fun exception Terminate -> ()))[@res.arity 1]) -let f = ((Function$ (fun exception Terminate -> fun exception Exit -> ())) - [@res.arity 2]) -let f = ((Function$ (fun [] -> ()))[@res.arity 1]) -let f = ((Function$ (fun (x::xs) -> x + (xs |.u Belt.List.length))) - [@res.arity 1]) -let f = ((Function$ (fun (x : int) -> fun (y : int) -> x + y))[@res.arity 2]) -let f = - ((Function$ - (fun ~a:((a)[@res.namedArgLoc ]) -> - fun ~b:((b)[@res.namedArgLoc ]) -> a + b)) - [@res.arity 2]) -let f = - ((Function$ - (fun ~a:((x)[@res.namedArgLoc ]) -> - fun ~b:((y)[@res.namedArgLoc ]) -> x + y)) - [@res.arity 2]) -let f = - ((Function$ - (fun ~a:(((x : int))[@res.namedArgLoc ]) -> - fun ~b:(((y : int))[@res.namedArgLoc ]) -> x + y)) - [@res.arity 2]) -let f = - ((Function$ - (fun ?a:(((a)[@res.namedArgLoc ])= 1) -> - fun ?b:(((b)[@res.namedArgLoc ])= 2) -> fun c -> (a + b) + c)) - [@res.arity 3]) -let f = - ((Function$ - (fun ?a:(((x)[@res.namedArgLoc ])= 1) -> - fun ?b:(((y)[@res.namedArgLoc ])= 2) -> fun c -> (x + y) + c)) - [@res.arity 3]) -let f = - ((Function$ - (fun ?a:((((x : int))[@res.namedArgLoc ])= 1) -> - fun ?b:((((y : int))[@res.namedArgLoc ])= 2) -> fun c -> (x + y) + c)) - [@res.arity 3]) -let f = - ((Function$ - (fun ?a:((a)[@res.namedArgLoc ]) -> - fun ?b:((b)[@res.namedArgLoc ]) -> - fun c -> - match (a, b) with | (Some a, Some b) -> (a + b) + c | _ -> 3)) - [@res.arity 3]) -let f = - ((Function$ - (fun ?a:((x)[@res.namedArgLoc ]) -> - fun ?b:((y)[@res.namedArgLoc ]) -> - fun c -> - match (x, y) with | (Some a, Some b) -> (a + b) + c | _ -> 3)) - [@res.arity 3]) -let f = - ((Function$ - (fun ?a:(((x : int option))[@res.namedArgLoc ]) -> - fun ?b:(((y : int option))[@res.namedArgLoc ]) -> - fun c -> - match (x, y) with | (Some a, Some b) -> (a + b) + c | _ -> 3)) - [@res.arity 3]) -let f = ((Function$ (fun a -> fun b -> a + b))[@res.arity 2]) -let f = ((Function$ (fun () -> ()))[@res.arity 1]) -let f = ((Function$ (fun () -> ()))[@res.arity 1]) -let f = ((Function$ (fun a -> fun b -> fun c -> ()))[@res.arity 3]) -let f = ((Function$ (fun a -> fun b -> fun c -> fun d -> ()))[@res.arity 4]) -let f = ((Function$ (fun a -> fun b -> fun c -> ()))[@res.arity 3]) -let f = - ((Function$ - (fun ~a:((a)[@res.namedArgLoc ][@attr ]) -> - fun b -> fun ~c:((c)[@res.namedArgLoc ][@attr ]) -> fun d -> ())) - [@res.arity 4]) -let f = - ((Function$ - (fun ~a:((a)[@res.namedArgLoc ][@attr ]) -> - fun ((b)[@attrOnB ]) -> - fun ~c:((c)[@res.namedArgLoc ][@attr ]) -> - fun ((d)[@attrOnD ]) -> ())) - [@res.arity 4]) -let f = ((Function$ (fun list -> list ()))[@res.arity 1]) +let f = Function$ (fun [arity:1]x -> x + 1) +let f = Function$ (fun [arity:1]_ -> Js.log {js|test|js}) +let f = Function$ (fun [arity:1]() -> Js.log {js|unit|js}) +let f = Function$ (fun [arity:1](Reducer (inst, comp)) -> inst.render comp) +let f = Function$ (fun [arity:1](Instance) -> ()) +let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> a + b) +let f = Function$ (fun [arity:2]1 -> fun [arity:1]2 -> ()) +let f = Function$ (fun [arity:1]{js|stringPattern|js} -> ()) +let f = + Function$ + (fun [arity:2]{js|stringPattern|js} -> + fun [arity:1]{js|stringPattern|js} -> ()) +let f = Function$ (fun [arity:1]() -> ()) +let f = Function$ (fun [arity:2](a : int) -> fun [arity:1](b : int) -> a + b) +let f = Function$ (fun [arity:2]_ -> fun [arity:1]_ -> ()) +let f = + Function$ + (fun [arity:2][|a;b|] -> fun [arity:1][|c;d|] -> ((a + b) + c) + d) +let f = Function$ (fun [arity:1]{ a } -> a + 1) +let f = + Function$ + (fun [arity:2]{ a; b } -> fun [arity:1]{ c; d } -> ((a + b) + c) + d) +let f = Function$ (fun [arity:1](a, b) -> a + b) +let f = + Function$ (fun [arity:2](a, b) -> fun [arity:1](c, d) -> ((a + b) + c) + d) +let f = Function$ (fun [arity:1]exception Terminate -> ()) +let f = + Function$ + (fun [arity:2]exception Terminate -> fun [arity:1]exception Exit -> ()) +let f = Function$ (fun [arity:1][] -> ()) +let f = Function$ (fun [arity:1](x::xs) -> x + (xs |.u Belt.List.length)) +let f = Function$ (fun [arity:2](x : int) -> fun [arity:1](y : int) -> x + y) +let f = + Function$ + (fun [arity:2]~a:((a)[@res.namedArgLoc ]) -> + fun [arity:1]~b:((b)[@res.namedArgLoc ]) -> a + b) +let f = + Function$ + (fun [arity:2]~a:((x)[@res.namedArgLoc ]) -> + fun [arity:1]~b:((y)[@res.namedArgLoc ]) -> x + y) +let f = + Function$ + (fun [arity:2]~a:(((x : int))[@res.namedArgLoc ]) -> + fun [arity:1]~b:(((y : int))[@res.namedArgLoc ]) -> x + y) +let f = + Function$ + (fun [arity:3]?a:(((a)[@res.namedArgLoc ])= 1) -> + fun [arity:2]?b:(((b)[@res.namedArgLoc ])= 2) -> + fun [arity:1]c -> (a + b) + c) +let f = + Function$ + (fun [arity:3]?a:(((x)[@res.namedArgLoc ])= 1) -> + fun [arity:2]?b:(((y)[@res.namedArgLoc ])= 2) -> + fun [arity:1]c -> (x + y) + c) +let f = + Function$ + (fun [arity:3]?a:((((x : int))[@res.namedArgLoc ])= 1) -> + fun [arity:2]?b:((((y : int))[@res.namedArgLoc ])= 2) -> + fun [arity:1]c -> (x + y) + c) +let f = + Function$ + (fun [arity:3]?a:((a)[@res.namedArgLoc ]) -> + fun [arity:2]?b:((b)[@res.namedArgLoc ]) -> + fun [arity:1]c -> + match (a, b) with | (Some a, Some b) -> (a + b) + c | _ -> 3) +let f = + Function$ + (fun [arity:3]?a:((x)[@res.namedArgLoc ]) -> + fun [arity:2]?b:((y)[@res.namedArgLoc ]) -> + fun [arity:1]c -> + match (x, y) with | (Some a, Some b) -> (a + b) + c | _ -> 3) +let f = + Function$ + (fun [arity:3]?a:(((x : int option))[@res.namedArgLoc ]) -> + fun [arity:2]?b:(((y : int option))[@res.namedArgLoc ]) -> + fun [arity:1]c -> + match (x, y) with | (Some a, Some b) -> (a + b) + c | _ -> 3) +let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> a + b) +let f = Function$ (fun [arity:1]() -> ()) +let f = Function$ (fun [arity:1]() -> ()) +let f = Function$ (fun [arity:3]a -> fun [arity:2]b -> fun [arity:1]c -> ()) +let f = + Function$ + (fun [arity:4]a -> + fun [arity:3]b -> fun [arity:2]c -> fun [arity:1]d -> ()) +let f = Function$ (fun [arity:3]a -> fun [arity:2]b -> fun [arity:1]c -> ()) +let f = + Function$ + (fun [arity:4]~a:((a)[@res.namedArgLoc ][@attr ]) -> + fun [arity:3]b -> + fun [arity:2]~c:((c)[@res.namedArgLoc ][@attr ]) -> + fun [arity:1]d -> ()) +let f = + Function$ + (fun [arity:4]~a:((a)[@res.namedArgLoc ][@attr ]) -> + fun [arity:3]((b)[@attrOnB ]) -> + fun [arity:2]~c:((c)[@res.namedArgLoc ][@attr ]) -> + fun [arity:1]((d)[@attrOnD ]) -> ()) +let f = Function$ (fun [arity:1]list -> list ()) ;;match colour with | Red when (l = l') || @@ -106,35 +105,33 @@ let f = ((Function$ (fun list -> list ()))[@res.arity 1]) -> (t1, t2) | _ -> () let arr = - [|((Function$ ((fun _ -> doThings ()))) - [@res.arity 1]);((Function$ ((fun _ -> doThings ()))) - [@res.arity 1]);((Function$ ((fun _ -> doThings ())))[@res.arity 1])|] + [|(Function$ ((fun [arity:1]_ -> doThings ())));(Function$ + ((fun [arity:1]_ -> + doThings ())));( + Function$ ((fun [arity:1]_ -> doThings ())))|] let list = - [((Function$ ((fun _ -> doThings ()))) - [@res.arity 1]); - ((Function$ ((fun _ -> doThings ()))) - [@res.arity 1]); - ((Function$ ((fun _ -> doThings ()))) - [@res.arity 1])] + [Function$ ((fun [arity:1]_ -> doThings ())); + Function$ ((fun [arity:1]_ -> doThings ())); + Function$ ((fun [arity:1]_ -> doThings ()))] let tuple = - (((Function$ (fun _ -> doThings ()))[@res.arity 1]), - ((Function$ (fun _ -> doThings ()))[@res.arity 1]), - ((Function$ (fun _ -> doThings ()))[@res.arity 1])) -;;((Function$ (fun _ -> doThings ()))[@res.arity 1]) + ((Function$ (fun [arity:1]_ -> doThings ())), + (Function$ (fun [arity:1]_ -> doThings ())), + (Function$ (fun [arity:1]_ -> doThings ()))) +;;Function$ (fun [arity:1]_ -> doThings ()) let x = Constructore - (((Function$ (fun _ -> copyChecklistItemCB ()))[@res.arity 1]), - ((Function$ (fun _ -> copyChecklistItemCB ()))[@res.arity 1])) + ((Function$ (fun [arity:1]_ -> copyChecklistItemCB ())), + (Function$ (fun [arity:1]_ -> copyChecklistItemCB ()))) let y = `Constructore - (((Function$ (fun _ -> copyChecklistItemCB ()))[@res.arity 1]), - ((Function$ (fun _ -> copyChecklistItemCB ()))[@res.arity 1])) -let f = ((Function$ (fun list -> list + 1))[@res.arity 1]) + ((Function$ (fun [arity:1]_ -> copyChecklistItemCB ())), + (Function$ (fun [arity:1]_ -> copyChecklistItemCB ()))) +let f = Function$ (fun [arity:1]list -> list + 1) let foo = (() : unit) type nonrec u = unit let un = (() : u) type nonrec ('a, 'b) d = ('a * 'b) -let c = ((Function$ (fun () -> ((1, 2) : ('a, 'b) d)))[@res.arity 1]) -let fn = ((Function$ (fun f -> f))[@res.arity 1]) +let c = Function$ (fun [arity:1]() -> ((1, 2) : ('a, 'b) d)) +let fn = Function$ (fun [arity:1]f -> f) type nonrec f = (int -> unit, [ `Has_arity1 ]) function$ -let a = fn (((Function$ (fun _ -> ()))[@res.arity 1]) : f) \ No newline at end of file +let a = fn (Function$ (fun [arity:1]_ -> ()) : f) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt index 5bc1666203..d76ad3ec36 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/async.res.txt @@ -1,19 +1,17 @@ let greetUser = - ((Function$ - ((fun userId -> - ((let name = ((getUserName userId)[@res.await ]) in - ({js|Hello |js} ^ name) ^ {js|!|js}) - [@res.braces ])) - [@res.async ])) - [@res.arity 1]) -;;((Function$ ((fun () -> 123)[@res.async ]))[@res.arity 1]) -let fetch = ((Function$ ((fun url -> browserFetch url)[@res.async ])) - [@res.braces ][@res.arity 1]) + Function$ + ((fun [arity:1]userId -> + ((let name = ((getUserName userId)[@res.await ]) in + ({js|Hello |js} ^ name) ^ {js|!|js}) + [@res.braces ])) + [@res.async ]) +;;Function$ ((fun [arity:1]() -> 123)[@res.async ]) +let fetch = + ((Function$ ((fun [arity:1]url -> browserFetch url)[@res.async ])) + [@res.braces ]) let fetch2 = - ((((Function$ (((fun url -> browserFetch url))[@res.async ])) - [@res.arity 1]); - ((Function$ (((fun url -> browserFetch2 url))[@res.async ])) - [@res.arity 1])) + ((Function$ (((fun [arity:1]url -> browserFetch url))[@res.async ]); + Function$ (((fun [arity:1]url -> browserFetch2 url))[@res.async ])) [@res.braces ]) let async = ((let f = async () in @@ -22,19 +20,21 @@ let async = async.async; { async = (async.(async)) }; (result |.u async) |.u - (mapAsync ((Function$ (fun a -> doStuff a))[@res.arity 1]))) + (mapAsync (Function$ (fun [arity:1]a -> doStuff a)))) [@res.braces ]) let f = ((if isPositive - then ((Function$ ((fun a -> fun b -> (a + b : int))[@res.async ])) - [@res.arity 2]) - else ((Function$ (((fun c -> fun d -> (c - d : int)))[@res.async ])) - [@res.arity 2])) + then + Function$ ((fun [arity:2]a -> fun [arity:1]b -> (a + b : int)) + [@res.async ]) + else + Function$ (((fun [arity:2]c -> fun [arity:1]d -> (c - d : int))) + [@res.async ])) [@res.ternary ]) let foo = async ~a:((34)[@res.namedArgLoc ]) let bar = - ((Function$ ((fun ~a:((a)[@res.namedArgLoc ]) -> a + 1)[@res.async ])) - [@res.arity 1]) + Function$ ((fun [arity:1]~a:((a)[@res.namedArgLoc ]) -> a + 1) + [@res.async ]) let ex1 = ((3)[@res.await ]) + ((4)[@res.await ]) let ex2 = ((3)[@res.await ]) ** ((4)[@res.await ]) let ex3 = ((foo |.u (bar ~arg:((arg)[@res.namedArgLoc ])))[@res.await ]) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/await.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/await.res.txt index 3ccb4c9d5e..12c2c1810f 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/await.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/await.res.txt @@ -19,21 +19,19 @@ let () = ((((delay 10)[@res.await ]); ((delay 20)[@res.await ])) let forEach = ((Js.Import Belt.List.forEach)[@res.await ][@a ][@b ]) module M = ((Belt.List)[@res.await ][@a ][@b ]) let f = - ((Function$ - (fun () -> - ((let module M = ((Belt.List)[@res.await ][@a ][@b ]) in M.forEach) - [@res.braces ]))) - [@res.arity 1]) + Function$ + (fun [arity:1]() -> + ((let module M = ((Belt.List)[@res.await ][@a ][@b ]) in M.forEach) + [@res.braces ])) let () = ((let module M = ((Belt.List)[@res.await ][@a ][@b ]) in M.forEach) [@res.braces ]) module type BeltList = module type of Belt.List let f = - ((Function$ - (fun () -> - ((let module M = (((Belt.List : BeltList))[@res.await ][@a ] - [@b ]) in M.forEach) - [@res.braces ]))) - [@res.arity 1]) + Function$ + (fun [arity:1]() -> + ((let module M = (((Belt.List : BeltList))[@res.await ][@a ][@b ]) in + M.forEach) + [@res.braces ])) let () = ((let module M = (((Belt.List : BeltList))[@res.await ][@a ][@b ]) in M.forEach) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt index 7d4bc6327e..7c2881e167 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binary.res.txt @@ -21,5 +21,4 @@ let x = a -. b let _ = ((Constructor (a, b); `Constructor (a, b))[@res.braces ]) ;;(library.getBalance account) |.u (Promise.Js.catch - ((Function$ (fun _ -> ((Promise.resolved None)[@res.braces ]))) - [@res.arity 1])) \ No newline at end of file + (Function$ (fun [arity:1]_ -> ((Promise.resolved None)[@res.braces ])))) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt index 77cf1dcb5f..9e4fb25ad9 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/binaryNoEs6Arrow.res.txt @@ -23,7 +23,7 @@ do () done ;;((div ~onClick:((Function$ - (fun event -> + (fun [arity:1]event -> ((match videoContainerRect with | Some videoContainerRect -> let newChapter = @@ -31,7 +31,6 @@ Video.chapter) in { a; b } |.u onChange | _ -> ()) - [@res.braces ]))) - [@res.namedArgLoc ][@res.braces ][@res.arity 1]) ~children:[] ()) - [@JSX ]) + [@res.braces ])))[@res.namedArgLoc ][@res.braces ]) + ~children:[] ())[@JSX ]) ;;if inclusions.(index) <- (uid, url) then onChange inclusions \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt index 30daf26a58..556b20feda 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/block.res.txt @@ -1,12 +1,11 @@ let b = ((let module Array = Belt.Array in - ([|1;2|] |.u (Array.map ((Function$ (fun x -> x + 1))[@res.arity 1]))) - |.u Js.log) + ([|1;2|] |.u (Array.map (Function$ (fun [arity:1]x -> x + 1)))) |.u + Js.log) [@res.braces ]) let b = ((let open Belt.Array in - ([|1;2|] |.u (map ((Function$ (fun x -> x + 1))[@res.arity 1]))) |.u - Js.log) + ([|1;2|] |.u (map (Function$ (fun [arity:1]x -> x + 1)))) |.u Js.log) [@res.braces ]) let b = ((let exception QuitEarly in raise QuitEarly)[@res.braces ]) let b = ((let a = 1 in let b = 2 in a + b)[@res.braces ]) @@ -22,7 +21,7 @@ let b = let a = 1 in let b = 2 in sideEffect (); - (let x = (1 + 2) |.u ((Function$ (fun x -> x + 1))[@res.arity 1]) in + (let x = (1 + 2) |.u (Function$ (fun [arity:1]x -> x + 1)) in raise (Terminate x))) [@res.braces ]) let b = ((f (); g (); h (); (let arr = [|1;2;3|] in ()))[@res.braces ]) @@ -43,52 +42,47 @@ let res = let nestedLet = ((let _ = 1 in ())[@res.braces ]) let nestedLet = ((let _ = 1 in 2)[@res.braces ]) let init = - ((Function$ (fun () -> ((foo (1 == 1); [%assert 1 == 2])[@res.braces ]))) - [@res.arity 1]) + Function$ + (fun [arity:1]() -> ((foo (1 == 1); [%assert 1 == 2])[@res.braces ])) let init = - ((Function$ - (fun () -> (([%assert 1 == 2]; foo (1 == 1); [%assert 1 == 2]) - [@res.braces ]))) - [@res.arity 1]) + Function$ + (fun [arity:1]() -> (([%assert 1 == 2]; foo (1 == 1); [%assert 1 == 2]) + [@res.braces ])) let f = - ((Function$ - (fun () -> ((let x = 1 in ((Function$ (fun _ -> ()))[@res.arity 1])) - [@res.braces ]))) - [@res.arity 1]) + Function$ + (fun [arity:1]() -> ((let x = 1 in Function$ (fun [arity:1]_ -> ())) + [@res.braces ])) let reifyStyle (type a) = - ((Function$ - (fun (x : 'a) -> - (((let module Internal = - struct - type constructor - external canvasGradient : constructor = "CanvasGradient" - [@@val ] - external canvasPattern : constructor = "CanvasPattern" - [@@val ] - let instanceOf = - ([%raw - (({js|function(x,y) {return +(x instanceof y)}|js}) - [@res.template ])] : ('a -> constructor -> bool, - [ `Has_arity2 ]) function$) - end in - ((if (Js.typeof x) = {js|string|js} - then Obj.magic String + Function$ + (fun [arity:1](x : 'a) -> + (((let module Internal = + struct + type constructor + external canvasGradient : constructor = "CanvasGradient" + [@@val ] + external canvasPattern : constructor = "CanvasPattern"[@@val ] + let instanceOf = + ([%raw + (({js|function(x,y) {return +(x instanceof y)}|js}) + [@res.template ])] : ('a -> constructor -> bool, + [ `Has_arity2 ]) function$) + end in + ((if (Js.typeof x) = {js|string|js} + then Obj.magic String + else + if Internal.instanceOf x Internal.canvasGradient + then Obj.magic Gradient else - if Internal.instanceOf x Internal.canvasGradient - then Obj.magic Gradient + if Internal.instanceOf x Internal.canvasPattern + then Obj.magic Pattern else - if Internal.instanceOf x Internal.canvasPattern - then Obj.magic Pattern - else - raise - (Invalid_argument - {js|Unknown canvas style kind. Known values are: String, CanvasGradient, CanvasPattern|js})), - (Obj.magic x))) - [@res.braces ]) : (a style * a)))) - [@res.arity 1]) + raise + (Invalid_argument + {js|Unknown canvas style kind. Known values are: String, CanvasGradient, CanvasPattern|js})), + (Obj.magic x))) + [@res.braces ]) : (a style * a))) let calc_fps = - ((Function$ - (fun t0 -> - fun t1 -> ((let delta = (t1 -. t0) /. 1000. in 1. /. delta) - [@res.braces ]))) - [@res.arity 2]) \ No newline at end of file + Function$ + (fun [arity:2]t0 -> + fun [arity:1]t1 -> ((let delta = (t1 -. t0) /. 1000. in 1. /. delta) + [@res.braces ])) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/bracedOrRecord.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/bracedOrRecord.res.txt index 1503dc741c..11388ed021 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/bracedOrRecord.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/bracedOrRecord.res.txt @@ -3,7 +3,7 @@ let r = { a } let r = { a = expr } let r = { a = expr } let r = { a = expr; b = expr2 } -let r = { f = ((Function$ (fun x -> x + b))[@res.arity 1]) } +let r = { f = (Function$ (fun [arity:1]x -> x + b)) } let e = ((a)[@res.braces ]) let e = ((a)[@res.braces ]) let e = ((a; b ())[@res.braces ]) @@ -16,20 +16,18 @@ let e = ((a.(0))[@res.braces ]) let e = ((f b)[@res.braces ]) let e = (((a.b).c)[@res.braces ]) let e = ((arr.(x) <- 20)[@res.braces ]) -let e = ((Function$ (fun x -> doStuff config (x + 1))) - [@res.braces ][@res.arity 1]) -let e = ((doStuff config ((Function$ (fun x -> x + 1))[@res.arity 1])) +let e = ((Function$ (fun [arity:1]x -> doStuff config (x + 1))) [@res.braces ]) -let e = - ((if ((Function$ (fun x -> x + 1))[@res.arity 1]) then true else false) +let e = ((doStuff config (Function$ (fun [arity:1]x -> x + 1))) + [@res.braces ]) +let e = ((if Function$ (fun [arity:1]x -> x + 1) then true else false) [@res.braces ][@res.ternary ]) let e = - ((sideEffect ((Function$ (fun x -> x + 1))[@res.arity 1]); - logToAnalytics Shady.ml) + ((sideEffect (Function$ (fun [arity:1]x -> x + 1)); logToAnalytics Shady.ml) + [@res.braces ]) +let f = ((Function$ (fun [arity:1]event -> (event.target).value)) + [@res.braces ]) +let f = ((Function$ (fun [arity:1]event -> ((event.target).value : string))) [@res.braces ]) -let f = ((Function$ (fun event -> (event.target).value)) - [@res.braces ][@res.arity 1]) -let f = ((Function$ (fun event -> ((event.target).value : string))) - [@res.braces ][@res.arity 1]) let x = ((let a = 1 in let b = 2 in a + b)[@res.braces ]) ;;(([(({js|\n|js} |.u React.string)[@res.braces ])])[@JSX ]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/coerce.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/coerce.res.txt index 91dac0bf41..493f8badeb 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/coerce.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/coerce.res.txt @@ -1,5 +1,5 @@ -let foo = ((Function$ (fun (x : int) -> (x :> int)))[@res.arity 1]) -let foo = ((Function$ (fun x -> ((x : t) :> int)))[@res.arity 1]) +let foo = Function$ (fun [arity:1](x : int) -> (x :> int)) +let foo = Function$ (fun [arity:1]x -> ((x : t) :> int)) let _ = (x : int) let foo = ((x : int), (y :> float)) let foo = ((x : int), (y :> float), (z :> int)) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/extension.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/extension.res.txt index 5b19a89e43..137deda8e9 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/extension.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/extension.res.txt @@ -1,5 +1,5 @@ ;;[%expr ] ;;[%expr.extension ] ;;[%expr.extension.with.args {js|argument|js}] -;;[%expr.extension.with.args ((Function$ (fun x -> f x))[@res.arity 1])] +;;[%expr.extension.with.args Function$ (fun [arity:1]x -> f x)] let x = ([%raw {js|1|js}]) + ([%raw {js|2|js}]) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt index e1f798dc53..f9f3af0c9c 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/firstClassModule.res.txt @@ -1,12 +1,11 @@ let makeSet (type s) = - ((Function$ - (fun cmp -> - ((let module S = - (Set.Make)(struct type nonrec t = s - let compare = cmp end) in ((module - S) : (module Set.S with type elt = s))) - [@res.braces ]))) - [@res.arity 1]) + Function$ + (fun [arity:1]cmp -> + ((let module S = + (Set.Make)(struct type nonrec t = s + let compare = cmp end) in ((module + S) : (module Set.S with type elt = s))) + [@res.braces ])) let three = ((module Three) : (module X_int)) let numbers = [|three;(module Four)|] let numbers = (three, (module Four)) @@ -15,55 +14,51 @@ let numbers = [|three;(module struct let x = 4 end)|] let numbers = (three, (module struct let x = 4 end)) let numbers = [three; (module struct let x = 4 end)] let plus = - ((Function$ - (fun m1 -> - fun m2 -> ((((module - struct let x = (to_int m1) + (to_int m2) end) : (module X_int))) - [@res.braces ]))) - [@res.arity 2]) + Function$ + (fun [arity:2]m1 -> + fun [arity:1]m2 -> ((((module + struct let x = (to_int m1) + (to_int m2) end) : (module X_int))) + [@res.braces ])) let plus = - ((Function$ - (fun m1 -> - fun m2 -> ((module - struct let x = (to_int m1) + (to_int m2) end) : (module X_int)))) - [@res.arity 2]) + Function$ + (fun [arity:2]m1 -> + fun [arity:1]m2 -> ((module + struct let x = (to_int m1) + (to_int m2) end) : (module X_int))) let unique_instance = ((module struct module Query_handler = Unique let this = Unique.create 0 end) : (module Query_handler_instance)) let build_instance (type a) = - ((Function$ - (fun ((module Q) : (module Query_handler with type config = a)) -> - fun config -> ((module - struct module Query_handler = Q - let this = Q.create config end) : (module - Query_handler_instance)))) - [@res.arity 2]) + Function$ + (fun [arity:2]((module Q) : (module Query_handler with type config = a)) + -> + fun [arity:1]config -> ((module + struct module Query_handler = Q + let this = Q.create config end) : (module + Query_handler_instance))) let build_instance (type a) = - ((Function$ - (fun ((module Q) : (module Query_handler with type config = a)) -> - fun config -> ((((module - struct module Query_handler = Q - let this = Q.create config end) : (module - Query_handler_instance))) - [@res.braces ]))) - [@res.arity 2]) + Function$ + (fun [arity:2]((module Q) : (module Query_handler with type config = a)) + -> + fun [arity:1]config -> ((((module + struct module Query_handler = Q + let this = Q.create config end) : (module + Query_handler_instance))) + [@res.braces ])) let unique_instance = build_instance (module Unique) 0 let build_dispatch_table = - ((Function$ - (fun handlers -> - ((let table = Hashtbl.create (module String) in - List.iter handlers - ~f:((Function$ - (fun - (((module I) : (module Query_handler_instance)) as - instance) - -> - Hashtbl.set table ~key:((I.Query_handler.name) - [@res.namedArgLoc ]) ~data:((instance) - [@res.namedArgLoc ]))) - [@res.namedArgLoc ][@res.arity 1]) table) - [@res.braces ]))) - [@res.arity 1]) + Function$ + (fun [arity:1]handlers -> + ((let table = Hashtbl.create (module String) in + List.iter handlers + ~f:((Function$ + (fun + [arity:1](((module I) : + (module Query_handler_instance)) as instance) + -> + Hashtbl.set table ~key:((I.Query_handler.name) + [@res.namedArgLoc ]) ~data:((instance) + [@res.namedArgLoc ])))[@res.namedArgLoc ]) table) + [@res.braces ])) ;;(module Three) ;;((module Three) : (module X_int)) ;;(module Teenager).(0) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt index b929c94c55..cd3f51ae10 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/jsx.res.txt @@ -10,13 +10,13 @@ let _ = ((div ~className:(({js|menu|js})[@res.namedArgLoc ]) ~children:[] ()) [@JSX ]) let _ = ((div ~className:(({js|menu|js})[@res.namedArgLoc ]) - ~onClick:((Function$ (fun _ -> Js.log {js|click|js})) - [@res.namedArgLoc ][@res.braces ][@res.arity 1]) ~children:[] ()) + ~onClick:((Function$ (fun [arity:1]_ -> Js.log {js|click|js})) + [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((div ~className:(({js|menu|js})[@res.namedArgLoc ]) - ~onClick:((Function$ (fun _ -> Js.log {js|click|js})) - [@res.namedArgLoc ][@res.braces ][@res.arity 1]) ~children:[] ()) + ~onClick:((Function$ (fun [arity:1]_ -> Js.log {js|click|js})) + [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((Navbar.createElement ~children:[] ())[@JSX ]) let _ = ((Navbar.createElement ~children:[] ())[@JSX ]) @@ -82,8 +82,7 @@ let _ = [@JSX ])] ()) [@JSX ]) let _ = ((div ~children:child ())[@JSX ]) -let _ = - ((Foo.createElement ~children:((Function$ (fun a -> 1))[@res.arity 1]) ()) +let _ = ((Foo.createElement ~children:(Function$ (fun [arity:1]a -> 1)) ()) [@JSX ]) let _ = ((Foo.createElement ~children:((Foo2.createElement ~children:[] ()) @@ -151,30 +150,30 @@ let y = ((Routes.createElement ~path:((Routes.stateToPath state) [@res.namedArgLoc ]) ~isHistorical:((true)[@res.namedArgLoc ]) ~onHashChange:((Function$ - (fun _oldPath -> - fun _oldUrl -> - fun newUrl -> + (fun [arity:3]_oldPath -> + fun [arity:2]_oldUrl -> + fun [arity:1]newUrl -> updater - ((Function$ - (fun latestComponentBag -> - fun _ -> - ((let currentActualPath = - Routes.hashOfUri newUrl in - let pathFromState = - Routes.stateToPath - latestComponentBag.state in - ((if - currentActualPath = - pathFromState - then None - else - dispatchEventless - (State.UriNavigated - currentActualPath) - latestComponentBag ()) - [@res.ternary ])) - [@res.braces ])))[@res.arity 2]) ())) - [@res.namedArgLoc ][@res.braces ][@res.arity 3]) ~children:[] ()) + (Function$ + (fun [arity:2]latestComponentBag -> + fun [arity:1]_ -> + ((let currentActualPath = + Routes.hashOfUri newUrl in + let pathFromState = + Routes.stateToPath + latestComponentBag.state in + ((if + currentActualPath = + pathFromState + then None + else + dispatchEventless + (State.UriNavigated + currentActualPath) + latestComponentBag ()) + [@res.ternary ])) + [@res.braces ]))) ())) + [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let z = ((div @@ -325,94 +324,101 @@ let _ = ~children:[child] ()) [@JSX ]) let _ = - ((div ~onClick:((Function$ (fun event -> handleChange event)) - [@res.namedArgLoc ][@res.braces ][@res.arity 1]) ~children:[] ()) + ((div ~onClick:((Function$ (fun [arity:1]event -> handleChange event)) + [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((div ~onClick:((Function$ - (fun eventWithLongIdent -> handleChange eventWithLongIdent)) - [@res.namedArgLoc ][@res.braces ][@res.arity 1]) ~children:[] ()) + (fun [arity:1]eventWithLongIdent -> + handleChange eventWithLongIdent)) + [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((div ~onClick:((Function$ - (fun event -> ((Js.log event; handleChange event) - [@res.braces ]))) - [@res.namedArgLoc ][@res.braces ][@res.arity 1]) ~children:[] ()) + (fun [arity:1]event -> ((Js.log event; handleChange event) + [@res.braces ])))[@res.namedArgLoc ][@res.braces ]) + ~children:[] ()) [@JSX ]) let _ = ((StaticDiv.createElement ~onClick:((Function$ - (fun foo -> - fun bar -> - fun baz -> - fun lineBreak -> - fun identifier -> + (fun [arity:5]foo -> + fun [arity:4]bar -> + fun [arity:3]baz -> + fun [arity:2]lineBreak -> + fun [arity:1]identifier -> ((doStuff foo bar baz; bar lineBreak identifier) [@res.braces ]))) - [@res.namedArgLoc ][@res.braces ][@res.arity 5]) ~children:[] ()) + [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((AttrDiv.createElement - ~onClick:((Function$ (fun event -> handleChange event)) - [@res.namedArgLoc ][@res.braces ][@bar ][@res.arity 1]) ~children:[] ()) + ~onClick:((Function$ (fun [arity:1]event -> handleChange event)) + [@res.namedArgLoc ][@res.braces ][@bar ]) ~children:[] ()) [@JSX ]) let _ = ((AttrDiv.createElement ~onClick:((Function$ - (fun eventLongIdentifier -> + (fun [arity:1]eventLongIdentifier -> handleChange eventLongIdentifier)) - [@res.namedArgLoc ][@res.braces ][@bar ][@res.arity 1]) ~children:[] ()) + [@res.namedArgLoc ][@res.braces ][@bar ]) ~children:[] ()) [@JSX ]) let _ = ((StaticDivNamed.createElement ~onClick:((Function$ - (fun ~foo:((foo)[@res.namedArgLoc ]) -> - fun ~bar:((bar)[@res.namedArgLoc ]) -> - fun ~baz:((baz)[@res.namedArgLoc ]) -> - fun ~lineBreak:((lineBreak)[@res.namedArgLoc ]) -> - fun ~identifier:((identifier)[@res.namedArgLoc ]) - -> fun () -> bar lineBreak identifier)) - [@res.namedArgLoc ][@res.braces ][@res.arity 6]) ~children:[] ()) + (fun [arity:6]~foo:((foo)[@res.namedArgLoc ]) -> + fun [arity:5]~bar:((bar)[@res.namedArgLoc ]) -> + fun [arity:4]~baz:((baz)[@res.namedArgLoc ]) -> + fun + [arity:3]~lineBreak:((lineBreak)[@res.namedArgLoc + ]) + -> + fun + [arity:2]~identifier:((identifier)[@res.namedArgLoc + ]) + -> fun [arity:1]() -> bar lineBreak identifier)) + [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((div ~onClick:((Function$ - (fun e -> (((doStuff (); bar foo)[@res.braces ]) : event))) - [@res.namedArgLoc ][@res.braces ][@res.arity 1]) ~children:[] ()) + (fun [arity:1]e -> (((doStuff (); bar foo) + [@res.braces ]) : event))) + [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((div ~onClick:((Function$ - (fun e -> - fun e2 -> (((doStuff (); bar foo) + (fun [arity:2]e -> + fun [arity:1]e2 -> (((doStuff (); bar foo) [@res.braces ]) : event))) - [@res.namedArgLoc ][@res.braces ][@res.arity 2]) ~children:[] ()) + [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((div ~onClick:((Function$ - (fun foo -> - fun bar -> - fun baz -> - fun superLongIdent -> - fun breakLine -> (((doStuff (); bar foo) + (fun [arity:5]foo -> + fun [arity:4]bar -> + fun [arity:3]baz -> + fun [arity:2]superLongIdent -> + fun [arity:1]breakLine -> (((doStuff (); bar foo) [@res.braces ]) : (event * event2 * event3 * event4 * event5)))) - [@res.namedArgLoc ][@res.braces ][@res.arity 5]) ~children:[] ()) + [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((div ~onClick:((Function$ - (fun foo -> - fun bar -> - fun baz -> - fun superLongIdent -> - fun breakLine -> + (fun [arity:5]foo -> + fun [arity:4]bar -> + fun [arity:3]baz -> + fun [arity:2]superLongIdent -> + fun [arity:1]breakLine -> (doStuff () : (event * event2 * event3 * event4 * event5)))) - [@res.namedArgLoc ][@res.braces ][@res.arity 5]) ~children:[] ()) + [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = ((div @@ -443,7 +449,7 @@ let _ = ((Animated.createElement ~initialValue:((0.0)[@res.namedArgLoc ]) ~value:((value)[@res.namedArgLoc ]) ~children:((Function$ - (fun value -> + (fun [arity:1]value -> ((div ~style:((ReactDOMRe.Style.make ~width:(({js|20px|js}) @@ -455,13 +461,13 @@ let _ = ~backgroundColor:(({js|red|js}) [@res.namedArgLoc ])) [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) - [@JSX ])))[@res.braces ][@res.arity 1]) ()) + [@JSX ])))[@res.braces ]) ()) [@JSX ]) let _ = ((Animated.createElement ~initialValue:((0.0)[@res.namedArgLoc ]) ~value:((value)[@res.namedArgLoc ]) ~children:((Function$ - (fun value -> + (fun [arity:1]value -> (((div ~style:((ReactDOMRe.Style.make ~width:(({js|20px|js}) @@ -474,14 +480,13 @@ let _ = [@res.namedArgLoc ])) [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) - [@JSX ]) : ReasonReact.element))) - [@res.braces ][@res.arity 1]) ()) + [@JSX ]) : ReasonReact.element)))[@res.braces ]) ()) [@JSX ]) let _ = ((Animated.createElement ~initialValue:((0.0)[@res.namedArgLoc ]) ~value:((value)[@res.namedArgLoc ]) ~children:((Function$ - (fun value -> + (fun [arity:1]value -> ((div ~style:((ReactDOMRe.Style.make ~width:(({js|20px|js}) @@ -493,14 +498,13 @@ let _ = ~backgroundColor:(({js|red|js}) [@res.namedArgLoc ])) [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) - [@res.braces ][@JSX ]))) - [@res.braces ][@foo ][@res.arity 1]) ()) + [@res.braces ][@JSX ])))[@res.braces ][@foo ]) ()) [@JSX ]) let _ = ((Animated.createElement ~initialValue:((0.0)[@res.namedArgLoc ]) ~value:((value)[@res.namedArgLoc ]) ~children:((Function$ - (fun value -> + (fun [arity:1]value -> ((let width = {js|20px|js} in let height = {js|20px|js} in ((div @@ -514,10 +518,10 @@ let _ = [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ])) - [@res.braces ])))[@res.braces ][@res.arity 1]) ()) + [@res.braces ])))[@res.braces ]) ()) [@JSX ]) let _ = - ((div ~callback:((reduce ((Function$ (fun () -> not state))[@res.arity 1])) + ((div ~callback:((reduce (Function$ (fun [arity:1]() -> not state))) [@res.namedArgLoc ][@res.braces ]) ~children:[] ()) [@JSX ]) let _ = @@ -578,44 +582,47 @@ let _ = ~children:[((ReasonReact.array (Array.of_list (List.map - ((Function$ - (fun possibleGradeValue -> - ((option - ~key:((string_of_int possibleGradeValue) - [@res.namedArgLoc ][@res.braces ]) - ~value:((string_of_int - possibleGradeValue) - [@res.namedArgLoc ][@res.braces ]) - ~children:[((str - (string_of_int - possibleGradeValue)) - [@res.braces ])] ()) - [@JSX ])))[@res.arity 1]) + (Function$ + (fun [arity:1]possibleGradeValue -> + ((option + ~key:((string_of_int possibleGradeValue) + [@res.namedArgLoc ][@res.braces ]) + ~value:((string_of_int + possibleGradeValue) + [@res.namedArgLoc ][@res.braces ]) + ~children:[((str + (string_of_int + possibleGradeValue)) + [@res.braces ])] ()) + [@JSX ]))) (List.filter - ((Function$ (fun g -> g <= state.maxGrade)) - [@res.arity 1]) possibleGradeValues)))) + (Function$ + (fun [arity:1]g -> g <= state.maxGrade)) + possibleGradeValues)))) [@res.braces ])] ())[@JSX ]) ;;((div ~children:[((Js.log (a <= 10))[@res.braces ])] ())[@JSX ]) ;;((div ~children:[((div ~children:[((Js.log (a <= 10))[@res.braces ])] ()) [@JSX ])] ())[@JSX ]) ;;((div - ~children:[((div ~onClick:((Function$ (fun _ -> Js.log (a <= 10))) - [@res.namedArgLoc ][@res.braces ][@res.arity 1]) + ~children:[((div + ~onClick:((Function$ + (fun [arity:1]_ -> Js.log (a <= 10))) + [@res.namedArgLoc ][@res.braces ]) ~children:[((div ~children:[((Js.log (a <= 10)) [@res.braces ])] ()) [@JSX ])] ()) [@JSX ])] ())[@JSX ]) ;;((div ~children:element ())[@JSX ]) -;;((div ~children:((Function$ (fun a -> 1))[@res.braces ][@res.arity 1]) ()) +;;((div ~children:((Function$ (fun [arity:1]a -> 1))[@res.braces ]) ()) [@JSX ]) ;;((div ~children:((span ~children:[] ())[@JSX ]) ())[@JSX ]) ;;((div ~children:[|a|] ())[@JSX ]) ;;((div ~children:(1, 2) ())[@JSX ]) ;;((div ~children:((array |.u f)[@res.braces ]) ())[@JSX ]) ;;(([element])[@JSX ]) -;;(([((Function$ ((fun a -> 1)))[@res.braces ][@res.arity 1])])[@JSX ]) +;;(([((Function$ ((fun [arity:1]a -> 1)))[@res.braces ])])[@JSX ]) ;;(([((span ~children:[] ())[@JSX ])])[@JSX ]) ;;(([[|a|]])[@JSX ]) ;;(([(1, 2)])[@JSX ]) diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/locallyAbstractTypes.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/locallyAbstractTypes.res.txt index 95bad3fb60..2e3d1e4b3b 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/locallyAbstractTypes.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/locallyAbstractTypes.res.txt @@ -1,29 +1,31 @@ -let f (type t) = ((Function$ (fun (xs : t list) -> ()))[@res.arity 1]) +let f (type t) = Function$ (fun [arity:1](xs : t list) -> ()) let f (type t) = - ((Function$ (fun (xs : t list) -> fun (type s) -> fun (ys : s list) -> ())) - [@res.arity 2]) + Function$ + (fun [arity:2](xs : t list) -> fun (type s) -> + fun [arity:1](ys : s list) -> ()) let f (type t) (type u) (type v) = - ((Function$ (fun (xs : (t * u * v) list) -> ()))[@res.arity 1]) + Function$ (fun [arity:1](xs : (t * u * v) list) -> ()) let f (type t) (type u) (type v) = - ((Function$ - (fun (xs : (t * u * v) list) -> fun (type s) -> fun (type w) -> fun - (type z) -> fun (ys : (s * w * z) list) -> ())) - [@res.arity 2]) + Function$ + (fun [arity:2](xs : (t * u * v) list) -> fun (type s) -> fun (type w) -> + fun (type z) -> fun [arity:1](ys : (s * w * z) list) -> ()) let f = ((fun (type t) -> fun (type u) -> fun (type v) -> - ((Function$ - (fun (xs : (t * u * v) list) -> ((fun (type s) -> fun (type w) -> fun - (type z) -> fun (ys : (s * w * z) list) -> ())[@attr2 ]))) - [@res.arity 2]))[@attr ]) + Function$ + (fun [arity:2](xs : (t * u * v) list) -> ((fun (type s) -> fun (type w) + -> fun (type z) -> fun [arity:1](ys : (s * w * z) list) -> ()) + [@attr2 ]))) + [@attr ]) let f = ((fun (type t) -> ((fun (type s) -> - ((Function$ - (fun (xs : (t * s) list) -> ((fun (type u) -> ((fun (type v) -> fun - (type w) -> fun (ys : (u * v * w) list) -> ())[@attr ]))[@attr ]))) - [@res.arity 2]))[@attr ]))[@attr ]) + Function$ + (fun [arity:2](xs : (t * s) list) -> ((fun (type u) -> ((fun (type v) -> + fun (type w) -> fun [arity:1](ys : (u * v * w) list) -> ())[@attr ])) + [@attr ]))) + [@attr ]))[@attr ]) let cancel_and_collect_callbacks : 'a 'u 'c . (packed_callbacks list -> ('a, 'u, 'c) promise -> packed_callbacks list, [ `Has_arity2 ]) function$ = fun (type x) -> - ((Function$ - (fun callbacks_accumulator -> fun (p : (_, _, c) promise) -> ())) - [@res.arity 2]) \ No newline at end of file + Function$ + (fun [arity:2]callbacks_accumulator -> + fun [arity:1](p : (_, _, c) promise) -> ()) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/record.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/record.res.txt index 082bb3a3f9..002b2e837f 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/record.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/record.res.txt @@ -13,10 +13,10 @@ let r = { expr with pexp_attributes = [||] } let r = { (make () : myRecord) with foo = bar } let r = { (make () : myRecord) with foo = bar } let r = { x = ?None; y = ?None; z = ?(None : tt) } -let z = ((Function$ (fun name -> { name?; x = 3 }))[@res.arity 1]) -let z = ((Function$ (fun name -> { name?; x = 3 }))[@res.arity 1]) -let z = ((Function$ (fun name -> { name; x? }))[@res.arity 1]) -let zz = ((Function$ (fun name -> { name; x? }))[@res.arity 1]) +let z = Function$ (fun [arity:1]name -> { name?; x = 3 }) +let z = Function$ (fun [arity:1]name -> { name?; x = 3 }) +let z = Function$ (fun [arity:1]name -> { name; x? }) +let zz = Function$ (fun [arity:1]name -> { name; x? }) let _ = match z with | { x? = None; y? = None; z? = (None : tt) } -> 11 diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/tupleVsDivision.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/tupleVsDivision.res.txt index 24f94f3599..46850dc5c8 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/tupleVsDivision.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/tupleVsDivision.res.txt @@ -2,7 +2,6 @@ ;;foo () ;;(1, 2) |.u printTuple let f = - ((Function$ - (fun () -> (((foo ()) / 1; foo (); (1, 2) |.u printTuple) - [@res.braces ]))) - [@res.arity 1]) \ No newline at end of file + Function$ + (fun [arity:1]() -> (((foo ()) / 1; foo (); (1, 2) |.u printTuple) + [@res.braces ])) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/uncurried.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/uncurried.res.txt index db8486599f..1b6cb630d1 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/uncurried.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/uncurried.res.txt @@ -1,30 +1,30 @@ -let f = ((Function$ (fun a -> fun b -> a + b))[@res.arity 2]) -let f = ((Function$ (fun a -> fun b -> a + b))[@res.arity 2]) -let f = ((Function$ (fun a -> fun b -> fun c -> fun d -> ((a + b) + c) + d)) - [@res.arity 4]) +let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> a + b) +let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> a + b) let f = - ((Function$ - ((fun a -> - ((Function$ - ((fun b -> - ((Function$ - ((fun c -> ((Function$ ((fun d -> ())[@attr4 ])) - [@res.arity 1])) - [@attr3 ])) - [@res.arity 1])) - [@attr2 ])) - [@res.arity 1])) - [@attr ])) - [@res.arity 1]) + Function$ + (fun [arity:4]a -> + fun [arity:3]b -> + fun [arity:2]c -> fun [arity:1]d -> ((a + b) + c) + d) let f = - ((Function$ - (fun ((a)[@attr ]) -> - fun ((b)[@attr2 ]) -> fun ((c)[@attr3 ]) -> fun ((d)[@attr4 ]) -> ())) - [@res.arity 4]) + Function$ + ((fun [arity:1]a -> + Function$ + ((fun [arity:1]b -> + Function$ + ((fun [arity:1]c -> + Function$ ((fun [arity:1]d -> ())[@attr4 ])) + [@attr3 ])) + [@attr2 ])) + [@attr ]) let f = - ((Function$ - (fun ((a)[@attr ]) -> - fun ((b)[@attr2 ]) -> fun ((c)[@attr3 ]) -> fun ((d)[@attr4 ]) -> ())) - [@res.arity 4]) + Function$ + (fun [arity:4]((a)[@attr ]) -> + fun [arity:3]((b)[@attr2 ]) -> + fun [arity:2]((c)[@attr3 ]) -> fun [arity:1]((d)[@attr4 ]) -> ()) +let f = + Function$ + (fun [arity:4]((a)[@attr ]) -> + fun [arity:3]((b)[@attr2 ]) -> + fun [arity:2]((c)[@attr3 ]) -> fun [arity:1]((d)[@attr4 ]) -> ()) ;;add 1 2 ;;add 2 3 4 5 6 7 8 9 10 \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt b/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt index f26f2f3d08..86a8b0da28 100644 --- a/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/expressions/expected/underscoreApply.res.txt @@ -1,45 +1,39 @@ let l = ([1; 2; 3] |.u - ((Function$ - (fun __x -> - List.map ((Function$ (fun i -> i + 1))[@res.arity 1]) __x)) - [@res.arity 1])) + (Function$ + (fun [arity:1]__x -> + List.map (Function$ (fun [arity:1]i -> i + 1)) __x))) |.u - ((Function$ - (fun __x -> - List.filter ((Function$ (fun i -> i > 0))[@res.arity 1]) __x)) - [@res.arity 1]) + (Function$ + (fun [arity:1]__x -> + List.filter (Function$ (fun [arity:1]i -> i > 0)) __x)) let l = - ((Function$ (fun i -> i + 1))[@res.arity 1]) |.u - ((Function$ (fun __x -> List.map __x [1; 2; 3]))[@res.arity 1]) -let x = ((Function$ (fun __x -> List.length __x))[@res.arity 1]) + (Function$ (fun [arity:1]i -> i + 1)) |.u + (Function$ (fun [arity:1]__x -> List.map __x [1; 2; 3])) +let x = Function$ (fun [arity:1]__x -> List.length __x) let nested = - ((Function$ - (fun x -> ((Function$ (fun __x -> List.length __x))[@res.arity 1]))) - [@res.arity 1]) -let incr = ((Function$ (fun ~v:((v)[@res.namedArgLoc ]) -> v + 1)) - [@res.arity 1]) + Function$ + (fun [arity:1]x -> Function$ (fun [arity:1]__x -> List.length __x)) +let incr = Function$ (fun [arity:1]~v:((v)[@res.namedArgLoc ]) -> v + 1) let l1 = List.length - (List.map ((Function$ (fun __x -> incr ~v:__x))[@res.arity 1]) [1; 2; 3]) + (List.map (Function$ (fun [arity:1]__x -> incr ~v:__x)) [1; 2; 3]) let l2 = List.length - (List.map ((Function$ (fun __x -> incr ~v:__x))[@res.arity 1]) [1; 2; 3]) + (List.map (Function$ (fun [arity:1]__x -> incr ~v:__x)) [1; 2; 3]) let optParam = - ((Function$ - (fun ?v:((v)[@res.namedArgLoc ]) -> - fun () -> ((if v = None then 0 else 1)[@res.ternary ]))) - [@res.arity 2]) + Function$ + (fun [arity:2]?v:((v)[@res.namedArgLoc ]) -> + fun [arity:1]() -> ((if v = None then 0 else 1)[@res.ternary ])) let l1 = List.length - (List.map ((Function$ (fun __x -> optParam ?v:__x ()))[@res.arity 1]) + (List.map (Function$ (fun [arity:1]__x -> optParam ?v:__x ())) [Some 1; None; Some 2]) let l2 = List.length - (List.map ((Function$ (fun __x -> optParam ?v:__x ()))[@res.arity 1]) + (List.map (Function$ (fun [arity:1]__x -> optParam ?v:__x ())) [Some 1; None; Some 2]) -;;((Function$ - (fun __x -> - underscoreWithComments - ((Function$ (fun x -> ((something ())[@res.braces ]))) - [@res.arity 1]) __x))[@res.arity 1]) \ No newline at end of file +;;Function$ + (fun [arity:1]__x -> + underscoreWithComments + (Function$ (fun [arity:1]x -> ((something ())[@res.braces ]))) __x) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/modexpr/expected/apply.res.txt b/tests/syntax_tests/data/parsing/grammar/modexpr/expected/apply.res.txt index 0de90cceb6..22f9a13cc2 100644 --- a/tests/syntax_tests/data/parsing/grammar/modexpr/expected/apply.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/modexpr/expected/apply.res.txt @@ -12,7 +12,6 @@ module X = (F)((A : SetLike)) module X = ((F)((A : SetLike)))((B : TreeLike)) module X = ((F)((A : SetLike)))((B : TreeLike)) let someFunctorAsFunction = - ((Function$ - (fun (x : (module MT)) -> ((module (SomeFunctor)((val - x))) : (module ResT)))) - [@res.arity 1]) \ No newline at end of file + Function$ + (fun [arity:1](x : (module MT)) -> ((module (SomeFunctor)((val + x))) : (module ResT))) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/modexpr/expected/firstClassModules.res.txt b/tests/syntax_tests/data/parsing/grammar/modexpr/expected/firstClassModules.res.txt index 668b92e718..1c09739d12 100644 --- a/tests/syntax_tests/data/parsing/grammar/modexpr/expected/firstClassModules.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/modexpr/expected/firstClassModules.res.txt @@ -3,17 +3,15 @@ module Device = (val try Hashtbl.find devices deviceName with | Not_found -> exit 2) [@res.braces ]) : (module Device))) let draw_using_device = - ((Function$ - (fun device_name -> - fun picture -> - ((let module Device = (val - (Hashtbl.find devices device_name : (module DEVICE))) in - Device.draw picture) - [@res.braces ]))) - [@res.arity 2]) + Function$ + (fun [arity:2]device_name -> + fun [arity:1]picture -> + ((let module Device = (val + (Hashtbl.find devices device_name : (module DEVICE))) in + Device.draw picture) + [@res.braces ])) module New_three = (val (three : (module X_int))) let to_int = - ((Function$ - (fun m -> ((let module M = (val (m : (module X_int))) in M.x) - [@res.braces ]))) - [@res.arity 1]) \ No newline at end of file + Function$ + (fun [arity:1]m -> ((let module M = (val (m : (module X_int))) in M.x) + [@res.braces ])) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/modexpr/expected/functor.res.txt b/tests/syntax_tests/data/parsing/grammar/modexpr/expected/functor.res.txt index ef100a32bf..7f898aba98 100644 --- a/tests/syntax_tests/data/parsing/grammar/modexpr/expected/functor.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/modexpr/expected/functor.res.txt @@ -30,27 +30,26 @@ module Make(Cmp:sig type nonrec coll = key list let empty = [] let add = - ((Function$ - (fun (y : coll) -> - fun (e : key) -> - if List.exists ((Function$ (fun x -> eq x e))[@res.arity 1]) y - then y - else e :: y)) - [@res.arity 2]) + Function$ + (fun [arity:2](y : coll) -> + fun [arity:1](e : key) -> + if List.exists (Function$ (fun [arity:1]x -> eq x e)) y + then y + else e :: y) end module Gen1(P:Primitive)() = struct type nonrec t = P.t type nonrec internal = P.t - let inject = ((Function$ (fun t -> t))[@res.arity 1]) + let inject = Function$ (fun [arity:1]t -> t) end module DistinctString() : StringBased = struct type nonrec t = string - let inject = ((Function$ (fun t -> t))[@res.arity 1]) + let inject = Function$ (fun [arity:1]t -> t) end module DistinctString() : StringBased = struct type nonrec t = string - let inject = ((Function$ (fun t -> t))[@res.arity 1]) + let inject = Function$ (fun [arity:1]t -> t) end \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/any.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/any.res.txt index a0d068e67d..3123064d47 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/any.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/any.res.txt @@ -17,13 +17,13 @@ let _ as _y|_ as _x = 1 | _ as _x|_ as _x -> () | (_ : unit) -> () | (_ : unit)|(_ : unit) -> () -let f = ((Function$ (fun _ -> ()))[@res.arity 1]) -let f = ((Function$ (fun (_ as _x) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (_ : unit) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (_ : unit) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ((_ : unit) as _x) -> ()))[@res.arity 1]) -let g = ((Function$ (fun a -> fun _ -> ()))[@res.arity 2]) -let g = ((Function$ (fun _ -> fun a -> ()))[@res.arity 2]) +let f = Function$ (fun [arity:1]_ -> ()) +let f = Function$ (fun [arity:1](_ as _x) -> ()) +let f = Function$ (fun [arity:1](_ : unit) -> ()) +let f = Function$ (fun [arity:1](_ : unit) -> ()) +let f = Function$ (fun [arity:1]((_ : unit) as _x) -> ()) +let g = Function$ (fun [arity:2]a -> fun [arity:1]_ -> ()) +let g = Function$ (fun [arity:2]_ -> fun [arity:1]a -> ()) ;;for _ = 0 to 10 do () done ;;for _ as _x = 0 to 10 do () done ;;for _ = 0 to 10 do () done diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/array.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/array.res.txt index 94ad52cb04..32b3c803d0 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/array.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/array.res.txt @@ -9,11 +9,11 @@ let ([|(1 : int);(2 : int)|] : int array) = () | [|1;2|] -> () | [|(1 : int);(2 : int)|] -> () | ([|(1 : int);(2 : int)|] : int) -> () -let f = ((Function$ (fun [||] -> ()))[@res.arity 1]) -let f = ((Function$ (fun [|x|] -> ()))[@res.arity 1]) -let f = ((Function$ (fun [|x;y|] -> x + y))[@res.arity 1]) -let f = ((Function$ (fun ([|x|] : int) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ([|x|] : int) -> ()))[@res.arity 1]) +let f = Function$ (fun [arity:1][||] -> ()) +let f = Function$ (fun [arity:1][|x|] -> ()) +let f = Function$ (fun [arity:1][|x;y|] -> x + y) +let f = Function$ (fun [arity:1]([|x|] : int) -> ()) +let f = Function$ (fun [arity:1]([|x|] : int) -> ()) ;;for [||] = 0 to 10 do () done ;;for [||] = 0 to 10 do () done ;;for [||] = 0 to 10 do () done diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/constant.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/constant.res.txt index add745ee57..713dc033fc 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/constant.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/constant.res.txt @@ -15,15 +15,13 @@ let ({js|stringPattern|js} : string) as s = () ;;for {js|stringPattern|js} = 0 to 10 do () done ;;for {js|stringPattern|js} as s = 0 to 10 do () done ;;for {js|stringPattern|js} as s = 0 to 10 do () done -let f = ((Function$ (fun {js|stringPattern|js} -> ()))[@res.arity 1]) -let f = ((Function$ (fun ({js|stringPattern|js} as s) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ({js|stringPattern|js} as s) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ({js|stringPattern|js} : string) -> ())) - [@res.arity 1]) -let f = ((Function$ (fun (({js|stringPattern|js} : string) as s) -> ())) - [@res.arity 1]) -let f = ((Function$ (fun ({js|stringPattern|js} : string) -> ())) - [@res.arity 1]) +let f = Function$ (fun [arity:1]{js|stringPattern|js} -> ()) +let f = Function$ (fun [arity:1]({js|stringPattern|js} as s) -> ()) +let f = Function$ (fun [arity:1]({js|stringPattern|js} as s) -> ()) +let f = Function$ (fun [arity:1]({js|stringPattern|js} : string) -> ()) +let f = + Function$ (fun [arity:1](({js|stringPattern|js} : string) as s) -> ()) +let f = Function$ (fun [arity:1]({js|stringPattern|js} : string) -> ()) let 1 = () let 1 as x = () let (1 : int) = () @@ -33,11 +31,11 @@ let (1 : int) as x = () | 1 as x -> () | (1 : int) -> () | (1 : int) as x -> () -let f = ((Function$ (fun 1 -> ()))[@res.arity 1]) -let f = ((Function$ (fun (1 as x) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (1 : int) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ((1 : int) as x) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (1 : int) -> ()))[@res.arity 1]) +let f = Function$ (fun [arity:1]1 -> ()) +let f = Function$ (fun [arity:1](1 as x) -> ()) +let f = Function$ (fun [arity:1](1 : int) -> ()) +let f = Function$ (fun [arity:1]((1 : int) as x) -> ()) +let f = Function$ (fun [arity:1](1 : int) -> ()) ;;for i = 0 to 10 do () done ;;for i as x = 0 to 10 do () done ;;for i = 0 to 10 do () done @@ -52,16 +50,15 @@ let f = ((Function$ (fun (1 : int) -> ()))[@res.arity 1]) makeListPattern loc patterns None let _0 = 0x9A let print = - ((Function$ - (fun ppf -> - fun i -> - match i.stamp with - | 0 -> fprintf ppf {js|%s!|js} i.name - | (-1) -> fprintf ppf {js|%s#|js} i.name - | 1 -> fprintf ppf {js|%s#|js} i.name - | (-1.) -> fprintf ppf {js|%s#|js} i.name - | 1. -> fprintf ppf {js|%s#|js} i.name)) - [@res.arity 2]) + Function$ + (fun [arity:2]ppf -> + fun [arity:1]i -> + match i.stamp with + | 0 -> fprintf ppf {js|%s!|js} i.name + | (-1) -> fprintf ppf {js|%s#|js} i.name + | 1 -> fprintf ppf {js|%s#|js} i.name + | (-1.) -> fprintf ppf {js|%s#|js} i.name + | 1. -> fprintf ppf {js|%s#|js} i.name) let (-1)..(-1.) = x ;;match science with | (1.12, (-3.13)) -> true diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/constructor.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/constructor.res.txt index 591a6bfb5c..cf5a42dd94 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/constructor.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/constructor.res.txt @@ -34,25 +34,24 @@ let ((Instance (component : comp)) : React.t) = i | Instance (comp, tree) -> () | React.Instance (comp, tree) -> () | (Instance (comp : Component.t) : React.t) -> () -let f = ((Function$ (fun (Instance) -> i))[@res.arity 1]) -let f = ((Function$ (fun (Instance as i) -> i))[@res.arity 1]) -let f = ((Function$ (fun (React.Instance) -> i))[@res.arity 1]) -let f = ((Function$ (fun (React.Instance as x) -> i))[@res.arity 1]) -let f = ((Function$ (fun (Instance component) -> i))[@res.arity 1]) -let f = ((Function$ (fun (Instance component) -> i))[@res.arity 1]) -let f = ((Function$ (fun (Instance { render; subtree }) -> i))[@res.arity 1]) -let f = ((Function$ (fun (Instance ({ render; subtree }, inst)) -> i)) - [@res.arity 1]) -let f = ((Function$ (fun (Instance ({ render; subtree } : Instance.t)) -> i)) - [@res.arity 1]) -let f = ((Function$ (fun (Instance ({ render; subtree } : Instance.t)) -> i)) - [@res.arity 1]) -let f = ((Function$ (fun (Instance (component, tree)) -> i))[@res.arity 1]) -let f = ((Function$ (fun (Instance (component, tree)) -> i))[@res.arity 1]) -let f = ((Function$ (fun (Instance : React.t) -> i))[@res.arity 1]) -let f = ((Function$ (fun (Instance : React.t) -> i))[@res.arity 1]) -let f = ((Function$ (fun (Instance (comp : Component.t) : React.t) -> ())) - [@res.arity 1]) +let f = Function$ (fun [arity:1](Instance) -> i) +let f = Function$ (fun [arity:1](Instance as i) -> i) +let f = Function$ (fun [arity:1](React.Instance) -> i) +let f = Function$ (fun [arity:1](React.Instance as x) -> i) +let f = Function$ (fun [arity:1](Instance component) -> i) +let f = Function$ (fun [arity:1](Instance component) -> i) +let f = Function$ (fun [arity:1](Instance { render; subtree }) -> i) +let f = Function$ (fun [arity:1](Instance ({ render; subtree }, inst)) -> i) +let f = + Function$ (fun [arity:1](Instance ({ render; subtree } : Instance.t)) -> i) +let f = + Function$ (fun [arity:1](Instance ({ render; subtree } : Instance.t)) -> i) +let f = Function$ (fun [arity:1](Instance (component, tree)) -> i) +let f = Function$ (fun [arity:1](Instance (component, tree)) -> i) +let f = Function$ (fun [arity:1](Instance : React.t) -> i) +let f = Function$ (fun [arity:1](Instance : React.t) -> i) +let f = + Function$ (fun [arity:1](Instance (comp : Component.t) : React.t) -> ()) ;;for Blue = x to y do () done ;;for Blue as c = x to y do () done ;;for Blue = x to y do () done diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/dict.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/dict.res.txt index 0da786cd5b..3061adaee6 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/dict.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/dict.res.txt @@ -1,13 +1,11 @@ let someDict = Primitive_dict.make [|("one", {js|one|js})|] let (({ one?;_})[@res.dictPattern ]) = someDict let foo = - ((Function$ - (fun () -> - match someDict with - | (({ one = {js|one|js};_})[@res.dictPattern ]) -> - Js.log {js|one|js} - | _ -> Js.log {js|not one|js})) - [@res.arity 1]) + Function$ + (fun [arity:1]() -> + match someDict with + | (({ one = {js|one|js};_})[@res.dictPattern ]) -> Js.log {js|one|js} + | _ -> Js.log {js|not one|js}) type json = | Boolean of bool | Null [@as null] @@ -19,23 +17,22 @@ type nonrec user = { name: string ; age?: float } let decodeUser = - ((Function$ - (fun (json : json) -> - (((match json with - | Object - (({ name = String name; age = ageJson;_})[@res.dictPattern ]) - -> - Some - { - name; - age = - ?((match ageJson with - | Number age -> Some age - | _ -> None)) - } - | _ -> (Js.log {js|Not an object.|js}; None)) - [@res.braces ]) : user option))) - [@res.arity 1]) + Function$ + (fun [arity:1](json : json) -> + (((match json with + | Object + (({ name = String name; age = ageJson;_})[@res.dictPattern ]) + -> + Some + { + name; + age = + ?((match ageJson with + | Number age -> Some age + | _ -> None)) + } + | _ -> (Js.log {js|Not an object.|js}; None)) + [@res.braces ]) : user option)) ;;Js.log (decodeUser (jsonParse (({js|{"name": "John", "age": 30}|js})[@res.template ]))) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/exception.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/exception.res.txt index 725cb04362..e3d9e96b47 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/exception.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/exception.res.txt @@ -25,14 +25,14 @@ let exception ((Foo : t exc) as e) = () | exception (Foo as e) -> () | exception Foo (a, b) -> () | (exception Foo : t exc) -> () -let f = ((Function$ (fun exception Foo -> ()))[@res.arity 1]) -let f = ((Function$ (fun (exception Foo as e) -> ()))[@res.arity 1]) -let f = ((Function$ (fun exception (Foo as e) -> ()))[@res.arity 1]) -let f = ((Function$ (fun exception Foo (a, b) -> ()))[@res.arity 1]) -let f = ((Function$ (fun exception Foo -> ()))[@res.arity 1]) -let f = ((Function$ (fun (exception Foo as e) -> ()))[@res.arity 1]) -let f = ((Function$ (fun exception Foo (a, b) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (exception Foo : t exc) -> ()))[@res.arity 1]) +let f = Function$ (fun [arity:1]exception Foo -> ()) +let f = Function$ (fun [arity:1](exception Foo as e) -> ()) +let f = Function$ (fun [arity:1]exception (Foo as e) -> ()) +let f = Function$ (fun [arity:1]exception Foo (a, b) -> ()) +let f = Function$ (fun [arity:1]exception Foo -> ()) +let f = Function$ (fun [arity:1](exception Foo as e) -> ()) +let f = Function$ (fun [arity:1]exception Foo (a, b) -> ()) +let f = Function$ (fun [arity:1](exception Foo : t exc) -> ()) ;;for exception Foo = 0 to 10 do () done ;;for exception Foo as e = 0 to 10 do () done ;;for exception Foo = 0 to 10 do () done diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/extension.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/extension.res.txt index 107533c8ed..9c5b5db261 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/extension.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/extension.res.txt @@ -11,14 +11,15 @@ let [%patExt1 ]|[%patExt2 ] = () | [%pat.stuff test] as _x -> () | ([%pat.stuff test] : unit) -> () | [%patExt1 ]|[%patExt2 ] -> () -let f = ((Function$ (fun [%patternExtension ] -> ()))[@res.arity 1]) -let f = ((Function$ (fun [%pattern.extension ] -> ()))[@res.arity 1]) -let f = ((Function$ (fun [%raw {js|x|js}] -> ()))[@res.arity 1]) -let f = ((Function$ (fun [%raw {js|x|js}] -> fun [%raw {js|y|js}] -> ())) - [@res.arity 2]) -let f = ((Function$ (fun ([%raw {js|x|js}] as _y) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ([%raw {js|x|js}] : unit) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ([%patExt1 ]|[%patExt2 ]) -> ()))[@res.arity 1]) +let f = Function$ (fun [arity:1][%patternExtension ] -> ()) +let f = Function$ (fun [arity:1][%pattern.extension ] -> ()) +let f = Function$ (fun [arity:1][%raw {js|x|js}] -> ()) +let f = + Function$ + (fun [arity:2][%raw {js|x|js}] -> fun [arity:1][%raw {js|y|js}] -> ()) +let f = Function$ (fun [arity:1]([%raw {js|x|js}] as _y) -> ()) +let f = Function$ (fun [arity:1]([%raw {js|x|js}] : unit) -> ()) +let f = Function$ (fun [arity:1]([%patExt1 ]|[%patExt2 ]) -> ()) ;;for [%ext ] = x to y do () done ;;for [%ext1 ]|[%ext2 ] = x to y do () done ;;for [%ext ] = x to y do () done diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/firstClassModules.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/firstClassModules.res.txt index bff40ddbbe..875aa2d5a5 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/firstClassModules.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/firstClassModules.res.txt @@ -1,22 +1,22 @@ -let sort (type s) = ((Function$ (fun (module Set) -> fun l -> ())) - [@res.arity 2]) let sort (type s) = - ((Function$ - (fun ((module Set) : (module Set.S with type elt = s)) -> fun l -> ())) - [@res.arity 2]) + Function$ (fun [arity:2](module Set) -> fun [arity:1]l -> ()) let sort (type s) = - ((Function$ - (fun - ((module Set) : (module Set.S with type elt = s and type elt2 = t)) - -> fun l -> ())) - [@res.arity 2]) -let foo = ((Function$ (fun (module Foo) -> fun baz -> Foo.bar baz)) - [@res.arity 2]) + Function$ + (fun [arity:2]((module Set) : (module Set.S with type elt = s)) -> + fun [arity:1]l -> ()) +let sort (type s) = + Function$ + (fun + [arity:2]((module Set) : + (module Set.S with type elt = s and type elt2 = t)) + -> fun [arity:1]l -> ()) +let foo = + Function$ (fun [arity:2](module Foo) -> fun [arity:1]baz -> Foo.bar baz) let bump_list (type a) = - ((Function$ - (fun ((module B) : (module Bumpable with type t = a)) -> - fun (l : a list) -> List.map ~f:((B.bump l)[@res.namedArgLoc ]))) - [@res.arity 2]) + Function$ + (fun [arity:2]((module B) : (module Bumpable with type t = a)) -> + fun [arity:1](l : a list) -> + List.map ~f:((B.bump l)[@res.namedArgLoc ])) ;;match x with | (module Set) -> () | ((module Set) : (module Set.S with type elt = s)) -> () diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/list.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/list.res.txt index 83fe31d17f..67522b4a55 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/list.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/list.res.txt @@ -33,24 +33,24 @@ let ((x::xs : int list) : int list) = () | x::(y::ys)::xs -> () | (x as p1)::((y as p2)::(ys as tail1))::(xs as tail2) as l -> () | (x::xs : int list) -> () -let f = ((Function$ (fun [] -> ()))[@res.arity 1]) -let f = ((Function$ (fun ([] as p) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (x::[]) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (((x : int) as p)::[]) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ((x as p)::[] as p2) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (x::xs) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (x::(xs as tail)) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (x::y::tail) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (x::y::[]) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (x::y::[]) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (x::xs) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (x::y::tail) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (x::(y::ys)::xs) -> ()))[@res.arity 1]) +let f = Function$ (fun [arity:1][] -> ()) +let f = Function$ (fun [arity:1]([] as p) -> ()) +let f = Function$ (fun [arity:1](x::[]) -> ()) +let f = Function$ (fun [arity:1](((x : int) as p)::[]) -> ()) +let f = Function$ (fun [arity:1]((x as p)::[] as p2) -> ()) +let f = Function$ (fun [arity:1](x::xs) -> ()) +let f = Function$ (fun [arity:1](x::(xs as tail)) -> ()) +let f = Function$ (fun [arity:1](x::y::tail) -> ()) +let f = Function$ (fun [arity:1](x::y::[]) -> ()) +let f = Function$ (fun [arity:1](x::y::[]) -> ()) +let f = Function$ (fun [arity:1](x::xs) -> ()) +let f = Function$ (fun [arity:1](x::y::tail) -> ()) +let f = Function$ (fun [arity:1](x::(y::ys)::xs) -> ()) let f = - ((Function$ - (fun ((x as p1)::((y as p2)::(ys as tail1))::(xs as tail2) as l) -> ())) - [@res.arity 1]) -let f = ((Function$ (fun (x::xs : int list) -> ()))[@res.arity 1]) + Function$ + (fun [arity:1]((x as p1)::((y as p2)::(ys as tail1))::(xs as tail2) as l) + -> ()) +let f = Function$ (fun [arity:1](x::xs : int list) -> ()) ;;for [] = x to y do () done ;;for [] as l = x to y do () done ;;for [] = x to y do () done diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/polyvariants.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/polyvariants.res.txt index 717f79bcca..8b18583c4b 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/polyvariants.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/polyvariants.res.txt @@ -31,26 +31,24 @@ let ((`Instance (component : comp)) : React.t) = i | `Instance ({ render; subtree } : Instance.t) -> () | `Instance (comp, tree) -> () | (`Instance (comp : Component.t) : React.t) -> () -let f = ((Function$ (fun `Instance -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance as i) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance component) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance component) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance { render; subtree }) -> i)) - [@res.arity 1]) -let f = ((Function$ (fun (`Instance ({ render; subtree }, inst)) -> i)) - [@res.arity 1]) +let f = Function$ (fun [arity:1]`Instance -> i) +let f = Function$ (fun [arity:1](`Instance as i) -> i) +let f = Function$ (fun [arity:1](`Instance component) -> i) +let f = Function$ (fun [arity:1](`Instance component) -> i) +let f = Function$ (fun [arity:1](`Instance { render; subtree }) -> i) +let f = Function$ (fun [arity:1](`Instance ({ render; subtree }, inst)) -> i) let f = - ((Function$ (fun (`Instance ({ render; subtree } : Instance.t)) -> i)) - [@res.arity 1]) + Function$ + (fun [arity:1](`Instance ({ render; subtree } : Instance.t)) -> i) let f = - ((Function$ (fun (`Instance ({ render; subtree } : Instance.t)) -> i)) - [@res.arity 1]) -let f = ((Function$ (fun (`Instance (component, tree)) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance (component, tree)) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance : React.t) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance : React.t) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance (comp : Component.t) : React.t) -> ())) - [@res.arity 1]) + Function$ + (fun [arity:1](`Instance ({ render; subtree } : Instance.t)) -> i) +let f = Function$ (fun [arity:1](`Instance (component, tree)) -> i) +let f = Function$ (fun [arity:1](`Instance (component, tree)) -> i) +let f = Function$ (fun [arity:1](`Instance : React.t) -> i) +let f = Function$ (fun [arity:1](`Instance : React.t) -> i) +let f = + Function$ (fun [arity:1](`Instance (comp : Component.t) : React.t) -> ()) ;;for `Blue = x to y do () done ;;for `Blue as c = x to y do () done ;;for `Blue = x to y do () done @@ -70,22 +68,21 @@ let f = ((Function$ (fun (`Instance (comp : Component.t) : React.t) -> ())) ;;for `Point { x; y; z } as p = x to y do () done ;;match x with | #typeVar -> () | `lowercase -> () let cmp = - ((Function$ - (fun selectedChoice -> - fun value -> - match (selectedChoice, value) with - | (#a, #a) -> true - | [|#b;#b|] -> true - | #b::#b::[] -> true - | { x = #c; y = #c } -> true - | Constructor (#a, #a) -> true - | `Constuctor (#a, #a) -> true - | #a as x -> true - | #a|#b -> true - | (#a : typ) -> true - | exception #a -> true - | _ -> false)) - [@res.arity 2]) + Function$ + (fun [arity:2]selectedChoice -> + fun [arity:1]value -> + match (selectedChoice, value) with + | (#a, #a) -> true + | [|#b;#b|] -> true + | #b::#b::[] -> true + | { x = #c; y = #c } -> true + | Constructor (#a, #a) -> true + | `Constuctor (#a, #a) -> true + | #a as x -> true + | #a|#b -> true + | (#a : typ) -> true + | exception #a -> true + | _ -> false) ;;match polyVar with | `ease-in -> () | `ease-out⛰ -> () diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/record.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/record.res.txt index 85b7386cb7..2cb8f470d8 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/record.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/record.res.txt @@ -32,27 +32,25 @@ let ({ a } : myRecord) = x | { a;_} -> () | { a;_} -> () | ({ a } : myRecord) -> () -let f = ((Function$ (fun { a } -> ()))[@res.arity 1]) -let f = ((Function$ (fun ({ a } as r) -> ()))[@res.arity 1]) -let f = ((Function$ (fun { a } -> ()))[@res.arity 1]) -let f = ((Function$ (fun { a; b } -> ()))[@res.arity 1]) -let f = ((Function$ (fun { a; b } -> ()))[@res.arity 1]) -let f = ((Function$ (fun { ReasonReact.state = state } -> ()))[@res.arity 1]) -let f = ((Function$ (fun { ReasonReact.state = (state as prevState) } -> ())) - [@res.arity 1]) -let f = ((Function$ (fun { ReasonReact.state = theState } -> ())) - [@res.arity 1]) -let f = ((Function$ (fun { a = u } -> ()))[@res.arity 1]) -let f = ((Function$ (fun { a = (u : int) } -> ()))[@res.arity 1]) -let f = ((Function$ (fun { a = (((u as x) : int) as r) } -> ())) - [@res.arity 1]) -let f = ((Function$ (fun { a = { x; y } } -> ()))[@res.arity 1]) -let f = ((Function$ (fun { a = { x = r; y = r2 } } -> ()))[@res.arity 1]) -let f = ((Function$ (fun { a;_} -> ()))[@res.arity 1]) -let f = ((Function$ (fun { a;_} -> ()))[@res.arity 1]) -let f = ((Function$ (fun ({ a } : myRecord) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ({ a } : myRecord) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (({ a } : myRecord) as p) -> ()))[@res.arity 1]) +let f = Function$ (fun [arity:1]{ a } -> ()) +let f = Function$ (fun [arity:1]({ a } as r) -> ()) +let f = Function$ (fun [arity:1]{ a } -> ()) +let f = Function$ (fun [arity:1]{ a; b } -> ()) +let f = Function$ (fun [arity:1]{ a; b } -> ()) +let f = Function$ (fun [arity:1]{ ReasonReact.state = state } -> ()) +let f = + Function$ (fun [arity:1]{ ReasonReact.state = (state as prevState) } -> ()) +let f = Function$ (fun [arity:1]{ ReasonReact.state = theState } -> ()) +let f = Function$ (fun [arity:1]{ a = u } -> ()) +let f = Function$ (fun [arity:1]{ a = (u : int) } -> ()) +let f = Function$ (fun [arity:1]{ a = (((u as x) : int) as r) } -> ()) +let f = Function$ (fun [arity:1]{ a = { x; y } } -> ()) +let f = Function$ (fun [arity:1]{ a = { x = r; y = r2 } } -> ()) +let f = Function$ (fun [arity:1]{ a;_} -> ()) +let f = Function$ (fun [arity:1]{ a;_} -> ()) +let f = Function$ (fun [arity:1]({ a } : myRecord) -> ()) +let f = Function$ (fun [arity:1]({ a } : myRecord) -> ()) +let f = Function$ (fun [arity:1](({ a } : myRecord) as p) -> ()) ;;for { a } = 0 to 10 do () done ;;for { a } as p = 0 to 10 do () done ;;for { a } = 0 to 10 do () done diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/tuple.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/tuple.res.txt index 076cb61d98..04a2d31947 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/tuple.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/tuple.res.txt @@ -15,15 +15,14 @@ let (((1 : int), (2 : int)) : (int * int)) as tup = () | (((1 as p1) : int), ((2 as p2) : int)) as tup -> () | (((1 : int), (2 : int)) : (int * int)) -> () | (((1 : int), (2 : int)) : (int * int)) as tup -> () -let f = ((Function$ (fun x -> ()))[@res.arity 1]) -let f = ((Function$ (fun x -> ()))[@res.arity 1]) -let f = ((Function$ (fun (x, y) -> x + y))[@res.arity 1]) -let f = ((Function$ (fun (((x as p1), (y as p2)) as tup) -> x + y)) - [@res.arity 1]) -let f = ((Function$ (fun ((x, y) : (int * int)) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ((x, y) : (int * int)) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ((((x, y) as tup1) : (int * int)) as tup) -> ())) - [@res.arity 1]) +let f = Function$ (fun [arity:1]x -> ()) +let f = Function$ (fun [arity:1]x -> ()) +let f = Function$ (fun [arity:1](x, y) -> x + y) +let f = Function$ (fun [arity:1](((x as p1), (y as p2)) as tup) -> x + y) +let f = Function$ (fun [arity:1]((x, y) : (int * int)) -> ()) +let f = Function$ (fun [arity:1]((x, y) : (int * int)) -> ()) +let f = + Function$ (fun [arity:1]((((x, y) as tup1) : (int * int)) as tup) -> ()) ;;for (x, y) = 0 to 10 do () done ;;for (x, y) as tup = 0 to 10 do () done ;;for (x, y) = 0 to 10 do () done diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/unit.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/unit.res.txt index 2ecd0e444a..f1d3f48961 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/unit.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/unit.res.txt @@ -26,13 +26,13 @@ let (() : unit) as x = () ;;for (() : unit) as _u = () to () do () done ;;for ((() as _u) : unit) = () to () do () done ;;for (() : unit) as _u = () to () do () done -let f = ((Function$ (fun () -> ()))[@res.arity 1]) -let f = ((Function$ (fun () -> ()))[@res.arity 1]) -let f = ((Function$ (fun (() as _u) -> ()))[@res.arity 1]) -let f = ((Function$ (fun () -> fun () -> ()))[@res.arity 2]) -let f = ((Function$ (fun (() as _u) -> fun (() as _u) -> ()))[@res.arity 2]) -let f = ((Function$ (fun (() : unit) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ((() as _u) : unit) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ((() : unit) as _u) -> ()))[@res.arity 1]) -let f = ((Function$ (fun (() : unit) -> ()))[@res.arity 1]) -let f = ((Function$ (fun ((() : unit) as _u) -> ()))[@res.arity 1]) \ No newline at end of file +let f = Function$ (fun [arity:1]() -> ()) +let f = Function$ (fun [arity:1]() -> ()) +let f = Function$ (fun [arity:1](() as _u) -> ()) +let f = Function$ (fun [arity:2]() -> fun [arity:1]() -> ()) +let f = Function$ (fun [arity:2](() as _u) -> fun [arity:1](() as _u) -> ()) +let f = Function$ (fun [arity:1](() : unit) -> ()) +let f = Function$ (fun [arity:1]((() as _u) : unit) -> ()) +let f = Function$ (fun [arity:1]((() : unit) as _u) -> ()) +let f = Function$ (fun [arity:1](() : unit) -> ()) +let f = Function$ (fun [arity:1]((() : unit) as _u) -> ()) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/variantSpreads.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/variantSpreads.res.txt index 70323d3ecf..39f0b14340 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/variantSpreads.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/variantSpreads.res.txt @@ -13,47 +13,42 @@ type nonrec d = | ... of b | ... of c let doWithA = - ((Function$ - (fun (a : a) -> - ((match a with - | One -> Js.log {js|aaa|js} - | Two -> Js.log {js|twwwoooo|js} - | Three -> Js.log {js|threeeee|js}) - [@res.braces ]))) - [@res.arity 1]) + Function$ + (fun [arity:1](a : a) -> + ((match a with + | One -> Js.log {js|aaa|js} + | Two -> Js.log {js|twwwoooo|js} + | Three -> Js.log {js|threeeee|js}) + [@res.braces ])) let doWithB = - ((Function$ - (fun (b : b) -> - ((match b with - | One -> Js.log {js|aaa|js} - | _ -> Js.log {js|twwwoooo|js}) - [@res.braces ]))) - [@res.arity 1]) + Function$ + (fun [arity:1](b : b) -> + ((match b with + | One -> Js.log {js|aaa|js} + | _ -> Js.log {js|twwwoooo|js}) + [@res.braces ])) let lookup = - ((Function$ - (fun (b : b) -> - match b with - | ((#a)[@res.patVariantSpread ]) as a -> doWithA a - | Four -> Js.log {js|four|js} - | Five -> Js.log {js|five|js})) - [@res.arity 1]) + Function$ + (fun [arity:1](b : b) -> + match b with + | ((#a)[@res.patVariantSpread ]) as a -> doWithA a + | Four -> Js.log {js|four|js} + | Five -> Js.log {js|five|js}) let lookup2 = - ((Function$ - (fun (d : d) -> - match d with - | ((#a)[@res.patVariantSpread ]) as a -> doWithA a - | ((#b)[@res.patVariantSpread ]) as b -> doWithB b - | Six|Seven -> Js.log {js|Got rest of d|js})) - [@res.arity 1]) + Function$ + (fun [arity:1](d : d) -> + match d with + | ((#a)[@res.patVariantSpread ]) as a -> doWithA a + | ((#b)[@res.patVariantSpread ]) as b -> doWithB b + | Six|Seven -> Js.log {js|Got rest of d|js}) let lookupOpt = - ((Function$ - (fun (b : b option) -> - match b with - | Some (((#a)[@res.patVariantSpread ]) as a) -> doWithA a - | Some (Four) -> Js.log {js|four|js} - | Some (Five) -> Js.log {js|five|js} - | None -> Js.log {js|None|js})) - [@res.arity 1]) + Function$ + (fun [arity:1](b : b option) -> + match b with + | Some (((#a)[@res.patVariantSpread ]) as a) -> doWithA a + | Some (Four) -> Js.log {js|four|js} + | Some (Five) -> Js.log {js|five|js} + | None -> Js.log {js|None|js}) module Foo = struct type nonrec zz = @@ -64,16 +59,14 @@ module Foo = | Third end let doWithZ = - ((Function$ - (fun (z : Foo.zz) -> - match z with - | First -> Js.log {js|First|js} - | Second -> Js.log {js|Second|js})) - [@res.arity 1]) + Function$ + (fun [arity:1](z : Foo.zz) -> + match z with + | First -> Js.log {js|First|js} + | Second -> Js.log {js|Second|js}) let lookup3 = - ((Function$ - (fun (d : Foo.xx) -> - match d with - | ((#Foo.zz)[@res.patVariantSpread ]) as z -> Js.log z - | Third -> Js.log {js|Third|js})) - [@res.arity 1]) \ No newline at end of file + Function$ + (fun [arity:1](d : Foo.xx) -> + match d with + | ((#Foo.zz)[@res.patVariantSpread ]) as z -> Js.log z + | Third -> Js.log {js|Third|js}) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/pattern/expected/variants.res.txt b/tests/syntax_tests/data/parsing/grammar/pattern/expected/variants.res.txt index 3ec7ed09e4..432975df14 100644 --- a/tests/syntax_tests/data/parsing/grammar/pattern/expected/variants.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/pattern/expected/variants.res.txt @@ -31,26 +31,24 @@ let ((`Instance (component : comp)) : React.t) = i | `Instance ({ render; subtree } : Instance.t) -> () | `Instance (comp, tree) -> () | (`Instance (comp : Component.t) : React.t) -> () -let f = ((Function$ (fun `Instance -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance as i) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance component) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance component) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance { render; subtree }) -> i)) - [@res.arity 1]) -let f = ((Function$ (fun (`Instance ({ render; subtree }, inst)) -> i)) - [@res.arity 1]) +let f = Function$ (fun [arity:1]`Instance -> i) +let f = Function$ (fun [arity:1](`Instance as i) -> i) +let f = Function$ (fun [arity:1](`Instance component) -> i) +let f = Function$ (fun [arity:1](`Instance component) -> i) +let f = Function$ (fun [arity:1](`Instance { render; subtree }) -> i) +let f = Function$ (fun [arity:1](`Instance ({ render; subtree }, inst)) -> i) let f = - ((Function$ (fun (`Instance ({ render; subtree } : Instance.t)) -> i)) - [@res.arity 1]) + Function$ + (fun [arity:1](`Instance ({ render; subtree } : Instance.t)) -> i) let f = - ((Function$ (fun (`Instance ({ render; subtree } : Instance.t)) -> i)) - [@res.arity 1]) -let f = ((Function$ (fun (`Instance (component, tree)) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance (component, tree)) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance : React.t) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance : React.t) -> i))[@res.arity 1]) -let f = ((Function$ (fun (`Instance (comp : Component.t) : React.t) -> ())) - [@res.arity 1]) + Function$ + (fun [arity:1](`Instance ({ render; subtree } : Instance.t)) -> i) +let f = Function$ (fun [arity:1](`Instance (component, tree)) -> i) +let f = Function$ (fun [arity:1](`Instance (component, tree)) -> i) +let f = Function$ (fun [arity:1](`Instance : React.t) -> i) +let f = Function$ (fun [arity:1](`Instance : React.t) -> i) +let f = + Function$ (fun [arity:1](`Instance (comp : Component.t) : React.t) -> ()) ;;for `Blue = x to y do () done ;;for `Blue as c = x to y do () done ;;for `Blue = x to y do () done diff --git a/tests/syntax_tests/data/parsing/grammar/signature/expected/itemExtension.res.txt b/tests/syntax_tests/data/parsing/grammar/signature/expected/itemExtension.res.txt index bd9926db75..93b79be024 100644 --- a/tests/syntax_tests/data/parsing/grammar/signature/expected/itemExtension.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/signature/expected/itemExtension.res.txt @@ -2,6 +2,6 @@ module type Ext = sig [%%item.extension ] [%%item.extension.with.args {js|argument|js}] - [%%item.extension.with.args ((Function$ (fun x -> f x))[@res.arity 1])] + [%%item.extension.with.args Function$ (fun [arity:1]x -> f x)] [%%item.extension ][@@withAttr ] end \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/signature/expected/standAloneAttribute.res.txt b/tests/syntax_tests/data/parsing/grammar/signature/expected/standAloneAttribute.res.txt index edf70877ed..1cbdcbe530 100644 --- a/tests/syntax_tests/data/parsing/grammar/signature/expected/standAloneAttribute.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/signature/expected/standAloneAttribute.res.txt @@ -2,5 +2,5 @@ module type StandaloneAttribute = sig [@@@standaloneAttribute ] [@@@standaloneAttribute withPayload] - [@@@standaloneAttribute ((Function$ (fun x -> x))[@res.arity 1])] + [@@@standaloneAttribute Function$ (fun [arity:1]x -> x)] end \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/structure/expected/itemExtension.res.txt b/tests/syntax_tests/data/parsing/grammar/structure/expected/itemExtension.res.txt index 79c8084e6a..433e21c0b2 100644 --- a/tests/syntax_tests/data/parsing/grammar/structure/expected/itemExtension.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/structure/expected/itemExtension.res.txt @@ -1,5 +1,5 @@ [%%itemExtension ] [%%item.extension ] [%%item.extension.with.args {js|argument|js}] -[%%item.extension.with.args ((Function$ (fun x -> f x))[@res.arity 1])] +[%%item.extension.with.args Function$ (fun [arity:1]x -> f x)] [%%itemExtension ][@@attrOnExtension ] \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/structure/expected/letBinding.res.txt b/tests/syntax_tests/data/parsing/grammar/structure/expected/letBinding.res.txt index 0d8bf07a45..e48fba501b 100644 --- a/tests/syntax_tests/data/parsing/grammar/structure/expected/letBinding.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/structure/expected/letBinding.res.txt @@ -3,11 +3,9 @@ let a = 1[@@onFirstBinding ] let a = 1[@@onFirstBinding ] and b = 2[@@onSecondBinding ] let f : type t. t foo = - ((Function$ - (fun sideEffect -> - ((let module M = struct exception E of t end in - sideEffect (); ((Function$ ((fun x -> M.E x)))[@res.arity 1])) - [@res.braces ]))) - [@res.arity 1]) -let f : type t x u. (t * x * y) list = ((Function$ (fun l -> f l)) - [@res.arity 1]) \ No newline at end of file + Function$ + (fun [arity:1]sideEffect -> + ((let module M = struct exception E of t end in + sideEffect (); Function$ ((fun [arity:1]x -> M.E x))) + [@res.braces ])) +let f : type t x u. (t * x * y) list = Function$ (fun [arity:1]l -> f l) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/structure/expected/modExprExtension.res.txt b/tests/syntax_tests/data/parsing/grammar/structure/expected/modExprExtension.res.txt index 4d4b2404ac..c4af1f86b1 100644 --- a/tests/syntax_tests/data/parsing/grammar/structure/expected/modExprExtension.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/structure/expected/modExprExtension.res.txt @@ -1,5 +1,4 @@ module A = [%modExprExtension ] module B = [%mod.expr.extension ] module C = [%mod.expr.extension.with.args {js|argument|js}] -module D = - [%mod.expr.extension.with.args ((Function$ (fun x -> f x))[@res.arity 1])] \ No newline at end of file +module D = [%mod.expr.extension.with.args Function$ (fun [arity:1]x -> f x)] \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/structure/expected/moduleTypeExtension.res.txt b/tests/syntax_tests/data/parsing/grammar/structure/expected/moduleTypeExtension.res.txt index b3d4e58075..1d7d7f81e0 100644 --- a/tests/syntax_tests/data/parsing/grammar/structure/expected/moduleTypeExtension.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/structure/expected/moduleTypeExtension.res.txt @@ -2,4 +2,4 @@ module type A = [%modTypeExtension ] module type B = [%mod.type.extension ] module type C = [%mod.type.extension.with.args {js|argument|js}] module type D = - [%mod.type.extension.with.args ((Function$ (fun x -> f x))[@res.arity 1])] \ No newline at end of file + [%mod.type.extension.with.args Function$ (fun [arity:1]x -> f x)] \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/structure/expected/standaloneAttribute.res.txt b/tests/syntax_tests/data/parsing/grammar/structure/expected/standaloneAttribute.res.txt index b14fa69434..54269ef167 100644 --- a/tests/syntax_tests/data/parsing/grammar/structure/expected/standaloneAttribute.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/structure/expected/standaloneAttribute.res.txt @@ -1,3 +1,3 @@ [@@@standaloneAttribute ] [@@@standaloneAttribute {js|with payload|js}] -[@@@standaloneAttribute ((Function$ (fun x -> x + 1))[@res.arity 1])] \ No newline at end of file +[@@@standaloneAttribute Function$ (fun [arity:1]x -> x + 1)] \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/typedefinition/expected/polyvariant.res.txt b/tests/syntax_tests/data/parsing/grammar/typedefinition/expected/polyvariant.res.txt index 105e2a5dfe..500268180a 100644 --- a/tests/syntax_tests/data/parsing/grammar/typedefinition/expected/polyvariant.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/typedefinition/expected/polyvariant.res.txt @@ -55,4 +55,4 @@ type nonrec t = [< `x [@a ]] type nonrec t = [< `a of ((int * int) * int) [@one ] | ((int)[@two ]) | `b of string [@three ]> `w `x `y] -let f = ((Function$ (fun (x : [ `b ]) -> x))[@res.arity 1]) \ No newline at end of file +let f = Function$ (fun [arity:1](x : [ `b ]) -> x) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/typexpr/expected/objectTypeSpreading.res.txt b/tests/syntax_tests/data/parsing/grammar/typexpr/expected/objectTypeSpreading.res.txt index daf3a17b05..ce8c44639a 100644 --- a/tests/syntax_tests/data/parsing/grammar/typexpr/expected/objectTypeSpreading.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/typexpr/expected/objectTypeSpreading.res.txt @@ -16,28 +16,23 @@ let steve = ((([%obj { name = {js|Steve|js}; age = 30 }] : < user ;age: int > )) [@res.braces ]) let printFullUser = - ((Function$ (fun (steve : < user ;age: int > ) -> Js.log steve)) - [@res.arity 1]) + Function$ (fun [arity:1](steve : < user ;age: int > ) -> Js.log steve) let printFullUser = - ((Function$ - (fun ~user:(((user : < user ;age: int > ))[@res.namedArgLoc ]) -> - Js.log steve)) - [@res.arity 1]) + Function$ + (fun [arity:1]~user:(((user : < user ;age: int > ))[@res.namedArgLoc ]) + -> Js.log steve) let printFullUser = - ((Function$ - (fun ~user:(((user : < user ;age: int > ))[@res.namedArgLoc ]) -> - Js.log steve)) - [@res.arity 1]) + Function$ + (fun [arity:1]~user:(((user : < user ;age: int > ))[@res.namedArgLoc ]) + -> Js.log steve) let printFullUser = - ((Function$ - (fun ?user:(((user)[@res.namedArgLoc ])= - (steve : < user ;age: int > )) -> Js.log steve)) - [@res.arity 1]) + Function$ + (fun [arity:1]?user:(((user)[@res.namedArgLoc ])= + (steve : < user ;age: int > )) -> Js.log steve) external steve : < user ;age: int > = "steve"[@@val ] let makeCeoOf30yearsOld = - ((Function$ - (fun name -> ([%obj { name; age = 30 }] : < user ;age: int > ))) - [@res.arity 1]) + Function$ + (fun [arity:1]name -> ([%obj { name; age = 30 }] : < user ;age: int > )) type nonrec optionalUser = < user ;age: int > option type nonrec optionalTupleUser = (< user ;age: int > * < user ;age: int > ) option diff --git a/tests/syntax_tests/data/parsing/grammar/typexpr/expected/typeconstr.res.txt b/tests/syntax_tests/data/parsing/grammar/typexpr/expected/typeconstr.res.txt index 7df7e5a953..6235a20fde 100644 --- a/tests/syntax_tests/data/parsing/grammar/typexpr/expected/typeconstr.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/typexpr/expected/typeconstr.res.txt @@ -60,5 +60,5 @@ type nonrec ('T, 'E) id_6 = | Ok of 'T | Err of { payload: 'E } -let foo = ((Function$ (fun (x : int as 'X) -> x))[@res.arity 1]) +let foo = Function$ (fun [arity:1](x : int as 'X) -> x) module type A = (Foo with type t = 'X constraint 'X = int) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/grammar/typexpr/expected/unit.res.txt b/tests/syntax_tests/data/parsing/grammar/typexpr/expected/unit.res.txt index de2e44b365..64bf9102df 100644 --- a/tests/syntax_tests/data/parsing/grammar/typexpr/expected/unit.res.txt +++ b/tests/syntax_tests/data/parsing/grammar/typexpr/expected/unit.res.txt @@ -3,14 +3,14 @@ type nonrec t = (unit -> unit, [ `Has_arity1 ]) function$ type nonrec t = (unit -> unit -> unit, [ `Has_arity2 ]) function$ type nonrec t = (unit -> unit, [ `Has_arity1 ]) function$ let f = - ((Function$ (fun (f : (unit -> unit, [ `Has_arity1 ]) function$) -> f ())) - [@res.arity 1]) + Function$ + (fun [arity:1](f : (unit -> unit, [ `Has_arity1 ]) function$) -> f ()) let f = - ((Function$ (fun (f : (unit -> unit, [ `Has_arity1 ]) function$) -> f ())) - [@res.arity 1]) + Function$ + (fun [arity:1](f : (unit -> unit, [ `Has_arity1 ]) function$) -> f ()) let f = - ((Function$ - (fun (f : (unit -> unit -> unit, [ `Has_arity2 ]) function$) -> f () ())) - [@res.arity 1]) + Function$ + (fun [arity:1](f : (unit -> unit -> unit, [ `Has_arity2 ]) function$) -> + f () ()) external svg : (unit -> React.element, [ `Has_arity1 ]) function$ = "svg" external thing : (unit -> unit, [ `Has_arity1 ]) function$ = "svg" \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt b/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt index 7478916b11..6e2dbf6a62 100644 --- a/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt +++ b/tests/syntax_tests/data/parsing/infiniteLoops/expected/equalAfterBinaryExpr.res.txt @@ -11,93 +11,106 @@ Did you mean `==` here? let rec _addLoop = - ((Function$ - (fun rbt -> - fun currentNode -> - ((if (Some currentNode) == (rbt |.u root) - then currentNode.color <- Black + Function$ + (fun [arity:2]rbt -> + fun [arity:1]currentNode -> + ((if (Some currentNode) == (rbt |.u root) + then currentNode.color <- Black + else + if (currentNode.parent |.u castNotOption).color == Black + then () else - if (currentNode.parent |.u castNotOption).color == Black - then () + if + (((let uncle = uncleOf currentNode in + (uncle != None) && + ((uncle |.u castNotOption).color == Red))) + [@res.braces ]) + then + ((currentNode.parent |.u castNotOption).color <- Black; + ((uncleOf currentNode) |.u castNotOption).color <- Black; + ((grandParentOf currentNode) |.u castNotOption).color <- + Red; + _addLoop rbt + ((grandParentOf currentNode) |.u castNotOption)) else - if - (((let uncle = uncleOf currentNode in - (uncle != None) && - ((uncle |.u castNotOption).color == Red))) - [@res.braces ]) - then - ((currentNode.parent |.u castNotOption).color <- Black; - ((uncleOf currentNode) |.u castNotOption).color <- Black; - ((grandParentOf currentNode) |.u castNotOption).color <- - Red; - _addLoop rbt - ((grandParentOf currentNode) |.u castNotOption)) - else - (let currentNode = + (let currentNode = + if + (not (isLeft currentNode)) && + (isLeft (currentNode.parent |.u castNotOption)) + then + (rotateLeft rbt (currentNode.parent |.u castNotOption); + currentNode.left |.u castNotOption) + else if - (not (isLeft currentNode)) && - (isLeft (currentNode.parent |.u castNotOption)) + (isLeft currentNode) && + (not + (isLeft (currentNode.parent |.u castNotOption))) then - (rotateLeft rbt + (rotateRight rbt (currentNode.parent |.u castNotOption); - currentNode.left |.u castNotOption) - else - if - (isLeft currentNode) && - (not - (isLeft (currentNode.parent |.u castNotOption))) - then - (rotateRight rbt - (currentNode.parent |.u castNotOption); - currentNode.right |.u castNotOption) - else currentNode in - (currentNode.parent |.u castNotOption).color <- Black; - ((grandParentOf currentNode) |.u castNotOption).color <- - Red; - if isLeft currentNode - then - rotateRight rbt - ((grandParentOf currentNode) |.u castNotOption) - else - rotateLeft rbt - ((grandParentOf currentNode) |.u castNotOption))) - [@res.braces ]))) - [@res.arity 2]) + currentNode.right |.u castNotOption) + else currentNode in + (currentNode.parent |.u castNotOption).color <- Black; + ((grandParentOf currentNode) |.u castNotOption).color <- + Red; + if isLeft currentNode + then + rotateRight rbt + ((grandParentOf currentNode) |.u castNotOption) + else + rotateLeft rbt + ((grandParentOf currentNode) |.u castNotOption))) + [@res.braces ])) let removeNode = - ((Function$ - (fun rbt -> - fun node -> - ((if nodeToRemove.color == Black - then - (if successor.color == Red - then - (successor.color <- Black; - if successor.parent == None - then rbt |.u (rootSet (Some successor))) - else - (let break = ref false in - let successorRef = ref successor in - while not break.contents do - let successor = successorRef.contents in - match successor.parent with - | None -> - (rbt |.u (rootSet (Some successor)); - break.contents <- true) - | Some successorParent -> - let sibling = siblingOf successor in - (if - (sibling != None) && - ((sibling |.u castNotOption).color == Red) - then - (successorParent.color <- Red; - (sibling |.u castNotOption).color <- Black; - if isLeft successor - then rotateLeft rbt successorParent - else rotateRight rbt successorParent); - (let sibling = siblingOf successor in - let siblingNN = sibling |.u castNotOption in + Function$ + (fun [arity:2]rbt -> + fun [arity:1]node -> + ((if nodeToRemove.color == Black + then + (if successor.color == Red + then + (successor.color <- Black; + if successor.parent == None + then rbt |.u (rootSet (Some successor))) + else + (let break = ref false in + let successorRef = ref successor in + while not break.contents do + let successor = successorRef.contents in + match successor.parent with + | None -> + (rbt |.u (rootSet (Some successor)); + break.contents <- true) + | Some successorParent -> + let sibling = siblingOf successor in + (if + (sibling != None) && + ((sibling |.u castNotOption).color == Red) + then + (successorParent.color <- Red; + (sibling |.u castNotOption).color <- Black; + if isLeft successor + then rotateLeft rbt successorParent + else rotateRight rbt successorParent); + (let sibling = siblingOf successor in + let siblingNN = sibling |.u castNotOption in + if + (successorParent.color == Black) && + ((sibling == None) || + (((siblingNN.color == Black) && + ((siblingNN.left == None) || + ((siblingNN.left |.u castNotOption).color + == Black))) + && + ((siblingNN.right == None) || + ((siblingNN.right |.u castNotOption).color + == Black)))) + then + (if sibling != None then siblingNN.color <- Red; + successorRef.contents <- successorParent) + else if - (successorParent.color == Black) && + (successorParent.color == Red) && ((sibling == None) || (((siblingNN.color == Black) && ((siblingNN.left == None) || @@ -109,78 +122,60 @@ let removeNode = == Black)))) then (if sibling != None then siblingNN.color <- Red; - successorRef.contents <- successorParent) + successorParent.color <- Black; + break.contents <- true) else if - (successorParent.color == Red) && - ((sibling == None) || - (((siblingNN.color == Black) && - ((siblingNN.left == None) || - ((siblingNN.left |.u castNotOption).color - == Black))) - && - ((siblingNN.right == None) || - ((siblingNN.right |.u castNotOption).color - == Black)))) + (sibling != None) && + ((sibling |.u castNotOption).color == Black) then - (if sibling != None - then siblingNN.color <- Red; - successorParent.color <- Black; - break.contents <- true) - else - if - (sibling != None) && - ((sibling |.u castNotOption).color == - Black) - then - (let sibling = sibling |.u castNotOption in + (let sibling = sibling |.u castNotOption in + if + (((isLeft successor) && + ((sibling.right == None) || + ((sibling.right |.u castNotOption).color + == Black))) + && (sibling.left != None)) + && + ((sibling.left |.u castNotOption).color + == Red) + then + (sibling.color <- Red; + (sibling.left |.u castNotOption).color <- + Black; + rotateRight rbt sibling) + else if - (((isLeft successor) && - ((sibling.right == None) || - ((sibling.right |.u castNotOption).color + (((not (isLeft successor)) && + ((sibling.left == None) || + ((sibling.left |.u castNotOption).color == Black))) - && (sibling.left != None)) + && (sibling.right != None)) && - ((sibling.left |.u castNotOption).color + ((sibling.right |.u castNotOption).color == Red) then (sibling.color <- Red; - (sibling.left |.u castNotOption).color - <- Black; - rotateRight rbt sibling) - else - if - (((not (isLeft successor)) && - ((sibling.left == None) || - ((sibling.left |.u castNotOption).color - == Black))) - && (sibling.right != None)) - && - ((sibling.right |.u castNotOption).color - == Red) - then - (sibling.color <- Red; - (sibling.right |.u castNotOption).color - <- Black; - rotateLeft rbt sibling); - break.contents <- true) - else - (let sibling = siblingOf successor in - let sibling = sibling |.u castNotOption in - sibling.color <- (successorParent.color); - if isLeft successor - then - ((sibling.right |.u castNotOption).color + (sibling.right |.u castNotOption).color <- Black; - rotateRight rbt successorParent) - else - ((sibling.left |.u castNotOption).color - <- Black; - rotateLeft rbt successorParent)))) - done)); - if isLeaf successor - then - (if (rbt |.u root) == (Some successor) - then (rbt |.u root) = None)) - [@res.braces ]))) - [@res.arity 2]) \ No newline at end of file + rotateLeft rbt sibling); + break.contents <- true) + else + (let sibling = siblingOf successor in + let sibling = sibling |.u castNotOption in + sibling.color <- (successorParent.color); + if isLeft successor + then + ((sibling.right |.u castNotOption).color <- + Black; + rotateRight rbt successorParent) + else + ((sibling.left |.u castNotOption).color <- + Black; + rotateLeft rbt successorParent)))) + done)); + if isLeaf successor + then + (if (rbt |.u root) == (Some successor) + then (rbt |.u root) = None)) + [@res.braces ])) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt b/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt index 4e272f04fb..b45c9d086d 100644 --- a/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt +++ b/tests/syntax_tests/data/parsing/infiniteLoops/expected/nonRecTypes.res.txt @@ -126,86 +126,102 @@ include ;;{js|BS:6.0.1\x84\x95\xa6\xbe\0\0\0\x13\0\0\0\x07\0\0\0\x14\0\0\0\x13\xb0\xa0\xa0A\x91@@A\x98\xa0'compare@|js} end let has = - ((Function$ - (fun rbt -> - fun value -> (_findNode rbt (rootGet rbt) value) != None)) - [@res.arity 2]) - let rec minNode = ((Function$ (fun node -> [%rescript.exprhole ])) - [@res.arity 1]) - let findMin = ((Function$ (fun rbt -> [%rescript.exprhole ])) - [@res.arity 1]) + Function$ + (fun [arity:2]rbt -> + fun [arity:1]value -> (_findNode rbt (rootGet rbt) value) != None) + let rec minNode = Function$ (fun [arity:1]node -> [%rescript.exprhole ]) + let findMin = Function$ (fun [arity:1]rbt -> [%rescript.exprhole ]) let removeNode = - ((Function$ - (fun rbt -> - fun node -> - ((let nodeToRemove = - match ((leftGet node), (rightGet node)) with - | (Some _, Some _) -> - let successor = - castNotOption (minNode (rightGet node)) in - (valueSet node (valueGet successor); - heightSet node (heightGet successor); - successor) - | _ -> node in - let successor = - match leftGet nodeToRemove with - | None -> rightGet nodeToRemove - | left -> left in - let (successor, isLeaf) = - match successor with - | None -> - let leaf = - createNode ~value:((Js.Internal.raw_expr {js|0|js}) - [@res.namedArgLoc ]) ~color:((Black) - [@res.namedArgLoc ]) ~height:((0.) - [@res.namedArgLoc ]) in - let isLeaf = - Js.Internal.fn_mk1 ((Function$ (fun x -> x == leaf)) - [@res.arity 1]) in - (leaf, isLeaf) - | Some successor -> - (successor, - (Js.Internal.fn_mk1 ((Function$ (fun _ -> false)) - [@res.arity 1]))) in - let nodeParent = parentGet nodeToRemove in - parentSet successor nodeParent; - (match nodeParent with - | None -> () - | Some parent -> - leftOrRightSet parent ~node:((nodeToRemove) - [@res.namedArgLoc ]) (Some successor)); - updateSumRecursive rbt successor; - if (colorGet nodeToRemove) == Black - then - (if (colorGet successor) == Red - then - (colorSet successor Black; - if (parentGet successor) == None - then rootSet rbt (Some successor)) - else - (let break = ref false in - let successorRef = ref successor in - while not break.contents do - let successor = successorRef.contents in - match parentGet successor with - | None -> - (rootSet rbt (Some successor); - break.contents <- true) - | Some successorParent -> - let sibling = siblingOf successor in - (if - (sibling != None) && - ((colorGet (castNotOption sibling)) == Red) - then - (colorSet successorParent Red; - colorSet (castNotOption sibling) Black; - if isLeft successor - then rotateLeft rbt successorParent - else rotateRight rbt successorParent); - (let sibling = siblingOf successor in - let siblingNN = castNotOption sibling in + Function$ + (fun [arity:2]rbt -> + fun [arity:1]node -> + ((let nodeToRemove = + match ((leftGet node), (rightGet node)) with + | (Some _, Some _) -> + let successor = castNotOption (minNode (rightGet node)) in + (valueSet node (valueGet successor); + heightSet node (heightGet successor); + successor) + | _ -> node in + let successor = + match leftGet nodeToRemove with + | None -> rightGet nodeToRemove + | left -> left in + let (successor, isLeaf) = + match successor with + | None -> + let leaf = + createNode ~value:((Js.Internal.raw_expr {js|0|js}) + [@res.namedArgLoc ]) ~color:((Black) + [@res.namedArgLoc ]) ~height:((0.) + [@res.namedArgLoc ]) in + let isLeaf = + Js.Internal.fn_mk1 + (Function$ (fun [arity:1]x -> x == leaf)) in + (leaf, isLeaf) + | Some successor -> + (successor, + (Js.Internal.fn_mk1 + (Function$ (fun [arity:1]_ -> false)))) in + let nodeParent = parentGet nodeToRemove in + parentSet successor nodeParent; + (match nodeParent with + | None -> () + | Some parent -> + leftOrRightSet parent ~node:((nodeToRemove) + [@res.namedArgLoc ]) (Some successor)); + updateSumRecursive rbt successor; + if (colorGet nodeToRemove) == Black + then + (if (colorGet successor) == Red + then + (colorSet successor Black; + if (parentGet successor) == None + then rootSet rbt (Some successor)) + else + (let break = ref false in + let successorRef = ref successor in + while not break.contents do + let successor = successorRef.contents in + match parentGet successor with + | None -> + (rootSet rbt (Some successor); + break.contents <- true) + | Some successorParent -> + let sibling = siblingOf successor in + (if + (sibling != None) && + ((colorGet (castNotOption sibling)) == Red) + then + (colorSet successorParent Red; + colorSet (castNotOption sibling) Black; + if isLeft successor + then rotateLeft rbt successorParent + else rotateRight rbt successorParent); + (let sibling = siblingOf successor in + let siblingNN = castNotOption sibling in + if + ((colorGet successorParent) == Black) && + ((sibling == None) || + ((((colorGet siblingNN) == Black) && + (((leftGet siblingNN) == None) || + ((colorGet + (castNotOption + (leftGet siblingNN))) + == Black))) + && + (((rightGet siblingNN) == None) || + ((colorGet + (castNotOption + (rightGet siblingNN))) + == Black)))) + then + (if sibling != None + then colorSet siblingNN Red; + successorRef.contents <- successorParent) + else if - ((colorGet successorParent) == Black) && + ((colorGet successorParent) == Red) && ((sibling == None) || ((((colorGet siblingNN) == Black) && (((leftGet siblingNN) == None) || @@ -222,359 +238,312 @@ include then (if sibling != None then colorSet siblingNN Red; - successorRef.contents <- successorParent) + colorSet successorParent Black; + break.contents <- true) else if - ((colorGet successorParent) == Red) && - ((sibling == None) || - ((((colorGet siblingNN) == Black) && - (((leftGet siblingNN) == None) || - ((colorGet - (castNotOption - (leftGet siblingNN))) - == Black))) - && - (((rightGet siblingNN) == None) || - ((colorGet - (castNotOption - (rightGet siblingNN))) - == Black)))) + (sibling != None) && + ((colorGet (castNotOption sibling)) == + Black) then - (if sibling != None - then colorSet siblingNN Red; - colorSet successorParent Black; - break.contents <- true) - else - if - (sibling != None) && - ((colorGet (castNotOption sibling)) == - Black) - then - (let sibling = castNotOption sibling in + (let sibling = castNotOption sibling in + if + (((isLeft successor) && + (((rightGet sibling) == None) || + ((colorGet + (castNotOption + (rightGet sibling))) + == Black))) + && ((leftGet sibling) != None)) + && + ((colorGet + (castNotOption (leftGet sibling))) + == Red) + then + (colorSet sibling Red; + colorSet + (castNotOption (leftGet sibling)) + Black; + rotateRight rbt sibling) + else if - (((isLeft successor) && - (((rightGet sibling) == None) || + (((not (isLeft successor)) && + (((leftGet sibling) == None) || ((colorGet (castNotOption - (rightGet sibling))) + (leftGet sibling))) == Black))) - && ((leftGet sibling) != None)) + && ((rightGet sibling) != None)) && ((colorGet (castNotOption - (leftGet sibling))) + (rightGet sibling))) == Red) then (colorSet sibling Red; colorSet - (castNotOption (leftGet sibling)) - Black; - rotateRight rbt sibling) - else - if - (((not (isLeft successor)) && - (((leftGet sibling) == None) || - ((colorGet - (castNotOption - (leftGet sibling))) - == Black))) - && ((rightGet sibling) != None)) - && - ((colorGet - (castNotOption - (rightGet sibling))) - == Red) - then - (colorSet sibling Red; - colorSet - (castNotOption - (rightGet sibling)) Black; - rotateLeft rbt sibling); - break.contents <- true) - else - (let sibling = siblingOf successor in - let sibling = castNotOption sibling in - colorSet sibling - (colorGet successorParent); - if isLeft successor - then - (colorSet (castNotOption (rightGet sibling)) Black; - rotateRight rbt successorParent) - else - (colorSet - (castNotOption (leftGet sibling)) - Black; - rotateLeft rbt successorParent)))) - done)); - if Js.Internal.fn_run1 isLeaf successor - then - (if (rootGet rbt) == (Some successor) - then rootSet rbt None; - (match parentGet successor with - | None -> () - | Some parent -> - leftOrRightSet parent ~node:((successor) - [@res.namedArgLoc ]) None))) - [@res.braces ]))) - [@res.arity 2]) - let remove = - ((Function$ - (fun rbt -> - fun value -> - match _findNode rbt (rootGet rbt) value with - | Some node -> - (removeNode rbt node; - sizeSet rbt ((sizeGet rbt) - 1); - Some (heightGet node)) - | None -> None)) - [@res.arity 2]) - let findThroughCallback = - ((Function$ - (fun rbt -> - fun cb -> - ((let rec findThroughCallback = - ((Function$ - (fun rbt -> - fun node -> - fun cb -> - match node with - | None -> None - | Some node -> - let cmp = - Js.Internal.fn_run1 cb (valueGet node) in - if cmp == 0 - then Some node - else - if cmp < 0 + rotateLeft rbt sibling); + break.contents <- true) + else + (let sibling = siblingOf successor in + let sibling = castNotOption sibling in + colorSet sibling + (colorGet successorParent); + if isLeft successor then - findThroughCallback rbt (leftGet node) - cb + (colorSet + (castNotOption (rightGet sibling)) + Black; + rotateRight rbt successorParent) else - findThroughCallback rbt (rightGet node) - cb)) - [@res.arity 3]) in - match findThroughCallback rbt (rootGet rbt) cb with - | None -> None - | Some node -> Some (valueGet node)) - [@res.braces ]))) - [@res.arity 2]) + (colorSet + (castNotOption (leftGet sibling)) + Black; + rotateLeft rbt successorParent)))) + done)); + if Js.Internal.fn_run1 isLeaf successor + then + (if (rootGet rbt) == (Some successor) then rootSet rbt None; + (match parentGet successor with + | None -> () + | Some parent -> + leftOrRightSet parent ~node:((successor) + [@res.namedArgLoc ]) None))) + [@res.braces ])) + let remove = + Function$ + (fun [arity:2]rbt -> + fun [arity:1]value -> + match _findNode rbt (rootGet rbt) value with + | Some node -> + (removeNode rbt node; + sizeSet rbt ((sizeGet rbt) - 1); + Some (heightGet node)) + | None -> None) + let findThroughCallback = + Function$ + (fun [arity:2]rbt -> + fun [arity:1]cb -> + ((let rec findThroughCallback = + Function$ + (fun [arity:3]rbt -> + fun [arity:2]node -> + fun [arity:1]cb -> + match node with + | None -> None + | Some node -> + let cmp = + Js.Internal.fn_run1 cb (valueGet node) in + if cmp == 0 + then Some node + else + if cmp < 0 + then + findThroughCallback rbt (leftGet node) cb + else + findThroughCallback rbt (rightGet node) cb) in + match findThroughCallback rbt (rootGet rbt) cb with + | None -> None + | Some node -> Some (valueGet node)) + [@res.braces ])) let make = - ((Function$ - (fun ~compare:((compare)[@res.namedArgLoc ]) -> - t ~size:((0)[@res.namedArgLoc ]) ~root:((None) - [@res.namedArgLoc ]) ~compare:((compare)[@res.namedArgLoc ]))) - [@res.arity 1]) + Function$ + (fun [arity:1]~compare:((compare)[@res.namedArgLoc ]) -> + t ~size:((0)[@res.namedArgLoc ]) ~root:((None)[@res.namedArgLoc ]) + ~compare:((compare)[@res.namedArgLoc ])) let rec heightOfInterval = - ((Function$ - (fun rbt -> - fun node -> - fun lhs -> - fun rhs -> - match node with - | None -> 0. - | Some n -> - if (lhs == None) && (rhs == None) - then sumGet n + Function$ + (fun [arity:4]rbt -> + fun [arity:3]node -> + fun [arity:2]lhs -> + fun [arity:1]rhs -> + match node with + | None -> 0. + | Some n -> + if (lhs == None) && (rhs == None) + then sumGet n + else + if + (lhs != None) && + ((Js.Internal.fn_run2 (compareGet rbt) + (valueGet n) (castNotOption lhs)) + < 0) + then heightOfInterval rbt (rightGet n) lhs rhs else if - (lhs != None) && + (rhs != None) && ((Js.Internal.fn_run2 (compareGet rbt) - (valueGet n) (castNotOption lhs)) - < 0) - then heightOfInterval rbt (rightGet n) lhs rhs + (valueGet n) (castNotOption rhs)) + > 0) + then heightOfInterval rbt (leftGet n) lhs rhs else - if - (rhs != None) && - ((Js.Internal.fn_run2 (compareGet rbt) - (valueGet n) (castNotOption rhs)) - > 0) - then heightOfInterval rbt (leftGet n) lhs rhs - else - ((heightGet n) +. - (heightOfInterval rbt (leftGet n) lhs None)) - +. - (heightOfInterval rbt (rightGet n) None rhs))) - [@res.arity 4]) + ((heightGet n) +. + (heightOfInterval rbt (leftGet n) lhs None)) + +. (heightOfInterval rbt (rightGet n) None rhs)) let heightOfInterval = - ((Function$ - (fun rbt -> - fun lhs -> fun rhs -> heightOfInterval rbt (rootGet rbt) lhs rhs)) - [@res.arity 3]) + Function$ + (fun [arity:3]rbt -> + fun [arity:2]lhs -> + fun [arity:1]rhs -> heightOfInterval rbt (rootGet rbt) lhs rhs) let rec firstVisibleNode = - ((Function$ - (fun node -> - fun offset -> - match node with - | None -> None - | Some node -> - if (sumGet node) <= offset - then None - else - (let nodeHeight = heightGet node in - let sumLeft = - match leftGet node with - | None -> 0.0 - | Some left -> sumGet left in - if sumLeft > offset - then firstVisibleNode (leftGet node) offset + Function$ + (fun [arity:2]node -> + fun [arity:1]offset -> + match node with + | None -> None + | Some node -> + if (sumGet node) <= offset + then None + else + (let nodeHeight = heightGet node in + let sumLeft = + match leftGet node with + | None -> 0.0 + | Some left -> sumGet left in + if sumLeft > offset + then firstVisibleNode (leftGet node) offset + else + if (sumLeft +. nodeHeight) > offset + then Some node else - if (sumLeft +. nodeHeight) > offset - then Some node - else - firstVisibleNode (rightGet node) - (offset -. (sumLeft +. nodeHeight))))) - [@res.arity 2]) + firstVisibleNode (rightGet node) + (offset -. (sumLeft +. nodeHeight)))) let lastVisibleNode = - ((Function$ - (fun node -> - fun offset -> - match firstVisibleNode node offset with - | None -> maxNode node - | first -> first)) - [@res.arity 2]) + Function$ + (fun [arity:2]node -> + fun [arity:1]offset -> + match firstVisibleNode node offset with + | None -> maxNode node + | first -> first) let firstVisible = - ((Function$ - (fun rbt -> - fun ~offset:((offset)[@res.namedArgLoc ]) -> - match firstVisibleNode (rootGet rbt) offset with - | None -> None - | Some node -> Some (valueGet node))) - [@res.arity 2]) + Function$ + (fun [arity:2]rbt -> + fun [arity:1]~offset:((offset)[@res.namedArgLoc ]) -> + match firstVisibleNode (rootGet rbt) offset with + | None -> None + | Some node -> Some (valueGet node)) let rec leftmost = - ((Function$ - (fun node -> - match leftGet node with - | None -> node - | Some node -> leftmost node)) - [@res.arity 1]) + Function$ + (fun [arity:1]node -> + match leftGet node with + | None -> node + | Some node -> leftmost node) let rec firstRightParent = - ((Function$ - (fun node -> - match parentGet node with - | None -> None - | Some parent -> - if isLeft node then Some parent else firstRightParent parent)) - [@res.arity 1]) + Function$ + (fun [arity:1]node -> + match parentGet node with + | None -> None + | Some parent -> + if isLeft node then Some parent else firstRightParent parent) let nextNode = - ((Function$ - (fun node -> - match rightGet node with - | None -> firstRightParent node - | Some right -> Some (leftmost right))) - [@res.arity 1]) + Function$ + (fun [arity:1]node -> + match rightGet node with + | None -> firstRightParent node + | Some right -> Some (leftmost right)) let rec sumLeftSpine = - ((Function$ - (fun node -> - fun ~fromRightChild:((fromRightChild)[@res.namedArgLoc ]) -> - ((let leftSpine = - match leftGet node with - | None -> heightGet node - | Some left -> - if fromRightChild - then (heightGet node) +. (sumGet left) - else 0.0 in - match parentGet node with - | None -> leftSpine - | Some parent -> - leftSpine +. - (sumLeftSpine parent - ~fromRightChild:(((rightGet parent) == (Some node)) - [@res.namedArgLoc ]))) - [@res.braces ]))) - [@res.arity 2]) + Function$ + (fun [arity:2]node -> + fun [arity:1]~fromRightChild:((fromRightChild)[@res.namedArgLoc ]) + -> + ((let leftSpine = + match leftGet node with + | None -> heightGet node + | Some left -> + if fromRightChild + then (heightGet node) +. (sumGet left) + else 0.0 in + match parentGet node with + | None -> leftSpine + | Some parent -> + leftSpine +. + (sumLeftSpine parent + ~fromRightChild:(((rightGet parent) == (Some node)) + [@res.namedArgLoc ]))) + [@res.braces ])) let getY = - ((Function$ - (fun node -> - (sumLeftSpine node ~fromRightChild:((true)[@res.namedArgLoc ])) - -. (heightGet node))) - [@res.arity 1]) + Function$ + (fun [arity:1]node -> + (sumLeftSpine node ~fromRightChild:((true)[@res.namedArgLoc ])) -. + (heightGet node)) let linearSearch = - ((Function$ - (fun rbt -> - fun callback -> - ((let rec find = - ((Function$ - (fun node -> - fun callback -> - if Js.Internal.fn_run1 callback (valueGet node) - then Some (valueGet node) - else - (match nextNode node with - | None -> None - | Some node -> find node callback))) - [@res.arity 2]) in - match minNode (rootGet rbt) with - | None -> None - | Some node -> find node callback) - [@res.braces ]))) - [@res.arity 2]) + Function$ + (fun [arity:2]rbt -> + fun [arity:1]callback -> + ((let rec find = + Function$ + (fun [arity:2]node -> + fun [arity:1]callback -> + if Js.Internal.fn_run1 callback (valueGet node) + then Some (valueGet node) + else + (match nextNode node with + | None -> None + | Some node -> find node callback)) in + match minNode (rootGet rbt) with + | None -> None + | Some node -> find node callback) + [@res.braces ])) let rec iterate = - ((Function$ - (fun ~inclusive:((inclusive)[@res.namedArgLoc ]) -> - fun firstNode -> - fun lastNode -> - fun ~callback:((callback)[@res.namedArgLoc ]) -> + Function$ + (fun [arity:4]~inclusive:((inclusive)[@res.namedArgLoc ]) -> + fun [arity:3]firstNode -> + fun [arity:2]lastNode -> + fun [arity:1]~callback:((callback)[@res.namedArgLoc ]) -> + match firstNode with + | None -> () + | Some node -> + (if inclusive then Js.Internal.fn_run1 callback node; + if firstNode != lastNode + then + (if not inclusive + then Js.Internal.fn_run1 callback node; + iterate ~inclusive:((inclusive)[@res.namedArgLoc ]) + (nextNode node) lastNode ~callback:((callback) + [@res.namedArgLoc ])))) + let rec iterateWithY = + Function$ + (fun [arity:5]?y:((y)[@res.namedArgLoc ]) -> + fun [arity:4]~inclusive:((inclusive)[@res.namedArgLoc ]) -> + fun [arity:3]firstNode -> + fun [arity:2]lastNode -> + fun [arity:1]~callback:((callback)[@res.namedArgLoc ]) -> match firstNode with | None -> () | Some node -> - (if inclusive then Js.Internal.fn_run1 callback node; + let y = match y with | None -> getY node | Some y -> y in + (if inclusive then Js.Internal.fn_run2 callback node y; if firstNode != lastNode then (if not inclusive - then Js.Internal.fn_run1 callback node; - iterate ~inclusive:((inclusive) + then Js.Internal.fn_run2 callback node y; + iterateWithY ~y:((y +. (heightGet node)) + [@res.namedArgLoc ]) ~inclusive:((inclusive) [@res.namedArgLoc ]) (nextNode node) lastNode - ~callback:((callback)[@res.namedArgLoc ]))))) - [@res.arity 4]) - let rec iterateWithY = - ((Function$ - (fun ?y:((y)[@res.namedArgLoc ]) -> - fun ~inclusive:((inclusive)[@res.namedArgLoc ]) -> - fun firstNode -> - fun lastNode -> - fun ~callback:((callback)[@res.namedArgLoc ]) -> - match firstNode with - | None -> () - | Some node -> - let y = - match y with | None -> getY node | Some y -> y in - (if inclusive - then Js.Internal.fn_run2 callback node y; - if firstNode != lastNode - then - (if not inclusive - then Js.Internal.fn_run2 callback node y; - iterateWithY ~y:((y +. (heightGet node)) - [@res.namedArgLoc ]) ~inclusive:((inclusive) - [@res.namedArgLoc ]) (nextNode node) lastNode - ~callback:((callback)[@res.namedArgLoc ]))))) - [@res.arity 5]) + ~callback:((callback)[@res.namedArgLoc ])))) let rec updateSum = - ((Function$ - (fun node -> - fun ~delta:((delta)[@res.namedArgLoc ]) -> - match node with + Function$ + (fun [arity:2]node -> + fun [arity:1]~delta:((delta)[@res.namedArgLoc ]) -> + match node with + | None -> () + | Some node -> + (sumSet node ((sumGet node) +. delta); + updateSum (parentGet node) ~delta:((delta) + [@res.namedArgLoc ]))) + let setHeight = + Function$ + (fun [arity:3]rbt -> + fun [arity:2]value -> + fun [arity:1]~height:((height)[@res.namedArgLoc ]) -> + match _findNode rbt (rootGet rbt) value with | None -> () | Some node -> - (sumSet node ((sumGet node) +. delta); - updateSum (parentGet node) ~delta:((delta) - [@res.namedArgLoc ])))) - [@res.arity 2]) - let setHeight = - ((Function$ - (fun rbt -> - fun value -> - fun ~height:((height)[@res.namedArgLoc ]) -> - match _findNode rbt (rootGet rbt) value with - | None -> () - | Some node -> - let delta = height -. (heightGet node) in - (heightSet node height; - updateSum (Some node) ~delta:((delta) - [@res.namedArgLoc ])))) - [@res.arity 3]) + let delta = height -. (heightGet node) in + (heightSet node height; + updateSum (Some node) ~delta:((delta)[@res.namedArgLoc ]))) type nonrec 'value oldNewVisibleNodes = { mutable old: 'value array ; diff --git a/tests/syntax_tests/data/parsing/infiniteLoops/expected/templateEof.res.txt b/tests/syntax_tests/data/parsing/infiniteLoops/expected/templateEof.res.txt index bd5be8ca2e..e32f3b1321 100644 --- a/tests/syntax_tests/data/parsing/infiniteLoops/expected/templateEof.res.txt +++ b/tests/syntax_tests/data/parsing/infiniteLoops/expected/templateEof.res.txt @@ -20,7 +20,6 @@ ;;et ;;foo = - ((Function$ - (fun x -> - match x with | (("")[@res.template ]) -> [%rescript.exprhole ])) - [@res.arity 1]) \ No newline at end of file + (Function$ + (fun [arity:1]x -> + match x with | (("")[@res.template ]) -> [%rescript.exprhole ])) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/recovery/expression/expected/emptyBlock.res.txt b/tests/syntax_tests/data/parsing/recovery/expression/expected/emptyBlock.res.txt index 545f257b92..b08fdd7412 100644 --- a/tests/syntax_tests/data/parsing/recovery/expression/expected/emptyBlock.res.txt +++ b/tests/syntax_tests/data/parsing/recovery/expression/expected/emptyBlock.res.txt @@ -1,2 +1,2 @@ let x = { } -let f = ((Function$ (fun a -> fun b -> { }))[@res.arity 2]) \ No newline at end of file +let f = Function$ (fun [arity:2]a -> fun [arity:1]b -> { }) \ No newline at end of file diff --git a/tests/syntax_tests/data/parsing/recovery/expression/expected/list.res.txt b/tests/syntax_tests/data/parsing/recovery/expression/expected/list.res.txt index 511169c1c6..3be57506a5 100644 --- a/tests/syntax_tests/data/parsing/recovery/expression/expected/list.res.txt +++ b/tests/syntax_tests/data/parsing/recovery/expression/expected/list.res.txt @@ -31,16 +31,15 @@ let flags = then ((let parts = Utils.split_on_char ' ' flags in let rec loop = - ((Function$ - (fun items -> - ((match items with - | [|{js|-pp|js};_ppFlag;rest|] -> loop rest - | [|x;rest|] -> - ((Belt.Array.concatMany)[@res.spread ]) - [|[|x|];(loop rest)|] - | [||] -> [||]) - [@res.braces ]))) - [@res.arity 1]) in + Function$ + (fun [arity:1]items -> + ((match items with + | [|{js|-pp|js};_ppFlag;rest|] -> loop rest + | [|x;rest|] -> + ((Belt.Array.concatMany)[@res.spread ]) + [|[|x|];(loop rest)|] + | [||] -> [||]) + [@res.braces ])) in String.concat {js| |js} (loop parts)) [@res.braces ]) else flags) diff --git a/tests/syntax_tests/data/printer/expr/expected/underscoreApply.res.txt b/tests/syntax_tests/data/printer/expr/expected/underscoreApply.res.txt index dc58ba4594..a5ef46cc9e 100644 --- a/tests/syntax_tests/data/printer/expr/expected/underscoreApply.res.txt +++ b/tests/syntax_tests/data/printer/expr/expected/underscoreApply.res.txt @@ -44,7 +44,7 @@ getDirector(a, b, _).name f(a, b, _) ? g(x, y, _) : h(alpha, beta, _) -
+
{f(a, b, _)}
f(a, b, _)[ix] diff --git a/tests/tools_tests/ppx/TestPpx.res b/tests/tools_tests/ppx/TestPpx.res index afbca8e037..5ac14dbddb 100644 --- a/tests/tools_tests/ppx/TestPpx.res +++ b/tests/tools_tests/ppx/TestPpx.res @@ -18,3 +18,9 @@ module OptionalFields = { let r = {y: 1.0} } + +module Arity = { + let one = x => x + let two = (x, y) => x + y + let n = two(one(1), 5) +} diff --git a/tests/tools_tests/src/expected/TestPpx.res.jsout b/tests/tools_tests/src/expected/TestPpx.res.jsout index 9aa7b06165..f1abca17ba 100644 --- a/tests/tools_tests/src/expected/TestPpx.res.jsout +++ b/tests/tools_tests/src/expected/TestPpx.res.jsout @@ -16,6 +16,22 @@ let OptionalFields = { } }; +function one(x) { + return x; +} + +function two(x, y) { + return x + y | 0; +} + +let n = 6; + +let Arity = { + one: one, + two: two, + n: n +}; + let a = "A"; let b = "B"; @@ -27,4 +43,5 @@ exports.b = b; exports.M = M; exports.vv = vv; exports.OptionalFields = OptionalFields; +exports.Arity = Arity; /* Not a pure module */ From ca652d855f1e2099265adf8872bdd6b0046a8f78 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 10 Dec 2024 09:33:23 +0100 Subject: [PATCH 2/6] Use uncurried type for `@deriving(jsConverter)` This goes towards making all arities explicit. --- compiler/frontend/ast_derive_js_mapper.ml | 44 ++++++++++++++--------- tests/tests/src/ast_abstract_test.mjs | 8 ++--- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/compiler/frontend/ast_derive_js_mapper.ml b/compiler/frontend/ast_derive_js_mapper.ml index 70f4babb77..ca10a03da1 100644 --- a/compiler/frontend/ast_derive_js_mapper.ml +++ b/compiler/frontend/ast_derive_js_mapper.ml @@ -128,7 +128,9 @@ let app1 = Ast_compatible.app1 let app2 = Ast_compatible.app2 -let ( ->~ ) a b = Ast_compatible.arrow a b +let ( ->~ ) a b = + Ast_uncurried.uncurried_type ~loc:Location.none ~arity:1 + (Ast_compatible.arrow a b) let raise_when_not_found_ident = Longident.Ldot (Lident Primitive_modules.util, "raiseWhenNotFound") @@ -167,9 +169,10 @@ let init () = in let to_js_body body = Ast_comb.single_non_rec_value pat_to_js - (Ast_compatible.fun_ ~arity:None - (Pat.constraint_ (Pat.var pat_param) core_type) - body) + (Ast_uncurried.uncurried_fun ~loc:Location.none ~arity:1 + (Ast_compatible.fun_ ~arity:None + (Pat.constraint_ (Pat.var pat_param) core_type) + body)) in let ( +> ) a ty = Exp.constraint_ (erase_type a) ty in let ( +: ) a ty = erase_type (Exp.constraint_ a ty) in @@ -211,12 +214,16 @@ let init () = in let from_js = Ast_comb.single_non_rec_value pat_from_js - (Ast_compatible.fun_ ~arity:None (Pat.var pat_param) - (if create_type then - Exp.let_ Nonrecursive - [Vb.mk (Pat.var pat_param) (exp_param +: new_type)] - (Exp.constraint_ obj_exp core_type) - else Exp.constraint_ obj_exp core_type)) + (Ast_uncurried.uncurried_fun ~loc:Location.none ~arity:1 + (Ast_compatible.fun_ ~arity:(Some 1) (Pat.var pat_param) + (if create_type then + Exp.let_ Nonrecursive + [ + Vb.mk (Pat.var pat_param) + (exp_param +: new_type); + ] + (Exp.constraint_ obj_exp core_type) + else Exp.constraint_ obj_exp core_type))) in let rest = [to_js; from_js] in if create_type then erase_type_str :: new_type_str :: rest @@ -253,12 +260,14 @@ let init () = app2 unsafe_index_get_exp exp_map exp_param else app1 erase_type_exp exp_param); Ast_comb.single_non_rec_value pat_from_js - (Ast_compatible.fun_ ~arity:None (Pat.var pat_param) - (let result = - app2 unsafe_index_get_exp rev_exp_map exp_param - in - if create_type then raise_when_not_found result - else result)); + (Ast_uncurried.uncurried_fun ~loc:Location.none ~arity:1 + (Ast_compatible.fun_ ~arity:(Some 1) + (Pat.var pat_param) + (let result = + app2 unsafe_index_get_exp rev_exp_map exp_param + in + if create_type then raise_when_not_found result + else result))); ] in if create_type then new_type_str :: v else v @@ -285,7 +294,8 @@ let init () = let pat_from_js = {Asttypes.loc; txt = from_js} in let to_js_type result = Ast_comb.single_non_rec_val pat_to_js - (Ast_compatible.arrow core_type result) + (Ast_uncurried.uncurried_type ~loc:Location.none ~arity:1 + (Ast_compatible.arrow core_type result)) in let new_type, new_tdcl = U.new_type_of_type_declaration tdcl ("abs_" ^ name) diff --git a/tests/tests/src/ast_abstract_test.mjs b/tests/tests/src/ast_abstract_test.mjs index 4044c5b37f..82fee77942 100644 --- a/tests/tests/src/ast_abstract_test.mjs +++ b/tests/tests/src/ast_abstract_test.mjs @@ -68,6 +68,10 @@ function idx(v) { eq("File \"ast_abstract_test.res\", line 29, characters 18-25", xFromJs(v), v); } +let x0 = "a"; + +let x1 = "b"; + idx("a"); idx("b"); @@ -76,10 +80,6 @@ idx("c"); Mt.from_pair_suites("Ast_abstract_test", suites.contents); -let x0 = "a"; - -let x1 = "b"; - export { suites, test_id, From d1d40c266f4ea3263addc2609565c4c50b4ca500 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 10 Dec 2024 09:42:34 +0100 Subject: [PATCH 3/6] Clean up arity in derive projector. The arity is later overridden anyway, but being explicit can help cleaning up later on if `Function$` is removed entirely. --- compiler/frontend/ast_derive_projector.ml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/frontend/ast_derive_projector.ml b/compiler/frontend/ast_derive_projector.ml index 6884dbe497..86514c4ef0 100644 --- a/compiler/frontend/ast_derive_projector.ml +++ b/compiler/frontend/ast_derive_projector.ml @@ -46,7 +46,7 @@ let init () = -> let txt = "param" in Ast_comb.single_non_rec_value ?attrs:gentype_attrs pld_name - (Ast_compatible.fun_ ~arity:None + (Ast_compatible.fun_ ~arity:(Some 1) (Pat.constraint_ (Pat.var {txt; loc}) core_type) (Exp.field (Exp.ident {txt = Lident txt; loc}) @@ -108,7 +108,7 @@ let init () = annotate_type in Ext_list.fold_right vars exp (fun var b -> - Ast_compatible.fun_ ~arity:None + Ast_compatible.fun_ ~arity:(Some 1) (Pat.var {loc; txt = var}) b) |> handle_uncurried_accessor_tranform ~loc ~arity)) From c1c8e11253de665ff7f50ea08ccc66b72bb34560 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 10 Dec 2024 09:53:24 +0100 Subject: [PATCH 4/6] Most of Untypeast is never used. --- compiler/ml/untypeast.ml | 561 -------------------------------------- compiler/ml/untypeast.mli | 53 ---- 2 files changed, 614 deletions(-) diff --git a/compiler/ml/untypeast.ml b/compiler/ml/untypeast.ml index da064d8d77..1ae24b62dc 100644 --- a/compiler/ml/untypeast.ml +++ b/compiler/ml/untypeast.ml @@ -13,95 +13,8 @@ (* *) (**************************************************************************) -open Longident open Asttypes open Parsetree -open Ast_helper - -module T = Typedtree - -type mapper = { - attribute: mapper -> T.attribute -> attribute; - attributes: mapper -> T.attribute list -> attribute list; - case: mapper -> T.case -> case; - cases: mapper -> T.case list -> case list; - constructor_declaration: - mapper -> T.constructor_declaration -> constructor_declaration; - expr: mapper -> T.expression -> expression; - extension_constructor: - mapper -> T.extension_constructor -> extension_constructor; - include_declaration: mapper -> T.include_declaration -> include_declaration; - include_description: mapper -> T.include_description -> include_description; - label_declaration: mapper -> T.label_declaration -> label_declaration; - location: mapper -> Location.t -> Location.t; - module_binding: mapper -> T.module_binding -> module_binding; - module_declaration: mapper -> T.module_declaration -> module_declaration; - module_expr: mapper -> T.module_expr -> module_expr; - module_type: mapper -> T.module_type -> module_type; - module_type_declaration: - mapper -> T.module_type_declaration -> module_type_declaration; - package_type: mapper -> T.package_type -> package_type; - open_description: mapper -> T.open_description -> open_description; - pat: mapper -> T.pattern -> pattern; - row_field: mapper -> T.row_field -> row_field; - object_field: mapper -> T.object_field -> object_field; - signature: mapper -> T.signature -> signature; - signature_item: mapper -> T.signature_item -> signature_item; - structure: mapper -> T.structure -> structure; - structure_item: mapper -> T.structure_item -> structure_item; - typ: mapper -> T.core_type -> core_type; - type_declaration: mapper -> T.type_declaration -> type_declaration; - type_extension: mapper -> T.type_extension -> type_extension; - type_kind: mapper -> T.type_kind -> type_kind; - value_binding: mapper -> T.value_binding -> value_binding; - value_description: mapper -> T.value_description -> value_description; - with_constraint: - mapper -> - Path.t * Longident.t Location.loc * T.with_constraint -> - with_constraint; -} - -open T - -(* -Some notes: - - * For Pexp_function, we cannot go back to the exact original version - when there is a default argument, because the default argument is - translated in the typer. The code, if printed, will not be parsable because - new generated identifiers are not correct. - - * For Pexp_apply, it is unclear whether arguments are reordered, especially - when there are optional arguments. - -*) - -(** Utility functions. *) - -let map_opt f = function - | None -> None - | Some e -> Some (f e) - -let rec lident_of_path = function - | Path.Pident id -> Longident.Lident (Ident.name id) - | Path.Pdot (p, s, _) -> Longident.Ldot (lident_of_path p, s) - | Path.Papply (p1, p2) -> - Longident.Lapply (lident_of_path p1, lident_of_path p2) - -let map_loc sub {loc; txt} = {loc = sub.location sub loc; txt} - -(** Try a name [$name$0], check if it's free, if not, increment and repeat. *) -let fresh_name s env = - let rec aux i = - let name = s ^ string_of_int i in - try - let _ = Env.lookup_value (Lident name) env in - name - with Not_found -> aux (i + 1) - in - aux 0 - -(** Mapping functions. *) let constant = function | Const_char c -> Pconst_char c @@ -112,477 +25,3 @@ let constant = function | Const_bigint (sign, i) -> Pconst_integer (Bigint_utils.to_string sign i, Some 'n') | Const_float f -> Pconst_float (f, None) - -let attribute sub (s, p) = (map_loc sub s, p) -let attributes sub l = List.map (sub.attribute sub) l - -let structure sub str = List.map (sub.structure_item sub) str.str_items - -let open_description sub od = - let loc = sub.location sub od.open_loc in - let attrs = sub.attributes sub od.open_attributes in - Opn.mk ~loc ~attrs ~override:od.open_override (map_loc sub od.open_txt) - -let structure_item sub item = - let loc = sub.location sub item.str_loc in - let desc = - match item.str_desc with - | Tstr_eval (exp, attrs) -> Pstr_eval (sub.expr sub exp, attrs) - | Tstr_value (rec_flag, list) -> - Pstr_value (rec_flag, List.map (sub.value_binding sub) list) - | Tstr_primitive vd -> Pstr_primitive (sub.value_description sub vd) - | Tstr_type (rec_flag, list) -> - Pstr_type (rec_flag, List.map (sub.type_declaration sub) list) - | Tstr_typext tyext -> Pstr_typext (sub.type_extension sub tyext) - | Tstr_exception ext -> Pstr_exception (sub.extension_constructor sub ext) - | Tstr_module mb -> Pstr_module (sub.module_binding sub mb) - | Tstr_recmodule list -> - Pstr_recmodule (List.map (sub.module_binding sub) list) - | Tstr_modtype mtd -> Pstr_modtype (sub.module_type_declaration sub mtd) - | Tstr_open od -> Pstr_open (sub.open_description sub od) - | Tstr_class () -> Pstr_class () - | Tstr_class_type () -> Pstr_class_type () - | Tstr_include incl -> Pstr_include (sub.include_declaration sub incl) - | Tstr_attribute x -> Pstr_attribute x - in - Str.mk ~loc desc - -let value_description sub v = - let loc = sub.location sub v.val_loc in - let attrs = sub.attributes sub v.val_attributes in - Val.mk ~loc ~attrs ~prim:v.val_prim (map_loc sub v.val_name) - (sub.typ sub v.val_desc) - -let module_binding sub mb = - let loc = sub.location sub mb.mb_loc in - let attrs = sub.attributes sub mb.mb_attributes in - Mb.mk ~loc ~attrs (map_loc sub mb.mb_name) (sub.module_expr sub mb.mb_expr) - -let type_parameter sub (ct, v) = (sub.typ sub ct, v) - -let type_declaration sub decl = - let loc = sub.location sub decl.typ_loc in - let attrs = sub.attributes sub decl.typ_attributes in - Type.mk ~loc ~attrs - ~params:(List.map (type_parameter sub) decl.typ_params) - ~cstrs: - (List.map - (fun (ct1, ct2, loc) -> - (sub.typ sub ct1, sub.typ sub ct2, sub.location sub loc)) - decl.typ_cstrs) - ~kind:(sub.type_kind sub decl.typ_kind) - ~priv:decl.typ_private - ?manifest:(map_opt (sub.typ sub) decl.typ_manifest) - (map_loc sub decl.typ_name) - -let type_kind sub tk = - match tk with - | Ttype_abstract -> Ptype_abstract - | Ttype_variant list -> - Ptype_variant (List.map (sub.constructor_declaration sub) list) - | Ttype_record list -> - Ptype_record (List.map (sub.label_declaration sub) list) - | Ttype_open -> Ptype_open - -let constructor_arguments sub = function - | Cstr_tuple l -> Pcstr_tuple (List.map (sub.typ sub) l) - | Cstr_record l -> Pcstr_record (List.map (sub.label_declaration sub) l) - -let constructor_declaration sub cd = - let loc = sub.location sub cd.cd_loc in - let attrs = sub.attributes sub cd.cd_attributes in - Type.constructor ~loc ~attrs - ~args:(constructor_arguments sub cd.cd_args) - ?res:(map_opt (sub.typ sub) cd.cd_res) - (map_loc sub cd.cd_name) - -let label_declaration sub ld = - let loc = sub.location sub ld.ld_loc in - let attrs = sub.attributes sub ld.ld_attributes in - Type.field ~loc ~attrs ~mut:ld.ld_mutable ~optional:ld.ld_optional - (map_loc sub ld.ld_name) (sub.typ sub ld.ld_type) - -let type_extension sub tyext = - let attrs = sub.attributes sub tyext.tyext_attributes in - Te.mk ~attrs - ~params:(List.map (type_parameter sub) tyext.tyext_params) - ~priv:tyext.tyext_private - (map_loc sub tyext.tyext_txt) - (List.map (sub.extension_constructor sub) tyext.tyext_constructors) - -let extension_constructor sub ext = - let loc = sub.location sub ext.ext_loc in - let attrs = sub.attributes sub ext.ext_attributes in - Te.constructor ~loc ~attrs (map_loc sub ext.ext_name) - (match ext.ext_kind with - | Text_decl (args, ret) -> - Pext_decl (constructor_arguments sub args, map_opt (sub.typ sub) ret) - | Text_rebind (_p, lid) -> Pext_rebind (map_loc sub lid)) - -let pattern sub pat = - let loc = sub.location sub pat.pat_loc in - (* todo: fix attributes on extras *) - let attrs = sub.attributes sub pat.pat_attributes in - let desc = - match pat with - | {pat_extra = [(Tpat_unpack, _, _attrs)]; pat_desc = Tpat_var (_, name); _} - -> - Ppat_unpack name - | {pat_extra = [(Tpat_type (_path, lid), _, _attrs)]; _} -> - Ppat_type (map_loc sub lid) - | {pat_extra = (Tpat_constraint ct, _, _attrs) :: rem; _} -> - Ppat_constraint (sub.pat sub {pat with pat_extra = rem}, sub.typ sub ct) - | _ -> ( - match pat.pat_desc with - | Tpat_any -> Ppat_any - | Tpat_var (id, name) -> ( - match (Ident.name id).[0] with - | 'A' .. 'Z' -> Ppat_unpack name - | _ -> Ppat_var name) - (* We transform (_ as x) in x if _ and x have the same location. - The compiler transforms (x:t) into (_ as x : t). - This avoids transforming a warning 27 into a 26. - *) - | Tpat_alias ({pat_desc = Tpat_any; pat_loc}, _id, name) - when pat_loc = pat.pat_loc -> - Ppat_var name - | Tpat_alias (pat, _id, name) -> Ppat_alias (sub.pat sub pat, name) - | Tpat_constant cst -> Ppat_constant (constant cst) - | Tpat_tuple list -> Ppat_tuple (List.map (sub.pat sub) list) - | Tpat_construct (lid, _, args) -> - Ppat_construct - ( map_loc sub lid, - match args with - | [] -> None - | [arg] -> Some (sub.pat sub arg) - | args -> Some (Pat.tuple ~loc (List.map (sub.pat sub) args)) ) - | Tpat_variant (label, pato, _) -> - Ppat_variant (label, map_opt (sub.pat sub) pato) - | Tpat_record (list, closed) -> - Ppat_record - ( List.map - (fun (lid, _, pat, opt) -> - (map_loc sub lid, sub.pat sub pat, opt)) - list, - closed ) - | Tpat_array list -> Ppat_array (List.map (sub.pat sub) list) - | Tpat_or (p1, p2, _) -> Ppat_or (sub.pat sub p1, sub.pat sub p2) - | Tpat_lazy p -> Ppat_lazy (sub.pat sub p)) - in - Pat.mk ~loc ~attrs desc - -let exp_extra sub (extra, loc, attrs) sexp = - let loc = sub.location sub loc in - let attrs = sub.attributes sub attrs in - let desc = - match extra with - | Texp_coerce ((), cty2) -> Pexp_coerce (sexp, (), sub.typ sub cty2) - | Texp_constraint cty -> Pexp_constraint (sexp, sub.typ sub cty) - | Texp_open (ovf, _path, lid, _) -> Pexp_open (ovf, map_loc sub lid, sexp) - | Texp_poly cto -> Pexp_poly (sexp, map_opt (sub.typ sub) cto) - | Texp_newtype s -> Pexp_newtype (mkloc s loc, sexp) - in - Exp.mk ~loc ~attrs desc - -let cases sub l = List.map (sub.case sub) l - -let case sub {c_lhs; c_guard; c_rhs} = - { - pc_lhs = sub.pat sub c_lhs; - pc_guard = map_opt (sub.expr sub) c_guard; - pc_rhs = sub.expr sub c_rhs; - } - -let value_binding sub vb = - let loc = sub.location sub vb.vb_loc in - let attrs = sub.attributes sub vb.vb_attributes in - Vb.mk ~loc ~attrs (sub.pat sub vb.vb_pat) (sub.expr sub vb.vb_expr) - -let expression sub exp = - let loc = sub.location sub exp.exp_loc in - let attrs = sub.attributes sub exp.exp_attributes in - let desc = - match exp.exp_desc with - | Texp_ident (_path, lid, _) -> Pexp_ident (map_loc sub lid) - | Texp_constant cst -> Pexp_constant (constant cst) - | Texp_let (rec_flag, list, exp) -> - Pexp_let - (rec_flag, List.map (sub.value_binding sub) list, sub.expr sub exp) - (* Pexp_function can't have a label, so we split in 3 cases. *) - (* One case, no guard: It's a fun. *) - | Texp_function - {arg_label; cases = [{c_lhs = p; c_guard = None; c_rhs = e}]; _} -> - let arity = assert false in - Pexp_fun (arg_label, None, sub.pat sub p, sub.expr sub e, arity) - (* No label: it's a function. *) - | Texp_function {arg_label = Nolabel; cases; _} -> - Pexp_function (sub.cases sub cases) - (* Mix of both, we generate `fun ~label:$name$ -> match $name$ with ...` *) - | Texp_function {arg_label = (Labelled s | Optional s) as label; cases; _} - -> - let name = fresh_name s exp.exp_env in - let arity = assert false in - Pexp_fun - ( label, - None, - Pat.var ~loc {loc; txt = name}, - Exp.match_ ~loc - (Exp.ident ~loc {loc; txt = Lident name}) - (sub.cases sub cases), - arity ) - | Texp_apply (exp, list) -> - Pexp_apply - ( sub.expr sub exp, - List.fold_right - (fun (label, expo) list -> - match expo with - | None -> list - | Some exp -> (label, sub.expr sub exp) :: list) - list [] ) - | Texp_match (exp, cases, exn_cases, _) -> - let merged_cases = - sub.cases sub cases - @ List.map - (fun c -> - let uc = sub.case sub c in - let pat = {uc.pc_lhs with ppat_desc = Ppat_exception uc.pc_lhs} in - {uc with pc_lhs = pat}) - exn_cases - in - Pexp_match (sub.expr sub exp, merged_cases) - | Texp_try (exp, cases) -> Pexp_try (sub.expr sub exp, sub.cases sub cases) - | Texp_tuple list -> Pexp_tuple (List.map (sub.expr sub) list) - | Texp_construct (lid, _, args) -> - Pexp_construct - ( map_loc sub lid, - match args with - | [] -> None - | [arg] -> Some (sub.expr sub arg) - | args -> Some (Exp.tuple ~loc (List.map (sub.expr sub) args)) ) - | Texp_variant (label, expo) -> - Pexp_variant (label, map_opt (sub.expr sub) expo) - | Texp_record {fields; extended_expression; _} -> - let list = - Array.fold_left - (fun l -> function - | _, Kept _, _ -> l - | _, Overridden (lid, exp), opt -> (lid, sub.expr sub exp, opt) :: l) - [] fields - in - Pexp_record (list, map_opt (sub.expr sub) extended_expression) - | Texp_field (exp, lid, _label) -> - Pexp_field (sub.expr sub exp, map_loc sub lid) - | Texp_setfield (exp1, lid, _label, exp2) -> - Pexp_setfield (sub.expr sub exp1, map_loc sub lid, sub.expr sub exp2) - | Texp_array list -> Pexp_array (List.map (sub.expr sub) list) - | Texp_ifthenelse (exp1, exp2, expo) -> - Pexp_ifthenelse - (sub.expr sub exp1, sub.expr sub exp2, map_opt (sub.expr sub) expo) - | Texp_sequence (exp1, exp2) -> - Pexp_sequence (sub.expr sub exp1, sub.expr sub exp2) - | Texp_while (exp1, exp2) -> - Pexp_while (sub.expr sub exp1, sub.expr sub exp2) - | Texp_for (_id, name, exp1, exp2, dir, exp3) -> - Pexp_for - (name, sub.expr sub exp1, sub.expr sub exp2, dir, sub.expr sub exp3) - | Texp_send (exp, meth, _) -> - Pexp_send - ( sub.expr sub exp, - match meth with - | Tmeth_name name -> mkloc name loc ) - | Texp_new _ | Texp_instvar _ | Texp_setinstvar _ | Texp_override _ -> - assert false - | Texp_letmodule (_id, name, mexpr, exp) -> - Pexp_letmodule (name, sub.module_expr sub mexpr, sub.expr sub exp) - | Texp_letexception (ext, exp) -> - Pexp_letexception (sub.extension_constructor sub ext, sub.expr sub exp) - | Texp_assert exp -> Pexp_assert (sub.expr sub exp) - | Texp_lazy exp -> Pexp_lazy (sub.expr sub exp) - | Texp_pack mexpr -> Pexp_pack (sub.module_expr sub mexpr) - | Texp_extension_constructor (lid, _) -> - Pexp_extension - ( {txt = "ocaml.extension_constructor"; loc}, - PStr [Str.eval ~loc (Exp.construct ~loc (map_loc sub lid) None)] ) - in - List.fold_right (exp_extra sub) exp.exp_extra (Exp.mk ~loc ~attrs desc) - -let package_type sub pack = - ( map_loc sub pack.pack_txt, - List.map (fun (s, ct) -> (s, sub.typ sub ct)) pack.pack_fields ) - -let module_type_declaration sub mtd = - let loc = sub.location sub mtd.mtd_loc in - let attrs = sub.attributes sub mtd.mtd_attributes in - Mtd.mk ~loc ~attrs - ?typ:(map_opt (sub.module_type sub) mtd.mtd_type) - (map_loc sub mtd.mtd_name) - -let signature sub sg = List.map (sub.signature_item sub) sg.sig_items - -let signature_item sub item = - let loc = sub.location sub item.sig_loc in - let desc = - match item.sig_desc with - | Tsig_value v -> Psig_value (sub.value_description sub v) - | Tsig_type (rec_flag, list) -> - Psig_type (rec_flag, List.map (sub.type_declaration sub) list) - | Tsig_typext tyext -> Psig_typext (sub.type_extension sub tyext) - | Tsig_exception ext -> Psig_exception (sub.extension_constructor sub ext) - | Tsig_module md -> Psig_module (sub.module_declaration sub md) - | Tsig_recmodule list -> - Psig_recmodule (List.map (sub.module_declaration sub) list) - | Tsig_modtype mtd -> Psig_modtype (sub.module_type_declaration sub mtd) - | Tsig_open od -> Psig_open (sub.open_description sub od) - | Tsig_include incl -> Psig_include (sub.include_description sub incl) - | Tsig_class () -> Psig_class () - | Tsig_class_type () -> Psig_class_type () - | Tsig_attribute x -> Psig_attribute x - in - Sig.mk ~loc desc - -let module_declaration sub md = - let loc = sub.location sub md.md_loc in - let attrs = sub.attributes sub md.md_attributes in - Md.mk ~loc ~attrs (map_loc sub md.md_name) (sub.module_type sub md.md_type) - -let include_infos f sub incl = - let loc = sub.location sub incl.incl_loc in - let attrs = sub.attributes sub incl.incl_attributes in - Incl.mk ~loc ~attrs (f sub incl.incl_mod) - -let include_declaration sub = include_infos sub.module_expr sub -let include_description sub = include_infos sub.module_type sub - -let module_type sub mty = - let loc = sub.location sub mty.mty_loc in - let attrs = sub.attributes sub mty.mty_attributes in - let desc = - match mty.mty_desc with - | Tmty_ident (_path, lid) -> Pmty_ident (map_loc sub lid) - | Tmty_alias (_path, lid) -> Pmty_alias (map_loc sub lid) - | Tmty_signature sg -> Pmty_signature (sub.signature sub sg) - | Tmty_functor (_id, name, mtype1, mtype2) -> - Pmty_functor - (name, map_opt (sub.module_type sub) mtype1, sub.module_type sub mtype2) - | Tmty_with (mtype, list) -> - Pmty_with - (sub.module_type sub mtype, List.map (sub.with_constraint sub) list) - | Tmty_typeof mexpr -> Pmty_typeof (sub.module_expr sub mexpr) - in - Mty.mk ~loc ~attrs desc - -let with_constraint sub (_path, lid, cstr) = - match cstr with - | Twith_type decl -> - Pwith_type (map_loc sub lid, sub.type_declaration sub decl) - | Twith_module (_path, lid2) -> - Pwith_module (map_loc sub lid, map_loc sub lid2) - | Twith_typesubst decl -> - Pwith_typesubst (map_loc sub lid, sub.type_declaration sub decl) - | Twith_modsubst (_path, lid2) -> - Pwith_modsubst (map_loc sub lid, map_loc sub lid2) - -let module_expr sub mexpr = - let loc = sub.location sub mexpr.mod_loc in - let attrs = sub.attributes sub mexpr.mod_attributes in - match mexpr.mod_desc with - | Tmod_constraint (m, _, Tmodtype_implicit, _) -> sub.module_expr sub m - | _ -> - let desc = - match mexpr.mod_desc with - | Tmod_ident (_p, lid) -> Pmod_ident (map_loc sub lid) - | Tmod_structure st -> Pmod_structure (sub.structure sub st) - | Tmod_functor (_id, name, mtype, mexpr) -> - Pmod_functor - ( name, - Misc.may_map (sub.module_type sub) mtype, - sub.module_expr sub mexpr ) - | Tmod_apply (mexp1, mexp2, _) -> - Pmod_apply (sub.module_expr sub mexp1, sub.module_expr sub mexp2) - | Tmod_constraint (mexpr, _, Tmodtype_explicit mtype, _) -> - Pmod_constraint (sub.module_expr sub mexpr, sub.module_type sub mtype) - | Tmod_constraint (_mexpr, _, Tmodtype_implicit, _) -> assert false - | Tmod_unpack (exp, _pack) -> Pmod_unpack (sub.expr sub exp) - (* TODO , sub.package_type sub pack) *) - in - Mod.mk ~loc ~attrs desc - -let core_type sub ct = - let loc = sub.location sub ct.ctyp_loc in - let attrs = sub.attributes sub ct.ctyp_attributes in - let desc = - match ct.ctyp_desc with - | Ttyp_any -> Ptyp_any - | Ttyp_var s -> Ptyp_var s - | Ttyp_arrow (label, ct1, ct2) -> - Ptyp_arrow (label, sub.typ sub ct1, sub.typ sub ct2) - | Ttyp_tuple list -> Ptyp_tuple (List.map (sub.typ sub) list) - | Ttyp_constr (_path, lid, list) -> - Ptyp_constr (map_loc sub lid, List.map (sub.typ sub) list) - | Ttyp_object (list, o) -> - Ptyp_object (List.map (sub.object_field sub) list, o) - | Ttyp_alias (ct, s) -> Ptyp_alias (sub.typ sub ct, s) - | Ttyp_variant (list, bool, labels) -> - Ptyp_variant (List.map (sub.row_field sub) list, bool, labels) - | Ttyp_poly (list, ct) -> - let list = List.map (fun v -> mkloc v loc) list in - Ptyp_poly (list, sub.typ sub ct) - | Ttyp_package pack -> Ptyp_package (sub.package_type sub pack) - in - Typ.mk ~loc ~attrs desc - -let row_field sub rf = - match rf with - | Ttag (label, attrs, bool, list) -> - Rtag (label, sub.attributes sub attrs, bool, List.map (sub.typ sub) list) - | Tinherit ct -> Rinherit (sub.typ sub ct) - -let object_field sub ofield = - match ofield with - | OTtag (label, attrs, ct) -> - Otag (label, sub.attributes sub attrs, sub.typ sub ct) - | OTinherit ct -> Oinherit (sub.typ sub ct) - -let location _sub l = l - -let default_mapper = - { - attribute; - attributes; - structure; - structure_item; - module_expr; - signature; - signature_item; - module_type; - with_constraint; - type_declaration; - type_kind; - typ = core_type; - type_extension; - extension_constructor; - value_description; - pat = pattern; - expr = expression; - module_declaration; - module_type_declaration; - module_binding; - package_type; - open_description; - include_description; - include_declaration; - value_binding; - constructor_declaration; - label_declaration; - cases; - case; - location; - row_field; - object_field; - } - -let untype_structure ?(mapper = default_mapper) structure = - mapper.structure mapper structure - -let untype_signature ?(mapper = default_mapper) signature = - mapper.signature mapper signature diff --git a/compiler/ml/untypeast.mli b/compiler/ml/untypeast.mli index a86e69be65..b4471a1ac6 100644 --- a/compiler/ml/untypeast.mli +++ b/compiler/ml/untypeast.mli @@ -13,57 +13,4 @@ (* *) (**************************************************************************) -open Parsetree - -val lident_of_path : Path.t -> Longident.t - -type mapper = { - attribute: mapper -> Typedtree.attribute -> attribute; - attributes: mapper -> Typedtree.attribute list -> attribute list; - case: mapper -> Typedtree.case -> case; - cases: mapper -> Typedtree.case list -> case list; - constructor_declaration: - mapper -> Typedtree.constructor_declaration -> constructor_declaration; - expr: mapper -> Typedtree.expression -> expression; - extension_constructor: - mapper -> Typedtree.extension_constructor -> extension_constructor; - include_declaration: - mapper -> Typedtree.include_declaration -> include_declaration; - include_description: - mapper -> Typedtree.include_description -> include_description; - label_declaration: mapper -> Typedtree.label_declaration -> label_declaration; - location: mapper -> Location.t -> Location.t; - module_binding: mapper -> Typedtree.module_binding -> module_binding; - module_declaration: - mapper -> Typedtree.module_declaration -> module_declaration; - module_expr: mapper -> Typedtree.module_expr -> module_expr; - module_type: mapper -> Typedtree.module_type -> module_type; - module_type_declaration: - mapper -> Typedtree.module_type_declaration -> module_type_declaration; - package_type: mapper -> Typedtree.package_type -> package_type; - open_description: mapper -> Typedtree.open_description -> open_description; - pat: mapper -> Typedtree.pattern -> pattern; - row_field: mapper -> Typedtree.row_field -> row_field; - object_field: mapper -> Typedtree.object_field -> object_field; - signature: mapper -> Typedtree.signature -> signature; - signature_item: mapper -> Typedtree.signature_item -> signature_item; - structure: mapper -> Typedtree.structure -> structure; - structure_item: mapper -> Typedtree.structure_item -> structure_item; - typ: mapper -> Typedtree.core_type -> core_type; - type_declaration: mapper -> Typedtree.type_declaration -> type_declaration; - type_extension: mapper -> Typedtree.type_extension -> type_extension; - type_kind: mapper -> Typedtree.type_kind -> type_kind; - value_binding: mapper -> Typedtree.value_binding -> value_binding; - value_description: mapper -> Typedtree.value_description -> value_description; - with_constraint: - mapper -> - Path.t * Longident.t Location.loc * Typedtree.with_constraint -> - with_constraint; -} - -val default_mapper : mapper - -val untype_structure : ?mapper:mapper -> Typedtree.structure -> structure -val untype_signature : ?mapper:mapper -> Typedtree.signature -> signature - val constant : Asttypes.constant -> Parsetree.constant From dfb4b2e4ec5c268e8993246738e6f81e9c403799 Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 10 Dec 2024 10:16:41 +0100 Subject: [PATCH 5/6] More explicit translation for `Function$`. Cosmetic change that will be needed later to remove `Function$`. --- compiler/ml/translcore.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/ml/translcore.ml b/compiler/ml/translcore.ml index 2e1afdfa29..1fdb458a0a 100644 --- a/compiler/ml/translcore.ml +++ b/compiler/ml/translcore.ml @@ -823,7 +823,9 @@ and transl_exp0 (e : Typedtree.expression) : Lambda.lambda = with Not_constant -> Lprim (Pmakeblock Blk_tuple, ll, e.exp_loc)) | Texp_construct ({txt = Lident "false"}, _, []) -> Lconst Const_false | Texp_construct ({txt = Lident "true"}, _, []) -> Lconst Const_true - | Texp_construct ({txt = Lident "Function$"}, _, [expr]) -> + | Texp_construct + ({txt = Lident "Function$"}, _, [({exp_desc = Texp_function _} as expr)]) + -> (* ReScript uncurried encoding *) let loc = expr.exp_loc in let lambda = transl_exp expr in From 0ba5b76e86962a5ad176577cf91844b3436e245b Mon Sep 17 00:00:00 2001 From: Cristiano Calcagno Date: Tue, 10 Dec 2024 16:36:14 +0100 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e6e4f8f00..e9bbc2ec47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Ast cleanup: remove exp object and exp unreachable. https://github.com/rescript-lang/rescript/pull/7189 - Ast cleanup: explicit representation for optional record fields in types. https://github.com/rescript-lang/rescript/pull/7190 https://github.com/rescript-lang/rescript/pull/7191 - AST cleanup: first-class expression and patterns for records with optional fields. https://github.com/rescript-lang/rescript/pull/7192 +- AST cleanup: Represent the arity of uncurried function definitions directly in the AST. https://github.com/rescript-lang/rescript/pull/7197 # 12.0.0-alpha.5