Skip to content

Commit c250201

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

Some content is hidden

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

54 files changed

+375
-451
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/ml/ast_uncurried.ml

+8-13
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ let uncurried_type ~loc ~arity (t_arg : Parsetree.core_type) =
77
{t_arg with ptyp_desc = Ptyp_arrow (l, t1, t2, Some arity)}
88
| _ -> assert false
99
in
10-
Ast_helper.Typ.constr ~loc {txt = Lident "function$"; loc} [t_arg]
10+
let _ = loc in
11+
t_arg
1112

1213
let uncurried_fun ~arity fun_expr =
1314
let fun_expr =
@@ -44,8 +45,9 @@ let tarrow_to_arity_opt (t_arity : Types.type_expr) =
4445
| _ -> None
4546

4647
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
48+
(* let lid : Longident.t = Lident "function$" in
49+
let path = Env.lookup_type lid env in *)
50+
let _ = env in
4951
let t =
5052
match t.desc with
5153
| Tarrow (l, t1, t2, c, _) ->
@@ -54,17 +56,13 @@ let make_uncurried_type ~env ~arity (t : Types.type_expr) =
5456
| Tvar _ -> t
5557
| _ -> assert false
5658
in
57-
Ctype.newconstr path [t]
59+
t
5860

5961
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
62+
tarrow_to_arity (Ctype.expand_head env typ)
6363

6464
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
65+
tarrow_to_arity_opt (Ctype.expand_head env typ)
6866

6967
let remove_function_dollar ?env typ =
7068
match
@@ -73,15 +71,12 @@ let remove_function_dollar ?env typ =
7371
| None -> Ctype.repr typ)
7472
.desc
7573
with
76-
| Tconstr (Pident {name = "function$"}, [t], _) -> t
7774
| _ -> typ
7875

7976
let core_type_remove_function_dollar (typ : Parsetree.core_type) =
8077
match typ.ptyp_desc with
81-
| Ptyp_constr ({txt = Lident "function$"}, [t]) -> t
8278
| _ -> typ
8379

8480
let tcore_type_remove_function_dollar (typ : Typedtree.core_type) =
8581
match typ.ctyp_desc with
86-
| Ttyp_constr (Pident {name = "function$"}, _, [t]) -> t
8782
| _ -> 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;

compiler/syntax/src/res_outcome_printer.ml

+3-22
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ let print_out_attributes_doc (attrs : Outcometree.out_attribute list) =
8282

8383
let rec collect_arrow_args (out_type : Outcometree.out_type) args =
8484
match out_type with
85-
| Otyp_arrow (label, arg_type, return_type) ->
85+
| Otyp_arrow (label, arg_type, return_type, arity)
86+
when arity = None || args = [] ->
8687
let arg = (label, arg_type) in
8788
collect_arrow_args return_type (arg :: args)
8889
| _ as return_type -> (List.rev args, return_type)
@@ -147,21 +148,6 @@ let rec print_out_type_doc (out_type : Outcometree.out_type) =
147148
Doc.text alias_txt;
148149
Doc.rparen;
149150
]
150-
| Otyp_constr (Oide_dot (Oide_dot (Oide_ident "Js", "Fn"), "arity0"), [typ])
151-
->
152-
(* Compatibility with compiler up to v10.x *)
153-
Doc.concat [Doc.text "(. ()) => "; print_out_type_doc typ]
154-
| Otyp_constr
155-
( Oide_dot (Oide_dot (Oide_ident "Js", "Fn"), _),
156-
[(Otyp_arrow _ as arrow_type)] ) ->
157-
(* Compatibility with compiler up to v10.x *)
158-
print_out_arrow_type arrow_type
159-
| Otyp_constr (Oide_ident "function$", [(Otyp_arrow _ as arrow_type)]) ->
160-
(* function$<(int, int) => int> -> (int, int) => int *)
161-
print_out_arrow_type arrow_type
162-
| Otyp_constr (Oide_ident "function$", [Otyp_var _]) ->
163-
(* function$<'a, arity> -> _ => _ *)
164-
print_out_type_doc (Otyp_stuff "_ => _")
165151
| Otyp_constr (out_ident, []) ->
166152
print_out_ident_doc ~allow_uident:false out_ident
167153
| Otyp_manifest (typ1, typ2) ->
@@ -295,12 +281,7 @@ and print_out_arrow_type typ =
295281
let args_doc =
296282
let needs_parens =
297283
match typ_args with
298-
| [
299-
( _,
300-
( Otyp_tuple _ | Otyp_arrow _
301-
| Otyp_constr (Oide_ident "function$", [Otyp_arrow _]) ) );
302-
] ->
303-
true
284+
| [(_, (Otyp_tuple _ | Otyp_arrow _))] -> true
304285
(* single argument should not be wrapped *)
305286
| [("", _)] -> false
306287
| _ -> true

compiler/syntax/src/res_parsetree_viewer.ml

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
open Parsetree
22

3-
let arrow_type ?(max_arity = max_int) ?(attrs = []) ct =
3+
let arrow_type ?(max_arity = max_int) ct =
44
let has_as_attr attrs =
55
Ext_list.exists attrs (fun (x, _) -> x.Asttypes.txt = "as")
66
in
77
let rec process attrs_before acc typ arity =
88
match typ with
9-
| typ when arity < 0 -> (attrs_before, List.rev acc, typ)
9+
| _ when arity < 0 -> (attrs_before, List.rev acc, typ)
10+
| {ptyp_desc = Ptyp_arrow (_, _, _, Some _); ptyp_attributes = []}
11+
when acc <> [] ->
12+
(attrs_before, List.rev acc, typ)
1013
| {
1114
ptyp_desc = Ptyp_arrow ((Nolabel as lbl), typ1, typ2, _);
1215
ptyp_attributes = [];
@@ -51,9 +54,8 @@ let arrow_type ?(max_arity = max_int) ?(attrs = []) ct =
5154
ptyp_desc = Ptyp_arrow (Nolabel, _typ1, _typ2, _);
5255
ptyp_attributes = attrs1;
5356
} as typ ->
54-
let attrs = attrs @ attrs1 in
55-
process attrs [] {typ with ptyp_attributes = []} max_arity
56-
| typ -> process attrs [] typ max_arity
57+
process attrs1 [] {typ with ptyp_attributes = []} max_arity
58+
| typ -> process [] [] typ max_arity
5759

5860
let functor_type modtype =
5961
let rec process acc modtype =

compiler/syntax/src/res_parsetree_viewer.mli

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* we restructure the tree into (a, b, c) and its returnType d *)
44
val arrow_type :
55
?max_arity:int ->
6-
?attrs:Parsetree.attributes ->
76
Parsetree.core_type ->
87
Parsetree.attributes
98
* (Parsetree.attributes * Asttypes.arg_label * Parsetree.core_type) list

compiler/syntax/src/res_printer.ml

+1-4
Original file line numberDiff line numberDiff line change
@@ -1587,17 +1587,14 @@ and print_label_declaration ~state (ld : Parsetree.label_declaration) cmt_tbl =
15871587
])
15881588

15891589
and print_typ_expr ~(state : State.t) (typ_expr : Parsetree.core_type) cmt_tbl =
1590-
let parent_attrs =
1591-
ParsetreeViewer.filter_parsing_attrs typ_expr.ptyp_attributes
1592-
in
15931590
let print_arrow ~arity typ_expr =
15941591
let max_arity =
15951592
match arity with
15961593
| Some arity -> arity
15971594
| None -> max_int
15981595
in
15991596
let attrs_before, args, return_type =
1600-
ParsetreeViewer.arrow_type ~max_arity ~attrs:parent_attrs typ_expr
1597+
ParsetreeViewer.arrow_type ~max_arity typ_expr
16011598
in
16021599
let return_type_needs_parens =
16031600
match return_type.ptyp_desc with

0 commit comments

Comments
 (0)