Kern
On this page

Kern plan

Goal: 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. Targets: macOS arm64, Linux arm64, Linux x86-64.

Done

  • Compiler prototype in Rust (the first compiler; removed, see the self-host items below).

  • Generic slices []T, alloc[T](n), sub-slices.

  • Test harness tests/run.sh (3 targets, error cases, trap cases, rule cases, project cases).

  • Modules and project layout: a folder is a module, use with qualified names, pub, import cycles are errors, kern api, symbols with the module path, traps with the file name (trap: overflow at src/a.kn:12). One fixed layout: kern.rules, src/main.kn, src/<module>/. Example: examples/calc.

  • Structure rules: max_fns_per_file, max_types_per_file, max_files_per_module, max_pub_per_module, max_imports, max_module_depth, unused_import, unused_pub, layers. unused_function works across the project.

  • Direct executable writer for macOS arm64: Kern encodes the instructions and writes a signed Mach-O file, with no as and ld. Write time: 0.4 ms for a small file (the cc path needs about 50 ms). --cc keeps the old path. Linux arm64 and x86-64 also have direct static ELF64 writers. All direct writers support cross builds.

  • Compiler source split into one folder for each phase under compiler/src/ (lexer, parser, typing, backend, ...), so agents can work in parallel.

  • Constants, enum, match, errors as values (!, fail, try).

  • Built-in quality rules with kern.rules config, comment rules included.

  • Incremental test runner: semantic function/type/constant hashes with recursive call groups, successful-test cache, --list with changed-function reasons, --force, --no-cache and --jobs.

  • Parallel isolated tests: one in-memory image on macOS arm64, one temporary executable on Linux or with --cc; one process per selected test. Unaffected projects skip code generation and linking.

  • Pure tests by default; test io always runs. test fn helpers are omitted from release code, and production callers cannot use them.

  • Test rules R037-R046: assertions, reachability, location, no test-only files, limits on test lines/count/runtime, public-function coverage and forced test helper scope. Defaults: 30 lines, 5 tests per function, 100 ms per test.

  • Mutation audit: actual compiled mutants, reachable-test selection, baseline validation, unique-kill redundancy and surviving-mutation diagnostics. Branch bitmap comparison is advisory and off by default.

  • Declared I/O inputs: frozen file snapshots, content hashing and rejection of undeclared reads.

  • Structure rules R050-R053: normalized duplicate bodies, named production numbers, one bool parameter, canonical formatting with kern fmt and kern fmt --check for files and projects.

  • Ownership: explicit moves, own and mutable-own parameters, interprocedural cleanup/lifetime checks, partial moves, immutable views, stale heap-header view invalidation, free and owned truncate.

  • Fixed-capacity arenas and typed handles, static same-region checks across helper calls, checked access/update, null links, and source-located capacity traps. Recursive owned graphs use arena handles.

  • Explicit generic functions, structs and enums, bounded monomorphization, small interfaces (one to five functions), exact/coherent implementation mappings and static bounded calls. Module visibility, API signatures, ownership, formatting, incremental fingerprints and mutation auditing include concrete instances.

  • Compact language specification (kern spec, also SPEC.md).

  • Read-only requires and successful-return ensures contracts, typed result, ownership-safe single evaluation, source-located release/test traps, generic specialization, API signatures and cache invalidation.

  • Linux direct ELF64 writers: architecture encoders, checked relocations, RX/R/RW segments, non-executable stack, reproducible cross builds, direct test images and explicit external-toolchain --cc fallback.

  • Self-host prerequisites: pure u64 bit operations and checked shifts; file writes, path metadata/rename/mode operations, owned directory listings, safe child processes with output capture/status/stop, monotonic timing, environment/path queries, descriptor/scratch cleanup and strict I/O/cache admission.

  • Compiler written in Kern: independent lexer/parser, module/type/interface/generic and ownership passes, contracts, all quality rules, canonical formatter, API/spec and complete native CLI.

  • Self-hosted direct Mach-O/ELF writers, incremental SCC-hashed pass cache, isolated parallel tests, macOS in-memory images, frozen declared inputs, executable mutation audit and advisory path bitmaps.

  • Self-hosted bootstrap: the Rust stage0 (src/) is removed (commit 387d16b). .cip/build-kern.sh unpacks the committed, hash-pinned compilers in .cip/bootstrap/ (.cip/bootstrap.lock) and rebuilds build/kern. Zero rustc in local builds or CI. Kern has one compiler.

  • Official self-bootstrap on all three targets: normal policy-enforced builds produce byte-identical stage2/3 executables with external compiler/assembler/linker commands blocked.

  • Standard library modules in std/ (use std.bytes), found through KERN_STD or beside the compiler, with kern test std and kern api std.MODULE.

Backend readiness plan (status checked against the code)

Goal: make Kern usable by agents for backend services on Linux (production) and macOS (local testing), with a standard library that covers what a service needs. MCU work is deferred. EMBEDDED.md (M0-M7) stays as a design record; finished MCU changes may still land. The optimizer (O1-O2) continues in parallel.

Status of steps 1-14 below: 13 are done, 1 is partial (12: no record of a production run behind Cloudflare). Concurrency (C0-C7, select, fd_wait, multi-core default across macOS arm64, Linux arm64 and Linux x86-64, and std.http.workers), std.redis, std.websocket, iterative std.json, non-blocking fd_wait across std, and kern.packages are landed and verified on main.

Decisions

  • Pure Kern, no C interface. Linux binaries stay static with raw system calls and no libc; macOS keeps its libc imports. A narrow, declared binding is reconsidered only when one library forces it.
  • Inbound TLS ends at the edge (Cloudflare, Caddy or nginx); services speak plain HTTP on a private network. Outbound HTTPS uses the native TLS client (step 11, std.http.https); an egress proxy is optional.
  • Event loop and multi-core tasks. std.http provides both the single-threaded epoll/kqueue server and multi-core std.http.workers built on structured tasks, channels and fd_wait. Hosted programs default to host CPU threads (1-64; KERN_THREADS overrides).
  • The standard library is Kern source shipped with the compiler and imported as use std.<module>. New compiler builtins are only the operating-system primitives below; everything else is a std module.
  • Acceptance is a real service: an internal HTTP JSON service running on Linux behind Cloudflare.

Steps

#StepContentStatusEvidence
1std modulesuse std.x resolves to modules shipped with the compiler; kern api std.x; test cache and self-host proof cover themDonestd/, tests/std_api.txt
2OS primitivesclock_unix_ns, random_bytes, signal_watch/signal_pending, fd_*, fd_wait, socket and poller builtins (epoll, kqueue)Donecompiler/src/builtins/names.kn
3Language gapsf64, slice ==, a[lo..]/a[..hi], more than six argument words, a stored ! resultDonecompiler/src/runtime_extra/float_arm.kn, tests/layout/f64.tsv
4std.bytes, std.fmt, std.collectionssplit/trim/find/parse/format, a byte builder, generic List[T], U64Map[V] and BytesMap[V] (no generic Map[K, V])Donestd/collections/u64_map.kn
5std.time, std.env, std.logUnix time, durations, RFC 3339; typed config from environment; JSON logsDonestd/time/rfc3339.kn
6std.encoding, std.cryptohex, base64, percent encoding; SHA-2, HMAC, HKDF, PBKDF2, constant-time compareDonestd/crypto/hmac.kn
7std.netTCP and UDP sockets, kqueue/epoll Poller, non-blocking fd_wait, native DNS (/etc/hosts, resolv.conf, UDP)Donestd/net/poll.kn
8std.jsoniterative strict parser to a typed tree and iterative emitter (depth 64 fits on a task stack), limits on depth and sizeDonestd/json/parser.kn
9std.http, std.websocketHTTP/1.1 server (router, keep-alive, limits, timeouts, graceful shutdown, fd_wait), multi-core std.http.workers, HTTP/HTTPS client, and std.websocketDonestd/http/server.kn, std/http/workers/workers.kn, std/websocket/session.kn
10std.postgres, std.redisPostgreSQL wire protocol v3, SCRAM-SHA-256, simple/extended queries, pool, TLS, fd_wait; std.redis RESP client, pipeline, pool, fd_waitDonestd/postgres/pool.kn, std/redis/pool.kn
11std.tlsTLS 1.3 client: X25519, AES-GCM, ChaCha20-Poly1305, X.509 verification against system roots, non-blocking fd_wait; no external audit recordedDonestd/tls/client.kn
12Reference serviceproject template, the acceptance service, Linux deploy (systemd or container), macOS local runPartial: the service, its tests, deploy files, template guide and a macOS run exist; no record of a run behind Cloudflareexamples/service/README.md
13ConcurrencyCONCURRENCY.md tasks and channels: C0-C7, select, fd_wait, multi-core default across macOS arm64 / Linux arm64 / Linux x64, std.http.workersDoneCONCURRENCY.md, tests/test_concurrency.sh, tests/test_select.sh, tests/test_threads.sh, tests/test_fd_threads.sh, std/http/workers/workers.kn
14Packageskern.packages manifests (name = path, $KERN_PACKAGES, vendored folders, diamond deduplication, cycle checks), documented in SPEC.md and tested in driver/loaderDonecompiler/src/loader/packages.kn, compiler/src/driver/compile.kn, SPEC.md

Each step is done when it works on all three targets, the self-host proof passes and the new modules have tests. Steps 2 and 3 do not depend on step 1; steps 4-12 need step 1.

Source: PLAN.md in the repository.