Borrow-checking without type-checking
6 hours ago
- #Borrow Checking
- #Dynamic Typing
- #Programming Languages
- Explores a toy language combining dynamic typing with a limited borrowing system less expressive than Rust but more than second-class references.
- Discusses Julia and Zig's type system approaches and proposes a third option: code is either dynamically typed (interpreted) or statically typed (compiled) with explicit transitions.
- Implements mutable value semantics using reference counting on the stack, enabling cheap dynamic borrow-checking with useful error messages, without atomic operations or heap overhead.
- Provides examples of references, moves (^), borrows (!), shares (&), and closures with explicit captures, illustrating safety rules and restrictions.
- Explains implementation details, including ref-count states, tracking lenders and owners for references, and constraints for crossing stacks (e.g., threads or static typing).
- Highlights expressiveness advantages: references can be in tuples, returned from functions, and used in iterators, surpassing second-class reference limitations.
- Reflects on design trade-offs, comparing with Rust, Hylo, C#, and other systems, and considers future directions like second-class references or static typing focus.