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,
usewith 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_functionworks across the project.Direct executable writer for macOS arm64: Kern encodes the instructions and writes a signed Mach-O file, with no
asandld. Write time: 0.4 ms for a small file (theccpath needs about 50 ms).--cckeeps 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.rulesconfig, comment rules included.Incremental test runner: semantic function/type/constant hashes with recursive call groups, successful-test cache,
--listwith changed-function reasons,--force,--no-cacheand--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 ioalways runs.test fnhelpers 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 fmtandkern fmt --checkfor files and projects.Ownership: explicit moves, own and mutable-own parameters, interprocedural cleanup/lifetime checks, partial moves, immutable views, stale heap-header view invalidation,
freeand ownedtruncate.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
requiresand successful-returnensurescontracts, typedresult, 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
--ccfallback.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.shunpacks the committed, hash-pinned compilers in.cip/bootstrap/(.cip/bootstrap.lock) and rebuildsbuild/kern. Zerorustcin 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 throughKERN_STDor beside the compiler, withkern test stdandkern 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.httpprovides both the single-threaded epoll/kqueue server and multi-corestd.http.workersbuilt on structured tasks, channels andfd_wait. Hosted programs default to host CPU threads (1-64;KERN_THREADSoverrides). - 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 astdmodule. - Acceptance is a real service: an internal HTTP JSON service running on Linux behind Cloudflare.
Steps
| # | Step | Content | Status | Evidence |
|---|---|---|---|---|
| 1 | std modules | use std.x resolves to modules shipped with the compiler; kern api std.x; test cache and self-host proof cover them | Done | std/, tests/std_api.txt |
| 2 | OS primitives | clock_unix_ns, random_bytes, signal_watch/signal_pending, fd_*, fd_wait, socket and poller builtins (epoll, kqueue) | Done | compiler/src/builtins/names.kn |
| 3 | Language gaps | f64, slice ==, a[lo..]/a[..hi], more than six argument words, a stored ! result | Done | compiler/src/runtime_extra/float_arm.kn, tests/layout/f64.tsv |
| 4 | std.bytes, std.fmt, std.collections | split/trim/find/parse/format, a byte builder, generic List[T], U64Map[V] and BytesMap[V] (no generic Map[K, V]) | Done | std/collections/u64_map.kn |
| 5 | std.time, std.env, std.log | Unix time, durations, RFC 3339; typed config from environment; JSON logs | Done | std/time/rfc3339.kn |
| 6 | std.encoding, std.crypto | hex, base64, percent encoding; SHA-2, HMAC, HKDF, PBKDF2, constant-time compare | Done | std/crypto/hmac.kn |
| 7 | std.net | TCP and UDP sockets, kqueue/epoll Poller, non-blocking fd_wait, native DNS (/etc/hosts, resolv.conf, UDP) | Done | std/net/poll.kn |
| 8 | std.json | iterative strict parser to a typed tree and iterative emitter (depth 64 fits on a task stack), limits on depth and size | Done | std/json/parser.kn |
| 9 | std.http, std.websocket | HTTP/1.1 server (router, keep-alive, limits, timeouts, graceful shutdown, fd_wait), multi-core std.http.workers, HTTP/HTTPS client, and std.websocket | Done | std/http/server.kn, std/http/workers/workers.kn, std/websocket/session.kn |
| 10 | std.postgres, std.redis | PostgreSQL wire protocol v3, SCRAM-SHA-256, simple/extended queries, pool, TLS, fd_wait; std.redis RESP client, pipeline, pool, fd_wait | Done | std/postgres/pool.kn, std/redis/pool.kn |
| 11 | std.tls | TLS 1.3 client: X25519, AES-GCM, ChaCha20-Poly1305, X.509 verification against system roots, non-blocking fd_wait; no external audit recorded | Done | std/tls/client.kn |
| 12 | Reference service | project template, the acceptance service, Linux deploy (systemd or container), macOS local run | Partial: the service, its tests, deploy files, template guide and a macOS run exist; no record of a run behind Cloudflare | examples/service/README.md |
| 13 | Concurrency | CONCURRENCY.md tasks and channels: C0-C7, select, fd_wait, multi-core default across macOS arm64 / Linux arm64 / Linux x64, std.http.workers | Done | CONCURRENCY.md, tests/test_concurrency.sh, tests/test_select.sh, tests/test_threads.sh, tests/test_fd_threads.sh, std/http/workers/workers.kn |
| 14 | Packages | kern.packages manifests (name = path, $KERN_PACKAGES, vendored folders, diamond deduplication, cycle checks), documented in SPEC.md and tested in driver/loader | Done | compiler/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.