Skip to content

← All updates

session

Native Linux executables, one ownership rule, a faster compiler

Nine days of work on fid, the self-hosted compiler. The v0.8.0-unstable installer was built on Nov 10 and holds the work up to that day; everything after it is on the main branch. The stable v1.0.0 release is still planned for December. The full suite was last run on Nov 2 with the frozen Rust compiler and has not been rerun with fid; each change below was checked with its own tests.

Native backends

  • Linux without a C compiler: fid emit --target x86_64-linux, aarch64-linux or riscv64-linux writes a static ELF executable. One machine layer serves the three targets, with its own register allocator and a runtime built on system calls (threads, tasks, channels, sockets, processes). On Nov 9, 272, 273 and 271 of 317 suite programs matched the interpreter (ARM64 and RISC-V under QEMU).
  • Windows: the native backend has a linear-scan register allocator for integer and xmm registers, tasks switch on their own stacks, and sockets wait through IOCP. fid emit --nat puts Windows on the same machine layer as Linux (opt-in; 301 of 338 suite programs).
  • Native async/await works: it broke in builds of Nov 9 afternoon and was fixed the same evening.
  • Bare metal (Nov 15): fid emit --bare and --boot write an x86-64 Multiboot kernel that boots under QEMU; 10 of 10 bare tests pass.
  • WebAssembly (Nov 15): fid wasm modules validate and run under WASI; 316 of 344 suite programs match fid run.
  • macOS (Nov 15): native Mach-O executables are written and checked for structure. They have not been run on a Mac.
  • fid ccompile --target cross-compiles through C with zig cc for aarch64-linux, riscv64-linux, x86_64-macos, aarch64-macos and wasm32-wasi.

Memory and values

  • One ownership rule (proposal 0004): a variable owns its value and the value is dropped at the end of its scope; keeping a value takes an owner; parameters are borrowed. Strings, Vec buffers and Boxes are reference-counted.
  • Value semantics: var b = a on a Vec, HashMap or str gives an independent value, shared until the first write. Since Nov 15, copying a struct also separates its Vec fields.
  • &v[i] and &mut v[i] are the element’s address, so writes through them reach the container.
  • A leak gate (scripts/leak-check.sh) checks that test programs free every block.

The language

  • Literals of generic structs of your own work (Nov 15): Pair { first: 1, second: "a" }.
  • Match exhaustiveness covers generic enums such as Option<T> and no longer counts a guarded arm as covering anything.
  • --borrowck=warn prints its warnings, and the borrow checker follows casts and nested field writes.
  • A match guard on a @secret value taints its arm, and file and socket writes are sinks.
  • 5e3 and 2E-3 lex as floats.

The optimizer and its checks

  • A rule-based mid-end with an e-graph, constant propagation, loop-invariant code motion and tail recursion into loops, plus an IR verifier that can run after every pass.
  • The 108 integer rewrite rules are proved with z3, and the instruction encoders are checked against clang’s assembler (1,181 forms, no mismatch).
  • tests/conformance/ adds 104 programs, each checking one rule of the language reference.

Speed

  • The compiler’s C is split into units and built at -O2. Compiling itself to C takes about 40 s (Nov 15), down from about 133 s on Nov 6.
  • The fixpoint was verified again on Nov 8 (stage 2 == stage 3, 67 MB of C). Later changes were checked on one-stage builds.
  • A CI workflow builds a change’s compiler and its base commit’s on one runner and compares the benchmarks.

Standard library and tools

  • 163 modules. New: brotli and zstd decoders, decimal, protobuf, tz (the IANA database), wss, Unicode normalization (NFC, NFD, NFKC, NFKD), a set of OS-development modules (elf, acpi, pci, virtio, multiboot, fdt, uart, pmm, slab), safetensors, bpe and infer for model inference, and gltf and tiled loaders.
  • fid lint --perf warns about loop hazards, and fid explain file.fd lists which run-time checks the compiler removed or kept, and why (--alloc: the allocation sites and why each is on the heap).
  • The repository gained a book, a cookbook and guides for readers coming from Rust, Go, Zig and C.

Still open

The full suite has not been run with fid as the compiler under test. Native code is slower than code built through C. A Vec passed to a spawned call is shared with the caller, and writes from both threads are not detected. macOS output has not been run on a Mac, SPIR-V output does not validate, and build --native (the old PIR path) crashes. The current list is on the Feature Status page.