Skip to content

Format: Backport scan_push change#2778

Open
Julow wants to merge 20 commits intoocaml-ppx:mainfrom
Julow:55-backport-format-scan_push
Open

Format: Backport scan_push change#2778
Julow wants to merge 20 commits intoocaml-ppx:mainfrom
Julow:55-backport-format-scan_push

Conversation

@Julow
Copy link
Collaborator

@Julow Julow commented Mar 11, 2026

Follow-up on #2777

This backports ocaml/ocaml#13853 and fix the worst formatting changes.
This changes the formatting in many cases but a lot of the changes are improvements.

Julow added 20 commits March 5, 2026 17:45
An minimal unsafe version of Domain.DLS is used to implement Format_.
This shim module just needs to be removed if OCamlformat ever use
parallelism.
This bug fix breaks OCamlformat and will be fixed in a separate PR.
Add commented-out code in order to reduce the textual diff with
upstream code.
The formatting of this option depended heavily on the Format bug.
Ensure that comments in chains of operators either fit on a single line
or break the line after each comments. For example:

    foo (* 1 *) ^ bar (* 2 *) ^ baz (* 3 *)

or if too long to fit a single line:

    foo (* 1 *)
    ^ bar (* 2 *)
    ^ baz (* 3 *)

But never:

    foo (* 1 *) ^ bar (* 2 *)
    ^ baz (* 3 *)
This restore the previous behavior.
@Julow
Copy link
Collaborator Author

Julow commented Mar 11, 2026

This change reflow a lot of comments and string literals, which might impact a lot of code.

However, many changes are less impacting or result in nicer code. For example, comments just after a then or a else:

       if
         i < Array.length g.constants
         && Constants.inlined ~target g.constants.(i)
-      then
-        (* Inlined constant *)
+      then (* Inlined constant *)
         let x, state = State.fresh_var state in
         let cst = g.constants.(i) in
         (x, state, Let (x, Constant cst) :: instrs)

Some or-patterns are also reflow:

   match (a, b) with
-  | ( ( ( TComment _ | T_EOF | T_LPAREN | T_LPAREN_ARROW | T_RPAREN
-        | T_SEMICOLON | T_VIRTUAL_SEMICOLON | T_COMMA ),
+  | ( ( ( TComment _ | T_EOF | T_LPAREN | T_LPAREN_ARROW | T_RPAREN | T_SEMICOLON
+        | T_VIRTUAL_SEMICOLON | T_COMMA ),
         _ )
       :: a,
       b ) ->

What are your opinion ?

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.

1 participant