Skip to content

Commit 572180c

Browse files
committed
AST cleanup: use inline record for Pexp_fun.
1 parent 7592d76 commit 572180c

27 files changed

+154
-130
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
1313
# 12.0.0-alpha.7 (Unreleased)
1414

15+
#### :house: Internal
16+
17+
- AST cleanup: use inline record for Pexp_fun. https://github.com/rescript-lang/rescript/pull/7213
18+
1519
# 12.0.0-alpha.6
1620

1721
#### :rocket: New Feature

analysis/src/CompletionFrontEnd.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1318,7 +1318,8 @@ 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
1322+
{arg_label = lbl; default = defaultExpOpt; lhs = pat; rhs = e} ->
13221323
let oldScope = !scope in
13231324
(match (!processingFun, !currentCtxPath) with
13241325
| 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_label = arg; lhs = pattern; rhs = nextExpr} ->
217217
"Pexp_fun(\n"
218218
^ addIndentation (indentation + 1)
219219
^ "arg: "

analysis/src/Hint.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ let inlay ~path ~pos ~maxLength ~debug =
6161
| Pexp_apply _ | Pexp_match _ | Pexp_construct _ | Pexp_ifthenelse _
6262
| Pexp_array _ | Pexp_ident _ | Pexp_try _ | Pexp_lazy _
6363
| Pexp_send _ | Pexp_field _ | Pexp_open _
64-
| Pexp_fun (_, _, _, _, Some _) );
64+
| Pexp_fun {arity = Some _} );
6565
};
6666
} ->
6767
push vb.pvb_pat.ppat_loc Type

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 {rhs = bodyExpr}
265265
when Loc.hasPos ~pos bodyExpr.pexp_loc
266266
&& isBracedExpr bodyExpr = false
267267
&& isFunction bodyExpr = false ->
@@ -303,9 +303,9 @@ 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 {arg_label; lhs = pat; rhs = e} ->
307307
let isUnlabeledOnlyArg =
308-
argNum = 1 && argLabel = Nolabel
308+
argNum = 1 && arg_label = Nolabel
309309
&&
310310
match e.pexp_desc with
311311
| Pexp_fun _ -> false

compiler/frontend/ast_compatible.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ let fun_ ?(loc = default_loc) ?(attrs = []) ~arity pat exp =
6868
{
6969
pexp_loc = loc;
7070
pexp_attributes = attrs;
71-
pexp_desc = Pexp_fun (Nolabel, None, pat, exp, arity);
71+
pexp_desc =
72+
Pexp_fun
73+
{arg_label = Nolabel; default = None; lhs = pat; rhs = exp; arity};
7274
}
7375

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

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 {rhs = 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 {arg_label = l; rhs = 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: 1 addition & 1 deletion
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; lhs = arg; rhs = 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))

compiler/frontend/bs_ast_mapper.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ module E = struct
315315
sub vbs)
316316
(sub.expr sub e)
317317
(* #end *)
318-
| Pexp_fun (lab, def, p, e, arity) ->
318+
| Pexp_fun {arg_label = lab; default = def; lhs = p; rhs = e; arity} ->
319319
fun_ ~loc ~attrs ~arity lab
320320
(map_opt (sub.expr sub) def)
321321
(sub.pat sub p) (sub.expr sub e)

compiler/frontend/bs_builtin_ppx.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
115115
let body = Ast_async.add_async_attribute ~async body in
116116
let res = self.expr self body in
117117
{e with pexp_desc = Pexp_newtype (s, res)}
118-
| Pexp_fun (label, _, pat, body, _arity) -> (
118+
| Pexp_fun {arg_label = label; lhs = pat; rhs = body} -> (
119119
let async = Ast_attributes.has_async_payload e.pexp_attributes <> None in
120120
match Ast_attributes.process_attributes_rev e.pexp_attributes with
121121
| Nothing, _ ->
@@ -579,7 +579,7 @@ let rec structure_mapper ~await_context (self : mapper) (stru : Ast_structure.t)
579579
| Pexp_ifthenelse (_, then_expr, Some else_expr) ->
580580
aux then_expr @ aux else_expr
581581
| Pexp_construct (_, Some expr) -> aux expr
582-
| Pexp_fun (_, _, _, expr, _) | Pexp_newtype (_, expr) -> aux expr
582+
| Pexp_fun {rhs = expr} | Pexp_newtype (_, expr) -> aux expr
583583
| _ -> acc
584584
in
585585
aux pvb_expr @ spelunk_vbs acc tl

0 commit comments

Comments
 (0)