Siddharth Bhat

A weblog of sorts

github linkedin email rss
This week in simplexhc: October 29th 2017
Oct 29, 2017
3 minutes read

This is going to be a weekly blog post about the status of simplexhc, an STG to LLVM compiler. Read more about this in the introduction blog post.

This has been a long time coming. Unfortunately, “next week” turned out to be “after 3 months”. To quickly cover ground, I’ll first write about stuff I’ve achieved in the past couple months:

  • Moved from Haskell to C++.
  • Implemented “fully functional” compiler for a subset of STG.
  • Have test cases for common patters which all seem to work :).
  • Started looking into integration with GHC.
  • Started looking into how to GC, how to implement multi-threading.
  • Wrote extentions to compiler-explorer so I can easily show differences online.
Move from Haskell to C++

I felt more and more tied down by haskell as the project grew, because I’m used to structuring algorithms with mutability in mind. Especially when it came to something like manipulating IR, I felt like I was wasting my time writing stuff in haskell when a large portion of LLVM’s ergonomics are meant to fit C++.

So, I simply rewrote the codebase in C++ from scratch.

Garbage collection for simplexhc

I attended LLVM Dev this year, where I met Denys Shabalin, one of the core authors of scala-native. He mentioned to me that they have a pretty solid GC implementation, and that it should be quite easy to integrate into my project.

I’m probably going to do just that for the prototype, benchmark, see how performance goes, and then make decisions as to whether I need to change things in the GC.

I’d much rather steal code, because stealing code is 0 effort for me :)

compiler-explorer support

Here is a live link to simplexhc hooked up on compiler-explorer. You can try out examples from the tests folder of the simplexhc repo. To browse the examples, you can also press the “floppy disk / save” option in the top bar of UI that will allow one to load samples.

I want to add support for code execution, but a little more hacking remains for that to work.

Note that the syntax closely follows that of David Luposchainsky (quchen)’s stgi

To dump LLVM IR, please use the option --emit-llvm in the options bar.

GHC integration

To integrate into GHC, I need to transfer STG over to my compiler and then compile that down to an object file. Ben gamari advised me to write a core -> core plugin that sneakily writes out my compiler format of STG to the side.

That way, it’s not “truly” integrated into GHC. Rather, it’s a side-channel from which I can conveniently convert hakell-proper to STG, because until now, I’ve been working with only hand-written STG.

Benchmarking and performance

I’m going to directly jump to this next, because I believe I have the basics down in the compiler. I haven’t started with either, but I’ll be very interested to see in which cases simplexhc does better than GHC.

Do note that these comparisons will be unfair, because GHC takes care of many things that my compiler is not even aware of - GC, multithreading, STM, etc.

Closing thoughts

I wrote this to get into the habit of jotting down what I’ve been doing in general, and to signal that the project is not dead yet :)

I haven’t written anything at all about my current instatiation of STG: It’s mostly just regular STG with some type information. I’m going to talk about code generation next time.

One thing I’d like to get working is the docker sandbox working so people can run examples on the compiler-explorer link.

Please leave ideas / issues found on the repo, they’re much appreciated!


Back to posts


comments powered by Disqus