Skip to content

Commit 674c4bf

Browse files
committed
Remove function$ entirely.
1 parent 6eae5c7 commit 674c4bf

File tree

64 files changed

+418
-497
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+418
-497
lines changed

compiler/frontend/ast_core_type.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ let mk_fn_type (new_arg_types_ty : param_type list) (result : t) : t =
156156
let list_of_arrow (ty : t) : t * param_type list =
157157
let rec aux (ty : t) acc =
158158
match ty.ptyp_desc with
159-
| Ptyp_arrow (label, t1, t2, _) ->
159+
| Ptyp_arrow (label, t1, t2, arity) when arity = None || acc = [] ->
160160
aux t2
161161
(({label; ty = t1; attr = ty.ptyp_attributes; loc = ty.ptyp_loc}
162162
: param_type)

compiler/frontend/ast_derive_js_mapper.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ let app1 = Ast_compatible.app1
130130
let app2 = Ast_compatible.app2
131131

132132
let ( ->~ ) a b =
133-
Ast_uncurried.uncurried_type ~loc:Location.none ~arity:1
133+
Ast_uncurried.uncurried_type ~arity:1
134134
(Ast_compatible.arrow ~arity:(Some 1) a b)
135135

136136
let raise_when_not_found_ident =
@@ -295,7 +295,7 @@ let init () =
295295
let pat_from_js = {Asttypes.loc; txt = from_js} in
296296
let to_js_type result =
297297
Ast_comb.single_non_rec_val pat_to_js
298-
(Ast_uncurried.uncurried_type ~loc:Location.none ~arity:1
298+
(Ast_uncurried.uncurried_type ~arity:1
299299
(Ast_compatible.arrow ~arity:(Some 1) core_type result))
300300
in
301301
let new_type, new_tdcl =

compiler/frontend/ast_derive_projector.ml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ let init () =
120120
Ext_list.flat_map tdcls handle_tdcl);
121121
signature_gen =
122122
(fun (tdcls : Parsetree.type_declaration list) _explict_nonrec ->
123-
let handle_uncurried_type_tranform ~loc ~arity t =
124-
if arity > 0 then Ast_uncurried.uncurried_type ~loc ~arity t
125-
else t
123+
let handle_uncurried_type_tranform ~arity t =
124+
if arity > 0 then Ast_uncurried.uncurried_type ~arity t else t
126125
in
127126
let handle_tdcl tdcl =
128127
let core_type =
@@ -142,8 +141,7 @@ let init () =
142141
Ast_comb.single_non_rec_val ?attrs:gentype_attrs pld_name
143142
(Ast_compatible.arrow ~arity:None core_type pld_type
144143
(*arity will alwys be 1 since these are single param functions*)
145-
|> handle_uncurried_type_tranform ~arity:1
146-
~loc:pld_name.loc))
144+
|> handle_uncurried_type_tranform ~arity:1))
147145
| Ptype_variant constructor_declarations ->
148146
Ext_list.map constructor_declarations
149147
(fun
@@ -170,7 +168,7 @@ let init () =
170168
{loc; txt = Ext_string.uncapitalize_ascii con_name}
171169
(Ext_list.fold_right pcd_args annotate_type (fun x acc ->
172170
Ast_compatible.arrow ~arity:None x acc)
173-
|> handle_uncurried_type_tranform ~arity ~loc))
171+
|> handle_uncurried_type_tranform ~arity))
174172
| Ptype_open | Ptype_abstract ->
175173
Ast_derive_util.not_applicable tdcl.ptype_loc deriving_name;
176174
[]

compiler/frontend/ast_exp_handle_external.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ let handle_ffi ~loc ~payload =
133133
match !is_function with
134134
| Some arity ->
135135
let type_ =
136-
Ast_uncurried.uncurried_type ~loc
136+
Ast_uncurried.uncurried_type
137137
~arity:(if arity = 0 then 1 else arity)
138138
(arrow ~arity)
139139
in

compiler/frontend/ast_external_process.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -938,7 +938,7 @@ let handle_attributes (loc : Bs_loc.t) (type_annotation : Parsetree.core_type)
938938
| {ptyp_desc = Ptyp_arrow (_, _, _, Some _); _} as t ->
939939
( t,
940940
fun ~arity (x : Parsetree.core_type) ->
941-
Ast_uncurried.uncurried_type ~loc ~arity x )
941+
Ast_uncurried.uncurried_type ~arity x )
942942
| _ -> (type_annotation, fun ~arity:_ x -> x)
943943
in
944944
let result_type, arg_types_ty =

compiler/frontend/ast_typ_uncurry.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,5 @@ let to_uncurry_type loc (mapper : Bs_ast_mapper.mapper)
6666
| _ -> assert false
6767
in
6868
match arity with
69-
| Some arity -> Ast_uncurried.uncurried_type ~loc ~arity fn_type
69+
| Some arity -> Ast_uncurried.uncurried_type ~arity fn_type
7070
| None -> assert false

compiler/gentype/TranslateCoreType.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ let rec translate_arrow_type ~config ~type_vars_gen
5252
~no_function_return_dependencies ~type_env ~rev_arg_deps ~rev_args
5353
(core_type : Typedtree.core_type) =
5454
match core_type.ctyp_desc with
55-
| Ttyp_arrow (Nolabel, core_type1, core_type2, _) ->
55+
| Ttyp_arrow (Nolabel, core_type1, core_type2, arity)
56+
when arity = None || rev_args = [] ->
5657
let {dependencies; type_} =
5758
core_type1 |> fun __x ->
5859
translateCoreType_ ~config ~type_vars_gen ~type_env __x
@@ -63,7 +64,8 @@ let rec translate_arrow_type ~config ~type_vars_gen
6364
~no_function_return_dependencies ~type_env ~rev_arg_deps:next_rev_deps
6465
~rev_args:((Nolabel, type_) :: rev_args)
6566
| Ttyp_arrow
66-
(((Labelled lbl | Optional lbl) as label), core_type1, core_type2, _) -> (
67+
(((Labelled lbl | Optional lbl) as label), core_type1, core_type2, arity)
68+
when arity = None || rev_args = [] -> (
6769
let as_label =
6870
match core_type.ctyp_attributes |> Annotation.get_gentype_as_renaming with
6971
| Some s -> s

compiler/gentype/TranslateTypeExprFromTypes.ml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ let rec translate_arrow_type ~config ~type_vars_gen ~type_env ~rev_arg_deps
268268
| Tlink t ->
269269
translate_arrow_type ~config ~type_vars_gen ~type_env ~rev_arg_deps
270270
~rev_args t
271-
| Tarrow (Nolabel, type_expr1, type_expr2, _, _) ->
271+
| Tarrow (Nolabel, type_expr1, type_expr2, _, arity)
272+
when arity = None || rev_args = [] ->
272273
let {dependencies; type_} =
273274
type_expr1 |> fun __x ->
274275
translateTypeExprFromTypes_ ~config ~type_vars_gen ~type_env __x
@@ -279,8 +280,12 @@ let rec translate_arrow_type ~config ~type_vars_gen ~type_env ~rev_arg_deps
279280
~rev_arg_deps:next_rev_deps
280281
~rev_args:((Nolabel, type_) :: rev_args)
281282
| Tarrow
282-
(((Labelled lbl | Optional lbl) as label), type_expr1, type_expr2, _, _)
283-
-> (
283+
( ((Labelled lbl | Optional lbl) as label),
284+
type_expr1,
285+
type_expr2,
286+
_,
287+
arity )
288+
when arity = None || rev_args = [] -> (
284289
match type_expr1 |> remove_option ~label with
285290
| None ->
286291
let {dependencies; type_ = type1} =

compiler/ml/ast_mapper_from0.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,7 @@ module T = struct
120120
| _ -> assert false
121121
in
122122
let arity = arity_from_type t_arity in
123-
let fun_t =
124-
{fun_t with ptyp_desc = Ptyp_arrow (lbl, t1, t2, Some arity)}
125-
in
126-
{typ0 with ptyp_desc = Ptyp_constr (lid, [fun_t])}
123+
{fun_t with ptyp_desc = Ptyp_arrow (lbl, t1, t2, Some arity)}
127124
| _ -> typ0)
128125
| Ptyp_object (l, o) ->
129126
object_ ~loc ~attrs (List.map (object_field sub) l) o

compiler/ml/ast_mapper_to0.ml

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -98,20 +98,21 @@ module T = struct
9898
match desc with
9999
| Ptyp_any -> any ~loc ~attrs ()
100100
| Ptyp_var s -> var ~loc ~attrs s
101-
| Ptyp_arrow (lab, t1, t2, _) ->
102-
arrow ~loc ~attrs lab (sub.typ sub t1) (sub.typ sub t2)
101+
| Ptyp_arrow (lab, t1, t2, arity) -> (
102+
let typ0 = arrow ~loc ~attrs lab (sub.typ sub t1) (sub.typ sub t2) in
103+
match arity with
104+
| None -> typ0
105+
| Some arity ->
106+
let arity_string = "Has_arity" ^ string_of_int arity in
107+
let arity_type =
108+
Ast_helper0.Typ.variant ~loc
109+
[Rtag (Location.mknoloc arity_string, [], true, [])]
110+
Closed None
111+
in
112+
Ast_helper0.Typ.constr ~loc
113+
{txt = Lident "function$"; loc}
114+
[typ0; arity_type])
103115
| Ptyp_tuple tyl -> tuple ~loc ~attrs (List.map (sub.typ sub) tyl)
104-
| Ptyp_constr
105-
( ({txt = Lident "function$"} as lid),
106-
[({ptyp_desc = Ptyp_arrow (_, _, _, Some arity)} as t_arg)] ) ->
107-
let encode_arity_string arity = "Has_arity" ^ string_of_int arity in
108-
let arity_type ~loc arity =
109-
Ast_helper0.Typ.variant ~loc
110-
[Rtag ({txt = encode_arity_string arity; loc}, [], true, [])]
111-
Closed None
112-
in
113-
constr ~loc ~attrs (map_loc sub lid)
114-
[sub.typ sub t_arg; arity_type ~loc:Location.none arity]
115116
| Ptyp_constr (lid, tl) ->
116117
constr ~loc ~attrs (map_loc sub lid) (List.map (sub.typ sub) tl)
117118
| Ptyp_object (l, o) ->

0 commit comments

Comments
 (0)