Skip to content
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

Proof process hang with bad tactics in Coq #514

Closed
mgree opened this issue Oct 6, 2020 · 15 comments
Closed

Proof process hang with bad tactics in Coq #514

mgree opened this issue Oct 6, 2020 · 15 comments

Comments

@mgree
Copy link

mgree commented Oct 6, 2020

When running the following script:

Theorem thm : True.
Proof. assert True.{ reflexivity. } apply H. Qed.

The proof process will hang when it gets to the first opening brace. I'm able to break things with C-c C-x, but some students have reported a general Emacs hang.

I'm running Emacs 26.3, Coq 8.10.2 (students are running 8.12.0), and ProofGeneral 20200623.1748. I'm on macOS 10.13.6.

@mgree mgree changed the title Proof process hang with bad tactics in Coq``` Proof process hang with bad tactics in Coq Oct 6, 2020
@cpitclaudel
Copy link
Member

The general Emacs hang seems surprising; do you / they have a repro? Otherwise, yes, there are many known ways to confuse the REPL, including defining notations that include periods or sending things to Coq that looks like sentence endings to Proof General. Migrating away from the REPL is the only robust solution here, I think.

@mgree
Copy link
Author

mgree commented Oct 6, 2020

I'm trying to work with students to get a repro, but (a) it's challenging with novices (this is a CS 2 course!) and (b) it's even more challenging with remote instruction. It could be that they're not aware of appropriate ways to break from the prover loop.

My understanding is that there are some longer term plans to switch to a better protocol... do you know where I can track that progress?

@cpitclaudel
Copy link
Member

It could be that they're not aware of appropriate ways to break from the prover loop.

I think pressing C-c C-c should break out of that loop (:crossed_fingers:)

My understanding is that there are some longer term plans to switch to a better protocol... do you know where I can track that progress?

We don't really have progress being tracked, unfortunately

@hendriktews
Copy link
Collaborator

hendriktews commented Oct 6, 2020 via email

@mgree
Copy link
Author

mgree commented Oct 6, 2020

C-c C-c does break for me, and such a hint or message would be helpful. I think this is the best course of action.

My memory says that sometimes C-c C-c doesn't work and C-c C-x is necessary, but I haven't been able to reproduce it. So, until students can help me out here, nevermind on that part.

I had not thought before about how Proof General knew what constituted a whole tactic. With Notations and Ltac in all its glory, it does seem challenging to get things right 100% of the time. That said, a tiny improvement here would save a great deal of trouble... if there were a way to be confident that it wouldn't regress behaviors for others' proofs.

@cpitclaudel
Copy link
Member

C-c C-c does break for me, and such a hint or message would be helpful.

It's difficult to give a hint reliably, because Proof General has no way to know (when speaking to the REPL) whether Coq is busy computing or whether it's waiting for more input.

I had not thought before about how Proof General knew what constituted a whole tactic. With Notations and Ltac in all its glory, it does seem challenging to get things right 100% of the time.

Yes, it's insane. The proper way is to let Coq do the parsing :)

@mgree
Copy link
Author

mgree commented Oct 7, 2020

While it seems risky to try to patch up the regex parser, a different parser might be able to diagnose when to give the hint. One such policy might be: when a multi-character command doesn't end in .[:space:]*.

Alternatively, a tiny hint appearing in *response* or minibuffer or in a modeline somewhere after 1 second would be harmless. (Make the timer configurable, so setting it to nil turns off the behavior?) C-c C-c isn't a bad thing to be reminded of for a long running tactic anyway...

@cpitclaudel
Copy link
Member

cpitclaudel commented Oct 7, 2020

One such policy might be: when a multi-character command doesn't end in .[:space:]*.

We'd also want to rule the hint out for :{ as well as ..., I think.

Alternatively, a tiny hint appearing in *response* or minibuffer or in a modeline somewhere after 1 second would be harmless. (Make the timer configurable, so setting it to nil turns off the behavior?) C-c C-c isn't a bad thing to be reminded of for a long running tactic anyway...

Not a bad idea at all :) I won't have time to work on it but I'd be happy to review the code

@hendriktews
Copy link
Collaborator

hendriktews commented Oct 7, 2020 via email

@mgree
Copy link
Author

mgree commented Oct 8, 2020

I was able to reproduce an Emacs freeze with a student today, with exactly the same example They were using Windows 10.

Using C-c C-c to interrupt the prover locked the Emacs entirely. Using C-c C-x worked.

EDIT: thinking about this more, I wonder if the issue is with the signal/process model on Windows. Dribs and drabs from old mailing list posts seem related to this issue, but nothing recent. Not sure when I'll have time to debug it, though.

@Matafou
Copy link
Contributor

Matafou commented Oct 12, 2020

Hi,
given that neither emacs nor coqtop is in a loop during this freeze, I suspect indeed a problem with interrupt signals.
Can you give the repro please?

I agree with Hendrik: only coq can parse coq files correctly. In this particular case the error is due to the fact that { if just after an end of command is itself an end of command (because it starts a parenthesized script). Notice by the way that this is recursive: Proof. {{{{ is actually 5 different commands).

So it seems that in .{ the { is wrongly detected as an end of command whereas it is not since the . isn't.

I will try to fix this.
P.

@mgree
Copy link
Author

mgree commented Oct 12, 2020

To reproduce, enter the following into a coq-mode buffer named test.v on Windows:

Theorem thm : True.
Proof. assert True.{reflexivity.} apply H. Qed.

Put your cursor after } and hit C-c C-RET. Running C-c C-c will not work. After running C-c C-c, if I try C-c C-x, emacs hangs with "Retracting buffer test.v...". On my computer, Emacs eventually manages to stop Coq and control is returned to Emacs after, say, 30s; on a students' (less powerful) computer, the hourglass appeared and he killed Emacs before we could wait it out.

I'm sorry this isn't the best quality repro possible... 😕

@Matafou
Copy link
Contributor

Matafou commented Oct 12, 2020

Thanks.
On my linux C-c C-c works immediately, so I guess this is a bug in coq for windows.

andyqhan added a commit to andyqhan/PG that referenced this issue Oct 12, 2020
andyqhan added a commit to andyqhan/PG that referenced this issue Oct 12, 2020
andyqhan added a commit to andyqhan/PG that referenced this issue Oct 12, 2020
@mgree
Copy link
Author

mgree commented Oct 12, 2020

I should add that it works immediately on macOS, too---I suspect it's a platform-dependent SIGINT issue.

Matafou added a commit that referenced this issue Oct 16, 2020
It was hard to separate this too fixes (same regexps).
Matafou added a commit that referenced this issue Oct 16, 2020
It was hard to separate this too fixes (same regexps).
@Matafou
Copy link
Contributor

Matafou commented Oct 16, 2020

I submitted a fix. It makes thing a bit more robust, but not perfect.

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

No branches or pull requests

4 participants