Add JavaScript backend
Giving GHC a proper JavaScript backend has been discussed before (#7496 (closed), #7933 (closed)) but it has never been done. We propose to do it by adapting code from GHCJS. Maintaining GHCJS out of GHC's tree is a lot of work that isn't sustainable. Moreover having a proper JS backend in GHC would make the compiler much easier to setup for end users and to maintain/enhance for GHC(JS) devs.
GHCJS's code currently relies on GHC 8.10 branch and there are several things that need to be adapted or removed. E.g. shims (JS code to replace C code) should be upstreamed in hackage libraries, we don't need to use GHC's hooks anymore, plugin support should be properly added (#20964 (closed), #14335), etc.
Hence we plan to add features one by one as if we were implementing the backend from scratch, except that we will copy/adapt a lot of code from GHCJS so the process should be faster and we already know that GHCJS's code works.
- Wiki page: https://gitlab.haskell.org/ghc/ghc/-/wikis/javascript-backend
- most up-to-date GHCJS branch: https://github.com/ghcjs/ghc/tree/ghc-8.10-ghcjs
- green GHCJS testsuite work: https://gitlab.haskell.org/ghc/ghc/-/commits/wip/jdm/ghcjs-testsuite/
TODO for 9.6:
-
Adapt GHCJS code into a new JS backend -
Make testsuite green -
Add CI job for the JS backend #22128 (closed) -
Merge JS backend into main branch
TODO later:
-
fix boot libraries that use C sources (reimplement in Haskell, in JS, or wait for C sources support via Emscripten) -
Reimplement GHCJS optimizations: -
compactor #22352 (closed) -
JS code optimizer (peephole optimization)
-
-
Implement HPC support -
Better documentation of the internals -
Reimplement "inline Javascript" feature of GHCJS that was done via custom FFI import syntax -
Implement support for C sources via an adapter for Emscripten generated code #22367 (closed) -
Support foreign exports (async/sync) -
Support Template Haskell with external interpreter
Our team at IOG is committed to do this but any help and feedback is appreciated.