Skip to content

Commit 49acad1

Browse files
committed
Remove function$ entirely.
1 parent 6eae5c7 commit 49acad1

File tree

62 files changed

+406
-492
lines changed

Some content is hidden

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

62 files changed

+406
-492
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/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) ->

compiler/ml/ast_uncurried.ml

Lines changed: 11 additions & 20 deletions
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

Lines changed: 1 addition & 19 deletions
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;

0 commit comments

Comments
 (0)