HeadlinesBriefing favicon HeadlinesBriefing.com

Toy Language Does Borrow-Checking at Runtime Instead of Compile Time

Hacker News •
×

A developer has built a demo of a toy programming language that performs borrow-checking dynamically rather than at compile time. The language features dynamic typing, inline values, stack allocation, interior pointers, and single ownership with a limited borrowing system. Unlike Rust's static borrow checker, this approach validates borrowing rules at runtime while still catching violations with useful error messages.

The project explores a type-system philosophy shared by Julia and Zig—starting with a dynamic type system and layering static type checking on top to prove dynamic checks unnecessary. This language goes further by requiring explicit annotations to switch between dynamic and static typing. The real challenge was enforcing mutable value semantics without relying on static type systems. The solution uses lightweight reference-counting that lives on the stack, avoiding heap allocation, and skips atomic operations since reference counts aren't shared across threads.

The language prevents copying boxed values by default, requiring explicit annotations: ^ for moves, ! for borrowed references that return values to their original location when dropped, and & for shared references. Mutations through shared references trigger runtime errors that identify the exact value at fault. The author estimates the scheme is about 60% sound.