A deep technical exploration of implementing borrow-checking in a dynamically-typed toy language without a static type system. The author demonstrates how ownership, borrowing, and shared references can be enforced at runtime using a compact reference-counting scheme stored on the stack. Key design decisions include: using a single integer per variable to encode moved/borrowed/shared states, storing lender and owner provenance in 42 bits per reference, and scanning the stack to produce useful error messages on violations. The system supports interior pointers, stack allocation, external iterators, and closures with explicit captures. Comparisons are drawn to Rust, Hylo, Mojo, Swift, C# refs, and other ownership systems, with honest discussion of tradeoffs and remaining limitations.
Table of contents
backgroundreplvaluesreferencesclosuressafetyexpressivenessimplementationerror messagesthoughtsrelated worknextSort: