Skip to content

← All updates

session

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 + B are checked; a turbofish f::<T>() must give as many type arguments as the function has. Generic enums and generic impl blocks are typed per receiver. Literals of generic structs of your own are still rejected.
  • if and match are values, also as a function’s last statement.
  • @cfg: windows, linux, macos, platform = "...", os = "...", arch, debug and release keep or drop functions and structs. The platform is the host’s.
  • Integer HashMap keys 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.md in the repository) documents what fid accepts, with the compiler function behind each rule.

Memory and borrowing

  • The compiler now frees locals it can prove are finished: Vec and HashMap locals, a Vec<str> or Vec<Vec<T>> with the elements it owns, collections declared in a region at its end, and string temporaries. There is still no GC; anything else lives until exit.
  • The borrow checker rejects changing a Vec while a for loop 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 as IO or Net effects.
  • Owned and borrowed strings: str is owned, &str borrowed. A str field of a @scoped struct reads as &str and cannot be returned as str or stored; str_clone makes an owned copy. http_serve_scoped uses 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 @send fields 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 fn with f64 or 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-alloc sees method calls (.push()), Vec::new() and string +; @no-indirect rejects calls through function parameters; @firmware rejects OS runtime calls; @gas counts literal loop trip counts; @tainted works on parameters.
  • 17 rules, each with a negative test (docs/reference/safety-rules.md).
  • fid qualify file.fd -o out.json writes the evidence: compiler and source hashes, the check result, the annotated functions, and each rule with its requirement and tests. It always reports NOT_QUALIFIED. It is evidence for review, not a certificate, and Fid is not suitable for medical, automotive or avionics use.

Speed and tooling

  • fid emit runs a small IR optimizer: inlining of small single-block functions, constant folding, dead code removal. Native code still has no full register allocator.
  • core.fd is type-checked once per compiler and core version; the build cache evicts past 64 files or 1 GB.
  • bench/run.sh and bench/check.sh flag 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).