Kern

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
}
From examples/wc.kn. The file also holds test blocks that kern test runs.
trap: overflow at src/a.kn:12
An arithmetic overflow stops the program and names the file and line (format from 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, own parameters, interprocedural cleanup and lifetime checks, arenas with typed handles. Use after move is error E130; a path that does not free or transfer an owner is E136.
Quality rules
Rules are part of the compiler and set in a kern.rules file. They limit file size, imports, duplicated bodies, test size and more. kern rules prints the active set.
Structured concurrency
scope, spawn, join, bounded typed channels and select. Tasks cannot outlive their scope. Programs use all host CPUs by default.
Errors as values
A fallible function says so in its signature (! ParseError). try and match are 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

TargetRuntimeOutput
macos-arm64libc importssigned Mach-O, written directly
linux-arm64raw system calls, no libcstatic ELF64, written directly
linux-x64raw system calls, no libcstatic ELF64, written directly
kern wasmWASIstandalone wasm32-wasi module
MCU (thumbv7m-none and others)no operating systemELF32; 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

  1. Rust -O290 ms
  2. C -O2320 ms
  3. Go350 ms
  4. Kern420 ms
  5. Bun460 ms
  6. C -O0700 ms
  7. Rust -O0900 ms
  8. Python7390 ms

Lower is better. Python takes 7390 ms, so its bar is cut.

Build time, same program

  1. Kern7.8 ms
  2. C -O020.6 ms
  3. C -O232.6 ms
  4. Rust -O66.7 ms
  5. Go90.2 ms

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.

Read the plan What v0 does not have