Biweekly update from the GHC DevX team at IOG.
IOG GHC Update #7
· 3 min read
Haskell DevX Engineer @ IOG
Haskell DevX Engineer @ IOG
Haskell DevX Engineer @ IOG
Haskell DevX Engineer @ IOG
Haskell DevX Intern @ IOG
Biweekly update from the GHC DevX team at IOG.
Biweekly update from the GHC DevX team at IOG.
Biweekly update from the GHC DevX team at IOG.
Biweekly update from the GHC DevX team at IOG.
Biweekly update from the GHC DevX team at IOG.
This is the second biweekly update of the IOG GHC DevX team. You can find the previous one here.
Starting in 2023 we–the IOG GHC DevX team–are going to provide biweekly updates about our work. This is the first edition.
This is the July 2022 monthly update from the GHC DevX team at IOG.
For a few months we have been merging GHCJS (Haskell to JavaScript compiler) into GHC. We set our first milestone to be the ability to compile and to run the usual "Hello World" program. This month we finally reached it!
We are now focusing on:
fixing failing tests in GHC's testsuite (~2800 unexpected failures). To do that, we have to implement new primops, to fix bugs we introduced while we ported the code from GHCJS, etc.
implementing support for the "js-sources" Cabal stanza in Hadrian. Currently the JS backend finds the JS sources required for the RTS and for base into explicitly defined location. It was only a stop-gap measure and we now need to implement proper support for user-provided JavaScript files.
documenting and refactoring the source code and making it similar to other GHC modules. As an example, GHCJS used the text package which isn't a boot package. Hence we first switched to use GHC's ShortText implementation and now we switched to a FastString based implementation.
adding back GHCJS's features that we haven't ported for some reasons (e.g. the compactor, TH, etc.).
You can follow our progress on our development branch here.
For the time being, we will focus blog post topics on GHCJS internals and related topics. A few of these blog posts are currently under review and should be published shortly.
This is the June 2022 monthly update from the GHC DevX team at IOG.
For a few months we have been merging GHCJS (Haskell to JavaScript compiler) into GHC. We set our first milestone to be the ability to compile and to run the usual "Hello World" program. It turned out to be much more involved than we initially thought (requiring FFI support, etc.), but we should be getting there soon.
This month we have made the following progress:
Linking: GHCJS requires some functions to be directly implemented in
JavaScript (e.g. the RTS, some low-level functions in base). We have added support
for linking .js files. We've also added support for a preprocessing pass with CPP
for .js.pp files.
js-sources: there is some ongoing work to load these external JavaScript
files from installed libraries. Cabal provides a js-sources stanza for this,
we need to adapt Hadrian to make use of it.
Binary vs Objectable: GHCJS used its own ByteString-based Objectable type-class: we replaced it with GHC's similar Binary type-class. Josh has published a blog post about their differences.
64-bit primops: we've added support for 64-bit primops (Word64# and Int64# types). In GHCJS (GHC 8.10), these were still implemented as foreign function calls. It's no longer true on GHC head.
base library: added CPP as required to support the JS backend. Ported and converted FFI imports from GHCJS to use JavaScript fat arrows (we haven't implemented GHCJS's fancy import syntax yet).
Now we can compile and link the "HelloWorld" program. To reach the first milestone we only have to fix the remaining runtime errors.
You can follow our progress on our development branch here. We now rebase this branch every Friday to avoid lagging too much behind GHC head.
The "Haskell Optimization Handbook" is an accepted proposal of the Haskell Foundation. Jeff has been steadily writing some initial material as per the project plan.
This is the May 2022 monthly update from the GHC DevX team at IOG.
For a few months we have been merging GHCJS (Haskell to JavaScript compiler) into GHC. We set our first milestone to be the ability to compile and to run the usual "Hello World" program. It turned out to be much more involved than we initially thought (requiring FFI support, etc.), but we should be getting there soon.
This month we have made the following progress:
RTS: we have modified Hadrian and rts.cabal in order to build a valid
native rts unit that GHC can use, in particular containing appropriate
header files.
linker: the JS linker has been hooked up with GHC's driver. We fixed several panics in the linker due to erroneous symbol generation code. These bugs were introduced while porting the code from the old 8.10 pretty-printing infrastructure to the newer one.
boot libraries: the JS backend can now build and link all the boot libraries. Note that we are not claiming that they are all usable yet. In particular complete FFI support is lacking, but the JS backend Hadrian build completes and so we can start using the produced JS cross-compiler.
levity polymorphism: building ghc-prim uncovered a lurking bug related to
levity polymorphism. It wasn't noticed in GHCJS 8.10 because it is also
related to the BoxedRep proposal that introduced a constructor application
in a commonly used RuntimeRep.
sized literals: support for new sized literals have been added to the code generator.
Now that have achieved a build process that actually produces a JS cross compiler, we are confronting and fixing issues in the produced JavaScript code, such as adding, managing, and debugging CPP conditional compilation blocks in JS shim files. You can follow our progress on our development branch here.
GHC doesn't support plugins in cross-compilers #14335. Some time ago, we came up with a solution called "external static plugins" !7377. These are plugins that are directly loaded from shared libaries, bypassing the issue with usual plugins.
Our colleague Shea Levy confirmed that the approach works, backported it to GHC 8.10, and has been working on making it work in stage1 cross-compilers for Windows. Kudos for this work, Shea.
As the current user-interface based on environment variables isn't convenient, we have been working on adding new command-line flags to GHC instead. We expect to propose this for integration into GHC when the new interface will be fully implemented.
Inspired by our friends and colleagues at Well-Typed and Tweag, we have been starting to write blog posts for IOG's engineering blog. They will mostly be about stuff we are working on or that we are interested in. Feel free to send us feedback about these posts and to send us topics you would be interested to read about.
The "Haskell Optimization Handbook" is an accepted proposal of the Haskell Foundation. Jeff has been working behind the scene to make this proposal concrete. More about this in the upcoming months.
Welcome to the (rather late) April 2022 monthly update from the GHC DevX team at IOG. Since the last update we've continued work on the upcoming JavaScript backend for GHC. Unfortunately, we have nothing to show quite yet but that doesn't mean nothing has happened! On the contrary, we've made great progress and are close to that crucial first milestone hello world. Besides our work on the JavaScript backend, we were pleased to finally push through the Modularizing GHC paper that Sylvain has been working on for 2+ years! It causes quite the splash on the Haskell discourse and reddit, we recommend reading it if you haven't already (links below). Alright, enough introduction let's get into the update.
We have made the following progresses in the implementation of a JavaScript backend for GHC (adapted from GHCJS):
linker: ported GHCJS's linker code into GHC. A lot of code was duplicated from GHC and slightly modified for GHCJS's needs, making the process far from trivial.
testsuite: fixed Hadrian to run GHC's testsuite with cross-compilers !7850. There are remaining issues though (see #21292).
build system: fixes for GHC's configure script were ported (e.g. support for
the "ghcjs" target in config.sub). GHCJS's custom
build script was integrated into configure.ac. We can now
configure the build with: ./configure --target=js-unknown-ghcjs
TH: we have conducted some experiments to find the best way to bridge GHCJS's TH runner and GHC's external interpreter. This will be described in details in a future blog post.
FFI: basic support for JavaScript FFI has been ported from GHCJS to GHC. We haven't ported the JavaScript parser, so we have dropped the fancy import syntax (e.g. "$1.xyz"). It should be enough to build boot libraries and we will add JS parsing support later.
At this stage, we are working on building boot libraries and on supporting linking with the JS RTS.
Development happens in the following branch: https://gitlab.haskell.org/ghc/ghc/-/tree/wip/js-staging
Sylvain, Jeffrey, and John Ericson (from Obsidian Systems) wrote a paper about "modularizing GHC" using domain-driven design.
We've got a lot of great feedback about it (expect a first revision soon). We also got a GHC contribution directly inspired by the paper (see !8160) which was very welcome!
In March the team focused on porting more GHCJS code to GHC head.
This month we worked on adapting code from GHCJS to merge into GHC head. We also started discussing the implementation process publicly and especially with our colleagues at Well-Typed.
deriveConstants is a program used to generate some header file included in the rts package. While it is mainly useful for native targets, we had to make it support Javascript targets [!7585]RuntimeRep to represent these values for Haskell codes interacting with JS codes via FFI. We opened !7577 into which we tried to make this new RuntimeRep non JS specific so that it could be reused for future backends targeting other managed platforms (e.g. CLR, JVM). It triggered a lot of discussions summarized in #21142.-c -fjavascript. It required many changes, not only to adapt to changes between GHC 8.10 and GHC head but also to avoid adding new package dependencies. It was also an opportunity to refactor and to document the code, which is still a work in progress.case alternatives in STG lacked them because they were represented with a triple. We took the opportunity to introduce a proper record type for them !7652plutus-ledger-constraints package. [Report]IOG is committed to improving Haskell developer experience, both by sponsoring the Haskell Foundation and by directly founding a team committed to this task: the Haskell DX team.
The team now tries to provide regular (monthly) updates about its work. This post is a bit longer because it covers all of 2021 which has not been covered anywhere else.
Word8, Int16...) use their unlifted counterparts (e.g. Word8#, Int16#...); in GHC 8.10.7 – a minor release – a less invasive but more fragile solution was implemented [commit].--target=... command-line flag [#11470]. It also means that a cross-compiling GHC could build plugins for its host platform in addition to building code for its target platform.fromIntegral function used to have many associated rewrite rules to make it fast (avoiding heap allocation of a passthrough Integer when possible) that were difficult to manage due to the combinatorial number of needed rules (#19907, #20062). We found a way to remove all these rules (!5862).DynFlags (parsed command-line flags):ghc --info. ghc-bignum now exposes a backendName function for this purpose [#20495,!6903]tmpDir from Settings to DynFlags [!6297]unsafePerfomIO in getProgName [!6137]ptext . sLit with text [!5625]HscEnv):-dynamic-too handling [#19264,!4905]divInt#, modInt# and divModInt# branchless and inlineable [#18067,#19636,!3229]showWord to use quotRemWordN [!5891,!5846]appendFS [!5989]replicateM . length with more efficient code [!7198]. No performance gain this time but the next reader of this code won’t have to wonder if fixing it could improve performance.exprIsCheapX inline for modest but easy perf improvements [!7183]Monoid ([a],[b]) operations in the driver [!7069], leading to 1.9% reduction in compiler allocations in MultiLayerModules test.platformConstants file; made GHC load constants from the RTS unit instead, allowing it to be reinstalled with different constants [!5427]deriveConstants output its file atomically [#19684,!5520]xz faster on CI [!5066]-no-hs-main [#18938,!4974]hi-boot dependencies with ghc -M [#14482,!4876]hi-file-parser to support GHC 8.10 and 9.0 [PR, Stack#5134]Hopefully 2022 should be the year GHC will get a JavaScript backend without relying on GHCJS. This month the team has been busy planning the work that needs to be done to get there!
DynFlags) [#17957, !7158, !7199, !7325]. This work resulted in a 10% reduction in call sites to DynFlags and has now removed all references to DynFlags up to the CoreToStg pass, which is almost the entire backend of GHC.