Skip to content

make map ~a:(fun and map (fun consistent #2706

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ profile. This started with version 0.26.0.
- Fix a crash where `type%e nonrec t = t` was formatted as `type nonrec%e t = t`,
which is invalid syntax. (#2712, @EmileTrotignon)

- \* The formatting of `f (fun` is now consistent with `f ~a:(fun`.
(#2706, @EmileTrotignon)

### Changed

- `|> begin`, `~arg:begin`, `begin if`, `lazy begin`, `begin match`,
Expand Down
16 changes: 3 additions & 13 deletions lib/Params.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,10 @@ module Exp = struct
| Some ((Labelled _ | Optional _), _, _) -> true
| _ -> false
in
let is_ctx_beginend =
match ctx0 with
| Exp {pexp_desc= Pexp_beginend _; _} -> true
| _ -> false
in
if Conf.(c.fmt_opts.ocp_indent_compat.v) then
if last_arg || is_labelled_arg then break 1 2 else str " "
else if is_labelled_arg then break 1 2
else if last_arg then break 1 0
else if is_ctx_beginend then break 1 0
else str " "
else break 1 0

let box_fun_decl_args ~ctx ~ctx0 ?(last_arg = false) ?epi c ~parens ~kw
~args ~annot =
Expand Down Expand Up @@ -215,11 +208,8 @@ module Exp = struct
match ctx_is_apply_and_exp_is_arg ~ctx ~ctx0 with
| Some (_, _, true) ->
(* Is last arg. *) hvbox ~name (if parens then 0 else 2)
| Some (Nolabel, _, false) ->
(* TODO: Inconsistent formatting of fun args. *)
hovbox ~name 0
| Some ((Labelled _ | Optional _), _, false) -> hvbox ~name 0
| None -> Fn.id
| Some (_, _, false) -> hvbox ~name 0
| None -> hvbox ~name 0
in
(box, not c.fmt_opts.wrap_fun_args.v)
in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ let f

let new_specialised_args =
Variable.Map.mapi
(fun new_inner_var______ (definition : Definition.t) :
Flambda.specialised_to -> ())
(fun
new_inner_var______
(definition : Definition.t)
:
Flambda.specialised_to
-> ())
foo

let new_specialised_args =
Expand Down
8 changes: 6 additions & 2 deletions test/passing/refs.ahrefs/break_fun_decl-smart.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ let f

let new_specialised_args =
Variable.Map.mapi
(fun new_inner_var______ (definition : Definition.t) :
Flambda.specialised_to -> ())
(fun
new_inner_var______
(definition : Definition.t)
:
Flambda.specialised_to
-> ())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not great but it is consistent. I would like to box the arguments, so that

fun
  arg1 arg2
  : return_type
->
  body

is allowed.

foo

let new_specialised_args =
Expand Down
8 changes: 6 additions & 2 deletions test/passing/refs.ahrefs/break_fun_decl-wrap.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ let f (module Store : Irmin.Generic_key.S with type repo = repo)

let new_specialised_args =
Variable.Map.mapi
(fun new_inner_var______ (definition : Definition.t) :
Flambda.specialised_to -> ())
(fun
new_inner_var______
(definition : Definition.t)
:
Flambda.specialised_to
-> ())
foo

let new_specialised_args =
Expand Down
8 changes: 6 additions & 2 deletions test/passing/refs.ahrefs/break_fun_decl.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ let f (module Store : Irmin.Generic_key.S with type repo = repo)

let new_specialised_args =
Variable.Map.mapi
(fun new_inner_var______ (definition : Definition.t) :
Flambda.specialised_to -> ())
(fun
new_inner_var______
(definition : Definition.t)
:
Flambda.specialised_to
-> ())
foo

let new_specialised_args =
Expand Down
Empty file.
3 changes: 2 additions & 1 deletion test/passing/refs.ahrefs/class_expr.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class c (* xx *) i (* yy *) = x
class c =
object
method class_infos : 'a. ('a -> 'res) -> 'a class_infos -> 'res =
fun _a
fun
_a
{ pci_virt; pci_params; pci_name; pci_expr; pci_loc; pci_attributes } ->
let pci_virt = self#virtual_flag pci_virt in
let pci_params = self#list in
Expand Down
9 changes: 2 additions & 7 deletions test/passing/refs.ahrefs/exp_grouping.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,7 @@ let v =
let v =
map x
begin fun
x
arggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
->
x arggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg ->
y
end

Expand Down Expand Up @@ -457,10 +455,7 @@ let _ =

let _ =
lazy begin fun
xxxxxxxxxxxxxxxxxxxxxxx
yyyyyyyyyyyyyyyyyyy
zzzzzzzzzzzzzzzzzzzzzzzz
->
xxxxxxxxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyy zzzzzzzzzzzzzzzzzzzzzzzz ->
print_endline xxxxxxxxx;
f xxxxxxxxxx yyyyyyyyyyyyy zzzzzzzzzzzzzzzzzzzzz
end
Expand Down
2 changes: 1 addition & 1 deletion test/passing/refs.ahrefs/fun_decl-no-wrap-fun-args.ml.err
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Warning: fun_decl-no-wrap-fun-args.ml:39 exceeds the margin
Warning: fun_decl-no-wrap-fun-args.ml:41 exceeds the margin
48 changes: 26 additions & 22 deletions test/passing/refs.ahrefs/fun_decl-no-wrap-fun-args.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,27 @@ let _ = fun (x : int) : int -> (some_large_computation : int)
let fooo = List.foooo ~f:(fun foooo foooo : bool -> foooooooooooooooooooooo)

let _ =
fun (x : int)
(x : int)
(x : int)
(x : int)
(x : int)
:
fooooooooooooooooooooooooooo foooooooooooooo foooooooooo ->
fun
(x : int)
(x : int)
(x : int)
(x : int)
(x : int)
:
fooooooooooooooooooooooooooo foooooooooooooo foooooooooo ->
some_large_computation

let _ =
fun (x : int)
(x : int)
(x : int)
(x : int)
(x : int)
(x : int)
(x : int)
:
fooooooooooooooooooooooooooo foooooooooooooo foooooooooo ->
fun
(x : int)
(x : int)
(x : int)
(x : int)
(x : int)
(x : int)
(x : int)
:
fooooooooooooooooooooooooooo foooooooooooooo foooooooooo ->
some_large_computation

let () =
Expand Down Expand Up @@ -94,17 +96,19 @@ let _ =

let _ =
let _ = () in
fun (context : Context.t)
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
->
fun
(context : Context.t)
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
->
let _ = () in
()

let _ =
print_endline "foo";
fun (context : Context.t)
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
->
fun
(context : Context.t)
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
->
let _ = () in
()

Expand Down
6 changes: 4 additions & 2 deletions test/passing/refs.ahrefs/fun_decl.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,17 @@ let _ =

let _ =
let _ = () in
fun (context : Context.t)
fun
(context : Context.t)
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
->
let _ = () in
()

let _ =
print_endline "foo";
fun (context : Context.t)
fun
(context : Context.t)
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
->
let _ = () in
Expand Down
2 changes: 1 addition & 1 deletion test/passing/refs.ahrefs/js_source.ml.err
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ Warning: js_source.ml:136 exceeds the margin
Warning: js_source.ml:170 exceeds the margin
Warning: js_source.ml:243 exceeds the margin
Warning: js_source.ml:255 exceeds the margin
Warning: js_source.ml:862 exceeds the margin
Warning: js_source.ml:864 exceeds the margin
6 changes: 4 additions & 2 deletions test/passing/refs.ahrefs/js_source.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ let _ =

let _ =
let x = x in
fun foooooooooooooooooo
fun
foooooooooooooooooo
foooooooooooooooooo
foooooooooooooooooo
foooooooooooooooooo
Expand Down Expand Up @@ -645,7 +646,8 @@ module M =

let _ =
Some
(fun fooooooooooooooooooooooooooooooo
(fun
fooooooooooooooooooooooooooooooo
fooooooooooooooooooooooooooooooo
fooooooooooooooooooooooooooooooo
-> foo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,12 @@ let f

let new_specialised_args =
Variable.Map.mapi
(fun new_inner_var______ (definition : Definition.t) :
Flambda.specialised_to -> ())
(fun
new_inner_var______
(definition : Definition.t)
:
Flambda.specialised_to
-> ())
foo

let new_specialised_args =
Expand Down
8 changes: 6 additions & 2 deletions test/passing/refs.default/break_fun_decl-smart.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,12 @@ let f

let new_specialised_args =
Variable.Map.mapi
(fun new_inner_var______ (definition : Definition.t) :
Flambda.specialised_to -> ())
(fun
new_inner_var______
(definition : Definition.t)
:
Flambda.specialised_to
-> ())
foo

let new_specialised_args =
Expand Down
8 changes: 6 additions & 2 deletions test/passing/refs.default/break_fun_decl-wrap.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ let f (module Store : Irmin.Generic_key.S with type repo = repo)

let new_specialised_args =
Variable.Map.mapi
(fun new_inner_var______ (definition : Definition.t) :
Flambda.specialised_to -> ())
(fun
new_inner_var______
(definition : Definition.t)
:
Flambda.specialised_to
-> ())
foo

let new_specialised_args =
Expand Down
8 changes: 6 additions & 2 deletions test/passing/refs.default/break_fun_decl.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,12 @@ let f (module Store : Irmin.Generic_key.S with type repo = repo)

let new_specialised_args =
Variable.Map.mapi
(fun new_inner_var______ (definition : Definition.t) :
Flambda.specialised_to -> ())
(fun
new_inner_var______
(definition : Definition.t)
:
Flambda.specialised_to
-> ())
foo

let new_specialised_args =
Expand Down
2 changes: 1 addition & 1 deletion test/passing/refs.default/class_expr.ml.err
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Warning: class_expr.ml:9 exceeds the margin
Warning: class_expr.ml:10 exceeds the margin
3 changes: 2 additions & 1 deletion test/passing/refs.default/class_expr.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ class c (* xx *) i (* yy *) = x
class c =
object
method class_infos : 'a. ('a -> 'res) -> 'a class_infos -> 'res =
fun _a
fun
_a
{ pci_virt; pci_params; pci_name; pci_expr; pci_loc; pci_attributes } ->
let pci_virt = self#virtual_flag pci_virt in
let pci_params = self#list in
Expand Down
9 changes: 2 additions & 7 deletions test/passing/refs.default/exp_grouping.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,7 @@ let v =
let v =
map x
begin fun
x
arggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg
->
x arggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg ->
y
end

Expand Down Expand Up @@ -474,10 +472,7 @@ let _ =

let _ =
lazy begin fun
xxxxxxxxxxxxxxxxxxxxxxx
yyyyyyyyyyyyyyyyyyy
zzzzzzzzzzzzzzzzzzzzzzzz
->
xxxxxxxxxxxxxxxxxxxxxxx yyyyyyyyyyyyyyyyyyy zzzzzzzzzzzzzzzzzzzzzzzz ->
print_endline xxxxxxxxx;
f xxxxxxxxxx yyyyyyyyyyyyy zzzzzzzzzzzzzzzzzzzzz
end
Expand Down
20 changes: 12 additions & 8 deletions test/passing/refs.default/fun_decl-no-wrap-fun-args.ml.ref
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ let _ = fun (x : int) : int -> (some_large_computation : int)
let fooo = List.foooo ~f:(fun foooo foooo : bool -> foooooooooooooooooooooo)

let _ =
fun (x : int)
fun
(x : int)
(x : int)
(x : int)
(x : int)
Expand All @@ -13,7 +14,8 @@ let _ =
some_large_computation

let _ =
fun (x : int)
fun
(x : int)
(x : int)
(x : int)
(x : int)
Expand Down Expand Up @@ -94,17 +96,19 @@ let _ =

let _ =
let _ = () in
fun (context : Context.t)
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
->
fun
(context : Context.t)
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
->
let _ = () in
()

let _ =
print_endline "foo";
fun (context : Context.t)
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
->
fun
(context : Context.t)
~(local_bins : origin Appendable_list.t Filename.Map.t Memo.Lazy.t)
->
let _ = () in
()

Expand Down
Loading