feat: implement early return handling for RC values
- Add pop_rc_scope_except() to skip decref'ing returned variables - Block expressions now properly preserve returned RC variables - Function returns skip cleanup for variables being returned - Track function return types for call expression type inference - Function calls returning RC types now register for cleanup - Fix main() entry point to call main_lux() when present Test result: [RC] No leaks: 17 allocs, 17 frees Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,14 +21,15 @@ The RC system is now functional for lists and boxed values.
|
||||
- **Scope tracking** - compiler tracks RC variable lifetimes
|
||||
- **Automatic decref at scope exit** - variables are freed when out of scope
|
||||
- **Memory tracking** - debug mode reports allocs/frees at program exit
|
||||
- **Early return handling** - variables being returned from blocks/functions are not decref'd
|
||||
- **Function call RC tracking** - values from RC-returning functions are tracked for cleanup
|
||||
|
||||
### Verified Working
|
||||
```
|
||||
[RC] No leaks: 28 allocs, 28 frees
|
||||
[RC] No leaks: 14 allocs, 14 frees
|
||||
```
|
||||
|
||||
### What's NOT Yet Implemented
|
||||
- Early return handling (decref before return in nested scopes)
|
||||
- Conditional branch handling (complex if/else patterns)
|
||||
|
||||
## The Problem
|
||||
@@ -414,10 +415,10 @@ Rust's ownership system is fundamentally different:
|
||||
- Generate drop functions for each ADT
|
||||
- ~100 lines
|
||||
|
||||
3. **Early return handling** - Cleanup all scopes on return
|
||||
- Current impl handles simple cases
|
||||
- Need nested scope cleanup
|
||||
- ~30 lines
|
||||
3. ~~**Early return handling**~~ ✅ DONE - Cleanup all scopes on return
|
||||
- Variables being returned are skipped during scope cleanup
|
||||
- Function calls returning RC types are tracked for cleanup
|
||||
- Blocks properly handle returning RC variables
|
||||
|
||||
4. **Complex conditionals** - If/else creating RC values
|
||||
- Switch from ternary to if-statements
|
||||
@@ -449,13 +450,13 @@ Rust's ownership system is fundamentally different:
|
||||
|-------|-------------|-------|----------|--------|
|
||||
| A1 | Closure RC | ~50 | P0 | ✅ Done |
|
||||
| A2 | ADT RC | ~150 | P1 | ✅ Done |
|
||||
| A3 | Early returns | ~30 | P1 - Edge cases | Pending |
|
||||
| A3 | Early returns | ~30 | P1 | ✅ Done |
|
||||
| A4 | Conditionals | ~50 | P2 - Uncommon | Pending |
|
||||
| B1 | Last-use opt | ~200 | P3 - Performance | Pending |
|
||||
| B2 | Reuse (FBIP) | ~300 | P3 - Performance | Pending |
|
||||
| B3 | Drop special | ~100 | P3 - Performance | Pending |
|
||||
|
||||
**Phase A remaining: ~80 lines** - Gets us to "no leaks"
|
||||
**Phase A remaining: ~50 lines** - Gets us to "no leaks"
|
||||
**Phase B total: ~600 lines** - Gets us to Koka-level performance
|
||||
|
||||
### Cycle Detection
|
||||
|
||||
Reference in New Issue
Block a user