Kern
A language that makes it hard or impossible for an LLM to write bad code, with a very fast compiler and a very fast test cycle.
Kern is a small, typed, explicit language for LLM agents. Its native compiler is written in Kern and bootstrapped from a pinned, self-hosted release binary.
Read the guide Build the compiler
Status: prototype v0. Not yet production-proven.
// Count lines, words and bytes of a file. Usage: wc <file>
struct Count { lines: usize, words: usize, bytes: usize }
fn count(buf: []u8) -> Count {
var c = Count{ lines: 0, words: 0, bytes: 0 }
var in_word = false
for b in buf {
c.bytes += 1
if b == '\n' { c.lines += 1 }
let ws = b == ' ' or b == '\n' or b == '\t'
if !ws and !in_word { c.words += 1 }
in_word = !ws
}
return c
}
test "count words and lines" {
let c = count("a b\nc\n")
assert c.words == 3
assert c.lines == 2
assert c.bytes == 6
}
examples/wc.kn. The file also holds test blocks that kern test runs.trap: overflow at src/a.kn:12
PLAN.md).What the compiler enforces
- Overflow and bounds traps
- No implicit conversion, no shadowing, read-only
let. Integer overflow, slice bounds and casts are checked, and a failure is a trap with a source location. - Ownership checking
- Explicit moves,
ownparameters, interprocedural cleanup and lifetime checks, arenas with typed handles. Use after move is errorE130; a path that does not free or transfer an owner isE136. - Quality rules
- Rules are part of the compiler and set in a
kern.rulesfile. They limit file size, imports, duplicated bodies, test size and more.kern rulesprints the active set. - Structured concurrency
scope,spawn,join, bounded typed channels andselect. Tasks cannot outlive their scope. Programs use all host CPUs by default.- Errors as values
- A fallible function says so in its signature (
! ParseError).tryandmatchare the only ways to read the result. There are no exceptions.
A fast test cycle
kern test file.kn --list shows which tests an edit affects and which functions changed. Function hashes and a cache of passing tests mean that unaffected tests do not run again, and unaffected projects skip code generation and linking.
--audit compiles mutants of your code and reports tests that would not catch them. Tests run as isolated parallel processes.
The compiler writes executables itself. On macOS arm64, the write time of a small file is under 1 ms; the cc path needs about 50 ms (PLAN.md). A cross build needs no assembler and no linker.
Linux binaries are static, use raw system calls and do not link libc.
Targets
| Target | Runtime | Output |
|---|---|---|
macos-arm64 | libc imports | signed Mach-O, written directly |
linux-arm64 | raw system calls, no libc | static ELF64, written directly |
linux-x64 | raw system calls, no libc | static ELF64, written directly |
kern wasm | WASI | standalone wasm32-wasi module |
MCU (thumbv7m-none and others) | no operating system | ELF32; see the embedded plan |
The compiler bootstraps itself on all three hosted targets. Three stages (bootstrap, stage1, stage2, stage3) must give byte-identical stage2 and stage3 executables with external compiler, assembler and linker commands blocked.
Benchmarks
One program (a sieve and fib) in each language, measured by bench/bench.py. Machine: Hetzner i9-13900, Linux x86-64, 2026-11-25. Median of 3 runs; the timer resolution is 10 ms. Kern checks overflow and bounds at run time.
Run time
Lower is better. Python takes 7390 ms, so its bar is cut.
Build time, same program
Lower is better. Kern builds in 7.8 ms.
Kern is slower than Rust -O, C -O2 and Go on this program, and close to Bun. The backend does not yet have a general optimizing middle end (README.md); the optimizer work is in EMBEDDED.md and PLAN.md.
Standard library
25 modules, written in Kern and shipped with the compiler. Import one with use std.json. The library has its own rules and tests (kern test std).
bytes
cipher
collections
compress
crypto
encoding
env
fmt
grpc
http
http2
json
log
metrics
mqtt
net
postgres
proto
redis
sqlite
sse
time
tls
webhook
websocket
Among them: HTTP/1.1 with a multi-core server, HTTP/2, gRPC, PostgreSQL and Redis clients with pools, a TLS 1.3 client, WebSocket, JSON, compression and crypto. The TLS client has no external audit on record. Read the full API.
Get started
The build script unpacks and verifies the pinned bootstrap compiler, builds stage1, then rebuilds the compiler as build/kern.
sh .cip/build-kern.sh # fetch/verify pinned bootstrap, build stage1 -> build/kern
build/kern check examples/wc.kn # type check, JSON result
build/kern test examples/wc.kn # run the `test` blocks
build/kern test examples/wc.kn --list # affected tests and the changed functions
build/kern test examples/wc.kn --force # run all tests, refreshing the cache
build/kern test examples/wc.kn --audit # compile mutants and audit test coverage
build/kern fmt examples/calc --check # verify canonical formatting
build/kern run examples/wc.kn README.md
build/kern asm examples/wc.kn # print the assembly
build/kern build examples/sieve.kn --time
Commands from Build and use. The guide covers project layout, modules, generics, ownership and the quality rules.
Status
Kern is a prototype (v0). The compiler builds itself, and 13 of the 14 steps of the backend readiness plan are done. The last step is partial: a reference HTTP and PostgreSQL service exists with tests and deploy files, but there is no record of a production run. The plan lists what v0 does not have yet; read it before you depend on Kern.