Skip to content

Commit 68afeab

Browse files
authored
Remove unnecessary usage of Ast_uncurried helpers (#7987)
* Remove unnecessary usage of Ast_uncurried helpers * CHANGELOG
1 parent 372ee8d commit 68afeab

File tree

7 files changed

+27
-51
lines changed

7 files changed

+27
-51
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
#### :house: Internal
3434

35+
- Clean up usage of `Ast_uncurried` helpers. https://github.com/rescript-lang/rescript/pull/7987
36+
3537
# 12.0.0-rc.2
3638

3739
#### :boom: Breaking Change

compiler/frontend/ast_derive_js_mapper.ml

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -174,10 +174,9 @@ let init () =
174174
in
175175
let to_js_body body =
176176
Ast_comb.single_non_rec_value pat_to_js
177-
(Ast_uncurried.uncurried_fun ~arity:1
178-
(Ast_compatible.fun_ ~arity:None
179-
(Pat.constraint_ (Pat.var pat_param) core_type)
180-
body))
177+
(Ast_compatible.fun_ ~arity:(Some 1)
178+
(Pat.constraint_ (Pat.var pat_param) core_type)
179+
body)
181180
in
182181
let ( +> ) a ty = Exp.constraint_ (erase_type a) ty in
183182
let ( +: ) a ty = erase_type (Exp.constraint_ a ty) in
@@ -227,16 +226,12 @@ let init () =
227226
in
228227
let from_js =
229228
Ast_comb.single_non_rec_value pat_from_js
230-
(Ast_uncurried.uncurried_fun ~arity:1
231-
(Ast_compatible.fun_ ~arity:(Some 1) (Pat.var pat_param)
232-
(if create_type then
233-
Exp.let_ Nonrecursive
234-
[
235-
Vb.mk (Pat.var pat_param)
236-
(exp_param +: new_type);
237-
]
238-
(Exp.constraint_ obj_exp core_type)
239-
else Exp.constraint_ obj_exp core_type)))
229+
(Ast_compatible.fun_ ~arity:(Some 1) (Pat.var pat_param)
230+
(if create_type then
231+
Exp.let_ Nonrecursive
232+
[Vb.mk (Pat.var pat_param) (exp_param +: new_type)]
233+
(Exp.constraint_ obj_exp core_type)
234+
else Exp.constraint_ obj_exp core_type))
240235
in
241236
let rest = [to_js; from_js] in
242237
if create_type then erase_type_str :: new_type_str :: rest
@@ -273,14 +268,12 @@ let init () =
273268
app2 unsafe_index_get_exp exp_map exp_param
274269
else app1 erase_type_exp exp_param);
275270
Ast_comb.single_non_rec_value pat_from_js
276-
(Ast_uncurried.uncurried_fun ~arity:1
277-
(Ast_compatible.fun_ ~arity:(Some 1)
278-
(Pat.var pat_param)
279-
(let result =
280-
app2 unsafe_index_get_exp rev_exp_map exp_param
281-
in
282-
if create_type then raise_when_not_found result
283-
else result)));
271+
(Ast_compatible.fun_ ~arity:(Some 1) (Pat.var pat_param)
272+
(let result =
273+
app2 unsafe_index_get_exp rev_exp_map exp_param
274+
in
275+
if create_type then raise_when_not_found result
276+
else result));
284277
]
285278
in
286279
if create_type then new_type_str :: v else v

compiler/frontend/ast_derive_projector.ml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,12 @@ let init () =
4646
->
4747
let txt = "param" in
4848
Ast_comb.single_non_rec_value ?attrs:gentype_attrs pld_name
49+
(* arity will always be 1 since these are single param functions *)
4950
(Ast_compatible.fun_ ~arity:(Some 1)
5051
(Pat.constraint_ (Pat.var {txt; loc}) core_type)
5152
(Exp.field
5253
(Exp.ident {txt = Lident txt; loc})
53-
{txt = Longident.Lident pld_label; loc})
54-
(*arity will alwys be 1 since these are single param functions*)
55-
|> handle_uncurried_accessor_tranform ~arity:1))
54+
{txt = Longident.Lident pld_label; loc})))
5655
| Ptype_variant constructor_declarations ->
5756
Ext_list.map constructor_declarations
5857
(fun

compiler/frontend/ast_exp_handle_external.ml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,7 @@ let handle_ffi ~loc ~payload =
134134
Ast_helper.Typ.arrows ~loc args any
135135
in
136136
match !is_function with
137-
| Some arity ->
138-
let type_ =
139-
Ast_uncurried.uncurried_type
140-
~arity:(if arity = 0 then 1 else arity)
141-
(arrow ~arity)
142-
in
143-
Ast_helper.Exp.constraint_ ~loc e type_
137+
| Some arity -> Ast_helper.Exp.constraint_ ~loc e (arrow ~arity)
144138
| _ -> err ()
145139
in
146140
wrap_type_constraint

compiler/syntax/src/jsx_v4.ml

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,8 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
628628
(* let make = React.forwardRef({
629629
let \"App" = (props, ref) => make({...props, ref: @optional (Js.Nullabel.toOption(ref))})
630630
})*)
631-
Exp.fun_ ~arity:None Nolabel None
631+
let total_arity = if has_forward_ref then 2 else 1 in
632+
Exp.fun_ ~arity:(Some total_arity) Nolabel None
632633
(match core_type_of_attr with
633634
| None -> make_props_pattern named_type_list
634635
| 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 =
639640
else inner_expression)
640641
~attrs:binding.pvb_expr.pexp_attributes
641642
in
642-
let full_expression =
643-
full_expression
644-
|> Ast_uncurried.uncurried_fun ~arity:(if has_forward_ref then 2 else 1)
645-
in
646643
let full_expression =
647644
match full_module_name with
648645
| "" -> full_expression
@@ -764,7 +761,8 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
764761
in
765762
let expression =
766763
(* Shape internal implementation to match wrapper: uncurried when using forwardRef. *)
767-
Exp.fun_ ~arity:(Some 1) ~async:is_async Nolabel None
764+
let total_arity = if has_forward_ref then 2 else 1 in
765+
Exp.fun_ ~arity:(Some total_arity) ~async:is_async Nolabel None
768766
(Pat.constraint_ record_pattern
769767
(Typ.constr ~loc:empty_loc
770768
{txt = Lident "props"; loc = empty_loc}
@@ -779,10 +777,6 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
779777
| _ -> [Typ.any ()]))))
780778
expression
781779
in
782-
let expression =
783-
if has_forward_ref then expression |> Ast_uncurried.uncurried_fun ~arity:2
784-
else expression
785-
in
786780
let expression =
787781
(* Add new tupes (type a,b,c) to make's definition *)
788782
newtypes
@@ -887,12 +881,9 @@ let map_binding ~config ~empty_loc ~pstr_loc ~file_name ~rec_flag binding =
887881
in
888882
let applied_expression = constrain_jsx_return applied_expression in
889883
let wrapper_expr =
890-
Exp.fun_ ~arity:None Nolabel None props_pattern
884+
Exp.fun_ ~arity:(Some 1) Nolabel None props_pattern
891885
~attrs:binding.pvb_expr.pexp_attributes applied_expression
892886
in
893-
894-
let wrapper_expr = Ast_uncurried.uncurried_fun ~arity:1 wrapper_expr in
895-
896887
let internal_expression =
897888
Exp.let_ Nonrecursive
898889
[Vb.mk (Pat.var {txt = full_module_name; loc}) wrapper_expr]

compiler/syntax/src/res_core.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -609,10 +609,7 @@ let process_underscore_application args =
609609
(Ppat_var (Location.mkloc hidden_var loc))
610610
~loc:Location.none
611611
in
612-
let fun_expr =
613-
Ast_helper.Exp.fun_ ~loc ~arity:(Some 1) Nolabel None pattern exp_apply
614-
in
615-
Ast_uncurried.uncurried_fun ~arity:1 fun_expr
612+
Ast_helper.Exp.fun_ ~loc ~arity:(Some 1) Nolabel None pattern exp_apply
616613
| None -> exp_apply
617614
in
618615
(args, wrap)

compiler/syntax/src/res_parsetree_viewer.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ let partition_doc_comment_attributes attrs =
567567
let is_fun_newtype expr =
568568
match expr.pexp_desc with
569569
| Pexp_fun _ | Pexp_newtype _ -> true
570-
| _ -> Ast_uncurried.expr_is_uncurried_fun expr
570+
| _ -> false
571571

572572
let requires_special_callback_printing_last_arg args =
573573
let rec loop args =

0 commit comments

Comments
 (0)