Skip to content

Insert a blank line between consecutive compiler messages#12024

Merged
gasche merged 6 commits intoocaml:trunkfrom
gasche:blank-line-between-messages
Feb 24, 2023
Merged

Insert a blank line between consecutive compiler messages#12024
gasche merged 6 commits intoocaml:trunkfrom
gasche:blank-line-between-messages

Conversation

@gasche
Copy link
Copy Markdown
Member

@gasche gasche commented Feb 21, 2023

This PR is inspired by user feedback from @mimoo on compiler error messages which originated in #11539.

Currently OCaml tools will include several messages concatenated together -- several warnings, possibly followed by one error -- and it may not be obvious especially for new users to visually split the output in several reports.

This PR introduces a blank line between consecutive reports.

(cc @Octachron)

Batch compiler example

Before:

File "b_bad.ml", lines 13-14, characters 29-28:
13 | .............................function
14 |     A.X s -> print_endline s
Error (warning 8 [partial-match]): this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
Y
File "b_bad.ml", line 18, characters 11-14:
18 | let () = f A.y
                ^^^
Error: Unbound value A.y

After:

File "b_bad.ml", lines 13-14, characters 29-28:
13 | .............................function
14 |     A.X s -> print_endline s
Error (warning 8 [partial-match]): this pattern-matching is not exhaustive.
Here is an example of a case that is not matched:
Y

File "b_bad.ml", line 18, characters 11-14:
18 | let () = f A.y
                ^^^
Error: Unbound value A.y

Toplevel example

Before:

# type _ t = Int : int -> int t | Bool : bool -> bool t;;
type _ t = Int : int -> int t | Bool : bool -> bool t
# let test : int t -> int = function Int n -> n | _ -> 0;;
Warning 4 [fragile-match]: this pattern-matching is fragile.
It will remain exhaustive when constructors are added to type t.
Warning 56 [unreachable-case]: this match case is unreachable.
Consider replacing it with a refutation case '<pat> -> .'
val test : int t -> int = <fun>

After:

# type _ t = Int : int -> int t | Bool : bool -> bool t;;
type _ t = Int : int -> int t | Bool : bool -> bool t
# let test : int t -> int = function Int n -> n | _ -> 0;;
Warning 4 [fragile-match]: this pattern-matching is fragile.
It will remain exhaustive when constructors are added to type t.

Warning 56 [unreachable-case]: this match case is unreachable.
Consider replacing it with a refutation case '<pat> -> .'

val test : int t -> int = <fun>

Implementation

Most of the logic is hidden in Location, but unfortunately there are other places in the compiler that print user messages than Location.print_report, so we need to break the abstraction a bit and expose a function "I'm about to print a new message" to be called by other modules. Not super nice, but not too bad either -- and very short.

Note

In the original report, the issue was at the build-system level (the build system would concatenate several errors coming from different files); I reported this issue on dune in ocaml/dune#6158 , and this is getting fixed by @esope in ocaml/dune#6823. The present PR is about messages concatenated by the compiler itself.

@gasche gasche force-pushed the blank-line-between-messages branch 3 times, most recently from cd16d3d to 94836c9 Compare February 22, 2023 13:34
@Octachron
Copy link
Copy Markdown
Member

The code change looks fine to me: it seems fine to have a function that is used to mark the start of separate user messages. I expect that if we move to a structured log for the compiler functions those function calls will be naturally subsumed by the more general API.

@gasche
Copy link
Copy Markdown
Member Author

gasche commented Feb 22, 2023

This reads like an approving review, without the approval stamp. What's your thought on what this PR needs next?

@gasche gasche force-pushed the blank-line-between-messages branch from ab541a5 to 7a31d6d Compare February 22, 2023 13:53
@Octachron
Copy link
Copy Markdown
Member

Octachron commented Feb 22, 2023

I am reading the testsuite changes before giving my approval.

As you could guess, Deprecated_module is deprecated.
Please use something else!


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The second blank line here comes for the deprecation message, which suggest that this PR might slightly affect the design of deprecation message.

Use the equivalent signed form: -f-r-a-g-i-l-e-m-a-t-h.
Hint: Enabling or disabling a warning by its mnemonic name requires a + or - prefix.
Hint: Did you make a spelling mistake when using a mnemonic name?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This newline is from an empty toplevel phrase.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ah, I guess my move to a signature option should be changed back into "is the empty signature?" to account for other ways the signature could be empty. I will do this.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I fixed this (now the toplevel-specific commit has a much shorter diff) and rebased. Thanks for the eagle eyes!

@Octachron
Copy link
Copy Markdown
Member

The regexp of ocamltex's catch_warning needs to be updated to be able to ignore blank lines before the warning.

@gasche gasche force-pushed the blank-line-between-messages branch from 7a31d6d to b847d4b Compare February 22, 2023 14:58
@gasche
Copy link
Copy Markdown
Member Author

gasche commented Feb 22, 2023

The regexp of ocamltex's catch_warning needs to be updated to be able to ignore blank lines before the warning.

Urgh, would you maybe be willing to do this part yourself? (You should have push rights on my fork.)

@Octachron
Copy link
Copy Markdown
Member

The fix for ocamltex is available at Octachron/ocaml@5b8852a16979af60 .

@gasche
Copy link
Copy Markdown
Member Author

gasche commented Feb 22, 2023

Thanks! I added it to the PR.

@gasche gasche force-pushed the blank-line-between-messages branch from e2b505b to 784f86a Compare February 22, 2023 21:26
@gasche
Copy link
Copy Markdown
Member Author

gasche commented Feb 22, 2023

There were some bits of testsuite changes left to promote, I did this and kept the fixup commits around for now for easier reviewing.

Copy link
Copy Markdown
Member

@Octachron Octachron left a comment

Choose a reason for hiding this comment

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

The testsuite is passing and adding some negative spaces to the compiler messages is a good idea.

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.

3 participants