From 9e9ebec1ede1ed81aaeef27baa796ff038f06756 Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Wed, 22 Oct 2025 20:19:33 +0200 Subject: [PATCH 1/2] Remove unnecessary usage of Ast_uncurried helpers --- compiler/frontend/ast_derive_js_mapper.ml | 37 ++++++++------------ compiler/frontend/ast_derive_projector.ml | 5 ++- compiler/frontend/ast_exp_handle_external.ml | 8 +---- compiler/syntax/src/jsx_v4.ml | 19 +++------- compiler/syntax/src/res_core.ml | 5 +-- compiler/syntax/src/res_parsetree_viewer.ml | 2 +- 6 files changed, 25 insertions(+), 51 deletions(-) diff --git a/compiler/frontend/ast_derive_js_mapper.ml b/compiler/frontend/ast_derive_js_mapper.ml index 58e20145cf..ffb5dbd6ec 100644 --- a/compiler/frontend/ast_derive_js_mapper.ml +++ b/compiler/frontend/ast_derive_js_mapper.ml @@ -174,10 +174,9 @@ let init () = in let to_js_body body = Ast_comb.single_non_rec_value pat_to_js - (Ast_uncurried.uncurried_fun ~arity:1 - (Ast_compatible.fun_ ~arity:None - (Pat.constraint_ (Pat.var pat_param) core_type) - body)) + (Ast_compatible.fun_ ~arity:(Some 1) + (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 @@ -227,16 +226,12 @@ let init () = in let from_js = Ast_comb.single_non_rec_value pat_from_js - (Ast_uncurried.uncurried_fun ~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))) + (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 @@ -273,14 +268,12 @@ 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_uncurried.uncurried_fun ~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))); + (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 diff --git a/compiler/frontend/ast_derive_projector.ml b/compiler/frontend/ast_derive_projector.ml index 74b989b592..3d2c7d1962 100644 --- a/compiler/frontend/ast_derive_projector.ml +++ b/compiler/frontend/ast_derive_projector.ml @@ -46,13 +46,12 @@ let init () = -> let txt = "param" in Ast_comb.single_non_rec_value ?attrs:gentype_attrs pld_name + (* arity will always be 1 since these are single param functions *) (Ast_compatible.fun_ ~arity:(Some 1) (Pat.constraint_ (Pat.var {txt; loc}) core_type) (Exp.field (Exp.ident {txt = Lident txt; loc}) - {txt = Longident.Lident pld_label; loc}) - (*arity will alwys be 1 since these are single param functions*) - |> handle_uncurried_accessor_tranform ~arity:1)) + {txt = Longident.Lident pld_label; loc}))) | Ptype_variant constructor_declarations -> Ext_list.map constructor_declarations (fun diff --git a/compiler/frontend/ast_exp_handle_external.ml b/compiler/frontend/ast_exp_handle_external.ml index 616c5cc9f8..73818242f3 100644 --- a/compiler/frontend/ast_exp_handle_external.ml +++ b/compiler/frontend/ast_exp_handle_external.ml @@ -134,13 +134,7 @@ let handle_ffi ~loc ~payload = Ast_helper.Typ.arrows ~loc args any in match !is_function with - | Some arity -> - let type_ = - Ast_uncurried.uncurried_type - ~arity:(if arity = 0 then 1 else arity) - (arrow ~arity) - in - Ast_helper.Exp.constraint_ ~loc e type_ + | Some arity -> Ast_helper.Exp.constraint_ ~loc e (arrow ~arity) | _ -> err () in wrap_type_constraint diff --git a/compiler/syntax/src/jsx_v4.ml b/compiler/syntax/src/jsx_v4.ml index 6def3993ac..4cf9c9a0dd 100644 --- a/compiler/syntax/src/jsx_v4.ml +++ b/compiler/syntax/src/jsx_v4.ml @@ -628,7 +628,8 @@ 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_ ~arity:None Nolabel None + let total_arity = if has_forward_ref then 2 else 1 in + Exp.fun_ ~arity:(Some total_arity) Nolabel None (match core_type_of_attr with | None -> make_props_pattern named_type_list | Some _ -> make_props_pattern typ_vars_of_core_type) @@ -639,10 +640,6 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding = else inner_expression) ~attrs:binding.pvb_expr.pexp_attributes in - let full_expression = - full_expression - |> Ast_uncurried.uncurried_fun ~arity:(if has_forward_ref then 2 else 1) - in let full_expression = match full_module_name with | "" -> full_expression @@ -764,7 +761,8 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding = in let expression = (* Shape internal implementation to match wrapper: uncurried when using forwardRef. *) - Exp.fun_ ~arity:(Some 1) ~async:is_async Nolabel None + let total_arity = if has_forward_ref then 2 else 1 in + Exp.fun_ ~arity:(Some total_arity) ~async:is_async Nolabel None (Pat.constraint_ record_pattern (Typ.constr ~loc:empty_loc {txt = Lident "props"; loc = empty_loc} @@ -779,10 +777,6 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding = | _ -> [Typ.any ()])))) expression in - let expression = - if has_forward_ref then expression |> Ast_uncurried.uncurried_fun ~arity:2 - else expression - in let expression = (* Add new tupes (type a,b,c) to make's definition *) newtypes @@ -887,12 +881,9 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding = in let applied_expression = constrain_jsx_return applied_expression in let wrapper_expr = - Exp.fun_ ~arity:None Nolabel None props_pattern + Exp.fun_ ~arity:(Some 1) Nolabel None props_pattern ~attrs:binding.pvb_expr.pexp_attributes applied_expression in - - let wrapper_expr = Ast_uncurried.uncurried_fun ~arity:1 wrapper_expr in - let internal_expression = Exp.let_ Nonrecursive [Vb.mk (Pat.var {txt = full_module_name; loc}) wrapper_expr] diff --git a/compiler/syntax/src/res_core.ml b/compiler/syntax/src/res_core.ml index 55a6ed5921..3718739c4b 100644 --- a/compiler/syntax/src/res_core.ml +++ b/compiler/syntax/src/res_core.ml @@ -609,10 +609,7 @@ let process_underscore_application args = (Ppat_var (Location.mkloc hidden_var loc)) ~loc:Location.none in - let fun_expr = - Ast_helper.Exp.fun_ ~loc ~arity:(Some 1) Nolabel None pattern exp_apply - in - Ast_uncurried.uncurried_fun ~arity:1 fun_expr + Ast_helper.Exp.fun_ ~loc ~arity:(Some 1) Nolabel None pattern exp_apply | None -> exp_apply in (args, wrap) diff --git a/compiler/syntax/src/res_parsetree_viewer.ml b/compiler/syntax/src/res_parsetree_viewer.ml index e97c4a03bf..b4fb22572b 100644 --- a/compiler/syntax/src/res_parsetree_viewer.ml +++ b/compiler/syntax/src/res_parsetree_viewer.ml @@ -567,7 +567,7 @@ let partition_doc_comment_attributes attrs = let is_fun_newtype expr = match expr.pexp_desc with | Pexp_fun _ | Pexp_newtype _ -> true - | _ -> Ast_uncurried.expr_is_uncurried_fun expr + | _ -> false let requires_special_callback_printing_last_arg args = let rec loop args = From bbe3078d5f732eef856e964e9ef4de170df3bdba Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Thu, 23 Oct 2025 16:46:53 +0200 Subject: [PATCH 2/2] CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00efe2a99a..76c76378d5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ #### :house: Internal +- Clean up usage of `Ast_uncurried` helpers. https://github.com/rescript-lang/rescript/pull/7987 + # 12.0.0-rc.2 #### :boom: Breaking Change