Skip to content

Commit 8ff4713

Browse files
committed
Represent the arity of uncurried function definitions directly in the AST.
1 parent 55f12e0 commit 8ff4713

File tree

100 files changed

+1616
-1601
lines changed

Some content is hidden

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

100 files changed

+1616
-1601
lines changed

analysis/src/CompletionFrontEnd.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,7 @@ let completionWithParser1 ~currentFile ~debug ~offset ~path ~posCursor
13181318
match exprToContextPath lhs with
13191319
| Some contextPath -> setResult (Cpath (CPObj (contextPath, label)))
13201320
| None -> ())
1321-
| Pexp_fun (lbl, defaultExpOpt, pat, e) ->
1321+
| Pexp_fun (lbl, defaultExpOpt, pat, e, _) ->
13221322
let oldScope = !scope in
13231323
(match (!processingFun, !currentCtxPath) with
13241324
| None, Some ctxPath -> processingFun := Some (ctxPath, 0)

analysis/src/DumpAst.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ and printExprItem expr ~pos ~indentation =
213213
| None -> ""
214214
| Some expr -> "," ^ printExprItem expr ~pos ~indentation)
215215
^ ")"
216-
| Pexp_fun (arg, _maybeDefaultArgExpr, pattern, nextExpr) ->
216+
| Pexp_fun (arg, _maybeDefaultArgExpr, pattern, nextExpr, _) ->
217217
"Pexp_fun(\n"
218218
^ addIndentation (indentation + 1)
219219
^ "arg: "

analysis/src/Xform.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ module AddBracesToFn = struct
261261
| _ -> false
262262
in
263263
(match e.pexp_desc with
264-
| Pexp_fun (_, _, _, bodyExpr)
264+
| Pexp_fun (_, _, _, bodyExpr, _)
265265
when Loc.hasPos ~pos bodyExpr.pexp_loc
266266
&& isBracedExpr bodyExpr = false
267267
&& isFunction bodyExpr = false ->
@@ -303,10 +303,10 @@ module AddTypeAnnotation = struct
303303
in
304304
let rec processFunction ~argNum (e : Parsetree.expression) =
305305
match e.pexp_desc with
306-
| Pexp_fun (argLabel, _, pat, e)
306+
| Pexp_fun (argLabel, _, pat, e, _)
307307
| Pexp_construct
308308
( {txt = Lident "Function$"},
309-
Some {pexp_desc = Pexp_fun (argLabel, _, pat, e)} ) ->
309+
Some {pexp_desc = Pexp_fun (argLabel, _, pat, e, _)} ) ->
310310
let isUnlabeledOnlyArg =
311311
argNum = 1 && argLabel = Nolabel
312312
&&

compiler/frontend/ast_compatible.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ let app3 ?(loc = default_loc) ?(attrs = []) fn arg1 arg2 arg3 : expression =
6363
Pexp_apply (fn, [(Nolabel, arg1); (Nolabel, arg2); (Nolabel, arg3)]);
6464
}
6565

66-
let fun_ ?(loc = default_loc) ?(attrs = []) pat exp =
66+
let fun_ ?(loc = default_loc) ?(attrs = []) ~arity pat exp =
6767
{
6868
pexp_loc = loc;
6969
pexp_attributes = attrs;
70-
pexp_desc = Pexp_fun (Nolabel, None, pat, exp);
70+
pexp_desc = Pexp_fun (Nolabel, None, pat, exp, arity);
7171
}
7272

7373
let const_exp_string ?(loc = default_loc) ?(attrs = []) ?delimiter (s : string)

compiler/frontend/ast_compatible.mli

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ val apply_labels :
7272
*)
7373

7474
val fun_ :
75-
?loc:Location.t -> ?attrs:attrs -> pattern -> expression -> expression
75+
?loc:Location.t ->
76+
?attrs:attrs ->
77+
arity:int option ->
78+
pattern ->
79+
expression ->
80+
expression
7681

7782
(* val opt_label : string -> Asttypes.arg_label *)
7883

compiler/frontend/ast_derive_js_mapper.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ let init () =
167167
in
168168
let to_js_body body =
169169
Ast_comb.single_non_rec_value pat_to_js
170-
(Ast_compatible.fun_
170+
(Ast_compatible.fun_ ~arity:None
171171
(Pat.constraint_ (Pat.var pat_param) core_type)
172172
body)
173173
in
@@ -211,7 +211,7 @@ let init () =
211211
in
212212
let from_js =
213213
Ast_comb.single_non_rec_value pat_from_js
214-
(Ast_compatible.fun_ (Pat.var pat_param)
214+
(Ast_compatible.fun_ ~arity:None (Pat.var pat_param)
215215
(if create_type then
216216
Exp.let_ Nonrecursive
217217
[Vb.mk (Pat.var pat_param) (exp_param +: new_type)]
@@ -253,7 +253,7 @@ let init () =
253253
app2 unsafe_index_get_exp exp_map exp_param
254254
else app1 erase_type_exp exp_param);
255255
Ast_comb.single_non_rec_value pat_from_js
256-
(Ast_compatible.fun_ (Pat.var pat_param)
256+
(Ast_compatible.fun_ ~arity:None (Pat.var pat_param)
257257
(let result =
258258
app2 unsafe_index_get_exp rev_exp_map exp_param
259259
in

compiler/frontend/ast_derive_projector.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ let init () =
4646
->
4747
let txt = "param" in
4848
Ast_comb.single_non_rec_value ?attrs:gentype_attrs pld_name
49-
(Ast_compatible.fun_
49+
(Ast_compatible.fun_ ~arity:None
5050
(Pat.constraint_ (Pat.var {txt; loc}) core_type)
5151
(Exp.field
5252
(Exp.ident {txt = Lident txt; loc})
@@ -108,7 +108,9 @@ let init () =
108108
annotate_type
109109
in
110110
Ext_list.fold_right vars exp (fun var b ->
111-
Ast_compatible.fun_ (Pat.var {loc; txt = var}) b)
111+
Ast_compatible.fun_ ~arity:None
112+
(Pat.var {loc; txt = var})
113+
b)
112114
|> handle_uncurried_accessor_tranform ~loc ~arity))
113115
| Ptype_abstract | Ptype_open ->
114116
Ast_derive_util.not_applicable tdcl.ptype_loc deriving_name;

compiler/frontend/ast_pat.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ let is_unit_cont ~yes ~no (p : t) =
3535
let arity_of_fun (pat : Parsetree.pattern) (e : Parsetree.expression) =
3636
let rec aux (e : Parsetree.expression) =
3737
match e.pexp_desc with
38-
| Pexp_fun (_, _, _, e) -> 1 + aux e (*FIXME error on optional*)
38+
| Pexp_fun (_, _, _, e, _) -> 1 + aux e (*FIXME error on optional*)
3939
(* | Pexp_fun _
4040
-> Location.raise_errorf
4141
~loc:e.pexp_loc "Label is not allowed in JS object" *)
@@ -45,7 +45,7 @@ let arity_of_fun (pat : Parsetree.pattern) (e : Parsetree.expression) =
4545

4646
let rec labels_of_fun (e : Parsetree.expression) =
4747
match e.pexp_desc with
48-
| Pexp_fun (l, _, _, e) -> l :: labels_of_fun e
48+
| Pexp_fun (l, _, _, e, _) -> l :: labels_of_fun e
4949
| _ -> []
5050

5151
let rec is_single_variable_pattern_conservative (p : t) =

compiler/frontend/ast_uncurry_gen.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ let to_method_callback loc (self : Bs_ast_mapper.mapper) label
3636
match Ast_attributes.process_attributes_rev body.pexp_attributes with
3737
| Nothing, attrs -> (
3838
match body.pexp_desc with
39-
| Pexp_fun (arg_label, _, arg, body) ->
39+
| Pexp_fun (arg_label, _, arg, body, _) ->
4040
Bs_syntaxerr.optional_err loc arg_label;
4141
aux ((arg_label, self.pat self arg, attrs) :: acc) body
4242
| _ -> (self.expr self body, acc))
@@ -45,7 +45,7 @@ let to_method_callback loc (self : Bs_ast_mapper.mapper) label
4545
let result, rev_extra_args = aux [(label, self_pat, [])] body in
4646
let body =
4747
Ext_list.fold_left rev_extra_args result (fun e (label, p, attrs) ->
48-
Ast_helper.Exp.fun_ ~loc ~attrs label None p e)
48+
Ast_helper.Exp.fun_ ~loc ~attrs ~arity:None label None p e)
4949
in
5050
let arity = List.length rev_extra_args in
5151
let arity_s = string_of_int arity in

compiler/frontend/bs_ast_mapper.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,8 @@ module E = struct
315315
sub vbs)
316316
(sub.expr sub e)
317317
(* #end *)
318-
| Pexp_fun (lab, def, p, e) ->
319-
fun_ ~loc ~attrs lab
318+
| Pexp_fun (lab, def, p, e, arity) ->
319+
fun_ ~loc ~attrs ~arity lab
320320
(map_opt (sub.expr sub) def)
321321
(sub.pat sub p) (sub.expr sub e)
322322
| Pexp_function pel -> function_ ~loc ~attrs (sub.cases sub pel)

0 commit comments

Comments
 (0)