Skip to content

Coq: run silently and explicitly Show when necessary - second attempt #762

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

Merged
merged 4 commits into from
May 16, 2025

Conversation

hendriktews
Copy link
Collaborator

This is another attempt towards fixing #568.

@hendriktews
Copy link
Collaborator Author

@Matafou , @erikmd , @cpitclaudel : With the option coq-run-completely-silent to switch back to old behavior, I believe the risk of breaking a use case of some user is manageable. Therefore I suggest to merge this in about a week.

@erikmd
Copy link
Member

erikmd commented May 12, 2024

Hi @hendriktews!

(I just quickly skimmed the PR code but) LGTM, thanks.

With the option ..., I believe the risk of breaking a use case of some user is manageable. Therefore I suggest to merge this in about a week.

Agree

@Matafou
Copy link
Contributor

Matafou commented May 13, 2024

Maybe I need to test how it interacts with debug mode. I don't have much time this week though.

@Matafou
Copy link
Contributor

Matafou commented Sep 10, 2024

@hendriktews can you tell us what remains to be tested/adapted pls? I think this PR should not rot.
You said elsewhere that the prefix arg C-u for queries like coq-Print wouldn't work. What else?

@hendriktews
Copy link
Collaborator Author

I use this code on a daily basis, so it is working for me. Remaining things that I know:

  • coq-Print with prefix arg
  • prooftree - I have local fixes on top of the commits in this PR to get prooftree working, but they need to be polished before uploading
  • I have never tried diff or debug mode, it would be nice, if somebody who knows what to expect could try this
  • Not sure if this is a problem: When you issue a search command (either via C-c C-a C-a or by typing Search into the buffer) inside a proof in two-pane mode (i.e., no response buffer visible), then the search results pop up in the response buffer only if there are results. That is, if you search for (3 + 4) you will be shown the current proof state. This might make the impression, search does not work at all. Outside a proof you will see an empty response buffer, making it obvious, that the search did not yield results.

@Matafou
Copy link
Contributor

Matafou commented Sep 12, 2024

I use this code on a daily basis, so it is working for me. Remaining things that I know:

* coq-Print with prefix arg

* prooftree - I have local fixes on top of the commits in this PR to get prooftree working, but they need to be polished before uploading

* I have never tried diff or debug mode, it would be nice, if somebody who knows what to expect could try this

I can test this.

* Not sure if this is a problem: [...] This might make the impression, search does not work at all.

I think this is a problem. I must admit I am always in 3 windows mode.

@hendriktews
Copy link
Collaborator Author

  • Not sure if this is a problem: [...] This might make the impression, search does not work at all.

I think this is a problem. I must admit I am always in 3 windows mode.

So it is not a problem for you. It is only a problem when there is no window showing the response buffer when you issue the command. Note that any nonempty response from the search command is correctly shown.

Meanwhile I discovered another problem:

  • When you are in proof mode without goals, i.e., just before you type QED, then no response from a search or locate command is visible, even in case these commands yield results.

@Matafou
Copy link
Contributor

Matafou commented Sep 19, 2024

  • Not sure if this is a problem: [...] This might make the impression, search does not work at all.

I think this is a problem. I must admit I am always in 3 windows mode.

So it is not a problem for you. It is only a problem when there is no window showing the response buffer when you issue the command. Note that any nonempty response from the search command is correctly shown.

No it is not a problem for me, but the lack of user feedback in this case is a (small) problem.

Meanwhile I discovered another problem:

* When you are in proof mode without goals, i.e., just before you type QED, then no response from a search or locate command is visible, even in case these commands yield results.

Indeed. It also happens after other messages like "This subproof is complete, ...".

The reason is that the search command is now followed by a Show. In this case the Show command triggers a response "No more goals.", which is detected as another response message instead of a goal message. Hence it immediately overwrites the response to the query.

I tested and adding "No more goals." to proof-shell-start-goals-regexp solves this problem, but it seems to trigger other problems, e.g. the message "No more goals." is not displayed in goals as expected. I think it is because "No more goals." is already in proof-shell-clear-goals-regexp and proof-shell-proof-completed-regexp. Understanding the interaction between these 3 variables is needed I guess.

@hendriktews hendriktews force-pushed the silent-2 branch 2 times, most recently from 942720d to 837fae8 Compare September 30, 2024 11:29
@hendriktews hendriktews force-pushed the silent-2 branch 2 times, most recently from 5bdedad to cf3398a Compare April 20, 2025 19:13
@Matafou
Copy link
Contributor

Matafou commented Apr 21, 2025

I support merging this now.
And see what happens with C-u prefix, debug mode (probably both rarely used) and anything else interacting with this. If ever we get an avalanche of bug reports then we will just switch the default value of coq-run-completely-silent to nil while we look for solutions.

@hendriktews
Copy link
Collaborator Author

OK, let's wait for another few days, in case somebody else wants to try it.
I have a simple fix for C-c C-a C-a with empty response, that also fixes C-c C-a C-a just before Qed. The same idea should also work for C-u coq-Print, I just need to roll it out.

@hendriktews
Copy link
Collaborator Author

Please excuse the delay, I thought it would be good to first add tests for the searches that get broken by this PR. Hopefully they are now ready, see #827

This is a step towards fixing ProofGeneral#568. It fixes the cases after Proof,
comments, auto, errors, Search and Check, leaving now 2 instead of 8
failing tests in ci/simple-tests/test-goals-present.el. Admitted is
not handled correctly any more, which is a regression.

Using proof-shell-handle-delayed-output-hook and
proof-shell-handle-error-or-interrupt-hook we issue a Show command as
a priority action item when the last (normal) action item has been
processed.

The new action item flag 'keep-response tells the generic machinery to
not clear the response buffer and to keep it present in two-pane mode
in case an error was detected or the last command was a Search or
Check that produced a response.

The new action item flag 'dont-show-when-silent is used to distinguish
the additional Show commands and to avoid an endless loop of Show
commands.

Set proof-shell-last-output-kind now in
proof-shell-handle-delayed-output such that it correctly reflects the
cases of goals and response (which has not been the case since commit
037dc9b from 2009.

This commit breaks coq-show-proof-stepwise to some extend. Expect
080_coq-test-regression-show-proof-stepwise to fail.

Additionally:
- update manuals
- expect errors in tests 020_coq-test-definition,
  090_coq-test-regression-Fail and 091_coq-test-regression-Fail
  because messages are not printed in silent mode
Add user option coq-run-completely-silent, which, when disabled,
switches Coq to old behavior where Coq is dynamically switched to
silent on longer action item lists.
- Inside the urgent prooftree action, call now the proof assistant
  specific function `proof-tree-assistant-specific-urgent-action'. For
  Coq/Rocq this adds a show command which calls
  `proof-tree-display-goal-callback' in its callback, which processes
  the output and sends appropriate commands to prooftree.
- Move the call of the urgent prooftree action before calling adding
  `proof-shell-empty-action-list-command', such that these last
  actions happen after the show command.
- In `proof-shell-filter-manage-output', save the end of the previous
  command in new variable `proof-shell-old-proof-marker-position' such
  that callbacks running after the next command has been sent to Coq
  can access it. This is used inside
  `proof-tree-display-goal-callback'.
- proof-tree display is now only supported when Coq runs completely
  silent. Supporting it in the other mode should not be too difficult,
  but I don't think it is worth the effort.
@hendriktews
Copy link
Collaborator Author

The last update rebases this PR onto #827 and marks some of these new tests as expected to fail. If nobody objects, I'll merge this Friday.

@hendriktews hendriktews merged commit f5d929e into ProofGeneral:master May 16, 2025
146 checks passed
@hendriktews hendriktews deleted the silent-2 branch May 16, 2025 09:13
@@ -413,6 +422,13 @@ For example, COMMENT could be (*test-definition*)"
;; (coq-should-buffer-regexp (regexp-quote "The command has indeed failed with message: Tactic failure: Cannot solve this goal.") "*response*")

(ert-deftest 091_coq-test-regression-Fail()
;; XXX What is the difference between this test and
Copy link
Contributor

Choose a reason for hiding this comment

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

The point in coq file is not the same: "(FailNoTrace)" vs "(FailTrace)". Concretelty the difference is the command Local Unset Ltac Backtrace..

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

OK, it would be nice if the documentation in that file would describe what is tested there.

@@ -200,6 +200,8 @@ For example, COMMENT could be (*test-definition*)"


(ert-deftest 020_coq-test-definition ()
;; There are no infomsgr when running silent.
:expected-result :failed
Copy link
Contributor

Choose a reason for hiding this comment

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

We should probably test this when only one command is sent at a time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

AFAICT there is only one command processed in this test. Even if you process one definition alone, there is no infomsg when running silent.

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right. this behaviour is ok for me. I wonder if someone really care about this fonfirmation messages outside pure textual coqtop use.

@Matafou
Copy link
Contributor

Matafou commented May 16, 2025

This works like a charm. Thanks a lot @hendriktews for this work.

@Matafou
Copy link
Contributor

Matafou commented May 27, 2025

After a few days of work the only annoying thing for me is the "Set some option; do the command; unset the option" triggered by the C-u prefix. Like C-u C-a C-b eq RET. The commans are sent, but the last unset command makes the response buffer immediately empty.

@hendriktews
Copy link
Collaborator Author

Do you mean C-u C-c C-a C-b, i.e., coq-About? Have you tried PR #831, which is supposed to fix these cases? (See also the tests response-buffer-visible-coq-check-print-all-inside-poof and response-buffer-visible-coq-check-print-all-poof-end in ci/simple-tests/coq-test-goals-present.el)
The problem that is still left is when you type About eq. in your proof script buffer just before a Qed after you saw the No more goals message.

@Matafou
Copy link
Contributor

Matafou commented May 27, 2025

Right! I forgot to use the fix.

@proux01
Copy link

proux01 commented Aug 18, 2025

FWIW, I found the suppression of infomsg really bad. As a user I'm expecting them during interactive sessions.
A least, thanks for adding the coq-run-completely-silent variable that enables to disable this bad behavior, but it should be the default.

@hendriktews
Copy link
Collaborator Author

Please open an issue that describes under which situations you miss a message. Then we can add a test and maybe fix it.

@proux01
Copy link

proux01 commented Aug 19, 2025

Here it is: #842 but it's basically all over the place, not a single instance. Virtually any command can produce a worthwile infomsg.

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.

4 participants