jank-lang / jank

The native Clojure dialect hosted on LLVM
https://jank-lang.org
Mozilla Public License 2.0
1.69k stars 50 forks source link

Switch from Cling to Clang for JIT compilation #82

Closed jeaye closed 4 months ago

jeaye commented 4 months ago

Cling has been upstreamed into the Clang/LLVM monorepo and most of the development is happening there. This happened several Clang releases ago, maybe around 15/16, but due to bugs in the Clang JIT code, we can only use the bleeding edge, unreleased Clang 19.

Using Clang's "interpreter" is very similar to Cling, since it was modeled after Cling, so the port doesn't involve any rewriting. However, we do have a dedicated "incremental" PCH now, which is separate from our AOT PCH. We also have a much more robust LLVM CMake setup.

Overall, when it comes to JIT compiling C++, Clang 19 is about 2x faster than Cling (which was a fork of Clang 13). This will improve startup times. Going forward, Clang 19 supports JIT loading of pre-compiled C++20 modules (PCMs), which should allow us to compile jank namespaces to modules and load them much, much more quickly.

Furthermore, Clang/LLVM itself is easier and less finicky to build, so the overall dev experience should be improved. The code has also been re-formatted using Clang-format 19, which should be what everyone developing on jank is using going forward. It's built as part of jank's build process, so just add that to your path.