wasm: revamp JSFFI internal implementation and documentation
This patch revamps the wasm backend's JSFFI internal implementation and documentation: - `JSValManager` logic to allocate a key is simplified to simple bumping. According to experiments with all major browsers, the internal `Map` would overflow the heap much earlier before we really exhaust the 32-bit key space, so there's no point in the extra complexity. - `freeJSVal` is now idempotent and safe to call more than once. This is achieved by attaching the `StablePtr#` to the `JSVal#` closure and nullifying it when calling `freeJSVal`, so the same stable pointer cannot be double freed. - `mkWeakJSVal` no longer exposes the internal `Weak#` pointer and always creates a new `Weak#` on the fly. Otherwise by finalizing that `Weak#`, user could accidentally drop the `JSVal`, but `mkWeakJSVal` is only supposed to create a `Weak` that observes the `JSVal`'s liveliness without actually interfering it. - `PromisePendingException` is no longer exported since it's never meant to be caught by user code; it's a severe bug if it's actually raised at runtime. - Everything exported by user-facing `GHC.Wasm.Prim` now has proper haddock documentation. - Note [JSVal representation for wasm] has been updated to reflect the new JSVal# memory layout. (cherry picked from commit fd40eaa1)
Showing
- docs/users_guide/wasm.rst 4 additions, 4 deletionsdocs/users_guide/wasm.rst
- libraries/ghc-experimental/src/GHC/Wasm/Prim.hs 4 additions, 5 deletionslibraries/ghc-experimental/src/GHC/Wasm/Prim.hs
- libraries/ghc-internal/src/GHC/Internal/Wasm/Prim.hs 4 additions, 5 deletionslibraries/ghc-internal/src/GHC/Internal/Wasm/Prim.hs
- libraries/ghc-internal/src/GHC/Internal/Wasm/Prim/Exports.hs 8 additions, 4 deletionslibraries/ghc-internal/src/GHC/Internal/Wasm/Prim/Exports.hs
- libraries/ghc-internal/src/GHC/Internal/Wasm/Prim/Flag.hs 4 additions, 0 deletionslibraries/ghc-internal/src/GHC/Internal/Wasm/Prim/Flag.hs
- libraries/ghc-internal/src/GHC/Internal/Wasm/Prim/Types.hs 155 additions, 52 deletionslibraries/ghc-internal/src/GHC/Internal/Wasm/Prim/Types.hs
- rts/wasm/JSFFI.c 10 additions, 9 deletionsrts/wasm/JSFFI.c
- rts/wasm/jsval.cmm 26 additions, 3 deletionsrts/wasm/jsval.cmm
- testsuite/tests/jsffi/jsffigc.hs 1 addition, 1 deletiontestsuite/tests/jsffi/jsffigc.hs
- utils/jsffi/prelude.mjs 2 additions, 18 deletionsutils/jsffi/prelude.mjs
Loading