feat: add FBIP debug counters to prove optimization effectiveness

Add runtime counters tracking FBIP reuse vs copy operations:
- lux_fbip_reuse_count: incremented when rc=1 allows in-place mutation
- lux_fbip_copy_count: incremented when rc>1 forces allocation

Output now shows both memory stats and FBIP stats:
  [RC] No leaks: 13 allocs, 13 frees
  [FBIP] 3 reuses, 0 copies

Rename test_no_fbip.lux to test_ownership_transfer.lux to better
reflect that ownership transfer enables FBIP even with aliases.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-14 14:52:35 -05:00
parent 25a3adf4fc
commit bba94b534d
3 changed files with 60 additions and 20 deletions

View File

@@ -0,0 +1,21 @@
// Test demonstrating ownership transfer with aliases
// The ownership transfer optimization ensures FBIP still works
// even when variables are aliased, because ownership is transferred
// rather than reference count being incremented.
fn main(): Unit = {
Console.print("=== Ownership Transfer Test ===")
let a = List.range(1, 100)
// Ownership transfers from 'a' to 'alias', keeping rc=1
let alias = a
let len1 = List.length(alias)
// Since ownership transferred, 'a' still has rc=1
// FBIP can still optimize map/filter/reverse
let b = List.map(a, fn(x: Int): Int => x * 2)
let c = List.filter(b, fn(x: Int): Bool => x > 50)
let d = List.reverse(c)
Console.print("Ownership transfer chain done")
}