Skip to content

Commit

Permalink
Remove uses of "Function$".
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianoc committed Dec 12, 2024
1 parent 2423ad0 commit 2df3b30
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
5 changes: 5 additions & 0 deletions compiler/ml/ast_uncurried.ml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ let expr_extract_uncurried_fun (expr : Parsetree.expression) =
e
| _ -> assert false

let remove_fun (expr : Parsetree.expression) =
match expr.pexp_desc with
| Pexp_construct ({txt = Lident "Function$"}, Some e) -> e
| _ -> expr

let core_type_is_uncurried_fun (typ : Parsetree.core_type) =
match typ.ptyp_desc with
| Ptyp_constr ({txt = Lident "function$"}, [{ptyp_desc = Ptyp_arrow _}; _]) ->
Expand Down
6 changes: 1 addition & 5 deletions compiler/syntax/src/res_parens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ let unary_expr_operand expr =
match opt_braces with
| Some ({Location.loc = braces_loc}, _) -> Braced braces_loc
| None -> (
let expr = Ast_uncurried.remove_fun expr in
match expr with
| {Parsetree.pexp_attributes = attrs}
when match ParsetreeViewer.filter_parsing_attrs attrs with
Expand Down Expand Up @@ -111,11 +112,6 @@ let unary_expr_operand expr =
Parenthesized
| _ when ParsetreeViewer.has_await_attribute expr.pexp_attributes ->
Parenthesized
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some expr)}
when ParsetreeViewer.is_underscore_apply_sugar expr ->
Nothing
| {pexp_desc = Pexp_construct ({txt = Lident "Function$"}, Some _)} ->
Parenthesized
| _ -> Nothing)

let binary_expr_operand ~is_lhs expr =
Expand Down
14 changes: 1 addition & 13 deletions compiler/syntax/src/res_printer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2793,19 +2793,7 @@ and print_expression ~state (e : Parsetree.expression) cmt_tbl =
None,
{ppat_desc = Ppat_var {txt = "__x"}},
{pexp_desc = Pexp_apply _},
_ )
| Pexp_construct
( {txt = Lident "Function$"},
Some
{
pexp_desc =
Pexp_fun
( Nolabel,
None,
{ppat_desc = Ppat_var {txt = "__x"}},
{pexp_desc = Pexp_apply _},
_ );
} ) ->
_ ) ->
(* (__x) => f(a, __x, c) -----> f(a, _, c) *)
print_expression_with_comments ~state
(ParsetreeViewer.rewrite_underscore_apply e_fun)
Expand Down

0 comments on commit 2df3b30

Please sign in to comment.