Skip to content

Commit 6f24778

Browse files
authored
Remove function$ entirely. (#7208)
1 parent b2ebcc0 commit 6f24778

File tree

82 files changed

+476
-658
lines changed

Some content is hidden

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

82 files changed

+476
-658
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- AST cleanup: Remove `Function$` entirely for function definitions. https://github.com/rescript-lang/rescript/pull/7200
3333
- AST cleanup: store arity in function type https://github.com/rescript-lang/rescript/pull/7195
3434
- AST cleanup: remove explicit uses of `function$` in preparation for removing the type entirely. https://github.com/rescript-lang/rescript/pull/7206
35+
- AST cleanup: remove `function$` entirely. https://github.com/rescript-lang/rescript/pull/7208
3536

3637
# 12.0.0-alpha.5
3738

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 & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ let app1 = Ast_compatible.app1
129129

130130
let app2 = Ast_compatible.app2
131131

132-
let ( ->~ ) a b =
133-
Ast_uncurried.uncurried_type ~loc:Location.none ~arity:1
134-
(Ast_compatible.arrow ~arity:(Some 1) a b)
132+
let ( ->~ ) a b = Ast_compatible.arrow ~arity:(Some 1) a b
135133

136134
let raise_when_not_found_ident =
137135
Longident.Ldot (Lident Primitive_modules.util, "raiseWhenNotFound")
@@ -295,8 +293,7 @@ let init () =
295293
let pat_from_js = {Asttypes.loc; txt = from_js} in
296294
let to_js_type result =
297295
Ast_comb.single_non_rec_val pat_to_js
298-
(Ast_uncurried.uncurried_type ~loc:Location.none ~arity:1
299-
(Ast_compatible.arrow ~arity:(Some 1) core_type result))
296+
(Ast_compatible.arrow ~arity:(Some 1) core_type result)
300297
in
301298
let new_type, new_tdcl =
302299
U.new_type_of_type_declaration tdcl ("abs_" ^ name)

compiler/frontend/ast_derive_projector.ml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ 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
126-
in
127123
let handle_tdcl tdcl =
128124
let core_type =
129125
Ast_derive_util.core_type_of_type_declaration tdcl
@@ -140,10 +136,9 @@ let init () =
140136
| Ptype_record label_declarations ->
141137
Ext_list.map label_declarations (fun {pld_name; pld_type} ->
142138
Ast_comb.single_non_rec_val ?attrs:gentype_attrs pld_name
143-
(Ast_compatible.arrow ~arity:None core_type pld_type
144-
(*arity will alwys be 1 since these are single param functions*)
145-
|> handle_uncurried_type_tranform ~arity:1
146-
~loc:pld_name.loc))
139+
(Ast_compatible.arrow ~arity:(Some 1) core_type
140+
pld_type
141+
(*arity will alwys be 1 since these are single param functions*)))
147142
| Ptype_variant constructor_declarations ->
148143
Ext_list.map constructor_declarations
149144
(fun
@@ -166,11 +161,15 @@ let init () =
166161
| Some x -> x
167162
| None -> core_type
168163
in
164+
let add_arity ~arity t =
165+
if arity > 0 then Ast_uncurried.uncurried_type ~arity t
166+
else t
167+
in
169168
Ast_comb.single_non_rec_val ?attrs:gentype_attrs
170169
{loc; txt = Ext_string.uncapitalize_ascii con_name}
171170
(Ext_list.fold_right pcd_args annotate_type (fun x acc ->
172171
Ast_compatible.arrow ~arity:None x acc)
173-
|> handle_uncurried_type_tranform ~arity ~loc))
172+
|> add_arity ~arity))
174173
| Ptype_open | Ptype_abstract ->
175174
Ast_derive_util.not_applicable tdcl.ptype_loc deriving_name;
176175
[]

0 commit comments

Comments
 (0)