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>
22 lines
749 B
Plaintext
22 lines
749 B
Plaintext
// 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")
|
|
}
|