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

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

compiler/ml/typecore.ml

+3-48
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ type error =
7575
| Literal_overflow of string
7676
| Unknown_literal of string * char
7777
| Illegal_letrec_pat
78-
| Labels_omitted of string list
7978
| Empty_record_literal
8079
| Uncurried_arity_mismatch of type_expr * int * int
8180
| Field_not_optional of string * type_expr
@@ -1945,7 +1944,7 @@ let rec list_labels_aux env visited ls ty_fun =
19451944
if List.memq ty visited then (List.rev ls, false)
19461945
else
19471946
match ty.desc with
1948-
| Tarrow (l, _, ty_res, _, _) ->
1947+
| Tarrow (l, _, ty_res, _, arity) when arity = None || visited = [] ->
19491948
list_labels_aux env (ty :: visited) (l :: ls) ty_res
19501949
| _ -> (List.rev ls, is_Tvar ty)
19511950
@@ -3539,7 +3538,7 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
35393538
in
35403539
unify_exp env funct uncurried_typ
35413540
else if
3542-
Ast_uncurried.tarrow_to_arity_opt
3541+
Ast_uncurried.uncurried_type_get_arity_opt ~env
35433542
(Ast_uncurried.remove_function_dollar ~env funct.exp_type)
35443543
= None
35453544
then
@@ -3700,23 +3699,6 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
37003699
type_unknown_args max_arity ~args ~top_arity omitted ty_fun0
37013700
sargs (* This is the hot path for non-labeled function*)
37023701
in
3703-
let () =
3704-
let ls, tvar = list_labels env funct.exp_type in
3705-
if not tvar then
3706-
let labels = Ext_list.filter ls (fun l -> not (is_optional l)) in
3707-
if
3708-
Ext_list.same_length labels sargs
3709-
&& List.for_all (fun (l, _) -> l = Nolabel) sargs
3710-
&& List.exists (fun l -> l <> Nolabel) labels
3711-
then
3712-
raise
3713-
(Error
3714-
( funct.exp_loc,
3715-
env,
3716-
Labels_omitted
3717-
(List.map Printtyp.string_of_label
3718-
(Ext_list.filter labels (fun x -> x <> Nolabel))) ))
3719-
in
37203702
if total_app then force_uncurried_type funct;
37213703
let ty, max_arity = extract_uncurried_type funct in
37223704
let top_arity = if total_app then Some max_arity else None in
@@ -3728,7 +3710,7 @@ and type_application ?type_clash_context total_app env funct (sargs : sargs) :
37283710
in
37293711
let exp = type_expect env sarg ty_arg in
37303712
(match (expand_head env exp.exp_type).desc with
3731-
| Tarrow _ ->
3713+
| Tarrow _ when not total_app ->
37323714
Location.prerr_warning exp.exp_loc Warnings.Partial_application
37333715
| Tvar _ ->
37343716
Delayed_checks.add_delayed_check (fun () ->
@@ -4345,23 +4327,6 @@ let report_error env ppf error =
43454327
let arity_a = arity_a |> string_of_int in
43464328
let arity_b = arity_b |> string_of_int in
43474329
report_arity_mismatch ~arity_a ~arity_b ppf
4348-
| Expr_type_clash
4349-
( ( _,
4350-
{
4351-
desc =
4352-
Tconstr
4353-
(Pdot (Pdot (Pident {name = "Js_OO"}, "Meth", _), a, _), _, _);
4354-
} )
4355-
:: ( _,
4356-
{
4357-
desc =
4358-
Tconstr
4359-
(Pdot (Pdot (Pident {name = "Js_OO"}, "Meth", _), b, _), _, _);
4360-
} )
4361-
:: _,
4362-
_ )
4363-
when a <> b ->
4364-
fprintf ppf "This method has %s but was expected %s" a b
43654330
| Expr_type_clash (trace, type_clash_context) ->
43664331
(* modified *)
43674332
fprintf ppf "@[<v>";
@@ -4544,16 +4509,6 @@ let report_error env ppf error =
45444509
fprintf ppf "Unknown modifier '%c' for literal %s%c" m n m
45454510
| Illegal_letrec_pat ->
45464511
fprintf ppf "Only variables are allowed as left-hand side of `let rec'"
4547-
| Labels_omitted [label] ->
4548-
fprintf ppf
4549-
"Label ~%s was omitted in the application of this labeled function." label
4550-
| Labels_omitted labels ->
4551-
let labels_string =
4552-
labels |> List.map (fun label -> "~" ^ label) |> String.concat ", "
4553-
in
4554-
fprintf ppf
4555-
"Labels %s were omitted in the application of this labeled function."
4556-
labels_string
45574512
| Empty_record_literal ->
45584513
fprintf ppf
45594514
"Empty record literal {} should be type annotated or used in a record \

compiler/ml/typecore.mli

-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,6 @@ type error =
118118
| Literal_overflow of string
119119
| Unknown_literal of string * char
120120
| Illegal_letrec_pat
121-
| Labels_omitted of string list
122121
| Empty_record_literal
123122
| Uncurried_arity_mismatch of type_expr * int * int
124123
| Field_not_optional of string * type_expr

compiler/ml/typedtree.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ and expression_desc =
7878
| Texp_let of rec_flag * value_binding list * expression
7979
| Texp_function of {
8080
arg_label: arg_label;
81-
arity: int option;
81+
arity: arity;
8282
param: Ident.t;
8383
case: case;
8484
partial: partial;

compiler/ml/typedtree.mli

+1-1
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ and expression_desc =
132132
*)
133133
| Texp_function of {
134134
arg_label: arg_label;
135-
arity: int option;
135+
arity: arity;
136136
param: Ident.t;
137137
case: case;
138138
partial: partial;

0 commit comments

Comments
 (0)