Closed
Description
Recently a lot of work on thread support has been done in WASI: https://github.com/WebAssembly/wasi-threads
After our toolchain support threading, it will unlock offloading computationally heavy operations to threads.
Here is a list of tasks to support threads in SwiftWasm:
- 1. Enable wasm-ld's
--gc-sections
to unlock wasi-libc upgrade
Enable wasm-ld's--gc-sections
option for code size and import requirements #5128 - 2. Remove pthread hack #5547
- 3. Update wasi-libc to the version, which includes pthread implementation based on wasi-threads
- 4. Support
wasm32-unknown-wasi-threads
target triple - 5. Build stdlib with atomics enabled
- 6. Add compiler options to enable atomics feature in LLVM code generator
- 7. Setup Swift SDK distribution for the threaded SDK
- 8. Fix unaligned or too large atomic load/store in HeapObject.cpp
- https://github.com/apple/llvm-project/blob/d7f1b250afdb37a89d02731acb26912c1fff5625/clang/lib/CodeGen/CGAtomic.cpp#L837
This libcall requires libclang_rt.builtin.a to include atomic.c with atomics and bulk-memory features enabled, but it makes it difficult to share the archive between non-threaded target, so we should fix Swift runtime side.- Build libclang_rt.builtin for wasip1-threads target separately swiftwasm-build#288 will fix this
- 9. Add required options to toolset.json in Swift SDK
- 10. Implement a transformation pass for
i32.atomic.wait
-> spin lock to work around browser limitation on main thread- See Lack of atomic.wait on the main thread seems limiting to a fault WebAssembly/threads#106 about details of this limitation
- 11. JS polyfill implementation of wasi-threads based on Web Worker
Feedback and any help are welcome :)
Metadata
Metadata
Assignees
Labels
No labels