-
Notifications
You must be signed in to change notification settings - Fork 72
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
buggy ppstring with notations #924
Comments
I prefer
I also believe there are some issues in coq itself, but the following example suggests that vscoqtop is doing some more wrong stuff. Definition F (q w e r t y u i o p : nat) : nat := q + w + e + r + t + y + u + i + o + p.
Definition equiv (x y : nat) := True.
Notation "x ≡ y" := (equiv x y) (at level 70, format "x ≡ y").
(* From Coq Require Import Utf8. *)
Lemma lemma {q} {a : bool} {w} {s : bool} {e} {d : bool} {r} (f : bool) {t y u i o p} :
F q w e r t y u i o p ≡ F q w e r t y u i o p /\ a = s /\ s = d /\ d = f.
Admitted.
About lemma. With
from both coqtop and vscoq2. But when
I would argue that this is an additional bug in the vscode client. The first 0 in |
Hi folks, it seems there is a bit of confusion about printing in Coq, let me see if I can be of help. Coq uses to print the OCaml Format library. The Traditionally, Coq then called Format to turn a Some years ago, I changed the way CoqIDE prints as with Format, printing in CoqIDE was a bit of a PITA if for example the window changed appearance. Also I found it convenient to allow clients to implemented more fancy printing. Thus, CoqIDE (which is an OCaml program) changed the wire representation and instead of sending a string started to send the I am not sure how current VsCoq algorithm is related to Format's algorithm, but my impression is that they are not the same? That is IMHO not a good idea as all the notations in Coq have been developed for the algorithm in OCaml's Format. In jsCoq / coq-lsp we use Shachar's JavaScript reimplementation of Format's algorithm, so our results then to be quite (not always tho) consistent with what you can see in |
@ejgallego thank you for the information, I have a feeling that maybe VsCoq's algorithm does a little bit more than is possible format as it allows for ellipsis/elided boxes that can be expanded and closed (although maybe this is possible with format and I am just unaware). Additionally, do you have any idea why it seems like the |
@Durbatuluk1701 Format can do that too, tho not interactively, see format's set_depth et al methods. Tho I think what you see here is just differences in the basic layout algo? I don't know, I'll let vsCoq devs comment on that.
Maybe it also needs the eq is as this in 8.21:
|
The pretty printers (ppstring -> rendered output) of VsCoq2's vscode client and vscoq.nvim are based on Oppen's algorithm (http://i.stanford.edu/pub/cstr/reports/cs/tr/79/770/CS-TR-79-770.pdf). I just took a quick look at OCaml's Format module (https://github.com/ocaml/ocaml/blob/trunk/stdlib/format.ml), and it seems it is also based on Oppen's algorithm, though it doesn't explicitly say so. Indeed, the rendered results of vscoq.nvim are quite similar to coqide's. In the cases where vscoq2/vscoq.nvim's results are significantly worse than coqide/coqtop (#924 (comment)), I noticed that the ppstring sent from the vscoqtop server doesn't contain enough Ppcmd_print_break. This means that either |
Many thanks for the detailed report! |
Thanks a lot for your report. In the above when you describe issues with the positioning of breaks in the |
While implementing pretty printer in vscoq.nvim (https://github.com/tomtomjhj/vscoq.nvim/blob/main/lua/vscoq/pp.lua), I noticed that ppstrings for terms that contain notations have some issues with breaks.
The following is tested with coq vesion 8.19.2, vscoq-language-server 2.2.1, latest version of vscoq.nvim with window width fixed to 80 character cells.
Let's first define some functions for testing.
1. Inconsistency in the locations of breaks
First, let's take a look at the ppstring for the
=
(the default notation foreq
) and a custom notation forequiv
defined similarly to=
.For the term containing
=
:Goal F 111 111 111 111 111 111 111 111 111 111 = F 111 111 111 111 111 111 111 111 111 111.
I get the following ppstring from vscoqtop,
which is supposed to be printed like this.
But for the term containing
≡
:Goal F 111 111 111 111 111 111 111 111 111 111 ≡ F 111 111 111 111 111 111 111 111 111 111.
I get this ppstring,
which is printed like this
Note that the location of break is different, despite that their notation definition is more or less the same.
What's more confusing is what the documentation says (https://coq.inria.fr/doc/v8.19/refman/user-extensions/syntax-extensions.html#notations) (emphasis mine)
According to the first emphasized point, the break location of
≡
is correct (before the symbols of the notation), but the second point says that the alignment of its rhs is wrong.If I understood the documentation correctly, it says the result should be something like this:
If I add extra space for
≡
notation (as per "This is performed by adding extra spaces between the symbols and parameters"), I get yet another different result:Notation "x ≡ y" := (equiv x y) (at level 70).
2. Lack of breaks
What's more critical is that when you specify format, it doesn't get any breaks at all.
Note that the ppstring doesn't have a hovbox around the whole term, and there is no break between lhs,
≡
, and rhs.A similar issue happens when you print something with the builtin utf8 notations.
For example, this is the rendered result of
vscoq/about
for a lemma in Iris:Note that there is no break between each binder for the
∀
notation, defined as follows in Unicode/Utf8_core.v.3. Lack of spaces with explicit breaks
Using
'/'
in the format ensures line breaksBut note that the
Ppcmd_print_break
doesn't have a space associated with it.So if the term is smaller than the window width, there is no space between
≡
and the rhs.Goal F 1 1 1 1 1 1 1 1 1 1 ≡ F 1 1 1 1 1 1 1 1 1 1.
The text was updated successfully, but these errors were encountered: