navid/haze / e56bca599248abc38c44cac6a5dff9d8e6a2d80d834d8cd929a5b6bacfa55901 / tests/m1_roots.hz

m1_roots.hz

← tests · 460 bytes · raw · download

// Internal M1 smoke test: a managed reference must survive a collection
// across nested calls, and the shadow-stack frame must keep it alive.

fn allocate_and_collect() {
    const p = __gc_alloc(64)
    __gc_store(p, 8, p)
    __gc_collect()
    __gc_verify()
}

fn main() {
    const q = __gc_alloc(48)
    allocate_and_collect()
    __gc_collect()
    __gc_verify()
    if __gc_alive(q) {
        print("alive")
    } else {
        print("dead")
    }
}