Skip to content

Commit b71324f

Browse files
committed
Remove function$ entirely.
1 parent b2ebcc0 commit b71324f

File tree

79 files changed

+462
-618
lines changed

Some content is hidden

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

79 files changed

+462
-618
lines changed

analysis/src/CompletionBackEnd.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1358,7 +1358,7 @@ let rec completeTypedValue ?(typeArgContext : typeArgContext option) ~rawOpens
13581358
in
13591359
(* Find all functions in the module that returns type t *)
13601360
let rec fnReturnsTypeT t =
1361-
match (Ast_uncurried.remove_function_dollar t).desc with
1361+
match t.Types.desc with
13621362
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> fnReturnsTypeT t1
13631363
| Tarrow _ -> (
13641364
match TypeUtils.extractFunctionType ~env ~package:full.package t with

analysis/src/CompletionJsx.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ let getJsxLabels ~componentPath ~findTypeOfValue ~package =
234234
| _ -> []
235235
in
236236
let rec getLabels (t : Types.type_expr) =
237-
match (Ast_uncurried.remove_function_dollar t).desc with
237+
match t.desc with
238238
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> getLabels t1
239239
| Tconstr (p, [propsType], _) when Path.name p = "React.component" -> (
240240
let rec getPropsType (t : Types.type_expr) =

analysis/src/CreateInterface.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ let printSignature ~extractor ~signature =
122122
let reactElement =
123123
Ctype.newconstr (Pdot (Pident (Ident.create "React"), "element", 0)) []
124124
in
125-
match (Ast_uncurried.remove_function_dollar typ).desc with
125+
match typ.desc with
126126
| Tarrow
127127
(_, {desc = Tconstr (Path.Pident propsId, typeArgs, _)}, retType, _, _)
128128
when Ident.name propsId = "props" ->

analysis/src/SignatureHelp.ml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,9 @@ let findFunctionType ~currentFile ~debug ~path ~pos =
105105
let extractParameters ~signature ~typeStrForParser ~labelPrefixLen =
106106
match signature with
107107
| [{Parsetree.psig_desc = Psig_value {pval_type = expr}}]
108-
when match
109-
(Ast_uncurried.core_type_remove_function_dollar expr).ptyp_desc
110-
with
108+
when match expr.ptyp_desc with
111109
| Ptyp_arrow _ -> true
112110
| _ -> false ->
113-
let expr = Ast_uncurried.core_type_remove_function_dollar expr in
114111
let rec extractParams expr params =
115112
match expr with
116113
| {

analysis/src/TypeUtils.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let findTypeViaLoc ~full ~debug (loc : Location.t) =
3535
| _ -> None
3636

3737
let pathFromTypeExpr (t : Types.type_expr) =
38-
match (Ast_uncurried.remove_function_dollar t).desc with
38+
match t.desc with
3939
| Tconstr (path, _typeArgs, _)
4040
| Tlink {desc = Tconstr (path, _typeArgs, _)}
4141
| Tsubst {desc = Tconstr (path, _typeArgs, _)}
@@ -239,7 +239,7 @@ let rec extractObjectType ~env ~package (t : Types.type_expr) =
239239

240240
let extractFunctionType ~env ~package typ =
241241
let rec loop ~env acc (t : Types.type_expr) =
242-
match (Ast_uncurried.remove_function_dollar t).desc with
242+
match t.desc with
243243
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> loop ~env acc t1
244244
| Tarrow (label, tArg, tRet, _, _) -> loop ~env ((label, tArg) :: acc) tRet
245245
| Tconstr (path, typeArgs, _) -> (
@@ -276,7 +276,7 @@ let maybeSetTypeArgCtx ?typeArgContextFromTypeManifest ~typeParams ~typeArgs env
276276
(* TODO(env-stuff) Maybe this could be removed entirely if we can guarantee that we don't have to look up functions from in here. *)
277277
let extractFunctionType2 ?typeArgContext ~env ~package typ =
278278
let rec loop ?typeArgContext ~env acc (t : Types.type_expr) =
279-
match (Ast_uncurried.remove_function_dollar t).desc with
279+
match t.desc with
280280
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) -> loop ?typeArgContext ~env acc t1
281281
| Tarrow (label, tArg, tRet, _, _) ->
282282
loop ?typeArgContext ~env ((label, tArg) :: acc) tRet
@@ -312,7 +312,7 @@ let rec extractType ?(printOpeningDebug = true)
312312
Printf.printf "[extract_type]--> %s"
313313
(debugLogTypeArgContext typeArgContext));
314314
let instantiateType = instantiateType2 in
315-
match (Ast_uncurried.remove_function_dollar t).desc with
315+
match t.desc with
316316
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) ->
317317
extractType ?typeArgContext ~printOpeningDebug:false ~env ~package t1
318318
| Tconstr (Path.Pident {name = "option"}, [payloadTypeExpr], _) ->
@@ -894,7 +894,7 @@ let rec resolveNestedPatternPath (typ : innerType) ~env ~full ~nested =
894894
let getArgs ~env (t : Types.type_expr) ~full =
895895
let rec getArgsLoop ~env (t : Types.type_expr) ~full ~currentArgumentPosition
896896
=
897-
match (Ast_uncurried.remove_function_dollar t).desc with
897+
match t.desc with
898898
| Tlink t1 | Tsubst t1 | Tpoly (t1, []) ->
899899
getArgsLoop ~full ~env ~currentArgumentPosition t1
900900
| Tarrow (Labelled l, tArg, tRet, _, _) ->

compiler/frontend/ast_core_type.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ let get_uncurry_arity (ty : t) =
124124
| _ -> None
125125

126126
let get_curry_arity (ty : t) =
127-
match Ast_uncurried.core_type_remove_function_dollar ty with
128-
| {ptyp_desc = Ptyp_arrow (_, _, _, Some arity)} -> arity
127+
match ty.ptyp_desc with
128+
| Ptyp_arrow (_, _, _, Some arity) -> arity
129129
| _ -> get_uncurry_arity_aux ty 0
130130

131131
let is_arity_one ty = get_curry_arity ty = 1
@@ -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_core_type_class_type.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ let default_typ_mapper = Bs_ast_mapper.default_mapper.typ
6666

6767
let typ_mapper (self : Bs_ast_mapper.mapper) (ty : Parsetree.core_type) =
6868
let loc = ty.ptyp_loc in
69-
match (Ast_uncurried.core_type_remove_function_dollar ty).ptyp_desc with
69+
match ty.ptyp_desc with
7070
| Ptyp_arrow (label, args, body, _)
7171
(* let it go without regard label names,
7272
it will report error later when the label is not empty

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -934,11 +934,11 @@ let handle_attributes (loc : Bs_loc.t) (type_annotation : Parsetree.core_type)
934934
Parsetree.core_type * External_ffi_types.t * Parsetree.attributes * bool =
935935
let prim_name_with_source = {name = prim_name; source = External} in
936936
let type_annotation, build_uncurried_type =
937-
match Ast_uncurried.core_type_remove_function_dollar type_annotation with
937+
match type_annotation with
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 & 3 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
@@ -114,7 +116,6 @@ let rec translate_arrow_type ~config ~type_vars_gen
114116
and translateCoreType_ ~config ~type_vars_gen
115117
?(no_function_return_dependencies = false) ~type_env
116118
(core_type : Typedtree.core_type) =
117-
let core_type = Ast_uncurried.tcore_type_remove_function_dollar core_type in
118119
match core_type.ctyp_desc with
119120
| Ttyp_alias (ct, _) ->
120121
ct

compiler/gentype/TranslateTypeExprFromTypes.ml

Lines changed: 9 additions & 5 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} =
@@ -312,8 +317,7 @@ let rec translate_arrow_type ~config ~type_vars_gen ~type_env ~rev_arg_deps
312317
{dependencies = all_deps; type_ = function_type}
313318

314319
and translateTypeExprFromTypes_ ~config ~type_vars_gen ~type_env
315-
(type_expr_ : Types.type_expr) =
316-
let type_expr = Ast_uncurried.remove_function_dollar type_expr_ in
320+
(type_expr : Types.type_expr) =
317321
match type_expr.desc with
318322
| Tvar None ->
319323
let type_name =

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: 7 additions & 47 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 =
@@ -43,45 +40,8 @@ let tarrow_to_arity_opt (t_arity : Types.type_expr) =
4340
| Tarrow (_, _, _, _, arity) -> arity
4441
| _ -> None
4542

46-
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
49-
let t =
50-
match t.desc with
51-
| Tarrow (l, t1, t2, c, _) ->
52-
{t with desc = Tarrow (l, t1, t2, c, Some arity)}
53-
| Tconstr _ -> assert false
54-
| Tvar _ -> t
55-
| _ -> assert false
56-
in
57-
Ctype.newconstr path [t]
58-
5943
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
44+
tarrow_to_arity (Ctype.expand_head env typ)
6345

6446
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
68-
69-
let remove_function_dollar ?env typ =
70-
match
71-
(match env with
72-
| Some env -> Ctype.expand_head env typ
73-
| None -> Ctype.repr typ)
74-
.desc
75-
with
76-
| Tconstr (Pident {name = "function$"}, [t], _) -> t
77-
| _ -> typ
78-
79-
let core_type_remove_function_dollar (typ : Parsetree.core_type) =
80-
match typ.ptyp_desc with
81-
| Ptyp_constr ({txt = Lident "function$"}, [t]) -> t
82-
| _ -> typ
83-
84-
let tcore_type_remove_function_dollar (typ : Typedtree.core_type) =
85-
match typ.ctyp_desc with
86-
| Ttyp_constr (Pident {name = "function$"}, _, [t]) -> t
87-
| _ -> typ
47+
tarrow_to_arity_opt (Ctype.expand_head env typ)

compiler/ml/ast_untagged_variants.ml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@ let type_to_instanceof_backed_obj (t : Types.type_expr) =
188188

189189
let get_block_type_from_typ ~env (t : Types.type_expr) : block_type option =
190190
let t = !expand_head env t in
191-
let t = Tmp_uncurried.remove_function_dollar t in
192191
match t with
193192
| {desc = Tconstr (path, _, _)} when Path.same path Predef.path_string ->
194193
Some StringType

0 commit comments

Comments
 (0)