Generics, borrowed strings, safety rules with evidence
Three days of work on fid, the self-hosted compiler, on the main branch. None of it is in a release: v1.0.0 stable is still planned for December, and fid version still prints 0.1.0. Each change below was checked with its own tests on the interpreter, the C backend and the native Windows backend. The full suite was last run on Nov 2 and has not been rerun with this compiler.
The language
- Generics (proposal 0002): type arguments are inferred at each call or the call is an error naming the parameter; bounds
T: A + Bare checked; a turbofishf::<T>()must give as many type arguments as the function has. Generic enums and genericimplblocks are typed per receiver. Literals of generic structs of your own are still rejected. ifandmatchare values, also as a function’s last statement.@cfg:windows,linux,macos,platform = "...",os = "...", arch,debugandreleasekeep or drop functions and structs. The platform is the host’s.- Integer
HashMapkeys work (they crashed before); 0 and -1 are ordinary keys. - Higher-order effects: a function that takes a function value gets the effects of the function passed at each call, so
apply(pure_fn, x)can be called from a!{}function. - The language reference (
docs/reference/reference.mdin the repository) documents whatfidaccepts, with the compiler function behind each rule.
Memory and borrowing
- The compiler now frees locals it can prove are finished:
VecandHashMaplocals, aVec<str>orVec<Vec<T>>with the elements it owns, collections declared in aregionat its end, and string temporaries. There is still no GC; anything else lives until exit. - The borrow checker rejects changing a
Vecwhile aforloop walks it, and assigning a field of a borrowed struct. Trait impl bodies and&v[i]are checked too. File, socket, process and clock runtime calls count asIOorNeteffects. - Owned and borrowed strings:
stris owned,&strborrowed. Astrfield of a@scopedstruct reads as&strand cannot be returned asstror stored;str_clonemakes an owned copy.http_serve_scopeduses this to free each request after its response, and is no longer@unsafe.
Concurrency
- Every argument of a spawned call must be
@send; a struct of@sendfields is@send; references and raw pointers are not. parallel { }branches run on threads:x = f(...)branches, and branches that read only word-sized locals.async fnwithf64or struct arguments runs as a task in the interpreter and through C. Native async programs still crash.- Per-thread free lists in the native runtime and per-thread arenas in the C runtime (no multi-thread stress test yet).
Safety rules
@no-allocsees method calls (.push()),Vec::new()and string+;@no-indirectrejects calls through function parameters;@firmwarerejects OS runtime calls;@gascounts literal loop trip counts;@taintedworks on parameters.- 17 rules, each with a negative test (
docs/reference/safety-rules.md). fid qualify file.fd -o out.jsonwrites the evidence: compiler and source hashes, the check result, the annotated functions, and each rule with its requirement and tests. It always reportsNOT_QUALIFIED. It is evidence for review, not a certificate, and Fid is not suitable for medical, automotive or avionics use.
Speed and tooling
fid emitruns a small IR optimizer: inlining of small single-block functions, constant folding, dead code removal. Native code still has no full register allocator.core.fdis type-checked once per compiler and core version; the build cache evicts past 64 files or 1 GB.bench/run.shandbench/check.shflag slowdowns against a baseline (not in CI).- Self-compile to C takes about 133 s (type check 59 s); the stage 2 and stage 3 C are byte-identical, 49 MB.
Written, not run yet
fid emit --checked-alloc (guard pages for native builds), scripts/sanitize.sh (ASan/UBSan through C), and a nightly fuzzing script.
Still open
Value semantics: copy-on-write for Vec and HashMap is written but off, because the compiler runs out of memory compiling itself with it, so var b = a on a Vec still aliases. Also open: native async, a full register allocator, macOS, native ELF, ARM64/RISC-V/WebAssembly backends, and bare metal (emit --bare panics).