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
[xml protocol] [coqide] Alternative PR fixing some loc problems in master. #17382
Conversation
Also: the PR fixes the wrong error line numbers in Errors tab. For loading @MSoegtropIMC's test file Flocq's Pff.v, it takes for me 3mns (compared to ~1mn with coqc and ~1mn 15s with coqide 8.16). So this seems too long (but I don't know which PR caused this). Location, message and tooltip on warnings works for e.g. |
I'll let @coq/coqide-maintainers be the judges, but I would tend to find this an acceptable performance regression in CoqIDE. From what I recall, the previous performance regression was way worse on this file. This should also be compared with the alternative in #17348, rather than with Coq 8.16. Another point of comparison is that this PR currently passes CI fully, but #17348 does not (although its backport for Coq 8.17 does). |
Oh, but I didn't realize that this fix actually changes the XML protocol, so would be good for Coq So, we could merge #17381 in |
Yes this PR changes the XML protocol hence it would be master-only. Hugo's idea was to see whether we could do better in There should not be any performance regression in master w.r.t. large files, if that is happening then we got a bug, wouldn't be surprised. If someone can profile CoqIDE and see where the time is spent with this patch that could be helpful. |
As discussed in Zulip I can test CoqIDE but I see still PRs opened. Please let me know when is a good time to test and then also which commit to test. |
The point is precisely to test PRs before they are merged though. |
It's standard that CoqIDE + go-to-end is slower than coqc on the same file. I'll profile this to see whether this PR has anything to do with it but this is unlikely. (Also the problem wouldn't happen in the same process, in the first case it's coqidetop but in the second it's coqide proper.) |
Sure, but afaik there are several PRs and some pushed to again and I don't have the bandwidth to test it 5 times. So I need to know what the sweet spot is. Btw.: with CoqIDE 8.17+rc1 I get for my favourite IDE test file https://gitlab.inria.fr/flocq/flocq/-/blob/master/src/Pff/Pff.v a strange syntax error when stepping over the tactic definitions right at the top. |
2..3 minutes is normal. If it is bad it is more like an hour. |
FWIW the runtime of go-to-end with CoqIDE on Pff.v with both this PR and master are the same. Furthermore I don't see anything suspect, neither in the profiling of coqide nor on the one of coqidetop. So for me this is good. |
@ppedrot : I guess this means you also don't get the strange syntax error I am getting with 8.17+rc1. I am currently working on getting the smoke test kit in Coq Platform master working - in creates _CoqProject files, so one can load all files directly into CoqIDE. It should work again today evening. |
Also, as I've already ranted about at the WG this still looks fundamentally broken to me because the protocol confuses lines with sentences. You can trigger line desynchronization with the following snippet. Ltac wait n := match n with 0 => idtac | S ?n => wait n; wait n end.
#[deprecated(since="8.16")] Notation tt0 := tt.
Goal True.
Proof.
fail.
Qed.
Goal True.
Proof.
wait 20.
elim tt0.
Qed. To trigger the bug, eval to end and before the "wait 20" line returns, introduce random text in the first Proof-Qed block. This will cause the warning location to be shifted by as many lines inserted. This kind of problem can only be solved by making locations sentenceid-based, but I'm not sure we want this. This would require changing the protocol, again. |
Wasn't #17348 already changing the XML protocol (in the sense of changing the conventions about the positions returned in Message outputs of Coq)? Conversely, what convention are Coqtail or vscoq expecting the locations returned by Coq? As far as I'm concerned, if Coqtail and vscoq are fine with the PR (i.e., see next comment, if neither #17348 nor this PR change their use of the protocol - up to adding a fallback when bol_pos and cie are not present, but this is easy to do), the locs seem good in what I tested and I would recommend merging the PR.
Then, ok, let's not make the current 2-3mns situation "blocking" (reminding that these 2-3 mins are indeed unrelated to this PR).
My (vague) perception is that the cause of the loc shift when interactively editing (also reported in #17023) is not about the use of lines per se but about how a returned message is dynamically "relocated" wrt to the beginning of the input initially sent (rather than kept relatively to the beginning of the buffer). |
So that it is possible to understand if vscoq is affected by either #17023 or PR, can someone (presumably @maximedenes or @gares I guess) explain the requirement for vscoq:
So that we know if has to be mandatorily a revert of #17023 or if this PR is ok (again knowing that the protocol can be made compatible if the way locs are interpreted in #17023 is not a problem). (Incidentally has someone in mind the summary of what had been the successive conventions regarding locating the Coq output along the history of the protocol?) |
The fix I proposed in #17012 handles this case just fine without changing the protocol and so could be included in 8.17. (IIRC it needs a little more work to handle the case when loc is not None--I abandoned the effort when this PR was dismissed out of hand. Edit: This example does, in fact, pass loc in the XML.) |
40ee30d
to
8c37244
Compare
Fixed by the last commit. Actually you only need to compensate for the offset difference of when the tooltip was created. At some we had a similar mechanism but was broken for other reasons, it should be now more principled.
Only may be a too strong statement here, given any sentence, you can actually compute the absolute offset that the sentenced has moved when compared to its creation, so you can adjust locations that were created a sentence-creation time, as done now. So no change in the protocol needed, just proper handling of information lifetime (in particular when you wanna do some incremental stuff such as not regenerating tooltips in later parts of the document) |
@jfehrle: if I'm correct, the fix in #17012 (for None) was included in #16978, right? I tested warnings, errors and tooltip in vscoq.
My conclusion on these tests is that this PR is not worse for vscoq than previous statuses. I don't know how to test coqtail. (*) maybe the same +1 missing somewhere in vscoq as it was in Coqide at some time? |
The code for the None case looks like it's probably equivalent. The code for the Some case was not included. Hard to remember who did what when 3 months after working on it. And hard to visualize the net change when it's split across multiple PRs.
Meaning this PR or #17012? |
You've adopted my approach, which is to save and apply the original offset in the sentence. Earlier you were rejecting that out of hand. (At the time, you seemed unable or unwilling to understand my short code.) If you use that approach, you don't need to modify the protocol at all. That seems like a better solution. |
Same analysis with coqide (confirming the analysis of @Zimmi48 here:
So, shortly, the PR looks good to me (no change for vscoq, improvement for coqide, even though the ltac breakpoint is still off by one and the tooltip on |
This PR (with or w/o the 3rd commit, which is anyway only for the case you add text while it is running, iiuc; the extra commit does not restore the empty tooltip on |
@herbelin the missing tooltip in focus is due to the tooltip being attached to the wrong sentence, the code in That's beyond what we can fix here I think. |
Yes, I don't think it is important to fix now (even if, apparently, vscoq knows how to do it correctly). So, @Zimmi48 may merge the PR tomorrow, if no opposition? |
Are you sure? I don't see that behavior with this PR. I'm on Windows+WSL if it is perhaps a machine/library version issue. (I couldn't remember the incantation to build and test on 8.16. I certainly would have noticed such an obvious debugger issue long ago.) |
I used the following example:
If I press F8 on the |
You have to click before you press F8. Do you see the cursor in this position before you press F8? If I press F8 at this point, CoqIDE highlights the "i". Click-drag to select text works uses similar cursor positioning. If you click on the left half of a character, the cursor goes before the character and otherwise after it. |
Yes, it is like you describe. I think I just got confused with the text in the reference manual which says "position the cursor on the first character of the tactic name in an Ltac construct", which I wrongly interpreted as "select the first character of the tactic name in an Ltac construct". |
If this PR is for master only, I'd rather have a CoqIDE maintainer merge it and I would handle the merging of the v8.17-only PR. |
@ejgallego any progress on this? |
@ejgallego This PR makes it already way better than we have on master, and it's a blocking issue for the 8.18 release. If you don't have a look soon, I'll forcefully merge this PR so that it does not delay 8.18. |
Indeed! Either this PR, or the solution that was merged in v8.17, should be merged in master and available in 8.18. |
Otherwise XML users can't use line number information coming from Coq.
…ove. This restores display of tooltips, same technique could be applied to other bugs.
This was a silly typo.
This was broken for a long time, likely since the debugger patch, see comment.
Turns out that we need to be a bit more careful at mark addition points as sometimes our info is coming from buffer's view and other times location information is coming from Coq which has an outdated view. For the tooltips, we make the choice to store them in Coq locations, which seems like a reasonable ground truth, as in the IDE side things could be much more dynamic, but it is also very efficient to perform the correction as the GTK iterators have the needed info in constant time. We also need to compute the drift of the line for the UTF-8 conversion fiction, otherwise we get things wrong on line-drifts.
1581a8f
to
8192c35
Compare
Ok, found the last problem, I think this looks ready to me. Last commit contains the detailed information, but basically we need to be careful about what our ground truth for locations are, and correct in all cases (coqide likes to use location sources with are related to the Coq location truth in different ways) Also, due to the UTF-8 conversion routine, we need to compute line_drift. All the examples I could come up with seem to be working now; I'd be there are more bugs lurking around (maybe the "errors" panel doesn't account for drift properly?), but IIANM, the current infrastructure should be solid in that sense and allow for quick fixes. |
@coqbot merge now |
@ppedrot: You cannot merge this PR because:
|
@coqbot merge now |
@ppedrot: You can't merge the PR because some changes are requested. |
@coqbot merge now |
@@ -40,13 +40,16 @@ module SentenceId : sig | |||
mutable flags : flag list; | |||
mutable tooltips : (int * int * string) list; | |||
start_offset : int; | |||
(** Original start offset of the sentence, to be compared when moved *) | |||
start_line : int; | |||
(** Original start line of the sentence, to be compared when moved *) |
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.
To clarify semantics, "Original" here means "location Coq thinks the sentence is at."
The start
/ stop
marks do contain the buffer real location of the sentence, so offset_compensation
below can be used to apply / track the delta between the two.
@herbelin suggested to have a look at the current status of Coq master problems, so indeed, the main source of pain on what we could see is just that the locations are not fully serialized, in particular missing line number on the protocol wire impedes us to properly handle Coq locations effectively (and without hacks).
We also fix a off-by-one error we hand't spot due to the missing line info.
We have verified that this PR seems to fix the loc part of #17023 , modulo the 8.16 behavior, which as noted by Théo is:
Not sure about the
idtac
display and we didn't get CoqIDE to display it, neither in 8.16.We submit this PR for testing against #17348 , as to see if
master
revert to 8.16 vsmaster
+ this fix has more bugs.Fixes #17023 fixes #16987