(module rc_list_drop
  (data IntList
    (doc "Recursive Int list. Iter 18c.4 RC fixture: codegen emits `drop_rc_list_drop_IntList` whose `Cons` arm recursively calls itself on the tail field.")
    (ctor Nil)
    (ctor Cons (con Int) (con IntList)))
  (fn sum_list
    (doc "Recursive fold over IntList.")
    (type (fn-type (params (own (con IntList))) (ret (own (con Int)))))
    (params xs)
    (body (match xs
      (case (pat-ctor Nil) 0)
      (case (pat-ctor Cons h t) (app + h (app sum_list t))))))
  (fn main
    (doc "Build a 5-element IntList [1,2,3,4,5] and print its sum (15). Under --alloc=rc the recursive drop_rc_list_drop_IntList fn cascades through the tail at process exit when sum_list returns ownership-implicit (the consume_count of `xs` is 1 so no dec at the outer let; the test's correctness invariant is the byte-identical stdout — leak quantification is 18f's bench).")
    (type (fn-type (params) (ret (own (con Unit))) (effects IO)))
    (params)
    (body (let xs (term-ctor IntList Cons 1 (term-ctor IntList Cons 2 (term-ctor IntList Cons 3 (term-ctor IntList Cons 4 (term-ctor IntList Cons 5 (term-ctor IntList Nil)))))) (app print (app sum_list xs))))))
