base: treat all FDs as "nonblocking" on wasm
On posix platforms, when performing read/write on FDs, we check the nonblocking flag first. For FDs without this flag (e.g. stdout), we call fdReady() first, which in turn calls poll() to wait for I/O to be available on that FD. This is problematic for wasm32-wasi: although select()/poll() is supported via the poll_oneoff() wasi syscall, that syscall is rather heavyweight and runtime behavior differs in different wasi implementations. The issue is even worse when targeting browsers, given there's no satisfactory way to implement async I/O as a synchronous syscall, so existing JS polyfills for wasi often give up and simply return ENOSYS. Before we have a proper I/O manager that avoids poll_oneoff() for async I/O on wasm, this patch improves the status quo a lot by merely pretending all FDs are "nonblocking". Read/write on FDs will directly invoke read()/write(), which are much more reliably handled in existing wasi implementations, especially those in browsers. Fixes #23275 and the following test cases: T7773 isEOF001 openFile009 T4808 cgrun025 Approved by CLC proposal #234: https://github.com/haskell/core-libraries-committee/issues/234
Showing
- libraries/base/cbits/inputReady.c 4 additions, 0 deletionslibraries/base/cbits/inputReady.c
- libraries/base/changelog.md 2 additions, 0 deletionslibraries/base/changelog.md
- libraries/base/tests/IO/all.T 2 additions, 3 deletionslibraries/base/tests/IO/all.T
- libraries/base/tests/all.T 2 additions, 3 deletionslibraries/base/tests/all.T
- testsuite/tests/codeGen/should_run/all.T 1 addition, 1 deletiontestsuite/tests/codeGen/should_run/all.T
-
mentioned in commit b1af69d7
-
mentioned in commit ce9ac3eb
-
mentioned in commit 288692dd
-
mentioned in commit 9ad4d7db
-
mentioned in commit 8d4851e3
-
mentioned in commit bdf12485
-
mentioned in commit 8def5aa1
-
mentioned in commit 009cdcc5
-
mentioned in commit 18ad43d1
-
mentioned in commit 7fe96b29
-
mentioned in commit 37a97622
-
mentioned in commit b83e14d1
-
mentioned in commit a1a37769
-
mentioned in commit 641ed0c7
Please register or sign in to comment