No description
  • Rust 61.2%
  • C 37.2%
  • Shell 0.5%
  • Python 0.4%
  • JavaScript 0.3%
  • Other 0.3%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-10-21 06:06:56 +00:00
bench fd 2026-10-20 08:34:33 +08:00
crates better lsp semantics 2026-10-21 13:46:52 +08:00
docs Move std/sync cells behind typed core helpers 2026-10-21 09:54:02 +08:00
examples fd 2026-10-20 08:34:33 +08:00
random Update shut.html 2026-10-10 09:43:25 +08:00
scripts LLVM IR backend, std-safety suite, fuzz harness, HTTP/net std refactor 2026-10-13 07:20:18 +08:00
std Move std/sync cells behind typed core helpers 2026-10-21 09:54:02 +08:00
tools http works for linux 2026-10-19 19:55:36 +08:00
tree-sitter-hiki Clear the warnings, and write down what is left 2026-10-04 14:31:04 +08:00
.gitignore Update .gitignore 2026-10-09 11:08:36 +08:00
6ctodo.md Resolve the typed-element-storage question: there is no decision to make 2026-09-26 15:50:01 +08:00
AGENTS.md mir debug 2026-10-19 21:08:15 +08:00
Cargo.lock stuff and lsp 2026-10-08 23:59:43 +08:00
Cargo.toml Split the workspace and add the language server's syntax layer 2026-10-04 15:24:46 +08:00
foo.md fmt 2026-10-11 19:28:41 +08:00
foo.yml Add fake await support with syntax, lowering, and tests 2026-10-03 20:40:32 +08:00
FUNC-VALUES.md LLVM IR backend, std-safety suite, fuzz harness, HTTP/net std refactor 2026-10-13 07:20:18 +08:00
README.md Rc 2026-09-24 21:48:18 +08:00
spec.md Move std/sync cells behind typed core helpers 2026-10-21 09:54:02 +08:00
STD-REFACTOR-PLAN.md LLVM IR backend, std-safety suite, fuzz harness, HTTP/net std refactor 2026-10-13 07:20:18 +08:00
TODO.md Move std/sync cells behind typed core helpers 2026-10-21 09:54:02 +08:00

Hiki

A small, Swift-flavored, natively compiled language for services that run all day and work for a few seconds of it.

Hiki is short for hikikomori (引きこもり) — the Japanese word for a shut-in, someone who stays in their room and only comes out when needed.

That is the joke, and it is also the design brief. A Hiki program is a long-running service that spends nearly all of its life asleep in the kernel, costs almost nothing while it sleeps, wakes when a request arrives, does its work, and goes back to its room.

This repository holds hikic, the Stage 0 compiler: a Rust program that reads .hiki source and emits ISO C11 for a system C compiler to build.

The program we're aiming at

const http = import("std/http")

struct StatusResponse: Serializable {
    var status: String = "ok"
    var code: u16 = 200
}

func handleStatus(req: http.Request) async throws -> http.Response {
    let payload = StatusResponse()
    return http.Response.json(status: payload.code, body: payload)
}

@main
func main() async throws {
    var server = http.Server()
    server.get("/status", handleStatus)

    print("Hiki daemon sleeping on port 8080...")
    try await server.listen(port: 8080)
}

The interesting property isn't the syntax. It's that this process, sitting there holding no connections, does nothing at all — no timer armed, no background thread, no garbage collector stepping, no runtime work of any kind. It is blocked in epoll_wait and it will stay there indefinitely. The target is zero CPU wakeups while idle, and a resident set small enough to run thousands of these on one small machine.

That number is the whole design. Everything below follows from it.

This particular program doesn't compile yet — async, std/http, and Serializable are all still ahead. It's here because it is the shape of the thing being built. Where it is shows what runs today.

What Hiki optimizes for, in order

  1. Idle cost — resident memory, CPU wakeups, and binary size while doing nothing.
  2. Per-connection cost — what one parked connection costs, in bytes.
  3. Determinism — no garbage collector, no hidden threads, no randomized iteration order.
  4. Ergonomics — Swift-like syntax that reads well and is hard to misuse.
  5. A small, boring implementation — emit plain C11 and let clang or gcc do the heavy optimization.

The performance numbers in the spec are marked target because they are goals to be measured, not results claimed today.

The bets

Swift is the default answer to anything the spec doesn't say. Surface syntax, let/var, structs with value semantics, enums with associated values, optionals, guard, argument labels, string interpolation, throws/try, protocols and generics. Hiki takes Swift's surface and leaves behind its classes, ARC, Objective-C interop, and the very heavy expression type checker.

No garbage collector. The alternative isn't obvious, so it's worth being specific about what Hiki does instead:

  • Primitives, structs, and enums have value semantics. They live on the stack or inline in a parent, and assignment copies them.
  • String, [T], [K: V], and closure environments are refcounted heap buffers, shared copy-on-write.
  • The compiler inserts every retain and release. You never write one.

Because there are no classes, you cannot construct a reference cycle, and because closures capture by value, neither can they. Cycle collection isn't a problem Hiki has; it's a problem Hiki doesn't have a way to create. The price is that ownership transfer is real, and the compiler is strict about it.

Errors are values, not unwinding. throws doesn't unwind a stack. A throwing function returns a generated result type on a second path, try is a branch, and catch is a comparison. There's no hidden control flow to reason about and no cost when you don't use it.

Traps instead of undefined behavior. Integer overflow, a bad array index, a nil force-unwrap: each is a defined trap with a message. The language never hands you a value that silently isn't what you meant.

C is the backend, not the intermediate representation. clang and gcc already do optimization, portability, static linking, and debugging well. What they can't do is see Hiki's semantics — where a temporary's refcount needs dropping on an error edge that only exists in the source language. So Hiki has a small MIR of its own that sits in front, does the handful of transforms C can't express, and then emits flat C. It's an IR whose entire job is to be a good hand-off.

The language is smaller than it looks. No classes, no inheritance, no runtime reflection, no implicit numeric conversions, no macros, no dynamic dispatch in v0, and no threads. Every one of those is a feature that costs idle memory or makes behavior hard to predict, and Hiki's problem domain doesn't need them.

Where it is

hikic currently implements the core language and compiles to working native binaries. What runs today:

enum NetworkError: Error {
    case socketBindFailed(port: u16)
    case invalidHost
}

func bindSocket(port: u16) throws -> i32 {
    if port == 0 { throw NetworkError.socketBindFailed(port: port) }
    return 10
}

@main
func main() {
    do {
        let fd = try bindSocket(port: 0)
        print("Bound on FD \(fd)")
    } catch NetworkError.socketBindFailed(let p) {
        print("Failed to bind on port \(p)")
    } catch {
        print("Unknown error")
    }
}

Structs and value semantics, enums with labeled payloads, exhaustiveness checking, optionals, generics and protocols with static dispatch, strings and arrays with real refcounting, error handling, modules with pub visibility, compile-time const, a low-level unsafe/Ptr<T>/@extern substrate, and Rc<T> with Deinit — the shared-count box that Phase 6c builds String, [T], and Map on top of. The standard library's std/fs, std/process, and std/unsafe are written in Hiki and bundled into the compiler binary.

Not yet: async/await, closures, maps, Substring, and the networking and HTTP layers. The honest gap list, with the reasoning behind each entry, is in docs/IMPLEMENTATION.md.

Build and run

cargo build
./target/debug/hiki run examples/hello.hiki

There are twenty programs in examples/, roughly one per feature area, from hello.hiki through errors.hiki to std_lib.hiki. The later ones are the interesting ones. Two of them — arrays.hiki and trap_overflow.hiki — trap on purpose; they're demonstrating that the trap fires.

-o <path> writes the binary somewhere exact, and:

hiki build examples/hello.hiki --release-small -o hello

--release-small makes a trap a bare __builtin_trap() that prints nothing and compiles out the refcount checker, so the release binary carries none of that bookkeeping. Generated C and binaries land in hiki-out/.

hiki emit-mir prints the MIR for a file, which is the clearest way to see what the compiler is actually doing.

Tests

cargo test                            # unit tests and end-to-end suites
./scripts/e2e.sh tests/errors         # leak fixtures on their own

Every allocation the compiler emits is routed through a debug allocator that counts allocations and frees, and a test binary that leaks or double-frees fails. That check is not decoration; it is how the error-path refcounting bugs in the current implementation were found. A String live across a throw is exactly the case that is easy to get wrong and invisible otherwise.

Layout

Path What's in it
spec.md The language specification. The design document, and the source of truth when this README and the implementation disagree
docs/IMPLEMENTATION.md How the compiler is built, phase by phase, and what's known to be missing
TODO.md The work list
src/ The compiler: lexer, parser, module resolver, monomorphizer, MIR, C emitter
std/ The standard library modules, in Hiki
examples/ One program per feature area
tests/ End-to-end suites
tree-sitter-hiki/ Grammar for editor support

The pipeline is:

lex -> parse -> module graph (import) -> monomorphize -> MIR
     -> CFG simplify -> dead code -> refcount insertion -> C11 -> cc

The standard library is worth a note: it is Hiki source compiled by this same compiler, over a small unsafe layer, with only a ~50-line C prelude that the compiler emits as a template. Nobody maintains that prelude by hand.

Design notes

spec.md is long, and most of it is a working document. The sections that explain why the language is shaped the way it are:

  • §1 Identity — the goals and the explicit non-goals
  • §2 Inspiration — what Hiki takes from Swift, Go, Rust, Zig, and C11, and what it deliberately leaves behind
  • §15 Concurrency — stackless async: a parked connection costs the bytes of its frame, and nothing else
  • §16 Memory Model — the ownership rules, in full
  • §19 Compiler Architecture — why there is a MIR at all

Status

Early. The compiler builds real binaries and the core language is solid, but this is a fraction of the specification and the ambitious parts — async, the event loop, the HTTP server — are still ahead. The roadmap and the risk list are both in the spec, and the latter is worth reading before taking any of the targets above seriously.

The bench/ directory the spec calls for — the same service in Go and Hiki, with CI tracking idle RSS and wakeups from the first milestone — is the missing piece that would turn the targets above into measurements. It doesn't exist yet.