{ "schema": "ailang/v0", "name": "str_field_in_adt_heap", "imports": [], "defs": [ { "kind": "type", "name": "Boxed", "vars": [], "doc": "Iter hs.4 fixture: single-cell ADT around a Str field. Used to pin the drop discipline for ADTs that carry a heap-Str payload — both the ADT cell and the heap-Str inside it must round-trip through the RC walk.", "ctors": [ { "name": "Box", "fields": [{ "k": "con", "name": "Str" }] } ] }, { "kind": "fn", "name": "main", "type": { "k": "fn", "params": [], "ret": { "k": "con", "name": "Unit" }, "effects": ["IO"] }, "params": [], "doc": "Iter hs.4: pin that `field_drop_call` for `Str` correctly dispatches to `ailang_rc_dec` when the Str payload is heap-Str. Construct `Box(int_to_str(42))`, bind, pattern-match to read the Str, print it. Under --alloc=rc with AILANG_RC_STATS=1: allocs >= 2 (ADT cell + heap-Str slab), allocs == frees, live == 0. drop.rs's Str-arm comment names the codegen-level elision that protects static-Str from this same path; here the Str is heap-allocated so rc_dec is the right (and only) consumer.", "body": { "t": "let", "name": "b", "value": { "t": "ctor", "type": "Boxed", "ctor": "Box", "args": [ { "t": "app", "fn": { "t": "var", "name": "int_to_str" }, "args": [{ "t": "lit", "lit": { "kind": "int", "value": 42 } }] } ] }, "body": { "t": "match", "scrutinee": { "t": "var", "name": "b" }, "arms": [ { "pat": { "p": "ctor", "ctor": "Box", "fields": [{ "p": "var", "name": "s" }] }, "body": { "t": "do", "op": "io/print_str", "args": [{ "t": "var", "name": "s" }] } } ] } } } ] }