Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Pexp_function, which is never produced by the parser. #7198

Merged
merged 3 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- 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
- AST cleanup: first-class expression and patterns for records with optional fields. https://github.com/rescript-lang/rescript/pull/7192
- AST cleanup: Represent the arity of uncurried function definitions directly in the AST. https://github.com/rescript-lang/rescript/pull/7197
- AST cleanup: Remove Pexp_function from the AST. https://github.com/rescript-lang/rescript/pull/7198


# 12.0.0-alpha.5
Expand Down
2 changes: 1 addition & 1 deletion analysis/reanalyze/src/Arnold.ml
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,7 @@ module Compile = struct
let open Command in
c +++ ConstrOption Rnone
| _ -> c)
| Texp_function {cases} -> cases |> List.map (case ~ctx) |> Command.nondet
| Texp_function {case = case_} -> case ~ctx case_
| Texp_match (e, casesOk, casesExn, _partial)
when not
(casesExn
Expand Down
22 changes: 10 additions & 12 deletions analysis/reanalyze/src/DeadValue.ml
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,16 @@ let rec collectExpr super self (e : Typedtree.expression) =
exp_desc =
Texp_function
{
cases =
[
{
c_lhs = {pat_desc = Tpat_var (etaArg, _)};
c_rhs =
{
exp_desc =
Texp_apply
({exp_desc = Texp_ident (idArg2, _, _)}, args);
};
};
];
case =
{
c_lhs = {pat_desc = Tpat_var (etaArg, _)};
c_rhs =
{
exp_desc =
Texp_apply
({exp_desc = Texp_ident (idArg2, _, _)}, args);
};
};
};
} )
when Ident.name idArg = "arg"
Expand Down
1 change: 0 additions & 1 deletion analysis/src/DocumentSymbol.ml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ let command ~path =
let rec exprKind (exp : Parsetree.expression) =
match exp.pexp_desc with
| Pexp_fun _ -> Function
| Pexp_function _ -> Function
| Pexp_constraint (e, _) -> exprKind e
| Pexp_constant (Pconst_string _) -> String
| Pexp_constant (Pconst_float _ | Pconst_integer _) -> Number
Expand Down
1 change: 0 additions & 1 deletion analysis/src/Utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ let identifyPexp pexp =
| Parsetree.Pexp_ident _ -> "Pexp_ident"
| Pexp_constant _ -> "Pexp_constant"
| Pexp_let _ -> "Pexp_let"
| Pexp_function _ -> "Pexp_function"
| Pexp_fun _ -> "Pexp_fun"
| Pexp_apply _ -> "Pexp_apply"
| Pexp_match _ -> "Pexp_match"
Expand Down
1 change: 0 additions & 1 deletion compiler/frontend/bs_ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ module E = struct
fun_ ~loc ~attrs ~arity lab
(map_opt (sub.expr sub) def)
(sub.pat sub p) (sub.expr sub e)
| Pexp_function pel -> function_ ~loc ~attrs (sub.cases sub pel)
| Pexp_apply (e, l) ->
apply ~loc ~attrs (sub.expr sub e) (List.map (map_snd (sub.expr sub)) l)
| Pexp_match (e, pel) ->
Expand Down
3 changes: 0 additions & 3 deletions compiler/frontend/bs_builtin_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,6 @@ let expr_mapper ~async_context ~in_function_def (self : mapper)
| Pexp_constant (Pconst_integer (s, Some 'l')) ->
{e with pexp_desc = Pexp_constant (Pconst_integer (s, None))}
(* End rewriting *)
| Pexp_function _ ->
async_context := false;
default_expr_mapper self e
| _
when Ast_uncurried.expr_is_uncurried_fun e
&&
Expand Down
7 changes: 3 additions & 4 deletions compiler/gentype/TranslateStructure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ open GenTypeCommon
let rec addAnnotationsToTypes_ ~config ~(expr : Typedtree.expression)
(arg_types : arg_type list) =
match (expr.exp_desc, expr.exp_type.desc, arg_types) with
| ( Texp_function {arg_label; param; cases = [{c_rhs}]},
_,
{a_type} :: next_types ) ->
| Texp_function {arg_label; param; case = {c_rhs}}, _, {a_type} :: next_types
->
let next_types1 =
next_types |> addAnnotationsToTypes_ ~config ~expr:c_rhs
in
Expand Down Expand Up @@ -51,7 +50,7 @@ and add_annotations_to_fields ~config (expr : Typedtree.expression)
(fields : fields) (arg_types : arg_type list) =
match (expr.exp_desc, fields, arg_types) with
| _, [], _ -> ([], arg_types |> add_annotations_to_types ~config ~expr)
| Texp_function {cases = [{c_rhs}]}, field :: next_fields, _ ->
| Texp_function {case = {c_rhs}}, field :: next_fields, _ ->
let next_fields1, types1 =
add_annotations_to_fields ~config c_rhs next_fields arg_types
in
Expand Down
1 change: 0 additions & 1 deletion compiler/ml/ast_helper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ module Exp = struct
let let_ ?loc ?attrs a b c = mk ?loc ?attrs (Pexp_let (a, b, c))
let fun_ ?loc ?attrs ~arity a b c d =
mk ?loc ?attrs (Pexp_fun (a, b, c, d, arity))
let function_ ?loc ?attrs a = mk ?loc ?attrs (Pexp_function a)
let apply ?loc ?attrs a b = mk ?loc ?attrs (Pexp_apply (a, b))
let match_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_match (a, b))
let try_ ?loc ?attrs a b = mk ?loc ?attrs (Pexp_try (a, b))
Expand Down
1 change: 0 additions & 1 deletion compiler/ml/ast_helper.mli
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ module Exp : sig
pattern ->
expression ->
expression
val function_ : ?loc:loc -> ?attrs:attrs -> case list -> expression
val apply :
?loc:loc ->
?attrs:attrs ->
Expand Down
1 change: 0 additions & 1 deletion compiler/ml/ast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,6 @@ module E = struct
iter_opt (sub.expr sub) def;
sub.pat sub p;
sub.expr sub e
| Pexp_function pel -> sub.cases sub pel
| Pexp_apply (e, l) ->
sub.expr sub e;
List.iter (iter_snd (sub.expr sub)) l
Expand Down
1 change: 0 additions & 1 deletion compiler/ml/ast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,6 @@ module E = struct
fun_ ~loc ~attrs ~arity lab
(map_opt (sub.expr sub) def)
(sub.pat sub p) (sub.expr sub e)
| Pexp_function pel -> function_ ~loc ~attrs (sub.cases sub pel)
| Pexp_apply (e, l) ->
apply ~loc ~attrs (sub.expr sub e) (List.map (map_snd (sub.expr sub)) l)
| Pexp_match (e, pel) ->
Expand Down
2 changes: 1 addition & 1 deletion compiler/ml/ast_mapper_from0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ module E = struct
fun_ ~loc ~attrs ~arity:None lab
(map_opt (sub.expr sub) def)
(sub.pat sub p) (sub.expr sub e)
| Pexp_function pel -> function_ ~loc ~attrs (sub.cases sub pel)
| Pexp_function _ -> assert false
| Pexp_apply (e, l) ->
apply ~loc ~attrs (sub.expr sub e) (List.map (map_snd (sub.expr sub)) l)
| Pexp_match (e, pel) ->
Expand Down
1 change: 0 additions & 1 deletion compiler/ml/ast_mapper_to0.ml
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ module E = struct
fun_ ~loc ~attrs lab
(map_opt (sub.expr sub) def)
(sub.pat sub p) (sub.expr sub e)
| Pexp_function pel -> function_ ~loc ~attrs (sub.cases sub pel)
| Pexp_apply (e, l) ->
apply ~loc ~attrs (sub.expr sub e) (List.map (map_snd (sub.expr sub)) l)
| Pexp_match (e, pel) ->
Expand Down
1 change: 0 additions & 1 deletion compiler/ml/depend.ml
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,6 @@ let rec add_expr bv exp =
| Pexp_fun (_, opte, p, e, _) ->
add_opt add_expr bv opte;
add_expr (add_pattern bv p) e
| Pexp_function pel -> add_cases bv pel
| Pexp_apply (e, el) ->
add_expr bv e;
List.iter (fun (_, e) -> add_expr bv e) el
Expand Down
1 change: 0 additions & 1 deletion compiler/ml/parsetree.ml
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,6 @@ and expression_desc =
(* let P1 = E1 and ... and Pn = EN in E (flag = Nonrecursive)
let rec P1 = E1 and ... and Pn = EN in E (flag = Recursive)
*)
| Pexp_function of case list (* function P1 -> E1 | ... | Pn -> En *)
| Pexp_fun of
arg_label * expression option * pattern * expression * int option
(* fun P -> E1 (Simple, None)
Expand Down
4 changes: 1 addition & 3 deletions compiler/ml/pprintast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ and expression ctxt f x =
pp f "((%a)@,%a)" (expression ctxt) {x with pexp_attributes=[]}
(attributes ctxt) x.pexp_attributes
else match x.pexp_desc with
| Pexp_function _ | Pexp_fun _ | Pexp_match _ | Pexp_try _ | Pexp_sequence _
| Pexp_fun _ | Pexp_match _ | Pexp_try _ | Pexp_sequence _
when ctxt.pipe || ctxt.semi ->
paren true (expression reset_ctxt) f x
| Pexp_ifthenelse _ | Pexp_sequence _ when ctxt.ifthenelse ->
Expand All @@ -551,8 +551,6 @@ and expression ctxt f x =
pp f "@[<2>fun@;%s%a->@;%a@]"
arity_str (label_exp ctxt) (l, e0, p)
(expression ctxt) e
| Pexp_function l ->
pp f "@[<hv>function%a@]" (case_list ctxt) l
| Pexp_match (e, l) ->
pp f "@[<hv0>@[<hv0>@[<2>match %a@]@ with@]%a@]"
(expression reset_ctxt) e (case_list ctxt) l
Expand Down
3 changes: 0 additions & 3 deletions compiler/ml/printast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,6 @@ and expression i ppf x =
line i ppf "Pexp_let %a\n" fmt_rec_flag rf;
list i value_binding ppf l;
expression i ppf e
| Pexp_function l ->
line i ppf "Pexp_function\n";
list i case ppf l
| Pexp_fun (l, eo, p, e, arity) ->
line i ppf "Pexp_fun\n";
let () =
Expand Down
4 changes: 2 additions & 2 deletions compiler/ml/printtyped.ml
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,11 @@ and expression i ppf x =
line i ppf "Texp_let %a\n" fmt_rec_flag rf;
list i value_binding ppf l;
expression i ppf e
| Texp_function {arg_label = p; param; cases; partial = _} ->
| Texp_function {arg_label = p; param; case = case_; partial = _} ->
line i ppf "Texp_function\n";
line i ppf "%a" Ident.print param;
arg_label i ppf p;
list i case ppf cases
case i ppf case_
| Texp_apply (e, l) ->
line i ppf "Texp_apply\n";
expression i ppf e;
Expand Down
4 changes: 2 additions & 2 deletions compiler/ml/rec_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ let rec expression : Env.env -> Typedtree.expression -> Use.t =
let case env {Typedtree.c_rhs} = expression env c_rhs in
Use.join (expression env e) (list case env cases)
| Texp_override () -> assert false
| Texp_function {cases} ->
Use.delay (list (case ~scrutinee:Use.empty) env cases)
| Texp_function {case = case_} ->
Use.delay (list (case ~scrutinee:Use.empty) env [case_])
| Texp_lazy e -> (
match Typeopt.classify_lazy_argument e with
| `Constant_or_function | `Identifier _ | `Float -> expression env e
Expand Down
2 changes: 1 addition & 1 deletion compiler/ml/tast_iterator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ let expr sub {exp_extra; exp_desc; exp_env; _} =
| Texp_let (rec_flag, list, exp) ->
sub.value_bindings sub (rec_flag, list);
sub.expr sub exp
| Texp_function {cases; _} -> sub.cases sub cases
| Texp_function {case; _} -> sub.case sub case
| Texp_apply (exp, list) ->
sub.expr sub exp;
List.iter (fun (_, o) -> Option.iter (sub.expr sub) o) list
Expand Down
4 changes: 2 additions & 2 deletions compiler/ml/tast_mapper.ml
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,8 @@ let expr sub x =
| Texp_let (rec_flag, list, exp) ->
let rec_flag, list = sub.value_bindings sub (rec_flag, list) in
Texp_let (rec_flag, list, sub.expr sub exp)
| Texp_function {arg_label; param; cases; partial} ->
Texp_function {arg_label; param; cases = sub.cases sub cases; partial}
| Texp_function {arg_label; arity; param; case; partial} ->
Texp_function {arg_label; arity; param; case = sub.case sub case; partial}
| Texp_apply (exp, list) ->
Texp_apply
(sub.expr sub exp, List.map (tuple2 id (opt (sub.expr sub))) list)
Expand Down
Loading
Loading