Skip to content
Snippets Groups Projects
  1. Mar 26, 2025
    • Cheng Shao's avatar
      wasm: make JSVal internal Weak# point to lifted JSVal · f4c51138
      Cheng Shao authored
      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 4f342431)
      f4c51138
    • Cheng Shao's avatar
      ghc-experimental: make JSVal abstract in GHC.Wasm.Prim · 4904a77d
      Cheng Shao authored
      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 8037f487)
      4904a77d
    • Cheng Shao's avatar
      compiler: avoid overwriting existing writers in putWithTables · a05bd287
      Cheng Shao authored
      This patch makes `putWithTables` avoid overwriting all existing
      UserData writers in the handle. This is crucial for GHC API users that
      use putWithUserData/getWithUserData for serialization logic that
      involve Names.
      
      (cherry picked from commit c331eebf)
      a05bd287
    • Cheng Shao's avatar
      wasm: add error message to WouldBlockException · 6a8fea39
      Cheng Shao authored
      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 9b54eecb)
      6a8fea39
    • Cheng Shao's avatar
      docs: document wasm backend JSFFI sync exports · 17686691
      Cheng Shao authored
      This commit updates wasm backend documentation to reflect the new
      JSFFI sync exports feature.
      
      (cherry picked from commit edae2874)
      17686691
    • Cheng Shao's avatar
      testsuite: test wasm backend JSFFI sync exports · 26deb7b2
      Cheng Shao authored
      This commit repurposes some existing JSFFI test cases to make them
      cover JSFFI sync exports as well.
      
      (cherry picked from commit b6ae908b)
      26deb7b2
    • Cheng Shao's avatar
      compiler: wasm backend JSFFI sync exports · f9bb0c3f
      Cheng Shao authored
      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 03ebab52)
      f9bb0c3f
    • Cheng Shao's avatar
      compiler: allow arbitrary label string for JSFFI exports · 7c7a9c06
      Cheng Shao authored
      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 a204df3a)
      7c7a9c06
    • Cheng Shao's avatar
      rts: fix top handler closure type signatures · 2499394e
      Cheng Shao authored
      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 c78d8f55)
      2499394e
    • Cheng Shao's avatar
      ghc-heap: fix HalfWord incompatible Binary instances for cross GHC · 4e0b5bfa
      Cheng Shao authored
      ghc-heap defines HalfWord as Word32/Word16 depending on host word
      size. For cross GHC with different host/target word sizes, the Binary
      instances are incompatible and breaks iserv serialization of any
      message type that involves HalfWord, breaking the ghci debugger. This
      patch fixes the issue and has been tested to fix ghci debugger
      functionality of the wasm backend. Fixes #25420 #25781.
      
      (cherry picked from commit b228fcb5)
      4e0b5bfa
    • Cheng Shao's avatar
      ghci: remove unused showBreakArray function · bc886a74
      Cheng Shao authored
      GHCi.BreakArray.showBreakArray is not used anywhere, hence the
      housecleaning.
      
      (cherry picked from commit 2d6a63ab)
      bc886a74
    • Cheng Shao's avatar
      hadrian: enable building docs for cross targets · dff08691
      Cheng Shao authored
      Hadrian used to omit the docs target as a part of binary-dist-dir for
      cross targets. This commit enables docs to be built as a part of cross
      bindists and it works just fine in CI.
      
      (cherry picked from commit a794e733)
      dff08691
    • Cheng Shao's avatar
      hadrian: enable building stage1 haddock for cross ghc · dc698595
      Cheng Shao authored
      This commit enables building stage1 haddock for cross ghc. Without
      this change, hadrian would panic with "Unknown program" error when
      building the _build/stage1/bin/cross-prefix-haddock program needed by
      the docs-haddock target, even if it only needs to copy from
      _build/stage0/bin/cross-prefix-haddock.
      
      (cherry picked from commit 272eaef0)
      dc698595
    • Fangyi Zhou's avatar
      wasm: use primitive opcodes for fabs and sqrt · 8a9f2c70
      Fangyi Zhou authored and Cheng Shao's avatar Cheng Shao committed
      - Add new `WasmInstr` constructor `WasmSqrt` for sqrt, corresponding to
        primitivie operations in wasm.
      - When lowering CallishMachOp, use `WasmAbs` and `WasmSqrt` for F32 and
        F64 fabs and sqrt.
      
      (cherry picked from commit 64b0d4d0)
      8a9f2c70
    • Cheng Shao's avatar
      libffi: update to 3.4.7 · 9a81511a
      Cheng Shao authored
      Bumps libffi submodule.
      
      (cherry picked from commit c318be56)
      9a81511a
    • Cheng Shao's avatar
      wasm: add Note [Variable passing in JSFFI] as !13583 follow up · 69d97c5e
      Cheng Shao authored
      This patch adds a note to explain how the magic variables like
      `__ghc_wasm_jsffi_dyld` are brought into scope of JSFFI code snippets,
      as follow up work of !13583.
      
      (cherry picked from commit f3bfe31e)
      69d97c5e
    • Cheng Shao's avatar
      driver: fix wasm backend sysroot lookup logic when -flto is passed · 28b18d26
      Cheng Shao authored
      For the wasm target, the driver calls `wasm32-wasi-clang
      --print-search-dirs` and finds the sysroot directory that contains
      libc.so etc, then passes the directory path to dyld. However, when GHC
      is configured with -flto as a part of C/C++ compiler flags, the clang
      driver would insert a llvm-lto specific directory in the
      --print-search-dirs output and the driver didn't take that into
      account. This patch fixes it and always selects the non-lto sysroot
      directory to be passed to dyld. This is one small step towards
      supporting building all cbits with lto for wasm.
      
      (cherry picked from commit 7eea38c8)
      28b18d26
    • Cheng Shao's avatar
      wasm: fix dyld for shared libraries created by llvm 20.x · f157d9c5
      Cheng Shao authored
      This patch fixes wasm dyld script for shared libraries created by llvm
      20.x. The __wasm_apply_data_relocs function is now optional and may be
      omitted for shared libraries without any runtime relocatable data
      segments, so only call __wasm_apply_data_relocs when it's present.
      
      (cherry picked from commit cb60da24)
      f157d9c5
    • Cheng Shao's avatar
      compiler: use fromAscList when applicable · 294906ce
      Cheng Shao authored
      This patch uses fromAscList (with O(n) complexity) instead of fromList
      (with O(nlogn) complexity) in certain Binary instances. It's safe to
      do so since the corresponding serialization logic is based on toList
      (same as toAscList).
      
      (cherry picked from commit 1c8e608a)
      294906ce
    • Cheng Shao's avatar
      testsuite: fix InternalCounters test with +debug_ghc · 1417e133
      Cheng Shao authored
      The `InternalCounters` test case fails when ghc is built with
      `+debug_ghc`. This patch skips it in that case and allows the
      testsuite to pass for the `+debug_ghc` flavour transformer.
      
      (cherry picked from commit 59b9307b)
      1417e133
    • Cheng Shao's avatar
      hadrian: so-mutex · 2ef5caea
      Cheng Shao authored
      2ef5caea
    • Cheng Shao's avatar
      compiler: remove unused assembleOneBCO function · 4a874fe5
      Cheng Shao authored
      This patch removes the unused assembleOneBCO function from the
      bytecode assembler.
      
      (cherry picked from commit 02794411)
      4a874fe5
    • Cheng Shao's avatar
      hadrian: fix bootstrap with 9.12.1 · e8314cc4
      Cheng Shao authored
      This patch bumps hadrian index-state to fix bootstrap with 9.12.1.
      
      (cherry picked from commit e16eae65)
      e8314cc4
    • Mateusz Goślinowski's avatar
      Allow multiline strings in JS FFI (#25633) · 3c7741a9
      Mateusz Goślinowski authored and Cheng Shao's avatar Cheng Shao committed
      (cherry picked from commit 14f8a7ec)
      3c7741a9
    • amesgen's avatar
      wasm: prevent bundlers from resolving import("node:timers") · 8206d4fd
      amesgen authored and Cheng Shao's avatar Cheng Shao committed
      This fixes the following esbuild error:
      
          ✘ [ERROR] Could not resolve "node:timers"
      
              www/ghc_wasm_jsffi.js:66:25:
                66 │     return (await import("node:timers")).setImmediate;
                   ╵                          ~~~~~~~~~~~~~
      
            The package "node:timers" wasn't found on the file system but is built into node. Are you trying
            to bundle for node? You can use "--platform=node" to do that, which will remove this error.
      
      Previously (i.e. after !13503), one had to work around this by passing
      `--external:node:timers`.
      
      (cherry picked from commit f6493dbc)
      8206d4fd
    • Cheng Shao's avatar
      xxhash: bump to v0.8.3 · 7009ee9d
      Cheng Shao authored
      (cherry picked from commit 42826a89)
      7009ee9d
    • Cheng Shao's avatar
      ci: avoid depending on stack job for test-bootstrap jobs · 2d32e8ce
      Cheng Shao authored
      This patch makes test-bootstrap related ci jobs only depend on
      hadrian-ghc-in-ghci job to finish, consistent with other jobs in the
      full-build stage generated by gen_ci.hs. This allows the jobs to be
      spawned earlier and improve overall pipeline parallelism.
      
      (cherry picked from commit e684c406)
      2d32e8ce
    • Cheng Shao's avatar
      ci: minor nix-in-docker improvements · 89563dd0
      Cheng Shao authored
      This patch makes some minor improvements re nix-in-docker logic in the
      ci configuration:
      
      - Update `nixos/nix` to the latest version
      - Apply $CPUS to `cores`/`max-jobs` to avoid oversubscribing while
        allowing a reasonable degree of parallelism
      - Remove redundant `--extra-experimental-features nix-command` in
        later `nix shell` invocations, it's already configured in
        `/etc/nix/nix.conf`
      
      (cherry picked from commit 291388e1)
      89563dd0
    • Cheng Shao's avatar
      compiler: remove unused GHC.Linker.Loader.loadExpr · 53dbac54
      Cheng Shao authored
      This patch removes the unused `GHC.Linker.Loader.loadExpr` function.
      It was moved from `GHC.Runtime.Linker.linkExpr` in `ghc-9.0` to
      `GHC.Linker.Loader.loadExpr` in `ghc-9.2`, and remain completely
      unused and untested ever since. There's also no third party user of
      this function to my best knowledge, so let's remove this. Anyone who
      wants to write their own GHC API function to load bytecode can consult
      the source code in older release branches.
      
      (cherry picked from commit 536cdf09)
      53dbac54
    • Cheng Shao's avatar
      wasm: fix foreign import javascript "wrapper" in TH/ghci · 1f773860
      Cheng Shao authored
      This patch fixes foreign import javascript "wrapper" in wasm backend's
      TH/ghci by fixing the handling of dyld/finalization_registry magic
      variables. Fixes T25473 and closes #25473.
      
      (cherry picked from commit bd0a8b7e)
      1f773860
    • Cheng Shao's avatar
      testsuite: add regression test T25473 · 0d8022d2
      Cheng Shao authored
      This commit adds regression test T25473 marked as broken due to #25473.
      It will be fixed in the subsequent commit.
      
      (cherry picked from commit ed2ed6c5)
      0d8022d2
    • Cheng Shao's avatar
      misc: improve clangd compile_flags.txt flags · 0aca9a59
      Cheng Shao authored
      This patch improves the compile_flags.txt config used to power clangd
      for the rts C codebase. The flags in the file are sampled & deduped
      from a real stage1 build with clang-19 and vastly improves the IDE
      accuracy when hacking the rts.
      
      For maximum code coverage under the default settings,
      compile_flags.txt defaults to threaded+profiled+dynamic+debug way.
      This does not mean profdyn needs to be actually built in _build/stage1
      for IDE to work. To activate IDE for other RTS ways, simply remove one
      of the -D flags at the end of compile_flags.txt and restart clangd.
      
      (cherry picked from commit 59e0a770)
      0aca9a59
    • Cheng Shao's avatar
      hadrian: fix bindist makefile for wasm32-wasi target · b2a8e60b
      Cheng Shao authored
      This patch fixes one incoherent place between bindist makefile and
      hadrian logic: I forgot to include wasi/wasm32 in
      OsSupportsGHCi/ArchSupportsGHCi as well. And this results in incorrect
      settings file generated after installing the bindist, and "Use
      interpreter"/"Have interpreter" fields incorrectly have "NO" values
      where they should be "YES" like --info output of in-tree version.
      
      (cherry picked from commit 75a2eae4)
      b2a8e60b
    • Cheng Shao's avatar
      Remove obsolete cross-port script · fb025170
      Cheng Shao authored
      This patch removes the obsolete cross-port script in the tree. The
      script was based on the legacy Make build system which has been pruned
      from the tree long ago. For hadrian, proper support for two-stage
      bootstrapping onto a new unsupported platform is a work in progress in
      !11444.
      
      (cherry picked from commit 00d551bf)
      fb025170
    • Cheng Shao's avatar
      wasm: fix FinalizationRegistry logic for Cloudflare Workers · 46ab4569
      Cheng Shao authored
      This patch fixes FinalizationRegistry related logic for Cloudflare
      Workers in wasm backend js post linker. Cloudflare Workers doesn't
      support FinalizationRegistry, in this case we use a dummy
      implementation that doesn't do anything.
      
      (cherry picked from commit bea8ea4c)
      46ab4569
    • Cheng Shao's avatar
      wasm: fix setImmediate() implementation for Cloudflare Workers · 92c2da2a
      Cheng Shao authored
      This patch fixes setImmediate() implementation for Cloudflare Workers
      in the wasm backend's js prelude script. Cloudflare Workers doesn't
      support the MessageChannel API, and we use a setTimeout() based
      fallback implementation in this case.
      
      (cherry picked from commit c37b96fa)
      92c2da2a
    • Cheng Shao's avatar
      Remove obsolete executable wrappers from the tree · 12252daf
      Cheng Shao authored
      The executable wrappers are handled by hadrian and bindist Makefile.
      The various .wrapper scripts in the tree are unused since removal of
      Make build system, so this patch removes them all.
      
      (cherry picked from commit 9ede97f3)
      12252daf
    • Cheng Shao's avatar
      Remove unused USE_REPORT_PRELUDE code paths from the tree · 5c3eb786
      Cheng Shao authored
      This patch removes unused `USE_REPORT_PRELUDE` code paths from the
      tree. They have been present since the first git revision
      4fb94ae5, and might have been useful
      for debugging purposes many years ago, but these code paths are never
      actually built. Removing these ease maintenance of relevant modules in
      the future, and also allows us to get rid of `CPP` extension in those
      modules as a nice byproduct.
      
      (cherry picked from commit 573cad4b)
      5c3eb786
    • Cheng Shao's avatar
      compiler: remove unused hscDecls/hscDeclsWithLocation · 034ef9a4
      Cheng Shao authored
      This patch removes unused `hscDecls`/`hscDeclsWithLocation` functions
      from the compiler, to reduce maintenance burden when doing
      refactorings related to ghci.
      
      (cherry picked from commit e3496ef6)
      034ef9a4
    • Cheng Shao's avatar
      wasm: fix safari console error message related to import("node:timers") · e545b6f6
      Cheng Shao authored
      This patch fixes the wasm backend JSFFI prelude script to avoid
      calling `import("node:timers")` on non-deno hosts. Safari doesn't like
      it and would print an error message to the console. Fixes
      https://gitlab.haskell.org/ghc/ghc-wasm-meta/-/issues/13.
      
      (cherry picked from commit 301c3b54)
      e545b6f6
Loading