The Fil-C Optimized Calling Convention

· coding · Source ↗

TLDR

  • Fil-C enforces memory safety across ABI mismatches (wrong signatures, misused va_list, symbol type confusion) while matching near-Yolo-C register-passing efficiency in the common case.

Key Takeaways

  • The generic calling convention passes arguments through thread-local CC buffers with full capability checks; three major inefficiencies are then eliminated by two optimizations.
  • The register calling convention uses arithmetically encoded 64-bit signature hashes stored in a function object; matching signatures bypass CC buffers entirely and pass args in registers.
  • Function objects carry a fast_entrypoint (register ABI), generic_entrypoint (CC buffer fallback), and a signature hash; mismatched signatures route to a generic call thunk at runtime.
  • Direct call optimizations let the caller skip getter resolution and capability checks in the common case, avoiding linker-mediated flight pointer lookups per call.
  • All safety guarantees hold adversarially: wrong arg count, type-cast function pointers, and cross-module signature mismatches either panic or follow strict GIMSO semantics.

Hacker News Comment Review

  • No substantive HN discussion yet; the one comment raises whether Fil-C’s GC could run on alloc calls only, avoiding threading dependencies, which is an open implementation question not addressed in the post.

Original | Discuss on HN