-
Notifications
You must be signed in to change notification settings - Fork 691
Show diffs in some error messages #8669
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a very cool feature, however I'm afraid that we must rethink the diffing strategy; this kind of state in Lexer will be frowned upon in 8.10.
I can try to have a look later, but going back to my question on the first ever diff PR: why are we not doing diffs over a Pp.t
? Maybe you want to implement a different rendering method Pp.t -> diff_structure
, what would be fine. However, having to re-lex seems indeed problematic [and will get more] as the lexer is not designed for this use case.
I was more looking for comments on changing Xmlprotocol--what that entails, how to do that cleanly without breaking, say, PG. Of course, let's discuss the lexer stuff, but if it requires much change to the diff code, I'll drop this idea. It's not worth the trouble to me. The concept was to do diffs on a token basis; Pp.t isn't necessarily grouped by tokens. |
I think you could extend the return message so you send both the Regarding the lexer I guess you could build a special entry point if you still want to diff at the token level, but I guess I'd be better if you could avoid this special mode. Why you need it anyways? |
If the client and server negotiate what protocol version to use, I would create a new Suppose I modify Coq to return (string, Pp.t) for a Fail. I expect an old, unmodified PG will not understand that and so won't show any error message for a Fail. That seems like a crippling issue. One approach to address this is for the client to announce what version of the XML protocol it wants to use, and then the server uses that version or tells the client it can't communicate with it. (One could also infer that if the client doesn't announce what protocol version it wants, it must want the old protocol.) Only 2 versions need to be supported in any version of Coq--just enough decoupling of software versions so you don't need to simultaneously update both Coq and PG (and any other clients using the protocol). Is there such a mechanism already? If not, I don't know how much work this would require for Coq--or whether we expect to enhance the XML protocol for other purposes (which might help justify the effort, if significant). I think this is the bigger part of the work needed to complete this PR.
Diffing at the token level is a much better match for how users read and think about these expressions than diffing at the character level. If a step replaces A Pp.t can contain an arbitrary series of strings; there's no guarantee that a The changes to the lexer shown here are quite small. I would expect providing the additional entry point in a new lexer would be similarly small. Is it necessary to delay any work on this until this new lexer is available--which I expect would be several to many months from now? When will the new lexer be available? Do other developers agree that rewriting the lexer is a priority? |
I mean why do you need this specific change in the lexer. |
I agree with @ejgallego that we should not increase the technical debt by adding more imperative state to the lexer. I also agree that we should perform the diff at the level of the pretty-printing AST, the current situation is clearly a hack. More generally, the diff feature is very hacky. I was not against inclusion for the end-users to quickly take advantage of it, but it would be great to polish it and remove many ugly details. |
Just to be clear in passing: PG (the version that most users rely on anyways) does not use the XML protocol. There is a branch which uses it but it's hard to know what its future will be given that the person who developed it is not around anymore. So while greater stability of the protocol would be an improvement, it's not something that matters much right now. |
96037b4
to
fa34262
Compare
I pushed a new version that removes the additional state, instead passing a flag when initializing the lexer.
When adding the diff highlights to the Pp.t, the code needs to have the character sequence of the tokens match (ignoring white space) the character sequence of the string passed to the lexer. That's so it can match the diff output to the Pp.t and, if necessary, split Pp.t strings that don't correspond to a single token. For example, passing the quoted string |
I would be interested to hear your suggestions for improvements. As I've said before, I'm new to OCaml. I've not found any useful style guidelines for OCaml--if you know of such, please let me know. (On the other hand, there are many things in Coq that deserve to be improved. Is it better to address some of those other areas or to perfect the diffs code?) |
OK, then we can change the XML protocol freely, assuming CoqIDE is the only client? Nonetheless I'd also want to look at the PG interface and make sure it can handle Pp.t's in error messages. Would you point me to the protocol code PG uses? |
It is not so much about the OCaml style than the specific guidelines of the Coq codebase, which unluckily are not quite written down but mostly passed by oral tradition in the PR comments and heated discussions on gitter or IRL. Note that they do change from a dev to another, even though we try to be somewhat consensual. As a general rule of thumb regarding your recent PRs, I'd highlight that:
I'd personally say that indeed you can. So far we didn't care about compatibility of the protocol across Coq versions. |
PG master branch uses no protocol, it just calls coqtop and parses the output using regexes, eg to detect when a goal is printer rather than when an error is. Yes, you have not misunderstood... PG server-protocol branch (IIRC the name) uses the very same XML protocol of CoqIDE. The code is known to work but also to have some bugs. If you are fluent in emacs lisp, you are surely welcome working/fixing on that code, but beware it is not the code most people run when they say PG. |
I agree too. If it is not the case, please add a version number to the protocol. I think I did it. Or maybe I forgot it. There is an init message, the version could go in there. |
The protocol is documented here and indeed it contains a version number. |
Thanks for helping my bad memory, |
fa34262
to
c44ebe1
Compare
c44ebe1
to
c2bd953
Compare
c2bd953
to
f22bc56
Compare
Please review. I updated the description. I was able to do this without changing the lexer (I'll make that a separate PR). Also, |
CHANGES.md
Outdated
Diffs | ||
|
||
- Some error messages that show problems with a pair of non-matching values will now | ||
highlight the differences (when diffs are enabled). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what is the point of requiring the user to turn diffs on (most users probably won't most of the time) to see diffs in error messages. It seems useful even to users who do not want diffs between successive goals (and it definitely sounds like two unrelated things).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A problem with the diff code is that it likes to die on quite a few inputs, it seems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but if there are such issues we will be more likely to detect them before 8.10 if this is activated by default. If this code path is never used in our tests, it is more likely to bitrot quickly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO the code needs significant work before is activated by default; also, it has the potential to increase compile time largely, so I guess we would be best served by specific tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In any case, it doesn't make sense to use the same option for diffs between successive goals and diffs in error messages, because the former should never be made the default while the latter should (as soon as it is realistic to do so).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure what is the point of requiring the user to turn diffs on (most users probably won't most of the time) to see diffs in error messages.
That makes sense; I would do that, though I would hope that users turn on diffs more often. In coqtop, we would need to check that -color on
was specified on the command line.
A problem with the diff code is that it likes to die on quite a few inputs, it seems.
No. I'm pretty careful about not breaking things for users:
- The values that are being compared in proof steps and in messages are terms and are unlikely to include the few input sequences that are not handled yet. Make diffs work for more input strings #8734 addresses those.
- In the unlikely case that the diff fails, it prints the message without diff highlighting and an additional message saying that diff failed. The user impact is negligible.
I guess we would be best served by specific tests.
Automatic testing is an interesting challenge. I included a .v file that generates an example message (for a manual test). Do we have a mechanism in place to verify that coqtop output contains the message?
IMHO the code needs significant work before is activated by default
Specifics please?
it has the potential to increase compile time largely
Huh?
If the user enters Surely there is some reasonable way to show the warning message |
@ejgallego Would you respond to my last comments, which are from 4 weeks ago? Thanks. |
7eb61c4
to
5581da2
Compare
c556c8c
to
979d5b8
Compare
979d5b8
to
f413b1f
Compare
Ping @herbelin, @ejgallego This PR has been waiting for two months for a response from Emilio to my last comments. If there's no response within a week or so, would it be reasonable to proceed to merging this? |
My comments still hold AFAICS, I am not happy with |
Would you respond more specifically to what I said? I was not just repeating myself in my last comment. My comment deserves a bit more thought and more of a response. From the very long delay and your terse comments, one might think that you don't value the proposal or my comments very highly. Or perhaps you're just too busy? |
I do value your proposal a lot @jfehrle , in fact I'd like to provide some more detailed feedback, but I am just too busy as to get a long enough slot for it to happen sorry :( :( |
I wish I could provide you with a date but I'm afraid I can't at the moment :S |
@jfehrle: I'm trying to understand the status of the PR. At the level of the user interaction, the current status is:
Otherwise, at the level of the code, could it be possible to use less references so that the possible interaction between flags is easier to follow. Ideally, could we have global references (such as I mean, this is per se more general than this PR, but could this PR not add more side effects than there is already (e.g. no PS: As a side example of having little structure in option, if I do, say,
|
@herbelin The unresolved issue is how Coq can generate an error message if the user enters Implementing this requires preserving the state of The color-enabled variable should be set to true when Coq is run from CoqIDE since CoqIDE assumes color; there is no command-line setting for color. The options for such a global variable are:
I'm agnostic about the details of the code as long as there's a way to generate the error message in this use case.
Let me know your thoughts, thanks. |
f413b1f
to
8ba54f8
Compare
Question (a naive one because I did not investigate all places from where the diff mode is called): would it work to have Would this answer @ejgallego's argument (with which I sympathetize) that diffing should not know about color?
I have otherwise more general thoughts. On one side, options are already stored in references dispatched in several files such as If ever it takes more time, merging the PR as it is seems to be a good solution, keeping in mind that a model where options are treated functionally and generically may eventually be adopted (see #9585 which I just created about this), avoiding in particular |
No, this wouldn't help--I already changed the code so the compute/print diffs part doesn't examine the color setting at all. The color setting is used only to generate a warning to the user when they try to
I'd be interested in seeing any proposal.
I'll wait to hear from @ejgallego in early March. We can consider merging as-is after that if the substantive discussion doesn't happen. In any case, let's get some form of this PR into master before 8.10 starts--a one-year delay (if it's not in 8.10) on shipping this seems unreasonable. |
122651d
to
faf2c9f
Compare
faf2c9f
to
ef2fce9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jfehrle , sorry for the delay on handling this, I had the impression that it would take me more than than it did; I still have some wishes w.r.t. general code organization of the diffs feature, but IMHO they should not block this patch which can be merged now.
I still believe that the diffs code should be agnostic to the output device, and the algorithm's domain changed, but surely these concerns can be addressed later [some of them will hopefully be when I get a slot to rebase #8728
Reviewed-by: Zimmi48 Reviewed-by: ejgallego Ack-by: gares Ack-by: jfehrle
Kind: feature.
Fixes: #8366
Show diffs for error messages that compare 2 similar values (when diffs are enabled).
For example, instead of:
it will be easier to pick out the differences between the "Unable to unify" expressions if they're highlighted:
In CoqIDE: