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

Upgrade to ocamlformat 0.26.0 #8064

Merged
merged 2 commits into from
Aug 1, 2023
Merged

Conversation

Julow
Copy link
Contributor

@Julow Julow commented Jun 27, 2023

The changed formatting of @@ let ... (any operator) cause huge diffs in the command descriptions. The changed indentation of if and let in parentheses also has a big impact.

The aim of this commit is to gather feedback.

Changelog can be found here: https://github.com/ocaml-ppx/ocamlformat/blob/main/CHANGES.md

@Julow Julow marked this pull request as draft June 27, 2023 16:49
@emillon
Copy link
Collaborator

emillon commented Jun 28, 2023

Once 3.9.0 is out I'll upgrade to 0.25.0 first so we can see what's going on more precisely (I'll also enable .git-blame-ignore-revs).

@@ -232,8 +233,9 @@ module Stanza = struct
enter
(let+ pat =
keyword "_" >>> return Any
<|> let+ p = Profile.decode in
Profile p
<|>
Copy link
Member

Choose a reason for hiding this comment

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

IMO the old code looked better here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What do you think of the similar change in cmd code, where the let-expression is much bigger and the operators are not chained ?

Copy link
Member

Choose a reason for hiding this comment

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

The old version is better there too. The additional line only pays off when the let expression has some ugly wrapping due to the lack of horizontal space. There was no such issue there.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Can ocamlformat pick the one that causes the least wrapping? (at least under the hood)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really, OCamlformat cannot compare two possible formatting. Only the input can be considered (though, multiple iterations on the whole code can be made).
But it can format differently whether there would be no wrapping at all and it can detect chained operators.

Such formatting could be possible:

<|> let+ p = Profile.decode in Profile p
<|> ...

falling back to this as soon as it doesn't fit on the line:

<|>
let+ p = Profile.decode in
(* longer code *)
Profile p
<|> ...

I'm mentioning chained operators because to me, the cmd code looks better with less indentation.
To me, that indentation can cause ugly wrapping means that it does.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

By looking at the diff again, I find that the reduced indentation do save lines by removing some wrapping. I also do not find a lot of chained operators so my previous suggestion is not valid.

Though, it should be possible have this formatting, as long as it fits on one line:

...
<|> let+ p = Profile.decode in Profile p

Should I add this before the next release ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

not a huge fan of saving lines at all cost, I think that the old version was better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I went back and found the reason for this change: ocaml-ppx/ocamlformat#2315
It's a consistency change, in the previous version, the line was broken on regular lets but not letops:

let _ =
  Cmd.v info
  @@ let+ trimmed_size = () in
     ()

let _ =
  ()
  <|> let+ p = Profile.decode in
      Profile p

let _ =
  Cmd.v info
  @@
  let trimmed_size = () in
  ()

let _ =
  ()
  <|>
  let p = Profile.decode in
  Profile p

The other form exists in the code: bin/describe/describe_workspace.ml line 378.

This diff can go away by keeping the line break from the source code, whether it's a let or a letop. (ocaml-ppx/ocamlformat#2396)
We try to add as few of these as possible but the regression is large enough to justify it.

I'll merge this patch and update this preview PR after the weekend.

@Julow
Copy link
Contributor Author

Julow commented Jun 28, 2023

Once 3.9.0 is out I'll upgrade to 0.25.0 first so we can see what's going on more precisely (I'll also enable .git-blame-ignore-revs).

Let me know and I'll rebase this.

bin/cache.ml Outdated Show resolved Hide resolved
src/dune_rules/dune_project.ml Outdated Show resolved Hide resolved
@emillon
Copy link
Collaborator

emillon commented Jul 5, 2023

Let me know and I'll rebase this.

you can go ahead!

@Julow Julow force-pushed the preview-ocamlformat-0.26.0 branch from a17d7ed to 15583f7 Compare July 10, 2023 10:13
@Julow
Copy link
Contributor Author

Julow commented Jul 10, 2023

I rebased and re-ran the preview with the @@ let+ fix.

@@ -1,2 +1,4 @@
# ocamlformat 0.25.1
3f01f6f3694e48cb1868018121f3959f8d23baca
# Upgrade to OCamlformat 0.26.0
8a1a919e3895787ae3781da1d6aff4cc41ce04c3
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need to do that in this PR since this will change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right!

I'll make sure to remove that and fix the version line before I mark the PR as ready.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Though, do you think this PR could be merged unsquashed ?

Copy link
Collaborator

Choose a reason for hiding this comment

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

for now I prefer doing this in 2 steps

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok!

.ocamlformat Outdated Show resolved Hide resolved
@Julow Julow force-pushed the preview-ocamlformat-0.26.0 branch from 15583f7 to 96f2092 Compare July 18, 2023 09:17
Copy link
Collaborator

@emillon emillon left a comment

Choose a reason for hiding this comment

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

In my opinion, these are all improvements. Let's wait for @rgrinberg's opinion as well.

@Julow
Copy link
Contributor Author

Julow commented Jul 18, 2023

Thanks :) Unless a problem is found, I intent to release today.

@Julow Julow force-pushed the preview-ocamlformat-0.26.0 branch from 96f2092 to 272a7b1 Compare July 20, 2023 10:23
@Julow Julow changed the title Preview: Upgrade to ocamlformat 0.26.0 (unreleased) Upgrade to ocamlformat 0.26.0 Jul 20, 2023
@Julow
Copy link
Contributor Author

Julow commented Jul 20, 2023

OCamlformat 0.26.0 has been released! This PR can be merged or closed if it's a bit too early to upgrade.

@Julow Julow marked this pull request as ready for review July 20, 2023 10:35
@Julow Julow force-pushed the preview-ocamlformat-0.26.0 branch from 272a7b1 to b3a1db3 Compare July 20, 2023 10:36
@emillon emillon force-pushed the preview-ocamlformat-0.26.0 branch from b3a1db3 to 400356c Compare July 31, 2023 16:16
@emillon
Copy link
Collaborator

emillon commented Jul 31, 2023

I rebased this; this can land once #8311 is merged.

Signed-off-by: Jules Aguillon <jules@j3s.fr>
Signed-off-by: Etienne Millon <me@emillon.org>
@emillon emillon force-pushed the preview-ocamlformat-0.26.0 branch from 400356c to a18c6fc Compare July 31, 2023 16:20
Comment on lines +986 to +988
~compare:(fun
(x : _ Install.Entry.t) (y : _ Install.Entry.t) ->
Path.compare x.src y.src)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Indentation here is kind of funny. Is this expected @Julow?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is expected: The -> was moved to the same line as the arguments to avoid the previous indentation. The arguments no longer fit on the line and have to break.

The arguments are indented more than the body for disambiguation.

Copy link
Collaborator

@Alizter Alizter left a comment

Choose a reason for hiding this comment

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

LGTM, just a non-blocking comment.

@emillon emillon merged commit 14d199f into ocaml:main Aug 1, 2023
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants