docs: update documentation with RC implementation status
- C_BACKEND.md: Update memory management from "Leaks" to "Scope-based RC", update comparison tables with Koka/Rust/Zig/Go - LANGUAGE_COMPARISON.md: Add status column to gap tables, add RC row - OVERVIEW.md: Add C backend RC to completed features, update limitations - REFERENCE_COUNTING.md: Add "Path to Koka/Rust Parity" section with: - What we have vs what Koka/Rust have - Remaining work for full memory safety (~230 lines) - Performance optimizations for Koka parity (~600 lines) - Cycle detection strategy Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,7 @@ Lux compiles to C code, then invokes a system C compiler (gcc/clang) to produce
|
||||
| **Koka** | C | Perceus reference counting |
|
||||
| **Nim** | C | ORC (configurable) |
|
||||
| **Chicken Scheme** | C | Generational GC |
|
||||
| **Lux (current)** | C | None (leaks) |
|
||||
| **Lux** | C | Scope-based reference counting |
|
||||
|
||||
## Compilation Pipeline
|
||||
|
||||
@@ -164,15 +164,18 @@ result->length = nums->length;
|
||||
|
||||
## Current Limitations
|
||||
|
||||
### 1. Memory Management (Partial RC)
|
||||
### 1. Memory Management ✅ WORKING (Lists/Boxed Values)
|
||||
|
||||
RC infrastructure is implemented but not fully integrated:
|
||||
Scope-based reference counting is now functional:
|
||||
- ✅ RC header structure with refcount + type tag
|
||||
- ✅ Lists, boxed values, and strings use RC allocation
|
||||
- ✅ List operations properly incref shared elements
|
||||
- ⏳ Automatic decref at scope exit (not yet implemented)
|
||||
- ✅ **Automatic decref at scope exit** - variables freed when out of scope
|
||||
- ✅ **Memory tracking** - debug mode reports allocs/frees at program exit
|
||||
- ⏳ Early return handling (decref before return in nested scopes)
|
||||
- ⏳ Closures and ADTs still leak
|
||||
|
||||
**Current state:** Memory is tracked with refcounts, but objects are not automatically freed at scope exit. This is acceptable for short-lived programs but not for long-running services.
|
||||
**Current state:** Lists and boxed values are properly memory-managed. When variables go out of scope, `lux_decref()` is automatically inserted. Test output shows `[RC] No leaks: 28 allocs, 28 frees`.
|
||||
|
||||
### 2. Effects ✅ MOSTLY COMPLETE
|
||||
|
||||
@@ -215,9 +218,10 @@ Koka also compiles to C with algebraic effects. Key differences:
|
||||
|
||||
| Aspect | Koka | Lux (current) |
|
||||
|--------|------|---------------|
|
||||
| Memory | Perceus RC | Leaks |
|
||||
| Effects | Evidence passing (zero-cost) | Runtime lookup |
|
||||
| Closures | Environment vectors | Heap-allocated structs |
|
||||
| Memory | Perceus RC (full) | Scope-based RC (lists/boxed) |
|
||||
| Effects | Evidence passing (zero-cost) | Evidence passing (zero-cost) |
|
||||
| Closures | Environment vectors | Heap-allocated structs (leak) |
|
||||
| Reuse (FBIP) | Yes | Not yet |
|
||||
| Maturity | Production-ready | Experimental |
|
||||
|
||||
### Rust
|
||||
@@ -225,8 +229,8 @@ Koka also compiles to C with algebraic effects. Key differences:
|
||||
| Aspect | Rust | Lux |
|
||||
|--------|------|-----|
|
||||
| Target | LLVM | C |
|
||||
| Memory | Ownership/borrowing | Leaks |
|
||||
| Safety | Compile-time guaranteed | Runtime (interpreter) |
|
||||
| Memory | Ownership/borrowing (compile-time) | RC (runtime) |
|
||||
| Safety | Compile-time guaranteed | Runtime RC |
|
||||
| Learning curve | Steep | Medium |
|
||||
|
||||
### Zig
|
||||
@@ -234,7 +238,7 @@ Koka also compiles to C with algebraic effects. Key differences:
|
||||
| Aspect | Zig | Lux |
|
||||
|--------|-----|-----|
|
||||
| Target | LLVM | C |
|
||||
| Memory | Manual with allocators | Leaks |
|
||||
| Memory | Manual with allocators | Automatic RC |
|
||||
| Philosophy | Explicit control | High-level abstraction |
|
||||
|
||||
### Go
|
||||
@@ -242,7 +246,7 @@ Koka also compiles to C with algebraic effects. Key differences:
|
||||
| Aspect | Go | Lux |
|
||||
|--------|-----|-----|
|
||||
| Target | Native | C |
|
||||
| Memory | Concurrent GC | Leaks |
|
||||
| Memory | Concurrent GC | Deterministic RC |
|
||||
| Effects | None | Algebraic effects |
|
||||
| Latency | Unpredictable (GC pauses) | Predictable (no GC) |
|
||||
|
||||
@@ -274,23 +278,26 @@ See [docs/EVIDENCE_PASSING.md](EVIDENCE_PASSING.md) for details.
|
||||
|
||||
## Future Roadmap
|
||||
|
||||
### Phase 4: Perceus Reference Counting 🔄 IN PROGRESS
|
||||
### Phase 4: Reference Counting ✅ WORKING (Basic)
|
||||
|
||||
**Goal:** Deterministic memory management without GC pauses.
|
||||
|
||||
Perceus is a compile-time reference counting system that:
|
||||
1. Inserts increment/decrement at precise points
|
||||
2. Detects when values can be reused in-place (FBIP)
|
||||
3. Guarantees no memory leaks without runtime GC
|
||||
Inspired by Perceus (Koka), our RC system:
|
||||
1. Tracks refcounts in object headers
|
||||
2. Inserts decref at scope exit automatically
|
||||
3. Provides memory leak detection in debug mode
|
||||
|
||||
**Current Status:**
|
||||
- ✅ RC infrastructure (header, alloc, incref/decref, drop)
|
||||
- ✅ Lists use RC allocation with proper element incref
|
||||
- ✅ Boxed values (Int, Bool, Float) use RC allocation
|
||||
- ✅ Dynamic strings use RC allocation
|
||||
- ⏳ Automatic decref at scope exit (TODO)
|
||||
- ⏳ Closure RC (TODO)
|
||||
- ⏳ Last-use optimization (TODO)
|
||||
- ✅ **Scope tracking** - compiler tracks RC variable lifetimes
|
||||
- ✅ **Automatic decref at scope exit** - verified leak-free
|
||||
- ⏳ Early return handling (decref before nested returns)
|
||||
- ⏳ Closure RC (environments still leak)
|
||||
- ⏳ ADT RC (algebraic data types)
|
||||
- ⏳ Last-use optimization / reuse (FBIP)
|
||||
|
||||
See [docs/REFERENCE_COUNTING.md](REFERENCE_COUNTING.md) for details.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user