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

+1-1
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

+2-2
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

+4-6
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

+1-1
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

+1-1
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

+1-1
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

+4-2
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

+8-3
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

+1-4
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

+14-13
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) ->

compiler/ml/ast_uncurried.ml

+11-20
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
(* Uncurried AST *)
22

3-
let uncurried_type ~loc ~arity (t_arg : Parsetree.core_type) =
4-
let t_arg =
5-
match t_arg.ptyp_desc with
6-
| Ptyp_arrow (l, t1, t2, _) ->
7-
{t_arg with ptyp_desc = Ptyp_arrow (l, t1, t2, Some arity)}
8-
| _ -> assert false
9-
in
10-
Ast_helper.Typ.constr ~loc {txt = Lident "function$"; loc} [t_arg]
3+
let uncurried_type ~arity (t_arg : Parsetree.core_type) =
4+
match t_arg.ptyp_desc with
5+
| Ptyp_arrow (l, t1, t2, _) ->
6+
{t_arg with ptyp_desc = Ptyp_arrow (l, t1, t2, Some arity)}
7+
| _ -> assert false
118

129
let uncurried_fun ~arity fun_expr =
1310
let fun_expr =
@@ -44,8 +41,9 @@ let tarrow_to_arity_opt (t_arity : Types.type_expr) =
4441
| _ -> None
4542

4643
let make_uncurried_type ~env ~arity (t : Types.type_expr) =
47-
let lid : Longident.t = Lident "function$" in
48-
let path = Env.lookup_type lid env in
44+
(* let lid : Longident.t = Lident "function$" in
45+
let path = Env.lookup_type lid env in *)
46+
let _ = env in
4947
let t =
5048
match t.desc with
5149
| Tarrow (l, t1, t2, c, _) ->
@@ -54,17 +52,13 @@ let make_uncurried_type ~env ~arity (t : Types.type_expr) =
5452
| Tvar _ -> t
5553
| _ -> assert false
5654
in
57-
Ctype.newconstr path [t]
55+
t
5856

5957
let uncurried_type_get_arity ~env typ =
60-
match (Ctype.expand_head env typ).desc with
61-
| Tconstr (Pident {name = "function$"}, [t], _) -> tarrow_to_arity t
62-
| _ -> assert false
58+
tarrow_to_arity (Ctype.expand_head env typ)
6359

6460
let uncurried_type_get_arity_opt ~env typ =
65-
match (Ctype.expand_head env typ).desc with
66-
| Tconstr (Pident {name = "function$"}, [t], _) -> Some (tarrow_to_arity t)
67-
| _ -> None
61+
tarrow_to_arity_opt (Ctype.expand_head env typ)
6862

6963
let remove_function_dollar ?env typ =
7064
match
@@ -73,15 +67,12 @@ let remove_function_dollar ?env typ =
7367
| None -> Ctype.repr typ)
7468
.desc
7569
with
76-
| Tconstr (Pident {name = "function$"}, [t], _) -> t
7770
| _ -> typ
7871

7972
let core_type_remove_function_dollar (typ : Parsetree.core_type) =
8073
match typ.ptyp_desc with
81-
| Ptyp_constr ({txt = Lident "function$"}, [t]) -> t
8274
| _ -> typ
8375

8476
let tcore_type_remove_function_dollar (typ : Typedtree.core_type) =
8577
match typ.ctyp_desc with
86-
| Ttyp_constr (Pident {name = "function$"}, _, [t]) -> t
8778
| _ -> typ

compiler/ml/oprint.ml

+1-19
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ let rec print_out_type ppf = function
249249
| ty -> print_out_type_1 ppf ty
250250

251251
and print_out_type_1 ppf = function
252-
| Otyp_arrow (lab, ty1, ty2) ->
252+
| Otyp_arrow (lab, ty1, ty2, _) ->
253253
pp_open_box ppf 0;
254254
if lab <> "" then (
255255
pp_print_string ppf lab;
@@ -271,24 +271,6 @@ and print_simple_out_type ppf = function
271271
fprintf ppf "@[%a%s#%a@]" print_typargs tyl
272272
(if ng then "_" else "")
273273
print_ident id
274-
| Otyp_constr (Oide_dot (Oide_dot (Oide_ident "Js", "Fn"), name), [tyl]) ->
275-
let res =
276-
if name = "arity0" then
277-
Otyp_arrow ("", Otyp_constr (Oide_ident "unit", []), tyl)
278-
else tyl
279-
in
280-
fprintf ppf "@[<0>(%a@ [@bs])@]" print_out_type_1 res
281-
| Otyp_constr (Oide_dot (Oide_dot (Oide_ident "Js_OO", "Meth"), name), [tyl])
282-
->
283-
let res =
284-
if name = "arity0" then
285-
Otyp_arrow ("", Otyp_constr (Oide_ident "unit", []), tyl)
286-
else tyl
287-
in
288-
fprintf ppf "@[<0>(%a@ [@meth])@]" print_out_type_1 res
289-
| Otyp_constr (Oide_dot (Oide_dot (Oide_ident "Js_OO", "Callback"), _), [tyl])
290-
->
291-
fprintf ppf "@[<0>(%a@ [@this])@]" print_out_type_1 tyl
292274
| Otyp_constr (id, tyl) ->
293275
pp_open_box ppf 0;
294276
print_typargs ppf tyl;

compiler/ml/outcometree.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type out_type =
5353
| Otyp_abstract
5454
| Otyp_open
5555
| Otyp_alias of out_type * string
56-
| Otyp_arrow of string * out_type * out_type
56+
| Otyp_arrow of string * out_type * out_type * Asttypes.arity
5757
| Otyp_class of bool * out_ident * out_type list
5858
| Otyp_constr of out_ident * out_type list
5959
| Otyp_manifest of out_type * out_type

compiler/ml/parsetree.ml

+1-2
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ and expression_desc =
224224
(* let P1 = E1 and ... and Pn = EN in E (flag = Nonrecursive)
225225
let rec P1 = E1 and ... and Pn = EN in E (flag = Recursive)
226226
*)
227-
| Pexp_fun of
228-
arg_label * expression option * pattern * expression * int option
227+
| Pexp_fun of arg_label * expression option * pattern * expression * arity
229228
(* fun P -> E1 (Simple, None)
230229
fun ~l:P -> E1 (Labelled l, None)
231230
fun ?l:P -> E1 (Optional l, None)

compiler/ml/printtyp.ml

+3-2
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ let rec tree_of_typexp sch ty =
587587
let non_gen = is_non_gen sch ty in
588588
let name_gen = if non_gen then new_weak_name ty else new_name in
589589
Otyp_var (non_gen, name_of_type name_gen ty)
590-
| Tarrow (l, ty1, ty2, _, _) ->
590+
| Tarrow (l, ty1, ty2, _, arity) ->
591591
let pr_arrow l ty1 ty2 =
592592
let lab = string_of_label l in
593593
let t1 =
@@ -599,7 +599,8 @@ let rec tree_of_typexp sch ty =
599599
| _ -> Otyp_stuff "<hidden>"
600600
else tree_of_typexp sch ty1
601601
in
602-
Otyp_arrow (lab, t1, tree_of_typexp sch ty2)
602+
(* should pass arity here? *)
603+
Otyp_arrow (lab, t1, tree_of_typexp sch ty2, arity)
603604
in
604605
pr_arrow l ty1 ty2
605606
| Ttuple tyl -> Otyp_tuple (tree_of_typlist sch tyl)

0 commit comments

Comments
 (0)