-
Notifications
You must be signed in to change notification settings - Fork 406
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
Signature formatter creates very long lines when many parameters share a type #5424
Comments
I believe this is from the way binders are formatted — the Here's an example of no wrapping: syntax "baz " num* : term
#eval show Lean.CoreM _ from
Lean.PrettyPrinter.formatTerm =<<
`(term| baz 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1) Changing this to Syntax definitions like |
|
I'm not seeing any running-together identifiers @digama0 even though explicit binders are using def foo (a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20
a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39 a40
a41 a42 a43 a44 a45 a46 a47 a48 a49 a50 a51 a52 a53 a54 a55 a56 a57 a58 a59 a60
a61 a62 a63 a64 a65 a66 a67 a68 a69 a70 a71 a72 a73 a74 a75 a76 a77 a78 a79 a80
a81 a82 a83 a84 a85 a86 a87 a88 a89 a90 a91 a92 a93 a94 a95 a96 a97 a98 a99 : Nat) : Nat := 0
#check foo
/-
foo
(a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 ... and so on ... :
Nat) :
Nat
-/ |
This is only true for regular identifiers, when the identifiers are hygienic they are suffixed with a non-identifier character which makes the pretty printer think that it is better not to put a space because no space recommendation was used. (Note the daggers in my example.) It seems though that it is difficult to come up with easy examples now to demonstrate this behavior because e.g. the signature printer no longer shows hygienic names. Here's a slightly contrived example based on the import Lean
open Lean PrettyPrinter
def fmt (stx : CoreM Syntax) : CoreM Format := do PrettyPrinter.ppCommand ⟨← stx⟩
#eval fmt `(command| def foo (x y : Nat) := x)
-- def foo✝ (x✝y✝ : Nat✝) :=
-- x✝ |
…tokens The formatter was using `tk ++ " "` to separate tokens from tokens they would merge with, but `" "` is not whitespace that could merge. This affected large binder lists, which wouldn't pretty print with any line breaks. Now they can be flowed across multiple lines. Closes leanprover#5424
I'm not sure yet what the best way to solve this inaccessible name issue is, but at least there's an easy fix for the long signature issue (#5513). This fixes it at the formatter level instead of adding missing |
Description
The signature formatter is used to display signatures for constants. If consecutive parameters share a type, then they are grouped, but these groups never get line breaks. This can lead to extremely long lines in the output of
#check
as well as in other contexts.Context
This was discovered when looking at Verso docstring output for
Lean.Meta.Simp.Config.mk
.While this particular issue is easy to work around by simply omitting constructors from the documentation output (as doc-gen does) and by setting a CSS overflow property, it could very well come up again elsewhere.
Steps to Reproduce
#check
on its constructor, and note that the grouped parameters include no line breaks.Here's an example:
Expected behavior:
I would expect line breaks to be inserted in the parameters as necessary to avoid long lines, e.g. via
Std.Format.fill
.Something like this:
Actual behavior:
Extremely long lines of output.
Versions
"4.12.0, commit bff638ef479b4f1feec3af92b2d9d4a29a06d4f8"
Mac OS 14.6.1
Additional Information
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: