· Mehdi Berel · Internals · 4 min read
The compiler that emits itself, bit-for-bit
fid emit compiles the entire 104K-line self-hosted compiler straight to a Windows executable (no assembler, no linker, no C compiler) and the output is byte-identical to the emitter that produced it. Here is why that matters and how it got there.
A self-hosting compiler is easy to claim and hard to prove. The strongest check there is: point the compiler’s native emitter at the compiler’s own source, and require the output to be byte-identical to the emitter that produced it. Session 35 closed that loop for Fid, and the binary that does it is the one in the installer.
What a fixpoint buys you
If fid emit compiler/main.fd produces the same bytes as the fid that ran it, then the executable descends from the source with no hidden steps. There is no build-server magic, no “the release binary was made differently”, and, the classic motivation, no place for a trusting-trust style gap between what you read and what you run. Every byte of the shipped compiler is accounted for by compiler/*.fd.
Fid verifies this twice, in two different technologies:
C pipeline fidesc dump-c → c1 → c2 → c3 → c4 → c5
fides-c4.c == fides-c5.c: 29,763,762 bytes, converges at generation 4/5
Native pipeline fid-n5.exe emit compiler/main.fd → fid-n6.exe
byte-identical: 12,304,896 bytes, zero C toolchain in the loopRELEASE=1 ./scripts/bootstrap.sh runs the C check on every release build: three stages, fixpoint verified, then installs release/fid.exe.
104K lines through a byte emitter
The native path is not a shortcut: it is the hard way. fid emit encodes x86-64 instructions and constructs the PE file itself: headers, sections, the kernel32.dll/msvcrt.dll import tables, relocations. No as, no link.exe, no cl. Getting 104,439 lines of real compiler through that pipeline required a Fides runtime for PE binaries (stdlib/pe_runtime/, where every builtin p_* runs as pert_*), Windows guard-page stack probes for frames over 4 KB, a vectored exception handler so stack overflows and invalid accesses panic instead of dying silently, and deterministic emission: free-slot order in the emitter no longer depends on HashMap iteration.
It is also fast. The natively-emitted compiler beats the C-built one:
| Measurement | Native-emit compiler | C-compiled compiler |
|---|---|---|
dump-c on the full compiler | 3m21s | 4m21s |
fid emit codegen on a typical test file | ~50 ms | n/a |
The speed came from unglamorous work: bulk strlen/memcpy stubs instead of byte loops, rep movsq struct copies, word-at-a-time hashing, a store→load forwarding peephole (−1,468 loads in a small exe), cmp+jcc fusion, slot reuse that shrank maximum stack frames from ~140 KB to ~1.28 KB, and inlining p_vec_len/p_map_len/*_is_empty.
And the boring bugs that only a full self-compile surfaces: p_string_starts_with was a stub returning true. Now it compares.
What ships
The installer (Fides-Setup-1.0.0.exe, 2.5 MB) puts fid.exe (the self-hosted compiler) on your PATH, with the Rust bootstrap reference beside it as fidesc.exe plus ark, scribe, and veil. fid also embeds the companion tools (fid ark, fid scribe, fid veil) and covers the everyday commands: run, ccompile, emit, build, dump-*, test, bench, profile, lint, fmt, lsp, repl, notebook.
Parity is not aspirational: fid run matches fidesc on all 302 test programs and all 10 examples; fid ccompile matches on 242 of 243 (test_sqlite needs libsqlite3). The Rust suite sits at interp 286/286, C 285/285, PE 287/287, expected-fail 66/66.
The honest footnote stays on the Feature Status page: the older build --native PIR path is superseded by emit, ccompile on minimal_game needs SDL2, and fid’s watch is not yet the hot-reload loop fidesc watch provides.
What’s next
The compiler is no longer the fragile thing it compiles: it is the most-tested Fid program in existence, rebuilt from its own source and checked byte-for-byte on every release. The 1.1 and 1.2 releases build on that floor: uniform ==, Option/Vec layout fixes, ? everywhere, richer patterns. The self-hosted codebase is where every one of those lands first.
# Watch it happen on your own machine:
git clone https://github.com/pledgeandgrow/fid
cd fid
RELEASE=1 ./scripts/bootstrap.sh # 3 stages, fixpoint checked
./release/fid.exe emit compiler/main.fd -o fid2.exe
# fid2.exe is byte-identical to the fid that emitted it.The full blow-by-blow is in the changelog and the self-hosted release entry.
- self-hosting
- backends
- release
Mehdi Berel
Engineering notes from the Fid compiler. Everything measured on the real toolchain: nothing on this blog is aspirational.