Skip to content

Commit b464b3b

Browse files
committed
Remove Pexp_function, which is never produced by the parser.
1 parent ba78715 commit b464b3b

19 files changed

+11
-43
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
- Ast cleanup: explicit representation for optional record fields in types. https://github.com/rescript-lang/rescript/pull/7190 https://github.com/rescript-lang/rescript/pull/7191
2525
- AST cleanup: first-class expression and patterns for records with optional fields. https://github.com/rescript-lang/rescript/pull/7192
2626
- AST cleanup: Represent the arity of uncurried function definitions directly in the AST. https://github.com/rescript-lang/rescript/pull/7197
27+
- AST cleanup: Remove Pexp_function from the AST. https://github.com/rescript-lang/rescript/pull/7198
2728

2829

2930
# 12.0.0-alpha.5

analysis/src/DocumentSymbol.ml

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ let command ~path =
4141
let rec exprKind (exp : Parsetree.expression) =
4242
match exp.pexp_desc with
4343
| Pexp_fun _ -> Function
44-
| Pexp_function _ -> Function
4544
| Pexp_constraint (e, _) -> exprKind e
4645
| Pexp_constant (Pconst_string _) -> String
4746
| Pexp_constant (Pconst_float _ | Pconst_integer _) -> Number

analysis/src/Utils.ml

-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ let identifyPexp pexp =
8585
| Parsetree.Pexp_ident _ -> "Pexp_ident"
8686
| Pexp_constant _ -> "Pexp_constant"
8787
| Pexp_let _ -> "Pexp_let"
88-
| Pexp_function _ -> "Pexp_function"
8988
| Pexp_fun _ -> "Pexp_fun"
9089
| Pexp_apply _ -> "Pexp_apply"
9190
| Pexp_match _ -> "Pexp_match"

compiler/frontend/bs_ast_mapper.ml

-1
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,6 @@ module E = struct
319319
fun_ ~loc ~attrs ~arity lab
320320
(map_opt (sub.expr sub) def)
321321
(sub.pat sub p) (sub.expr sub e)
322-
| Pexp_function pel -> function_ ~loc ~attrs (sub.cases sub pel)
323322
| Pexp_apply (e, l) ->
324323
apply ~loc ~attrs (sub.expr sub e) (List.map (map_snd (sub.expr sub)) l)
325324
| Pexp_match (e, pel) ->

compiler/frontend/bs_builtin_ppx.ml

-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,6 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
110110
| Pexp_constant (Pconst_integer (s, Some 'l')) ->
111111
{e with pexp_desc = Pexp_constant (Pconst_integer (s, None))}
112112
(* End rewriting *)
113-
| Pexp_function _ ->
114-
async_context := false;
115-
default_expr_mapper self e
116113
| _
117114
when Ast_uncurried.expr_is_uncurried_fun e
118115
&&

compiler/ml/ast_helper.ml

-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ module Exp = struct
152152
let let_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_let (a, b, c))
153153
let fun_ ?loc ?attrs ~arity a b c d =
154154
mk ?loc ?attrs (Pexp_fun (a, b, c, d, arity))
155-
let function_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_function a)
156155
let apply ?loc ?attrs a b = mk ?loc ?attrs (Pexp_apply (a, b))
157156
let match_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_match (a, b))
158157
let try_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_try (a, b))

compiler/ml/ast_helper.mli

-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ module Exp : sig
138138
pattern ->
139139
expression ->
140140
expression
141-
val function_ : ?loc:loc -> ?attrs:attrs -> case list -> expression
142141
val apply :
143142
?loc:loc ->
144143
?attrs:attrs ->

compiler/ml/ast_iterator.ml

-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,6 @@ module E = struct
286286
iter_opt (sub.expr sub) def;
287287
sub.pat sub p;
288288
sub.expr sub e
289-
| Pexp_function pel -> sub.cases sub pel
290289
| Pexp_apply (e, l) ->
291290
sub.expr sub e;
292291
List.iter (iter_snd (sub.expr sub)) l

compiler/ml/ast_mapper.ml

-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ module E = struct
282282
fun_ ~loc ~attrs ~arity lab
283283
(map_opt (sub.expr sub) def)
284284
(sub.pat sub p) (sub.expr sub e)
285-
| Pexp_function pel -> function_ ~loc ~attrs (sub.cases sub pel)
286285
| Pexp_apply (e, l) ->
287286
apply ~loc ~attrs (sub.expr sub e) (List.map (map_snd (sub.expr sub)) l)
288287
| Pexp_match (e, pel) ->

compiler/ml/ast_mapper_from0.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ module E = struct
288288
fun_ ~loc ~attrs ~arity:None lab
289289
(map_opt (sub.expr sub) def)
290290
(sub.pat sub p) (sub.expr sub e)
291-
| Pexp_function pel -> function_ ~loc ~attrs (sub.cases sub pel)
291+
| Pexp_function _ -> assert false
292292
| Pexp_apply (e, l) ->
293293
apply ~loc ~attrs (sub.expr sub e) (List.map (map_snd (sub.expr sub)) l)
294294
| Pexp_match (e, pel) ->

compiler/ml/ast_mapper_to0.ml

-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,6 @@ module E = struct
287287
fun_ ~loc ~attrs lab
288288
(map_opt (sub.expr sub) def)
289289
(sub.pat sub p) (sub.expr sub e)
290-
| Pexp_function pel -> function_ ~loc ~attrs (sub.cases sub pel)
291290
| Pexp_apply (e, l) ->
292291
apply ~loc ~attrs (sub.expr sub e) (List.map (map_snd (sub.expr sub)) l)
293292
| Pexp_match (e, pel) ->

compiler/ml/depend.ml

-1
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,6 @@ let rec add_expr bv exp =
221221
| Pexp_fun (_, opte, p, e, _) ->
222222
add_opt add_expr bv opte;
223223
add_expr (add_pattern bv p) e
224-
| Pexp_function pel -> add_cases bv pel
225224
| Pexp_apply (e, el) ->
226225
add_expr bv e;
227226
List.iter (fun (_, e) -> add_expr bv e) el

compiler/ml/parsetree.ml

-1
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,6 @@ 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_function of case list (* function P1 -> E1 | ... | Pn -> En *)
228227
| Pexp_fun of
229228
arg_label * expression option * pattern * expression * int option
230229
(* fun P -> E1 (Simple, None)

compiler/ml/pprintast.ml

+1-3
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ and expression ctxt f x =
535535
pp f "((%a)@,%a)" (expression ctxt) {x with pexp_attributes=[]}
536536
(attributes ctxt) x.pexp_attributes
537537
else match x.pexp_desc with
538-
| Pexp_function _ | Pexp_fun _ | Pexp_match _ | Pexp_try _ | Pexp_sequence _
538+
| Pexp_fun _ | Pexp_match _ | Pexp_try _ | Pexp_sequence _
539539
when ctxt.pipe || ctxt.semi ->
540540
paren true (expression reset_ctxt) f x
541541
| Pexp_ifthenelse _ | Pexp_sequence _ when ctxt.ifthenelse ->
@@ -551,8 +551,6 @@ and expression ctxt f x =
551551
pp f "@[<2>fun@;%s%a->@;%a@]"
552552
arity_str (label_exp ctxt) (l, e0, p)
553553
(expression ctxt) e
554-
| Pexp_function l ->
555-
pp f "@[<hv>function%a@]" (case_list ctxt) l
556554
| Pexp_match (e, l) ->
557555
pp f "@[<hv0>@[<hv0>@[<2>match %a@]@ with@]%a@]"
558556
(expression reset_ctxt) e (case_list ctxt) l

compiler/ml/printast.ml

-3
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ and expression i ppf x =
233233
line i ppf "Pexp_let %a\n" fmt_rec_flag rf;
234234
list i value_binding ppf l;
235235
expression i ppf e
236-
| Pexp_function l ->
237-
line i ppf "Pexp_function\n";
238-
list i case ppf l
239236
| Pexp_fun (l, eo, p, e, arity) ->
240237
line i ppf "Pexp_fun\n";
241238
let () =

compiler/ml/typecore.ml

-6
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ let iter_expression f e =
137137
| Pexp_extension _ (* we don't iterate under extension point *)
138138
| Pexp_ident _ | Pexp_new _ | Pexp_constant _ ->
139139
()
140-
| Pexp_function pel -> List.iter case pel
141140
| Pexp_fun (_, eo, _, e, _) ->
142141
may expr eo;
143142
expr e
@@ -1917,8 +1916,6 @@ let rec type_approx env sexp =
19171916
| Pexp_fun (p, _, _, e, _arity) ->
19181917
let ty = if is_optional p then type_option (newvar ()) else newvar () in
19191918
newty (Tarrow (p, ty, type_approx env e, Cok))
1920-
| Pexp_function ({pc_rhs = e} :: _) ->
1921-
newty (Tarrow (Nolabel, newvar (), type_approx env e, Cok))
19221919
| Pexp_match (_, {pc_rhs = e} :: _) -> type_approx env e
19231920
| Pexp_try (e, _) -> type_approx env e
19241921
| Pexp_tuple l -> newty (Ttuple (List.map (type_approx env) l))
@@ -2417,9 +2414,6 @@ and type_expect_ ?type_clash_context ?in_function ?(recarg = Rejected) env sexp
24172414
| Pexp_fun (l, None, spat, sbody, _arity) ->
24182415
type_function ?in_function loc sexp.pexp_attributes env ty_expected l
24192416
[Ast_helper.Exp.case spat sbody]
2420-
| Pexp_function caselist ->
2421-
type_function ?in_function loc sexp.pexp_attributes env ty_expected Nolabel
2422-
caselist
24232417
| Pexp_apply (sfunct, sargs) ->
24242418
assert (sargs <> []);
24252419
begin_def ();

compiler/syntax/src/res_ast_debugger.ml

-3
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,6 @@ module SexpAst = struct
558558
Sexp.list (map_empty ~f:value_binding vbs);
559559
expression expr;
560560
]
561-
| Pexp_function cases ->
562-
Sexp.list
563-
[Sexp.atom "Pexp_function"; Sexp.list (map_empty ~f:case cases)]
564561
| Pexp_fun (arg_lbl, expr_opt, pat, expr, _) ->
565562
Sexp.list
566563
[

compiler/syntax/src/res_parens.ml

+8-12
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ let call_expr expr =
5151
| {
5252
pexp_desc =
5353
( Pexp_lazy _ | Pexp_assert _ | Pexp_fun _ | Pexp_newtype _
54-
| Pexp_function _ | Pexp_constraint _ | Pexp_setfield _ | Pexp_match _
55-
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
54+
| Pexp_constraint _ | Pexp_setfield _ | Pexp_match _ | Pexp_try _
55+
| Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
5656
} ->
5757
Parenthesized
5858
| _ when Ast_uncurried.expr_is_uncurried_fun expr -> Parenthesized
@@ -104,7 +104,7 @@ let unary_expr_operand expr =
104104
| {
105105
pexp_desc =
106106
( Pexp_lazy _ | Pexp_assert _ | Pexp_fun _ | Pexp_newtype _
107-
| Pexp_function _ | Pexp_constraint _ | Pexp_setfield _
107+
| Pexp_constraint _ | Pexp_setfield _
108108
| Pexp_extension _ (* readability? maybe remove *) | Pexp_match _
109109
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
110110
} ->
@@ -132,10 +132,7 @@ let binary_expr_operand ~is_lhs expr =
132132
| {pexp_desc = Pexp_fun _}
133133
when ParsetreeViewer.is_underscore_apply_sugar expr ->
134134
Nothing
135-
| {
136-
pexp_desc =
137-
Pexp_constraint _ | Pexp_fun _ | Pexp_function _ | Pexp_newtype _;
138-
} ->
135+
| {pexp_desc = Pexp_constraint _ | Pexp_fun _ | Pexp_newtype _} ->
139136
Parenthesized
140137
| _ when Ast_uncurried.expr_is_uncurried_fun expr -> Parenthesized
141138
| expr when ParsetreeViewer.is_binary_expression expr -> Parenthesized
@@ -228,8 +225,8 @@ let lazy_or_assert_or_await_expr_rhs ?(in_await = false) expr =
228225
| {
229226
pexp_desc =
230227
( Pexp_lazy _ | Pexp_assert _ | Pexp_fun _ | Pexp_newtype _
231-
| Pexp_function _ | Pexp_constraint _ | Pexp_setfield _ | Pexp_match _
232-
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
228+
| Pexp_constraint _ | Pexp_setfield _ | Pexp_match _ | Pexp_try _
229+
| Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
233230
} ->
234231
Parenthesized
235232
| _
@@ -276,9 +273,8 @@ let field_expr expr =
276273
pexp_desc =
277274
( Pexp_lazy _ | Pexp_assert _
278275
| Pexp_extension _ (* %extension.x vs (%extension).x *) | Pexp_fun _
279-
| Pexp_newtype _ | Pexp_function _ | Pexp_constraint _ | Pexp_setfield _
280-
| Pexp_match _ | Pexp_try _ | Pexp_while _ | Pexp_for _
281-
| Pexp_ifthenelse _ );
276+
| Pexp_newtype _ | Pexp_constraint _ | Pexp_setfield _ | Pexp_match _
277+
| Pexp_try _ | Pexp_while _ | Pexp_for _ | Pexp_ifthenelse _ );
282278
} ->
283279
Parenthesized
284280
| _ when ParsetreeViewer.has_await_attribute expr.pexp_attributes ->

compiler/syntax/src/res_printer.ml

-2
Original file line numberDiff line numberDiff line change
@@ -3394,8 +3394,6 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
33943394
Doc.space;
33953395
print_cases ~state cases cmt_tbl;
33963396
]
3397-
| Pexp_function cases ->
3398-
Doc.concat [Doc.text "x => switch x "; print_cases ~state cases cmt_tbl]
33993397
| Pexp_coerce (expr, (), typ) ->
34003398
let doc_expr = print_expression_with_comments ~state expr cmt_tbl in
34013399
let doc_typ = print_typ_expr ~state typ cmt_tbl in

0 commit comments

Comments
 (0)