feat: implement FBIP (Functional But In-Place) reuse analysis
When rc=1 at update sites, mutate in-place instead of allocating new: List.reverse: - Swap element pointers in-place instead of creating new list List.take: - Truncate list in-place, decref dropped elements List.drop: - Shift elements to front in-place, decref dropped elements List.map: - Mutate elements in-place, decref old values before storing new List.filter: - Filter in-place by shifting kept elements, decref filtered-out elements All operations check LUX_RC_HEADER(list)->rc == 1 at runtime and fall back to allocation when rc > 1 (list is shared). This completes Phase B performance optimizations: - B1: Last-use optimization (ownership transfer) ✅ - B2: Reuse analysis (FBIP) ✅ - B3: Drop specialization ✅ Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -33,7 +33,7 @@ The RC system is now functional for lists and boxed values.
|
||||
```
|
||||
|
||||
### What's NOT Yet Implemented
|
||||
- Reuse analysis (FBIP) - mutate in-place when rc=1
|
||||
- Drop fusion - combining consecutive drops (minor optimization)
|
||||
|
||||
## The Problem
|
||||
|
||||
@@ -345,7 +345,7 @@ void lux_check_leaks() {
|
||||
| Conditionals | Yes | Yes ✅ |
|
||||
| Last-use opt | Yes | Yes ✅ (ownership transfer) |
|
||||
| Drop special | Yes | Yes ✅ |
|
||||
| Reuse (FBIP) | Yes | No |
|
||||
| Reuse (FBIP) | Yes | Yes ✅ |
|
||||
| Drop fusion | Yes | No |
|
||||
|
||||
---
|
||||
@@ -438,11 +438,12 @@ Rust's ownership system is fundamentally different:
|
||||
- Source variable unregistered from RC tracking
|
||||
- No double-free, no unnecessary incref/decref
|
||||
|
||||
2. **Reuse analysis (FBIP)** - NOT YET IMPLEMENTED
|
||||
- Detect `rc=1` at update sites
|
||||
- Mutate in-place instead of copy
|
||||
- Major change to list operations
|
||||
- ~300 lines
|
||||
2. ~~**Reuse analysis (FBIP)**~~ ✅ DONE
|
||||
- Runtime check `LUX_RC_HEADER(list)->rc == 1`
|
||||
- List.map: mutate elements in-place, decref old values
|
||||
- List.filter: filter in-place, decref removed elements
|
||||
- List.reverse: swap pointers in-place
|
||||
- List.take/drop: truncate/shift in-place
|
||||
|
||||
3. ~~**Drop specialization**~~ ✅ DONE
|
||||
- Specialized decref functions: `lux_decref_list`, `lux_decref_closure`, etc.
|
||||
@@ -458,12 +459,13 @@ Rust's ownership system is fundamentally different:
|
||||
| A3 | Early returns | ~30 | P1 | ✅ Done |
|
||||
| A4 | Conditionals | ~50 | P2 | ✅ Done |
|
||||
| B1 | Last-use opt | ~80 | P3 | ✅ Done |
|
||||
| B2 | Reuse (FBIP) | ~300 | P3 - Performance | Pending |
|
||||
| B2 | Reuse (FBIP) | ~150 | P3 | ✅ Done |
|
||||
| B3 | Drop special | ~100 | P3 | ✅ Done |
|
||||
|
||||
**Phase A: COMPLETE** ✅ - All leak prevention implemented
|
||||
**Phase B: 2/3 DONE** ✅ - Major performance optimizations implemented
|
||||
**Remaining: FBIP (~300 lines)** - In-place mutation when rc=1
|
||||
**Phase B: COMPLETE** ✅ - All major performance optimizations implemented
|
||||
|
||||
Only remaining: Drop fusion (minor optimization, low priority)
|
||||
|
||||
### Cycle Detection
|
||||
|
||||
|
||||
Reference in New Issue
Block a user