Writing to C/C++ standard output causes the server file worker to hang
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 9.2k
- Forks
- 990
- Avg merge
- 1d 17h
- Merged PRs (30d)
- 175
Description
Prerequisites
- Put an X between the brackets on this line if you have done all of the following:
- Checked that your issue isn't already filed.
- Reduced the issue to a self-contained, reproducible test case.
Description
Lean server file workers hang eternally when code writes to the C/C++ standard output (i.e., not to the Lean standard output via IO methods). Restarting them in VS Code requires reloading the window (restarting the server does not restart the work).
Steps to Reproduce
- Pack the following C++ code:
extern.cpp:
#include <stdio.h>
#include <lean/io.h>
extern "C" uint32_t my_add(uint32_t a, uint32_t b) {
return a + b;
}
extern "C" lean_obj_res my_hello(lean_obj_arg /* w */) {
puts("Hello World");
return lean_io_result_mk_ok(lean_box(0));
}
And the following Lean code:
Extern.lean:
@[extern "my_hello"] constant myHello : IO PUnit
@[extern "my_add"] constant myAdd : UInt32 → UInt32 → UInt32
into a plugin.
- Run the following code with said plugin passed to the server:
Bug.lean:
import Extern
#eval myAdd 1 2 -- evaluates to 3, as expected
#eval myHello -- hangs eternally
- Observe the bug. Note that running this file with Lean directly produces the following output:
Hello World
3
Expected behavior:
Ideally, the message would appear in the Infoview. Alternatively, the output could be printed to the 'Output' tab of VS Code (like messages written to standard error) if the former is not possible.
Actual behavior:
The file worker hangs eternally.
Reproduces how often:
Always.
Versions
OS: Windows 20H2
Lean (version 4.0.0-nightly-2021-08-20, commit 1624e42a5d6d, Release)
Additional Information
This is follow-up of #639. I did some more testing and discovered this bug, which explains that issue. Since the error message for missing external symbols is written directly to the C/C++ standard output (see this line), it hangs.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the hang with extern.cpp, Extern.lean, and Bug.lean, then inspect src/library/compiler/ir_interpreter.cpp around the linked line 837 where missing external-symbol errors are written to C/C++ standard output. Compare server file-worker behavior with direct Lean execution; done means the worker no longer hangs and the output is handled through the expected Infoview or VS Code output path.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100