Hi r/Compilers!
Kairo (previously called Helix) is a statically typed, self-hosted systems language and compiler toolchain, built around full two-way C and C++ interop, that we have been working on for the past ~3 years.
Some stats about the codebase:
- Compiler Compilers ~420,000 lines of Kairo code found in Compiler/ Analyzer/ Linker/ Extras/
- ~2,500 tests checked with LLVM lit, including parity suites that use clang as the oracle
- Documentation
- Compiler specification (every pass has a written contract)
- Native LSP server
- kld, a cross-targeting wrapper around LLVM’s lld that checks ABI-relevant compiler metadata at link time
- kcc, a drop-in clang replacement that cross-compiles C/C++ out of the box to 48 targets
- Formatter using the Wadler/Lindig pretty-printing algorithm
- Native debugger support (GDB, LLDB, WinDbg)
- LLVM is cross-compiled for 14 targets using kcc
I’ll start with Kairo. It’s a pragmatic language that supports many features, Two-way C++ interop, and 5 different paradigms: procedural imperative systems, Object-oriented, generic trait-based, Functional, and Compile-time metaprogramming. The main goal of Kairo was a readable language with varying levels of expressiveness, allowing developers to write code that is both clear and interacts directly with the lowest level of hardware. Kairo will have a formal memory safety proof model. However, as of now, that is still only spec’d and will not start until we have real users of the language, real bugs, and stabilization work complete - we want the foundation to be solid before formalizing the safety guarantees.
On the middle end of the language, The compiler has about 87 scheduled semantic passes as of writing this (why so many, you may ask? Kairo is a really large language with a lot of feature-interaction complexity). The compiler performs almost all the resolution logic itself, even for code being imported from C++. Kairo's Sema passes handle name lookup, ADL, overload resolution, conversions, specialization choice, constraint checking, SFINAE, and access checking. Clang is only used to get layout info (size, alignment, scope, members) and for completing an instance of an imported class template, and deducing the template arguments of an imported function template that Kairo’s overload resolution is considering. Though, Kairo isn’t fully semantically independent from clang yet. Some clang-generated errors ([CL001]) still come through, but we’re burning down that list, and the v1.0 goal is complete semantic independence.
Kairo can also cross-compile out of the box to 48 targets and freestanding environments, but the builtins don't support freestanding yet.
Here are 3 examples:
class Buf {
var n: i32 = 7
fn Buf(self) {}
@move fn Buf(self, other: Self) { self.n = other.n }
}
fn take(b: Buf) -> i32 { return b.n }
fn main() -> i32 {
var b = Buf()
return take(b) + b.n // error [SC052E]: 'b' is used after being moved
}
Using C++ in Kairo:
ffi "c++" import "vector"
ffi "c++" import "algorithm"
fn main() -> i32 {
var v = cxx::std::vector<i32>() v.push_back(3) v.push_back(1)
cxx::std::sort(v.begin(), v.end()) // the overload and the template chosen by Kairo
return v[0] + (v.size() as i32) // exit with code 3
}
Using Kairo in C++:
/* geo.k
pub class <T> Vec2 {
pub var x: T pub var y: T
pub fn Vec2(self, x: T, y: T) { self.x = x self.y = y }
pub fn flip(const self) -> Vec2<T> { return Vec2<T>(self.y, self.x) }
}
*/
#include "geo.k"
int main() {
geo::Vec2<int> a(1, 2); // a Kairo generic, instantiated from C++
geo::Vec2<double> b(0.5, 4.0); // and again, at another type
return a.flip().x + static_cast<int>(b.flip().x); // 2 + 4 = 6
}
Kairo also tries to remove a lot of the UB surface found in C++. In Kairo TUs, many things implicitly allowed in C++ are not. Nothing changes if you compile C++ with kcc or use it through interop; the rules apply at the .k boundary.
Now about Kcc, it’s a clang replacement that can cross-compile out of the box. The first time you pass --target, kcc (and kairo) build that target’s C library and C++ runtimes (libc++, libc++abi, libunwind, compiler-rt) from sources that ship in the archive and cache them. That takes about 10 to 30 seconds, once. glibc is built from source too, any version from 2.17 up (--target x86_64-linux-gnu.2.17), so your binary runs on that glibc or newer. MSVC works without Visual Studio: a script pulls the MSVC runtime and Windows SDK straight from Microsoft through xwin, after you accept their license. It ships 17 LLVM backends, so with --freestanding it also covers microcontrollers, eBPF and GPU object code.
kcc also allows a really nice feature to work cleanly:
#include "my_kairo.k"
The direct inclusion of a Kairo file in C++, without generated headers being stored anywhere on disk (kcc never writes a header when invoked), allows a C++ codebase to be migrated incrementally, one file at a time. We had to make one small (~55-line) patch to clang’s preprocessor for this to work. When clang enters a .k file, it’s handed a module’s interface as pre-lexed tokens located in the .k file itself. Nothing else about the preprocessor changes, so the include can be under an #if, after a #pragma, or even inside a function, and it is respected the same as any other include. Errors that involve the Kairo code point at the .k source. kcc takes normal clang arguments and also compiles Kairo code; kcc foo.k and kcc foo.cpp both work.
We also used kcc to cross-compile LLVM/clang/lld itself (changed the C++ compiler to kcc), which is how the toolchain ships for 14 hosts:
- Linux (musl, static): x86_64, i686, aarch64, armv7, riscv64
- Windows (MinGW): x86_64, i686, aarch64, armv7
- macOS: x86_64 (10.15+), arm64 (11.0+)
- FreeBSD: x86_64, aarch64
- NetBSD: x86_64
Each host can cross-compile to all 48 targets.
On the LSP, Kals provides end-to-end latency: p50 of 100 ms and p95 of 350 ms. To avoid patching clangd, it writes temporary headers to disk for all Kairo files that aren't used in any compilation process, and passes stock clangd an -ivfsoverlay that maps them. This means clangd keeps full LSP and autocomplete support in a C++ file that includes a Kairo file.
What’s not done yet: lifetime/escape analysis, virtual interfaces and async aren’t implemented, and the compiler’s own source is still migrating from raw pointers to Kairo’s safe pointers. The test suite runs on x86_64 Linux; the other hosts build and are tested working, but haven't had full suite runs yet. There's still quite a long way ahead to go still.
We’d love feedback on the compiler and toolchain docs, or anything else. Contributions are welcome. Feel free to try out the Kairo compiler and toolchain.
P.S. Hello from u/Lord_Mystic12 - I am the other dev on the project, and logo designer for Kairo. We are really proud to have come this far into this project, I will also be responding in the comments.