-
Notifications
You must be signed in to change notification settings - Fork 676
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
Fix "Interrupt computations" on Windows #16142
Conversation
86d2b93
to
011fbdf
Compare
The dune file and the setup for the additional OS specific file seem pretty wordy. I'm open to suggestions on how to improve them. Rudi had some suggestions in #16139. |
011fbdf
to
a2b5c42
Compare
ide/coqide/coq.ml
Outdated
try !interrupter (CoqTop.unixpid coqtop.handle.proc) | ||
try | ||
let pid = CoqTop.unixpid coqtop.handle.proc in | ||
if Sys.os_type = "Win32" then begin |
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.
There is also a "Cygwin" value for this. Which windows setup does the issue occur on?
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.
The documentation you linked to says
"Cygwin" (for MS-Windows, OCaml compiled with Cygwin).
We don't support CoqIDE on Cygwin. Compiling CoqIDE with Cygwin libraries gives an unusable binary.
a2b5c42
to
d60e0da
Compare
Updated. @MSoegtropIMC, would you be willing to test this? I don't know of any other developer who has Windows available. |
@andrew-appel Your description of the behavior in #13550 is somewhat different from what I found. Please let me know if my description doesn't match the behavior you see. If it doesn't match, what version of Windows do you use? Did you see the issue with the 32-bit binaries and/or 64-bit binaries? I'm using Windows 10 with 64-bit binaries. |
@@ -0,0 +1,16 @@ | |||
#define _WIN32_WINNT 0x0501 /* Cf below, we restrict to */ | |||
|
|||
#include <caml/mlvalues.h> |
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.
We already have a C stub file per OS, is there a solid reason to add a new one? I think it's not very good practice from the OCaml world to have a lot of C stubs lying around (especially given that they're preprocessed).
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 didn't want to add the second one. win32_cvtpid
is used both in CoqIDE and in coqidetop. In the dune file, coqide_WIN32.ml.in
is part of library coqide_gui
. When I included win32_cvtpid
in coqide_WIN32.c.in
and included the library in the idetop
executable as @rgrinberg suggested, I got very strange behavior in CoqIDE (delay of a second or so for each character entered). I'm guessing that all the files in the library were not merely linked, but in fact loaded. So their let () = ...
expressions were executed rather than just the ones that were referenced, e.g. as in coqide_main.ml
, which is bad.
If there's a way to link specific modules without loading everything in the library, I'm all for it. I didn't understand Rudi's suggestion here well enough to try it.
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 figured out a way to avoid the need for shared_WIN32.c.in
and its friends. Now there's os_specific.ml
which has the references to C code (usable in both coqide and coqidetop) and gui_specific.ml
, containing items that depend on GTK and the GUI. Tedious to sort these out. If you're OK with this, I'll squash before the merge.
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 spoke too soon. It appears that Glib.Io.channel_of_descr_socket
in GTK is Windows-only. Whatever library contains that can't be linked into coqtopide
, while win32_cvtpid
must be linked into both coqide
and coqtopide
. It appears they need to be two separate libraries. Let's go with the first commit. I'll remove the second one momentarily.
4fa8ec1
to
45ecf17
Compare
This is something I believe most of the dev team is lacking unfortunately. I've had a visual look through your changes and they seem sound to me. If you have been able to get interrupt working on Windows again, then I trust it has been done properly. @MSoegtropIMC How do you test the Windows installations for Coq platform, especially CoqIDE. Would you be able to lend a hand testing this? |
@Alizter : I download the installer from CI, install it to some test folder and go through some test files from the smoke test kit in CoqIDE. I don't do fancy testing of CoqIDE - I would consider this to be part of Coq testing (not Coq Platform). In Coq Platform testing I concentrate on correct installation. I am fairly busy with Coq Platform (and other things), but if there is no one else with a Windows machine, I could give it a try. |
Thanks @MSoegtropIMC, whenever you have some spare time, if you could give this PR a test that would be most welcome. |
Hmm, if a lack of hardware is the main problem for potential testers, that seems like a readily solvable problem. I suppose it's also possible to install Windows in a virtual machine, but that may require more work to set up/maintain. There's also a question of how often we need to test on Windows (and perhaps whether the other Coq IDEs have much need to test on Windows). I hope to make more improvements to CoqIDE fairly soon, though most of them shouldn't have OS-specific code (as does this one). I think the harder part may be finding someone willing to test things from time to time. |
For installation in a VM you need a WIndows license and 16GB RAM. Since I switched to Mac (and VSCoq for that matter - except when I need your Ltac debugger, which is frequent wnough) I am only doing essential testing for CoqIDE on Windows - which is not sufficient to guarantee the quality we want. I will ask the Windows users I know if they can take some responsibility in testing Coq / CoqIDE / Coq Platform on Windows. |
45ecf17
to
5b06aa0
Compare
Let's not delay this any more waiting for a tester. While it would be good to have a second tester for Windows specific changes, the relevant functionality is almost completely broken on Windows, so there is little risk it will be worse than before. I have no specific reason to expect this PR may not work for others. @ppedrot If you have no further review comments, would you merge? Thanks. |
How about I take the patch into the 2022.09 beta release (I likely build the installers today and they should be signed on Monday)? There is anyway already a patch in for CoqIDE for the Mac preferences dialog crash. |
And I will send a reminder to the Windows users I had in mind ... |
I added this as opam level patch to the Coq Platform beta. |
@MSoegtropIMC Sounds good, thanks. |
Is this correct? The patch copied the code from the PR rather than depending on it, so if I change the code here, it won't affect the platform? |
@jfehrle : yes, a Coq Platform release is carved in stone. Since you asked this to be merged I guessed that this is appropriate. |
Great! I was thinking about when you did the debugger preview and my subsequent tweaking of the PR meant you had to update the platform a bit, too. |
This was a dev pick - the coqide package in it linked to a branch. |
@MSoegtropIMC I'm surprised to discover that this patch is included in the upcoming 8.16 beta Platform release. If that's the case, doesn't it mean that the patch should eventually be in 8.16.1 instead of 8.17? (cc @ppedrot) |
We can indeed backport this, it looks like an important bugfix. |
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.
Seems a bit contrived to me, but if it works...
@coqbot merge now |
(foreign_stubs | ||
(language c) | ||
(names coqide_os_stubs)) | ||
(libraries coqide-server.protocol coqide-server.core lablgtk3-sourceview3)) | ||
(optional) |
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 think this optional
wasn't meant to be added back
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.
Not the first time I see some old stuff being added back. Be careful with how you resolve merge conflicts @jfehrle 😉
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.
See #16672.
I am careful, but also fallible.
We could avoid some rebasing and resulting merge errors by reducing the long wait between writing the code and its merge (about 4 months for this fairly small PR). That's long enough to forget many details. It took me a couple hours over two days to remember how to build and retest the code on Windows. (The weirdest detail being that I can't push from the cygwin/Windows command line because I couldn't figure out how to set up the security token in Windows--as it was last time. I can only push from the WSL command line.)
Windows doesn't support signals, so another mechanism was used to support "Interrupt computations" in CoqIDE. On Windows, every process that shares a console (i.e. coqide and all the coqidetop's and worker processes) receives the interrupt. This PR creates an empty file in a temp directory to signal which coqtopide should pay attention to the interrupt. The others will ignore it.
For all major releases back to 8.5pl3, interrupt stops working in a buffer after it's been reset. The original code in
coqide_WIN32.c.in
dating from 2011 calledFreeConsole()
, which detaches coqide from the console. Then when you subsequently reset the CoqIDE buffer, creating a new process, the new coqidetop doesn't inherit the console, so it can't be interrupted.Also, contrary to the documentation, the
SetConsoleCtrlHandler
appears to affect more than the calling process. Removing that means that coqide will send the signal to itself, so I added code to ignore the signal in that case.I suspect the bug dates to the original code rather than being a regression. It's possible this worked in 2011 and that the behavior of these Windows calls has changed. I'm on Windows 10.
While I've tested this a lot, it would be nice to get someone with a fresh perspective to try it on Windows in case I missed something.
Fixes: #13550