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:
@@ -1,20 +0,0 @@
|
||||
// Test WITHOUT FBIP by forcing rc>1 (shared reference)
|
||||
fn useList(l: List<Int>): Int = {
|
||||
List.length(l)
|
||||
}
|
||||
|
||||
fn main(): Unit = {
|
||||
Console.print("=== Without FBIP (forced rc>1) ===")
|
||||
|
||||
let a = List.range(1, 100)
|
||||
// Create alias to bump rc, preventing FBIP
|
||||
let alias = a
|
||||
let len1 = useList(alias)
|
||||
|
||||
// Now 'a' has rc>1 so map must allocate new list
|
||||
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("Shared reference chain done")
|
||||
}
|
||||
21
examples/test_ownership_transfer.lux
Normal file
21
examples/test_ownership_transfer.lux
Normal 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")
|
||||
}
|
||||
Reference in New Issue
Block a user