Files
AILang/examples/rc_own_param_partial_drop_leak.ailx
T
Brummel caefcf996a codegen rc: tag-conditional partial-drop helper closes 3 carve-outs
Three sibling sites previously fell back to shallow `ailang_rc_dec`
when a binder had non-empty `moved_slots` and a dynamic runtime ctor
tag: Iter B Own-param dec at fn-return (lib.rs), Iter A arm-close
pattern-binder dec (match_lower.rs), and emit_inlined_partial_drop's
non-Ctor branch (drop.rs). Shallow freed the outer cell but did not
walk the unmoved ptr fields — silent leak.

Adds `emit_partial_drop_fn_for_type`: a per-ADT helper structurally
parallel to `emit_drop_fn_for_type` but taking an i64 moved-slots
bitmask. Each ptr-field's dec is gated on the corresponding mask
bit; the outer box is dec'd at join. Emitted alongside the per-type
drop fn for every ADT under --alloc=rc.

Three call sites rewritten to resolve the partial_drop symbol from
the binder's static type and build the mask from `moved_slots`.

Three RED-then-GREEN fixtures (rc_own_param_/rc_match_arm_/
rc_app_let_partial_drop_leak) pin the carve-outs in regression
coverage; live cell counts go from 3/1/3 (pre-fix) to 0/0/0.
e2e count: 66 → 69.

The pre-existing `alloc_rc_own_param_dec_at_fn_return` IR-shape
assertion is widened to accept `partial_drop_<m>_<T>(%arg_xs,
i64 mask)` as a third valid drop shape (the canonical fu2 case).

Closes the JOURNAL queue's only remaining iter; the "wait for
organic fixture" stance from the 18g tidy is retracted — known
leaks are bugs, CLAUDE.md's TDD rule covers them autonomously.
2026-05-08 16:25:40 +02:00

66 lines
1.9 KiB
Plaintext

; Iter 18g.tidy.fu2 RED-test fixture 1/3: dynamic-tag partial-drop
; carve-out at fn-return (Iter B / lib.rs:1093).
;
; Shape:
; - `Pair` carries two `Cell` fields (both pointer-typed).
; - `Cell` carries two `Wrap` fields (both pointer-typed).
; - `use_first` takes `(own Pair)` and pattern-binds the first
; slot only, wildcarding the second.
; - The bound slot's `Cell` is dec'd via `drop_<m>_Cell` at the
; outer arm-close (moves[a] empty → field_drop_call routes
; correctly).
; - At fn return, `p`'s `consume_count == 0`, mode = Own, and
; `moved_slots[p] = {0}`. Iter B's drop (lib.rs:1093) hits the
; dynamic-tag carve-out: moves non-empty → shallow
; `ailang_rc_dec(p)`. p's outer cell is freed; slot 1 (the
; wildcarded second Cell + its two MkWrap children = 3 cells)
; leaks.
;
; Pre-fix: live = 3 (one Cell + two MkWrap children).
; Post-fix: live = 0.
;
; This fixture is the cleanest of the three because no inner match
; is involved: the leak surfaces from Iter B alone.
(module rc_own_param_partial_drop_leak
(data Wrap
(ctor MkWrap (con Int)))
(data Cell
(ctor MkCell (con Wrap) (con Wrap)))
(data Pair
(ctor MkPair (con Cell) (con Cell)))
(fn build_pair
(type
(fn-type
(params (con Int))
(ret (own (con Pair)))))
(params n)
(body
(term-ctor Pair MkPair
(term-ctor Cell MkCell
(term-ctor Wrap MkWrap n)
(term-ctor Wrap MkWrap 2))
(term-ctor Cell MkCell
(term-ctor Wrap MkWrap 3)
(term-ctor Wrap MkWrap 4)))))
(fn use_first
(type
(fn-type
(params (own (con Pair)))
(ret (con Int))))
(params p)
(body
(match p
(case (pat-ctor MkPair a _) 1))))
(fn main
(type (fn-type (params) (ret (con Unit)) (effects IO)))
(params)
(body
(do io/print_int (app use_first (app build_pair 1))))))