-
d4489170
by Cheng Shao at 2025-11-21T15:50:36+01:00
rts: fix top handler closure type signatures
This commit fixes the runIO/runNonIO closure type signatures in the
RTS which should be extern StgClosure. This allows us to remove an
unnecessary type cast in the C foreign desugaring logic, as well as
unneeded complications of JSFFI desugaring logic that also needs to
generate C stubs that may refer to those top handler closures.
Otherwise, we'll have to take special care to avoid generating "extern
StgClosure" declarations for them as we would for other closures, just
to avoid conflicting type signature error at stub compile time.
(cherry picked from commit c78d8f55afacfd559b1602bc2fbc35b1f326f1c1)
-
18d6cf11
by Cheng Shao at 2025-11-21T15:50:36+01:00
compiler: allow arbitrary label string for JSFFI exports
This commit allows arbitrary label string to appear in a foreign
export declaration, as long as the calling convention is javascript.
Well, doesn't make sense to enforce it's a C function symbol for a
JSFFI declaration anyway, and it gets in the way of implementing the
"sync" flavour of exports.
(cherry picked from commit a204df3aa5a7be00c67aa7c92c5091ab32522226)
-
3ecb5e0b
by Cheng Shao at 2025-11-21T15:50:36+01:00
compiler: wasm backend JSFFI sync exports
This commit implements the synchronous flavour of the wasm backend
JSFFI exports:
- `foreign export javascript "foo sync"` exports a top-level Haskell
binding as a synchronous JS function
- `foreign import javascript "wrapper sync"` dynamically exports a
Haskell function closure as a synchronous JS function
- `foreign import javascript unsafe` is now re-entrant by lowering to
a safe ccall
- Also fix the issue that JSFFI dynamic exports didn't really work in
TH & ghci (#25473)
(cherry picked from commit 03ebab52bd00d4726735829cf6a24e5c9d3ac0c1)
-
5afe9c33
by Cheng Shao at 2025-11-21T15:50:36+01:00
testsuite: test wasm backend JSFFI sync exports
This commit repurposes some existing JSFFI test cases to make them
cover JSFFI sync exports as well.
(cherry picked from commit b6ae908bd3ae7b75b79925e56c3e11ba5c40b5ec)
-
9efbf3f4
by Cheng Shao at 2025-11-21T15:50:37+01:00
docs: document wasm backend JSFFI sync exports
This commit updates wasm backend documentation to reflect the new
JSFFI sync exports feature.
(cherry picked from commit edae287402792c09fa92b655e0cbd01100db9856)
-
61754416
by Cheng Shao at 2025-11-21T15:50:37+01:00
wasm: add error message to WouldBlockException
This commit attaches an error message to WouldBlockException, for now
the error message consists of the JS async import code snippet that
thunk is trying to block for. This is useful for debugging synchronous
callbacks that accidentally call an async JS function.
(cherry picked from commit 9b54eecbee7329543e5016cec1574831bfb788c2)
-
3b26d306
by Cheng Shao at 2025-11-21T15:50:37+01:00
ghc-experimental: make JSVal abstract in GHC.Wasm.Prim
This commit makes JSVal an abstract type in the export list of
GHC.Wasm.Prim. JSVal's internal representation is supposed to be a non
user facing implementation detail subject to change at any time. We
should only expose things that are newtypes of JSVal, not JSVal
itself.
(cherry picked from commit 8037f487ff1721973737b01e29136c671fd25157)
-
03600749
by Cheng Shao at 2025-11-21T15:50:37+01:00
wasm: make JSVal internal Weak# point to lifted JSVal
JSVal has an internal Weak# with the unlifted JSVal# object as key to
arrange its builtin finalization logic. The Weak# used to designate
Unit_closure as a dummy value; now this commit designates the lifted
JSVal closure as the Weak# value. This allows the implementation of
mkWeakJSVal which can be used to observe the liveliness of a JSVal and
attach a user-specified finalizer.
(cherry picked from commit 4f34243101684a0ad15f5986abec00c675b48955)
-
f66e52c8
by Cheng Shao at 2025-11-21T15:50:37+01:00
ghc-experimental: add mkWeakJSVal
This commit adds a mkWeakJSVal function that can be used to set up a
Weak pointer with a JSVal key to observe the key's lifetime and
optionally attach a finalizer.
(cherry picked from commit 55af20e6ed5c72a46a09b88e8590b6b2309eb41b)
-
da0ccd0e
by Cheng Shao at 2025-11-21T15:50:37+01:00
wasm: don't create a wasm global for dyld poison
There's a much more efficient way to convert an unsigned i32 to a
signed one. Thanks, o3-mini-high.
(cherry picked from commit 75fcc5c9ab900cb80834802c581283681cf8c398)
-
8003474f
by Cheng Shao at 2025-11-21T16:01:18+01:00
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 fd40eaa17c6ce8716ec2eacc95beae194a935352)
-
60acee61
by Cheng Shao at 2025-11-21T16:03:36+01:00
rts: add hs_try_putmvar_with_value to RTS API
This commit adds hs_try_putmvar_with_value to rts. It allows more
flexibility than hs_try_putmvar by taking an additional value argument
as a closure to be put into the MVar. This function is used & tested
by the wasm backend runtime, though it makes sense to expose it as a
public facing RTS API function as well.
(cherry picked from commit f75e823e0a9ac9fbe661fce232324c5b103ee8a8)
-
cdfb37c3
by Cheng Shao at 2025-11-21T16:03:36+01:00
wasm: use MVar as JSFFI import blocking mechanism
Previously, when blocking on a JSFFI import, we push a custom
stg_jsffi_block stack frame and arrange the `promise.then` callback to
write to that stack frame. It turns out we can simply use the good old
MVar to implement the blocking logic, with a few benefits:
- Less maintenance burden. We can drop the stg_jsffi_block related Cmm
code without loss of functionality.
- It interacts better with existing async exception mechanism. throwTo
would properly block the caller if the target thread is masking
async exceptions.
(cherry picked from commit 9cd9f34787b4d54e1ba3fbbf927a160a0f8eab99)
-
8dfb64de
by Cheng Shao at 2025-11-21T16:03:36+01:00
wasm: properly pin the raiseJSException closure
We used to use keepAlive# to pin the raiseJSException closure when
blocking on a JSFFI import thunk, since it can potentially be used by
RTS. But raiseJSException may be used in other places as well (e.g.
the promise.throwTo logic), and it's better to simply unconditionally
pin it in the JSFFI initialization logic.
(cherry picked from commit da34f0aa2082d1c5a306cc8356abba15f3d59aad)
-
0166eb5d
by Cheng Shao at 2025-11-21T16:03:36+01:00
wasm: implement promise.throwTo() for async JSFFI exports
This commit implements promise.throwTo() for wasm backend JSFFI
exports. This allows the JavaScript side to interrupt Haskell
computation by raising an async exception. See subsequent docs/test
commits for more details.
(cherry picked from commit dc904bfdd17ed1108580367b34bbe7204ed4ea95)
-
93de375e
by Cheng Shao at 2025-11-21T16:03:36+01:00
testsuite: add test for wasm promise.throwTo() logic
This commit adds a test case to test the wasm backend
promise.throwTo() logic.
(cherry picked from commit 7f80455ee45e70d142bbc69478b9a8db43082187)
-
791ac161
by Cheng Shao at 2025-11-21T16:03:36+01:00
docs: document the wasm backend promise.throwTo() feature
(cherry picked from commit afdd3fe7fff60e046f6a3ee4795c58abe81f03a2)
-
8d8807f2
by Cheng Shao at 2025-11-21T16:24:59+01:00
rts: fix wasm JSFFI initialization constructor code
This commit fixes wasm JSFFI initialization constructor code so that
the constructor is self-contained and avoids invoking a fake
__main_argc_argv function. The previous approach of reusing
__main_void logic in wasi-libc saves a tiny bit of code, at the
expense of link-time trouble whenever GHC links a wasm module without
-no-hs-main, in which case the driver-generated main function would
clash with the definition here, resulting in a linker error. It's
simply better to avoid messing with the main function, and it would
additionally allow linking wasm32-wasi command modules that does make
use of synchronous JSFFI.
(cherry picked from commit bdc9d130a838017f863f5c7a380cb0858035f859)
-
6d38b32c
by Cheng Shao at 2025-11-21T17:16:11+01:00
wasm: fix remaining regressions in upstream 9.12 branch
This commit fixes remaining regressions in upstream 9.12 branch caused
by broken backporting of !14892. Fixes #26600.
-
3cd27895
by Cheng Shao at 2025-11-25T14:30:05+01:00
docs: add wasm related items in 9.12.3 notes
-
bd923b84
by Ben Gamari at 2025-12-09T12:32:43+05:30
Revert "configure: do not set LLC/OPT/LLVMAS fallback values when FIND_LLVM_PROG fails"
While dropping these fallbacks is likely the right thing in the long
run, doing so now makes it needlessly difficult for users to use the
LLVM backend. See #26209. This will change once `ghc-toolchain` becomes
the default path.
This reverts commit 4eb5ad09cf93caa5791a735baa0e7ba86b916f2a.
(cherry picked from commit 9922faa74dcf7975def67ab82d27da05da7d29f2)
-
85edfeb1
by Zubin Duggal at 2025-12-09T12:35:05+05:30
rts/linker/PEi386: Copy strings before they are inserted into LoadedDllCache. The original strings are temporary and might be freed at an arbitrary point.
Fixes #26613
(cherry picked from commit 5072da477b8ec883aea4b9ea27763fcc1971af1a)
-
65621219
by Zubin Duggal at 2025-12-09T22:32:33+05:30
haddock: Bump version to 2.32.0