{
  "schema": "ailang/v0",
  "name": "rc_list_drop",
  "imports": [],
  "defs": [
    {
      "kind": "type",
      "name": "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.",
      "ctors": [
        { "name": "Nil", "fields": [] },
        {
          "name": "Cons",
          "fields": [
            { "k": "con", "name": "Int" },
            { "k": "con", "name": "IntList" }
          ]
        }
      ]
    },
    {
      "kind": "fn",
      "name": "sum_list",
      "type": {
        "k": "fn",
        "params": [{ "k": "con", "name": "IntList" }],
        "ret": { "k": "con", "name": "Int" },
        "effects": []
      },
      "params": ["xs"],
      "doc": "Recursive fold over IntList.",
      "body": {
        "t": "match",
        "scrutinee": { "t": "var", "name": "xs" },
        "arms": [
          {
            "pat": { "p": "ctor", "ctor": "Nil", "fields": [] },
            "body": { "t": "lit", "lit": { "kind": "int", "value": 0 } }
          },
          {
            "pat": {
              "p": "ctor",
              "ctor": "Cons",
              "fields": [
                { "p": "var", "name": "h" },
                { "p": "var", "name": "t" }
              ]
            },
            "body": {
              "t": "app",
              "fn": { "t": "var", "name": "+" },
              "args": [
                { "t": "var", "name": "h" },
                {
                  "t": "app",
                  "fn": { "t": "var", "name": "sum_list" },
                  "args": [{ "t": "var", "name": "t" }]
                }
              ]
            }
          }
        ]
      }
    },
    {
      "kind": "fn",
      "name": "main",
      "type": {
        "k": "fn",
        "params": [],
        "ret": { "k": "con", "name": "Unit" },
        "effects": ["IO"]
      },
      "params": [],
      "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).",
      "body": {
        "t": "let",
        "name": "xs",
        "value": {
          "t": "ctor",
          "type": "IntList",
          "ctor": "Cons",
          "args": [
            { "t": "lit", "lit": { "kind": "int", "value": 1 } },
            {
              "t": "ctor",
              "type": "IntList",
              "ctor": "Cons",
              "args": [
                { "t": "lit", "lit": { "kind": "int", "value": 2 } },
                {
                  "t": "ctor",
                  "type": "IntList",
                  "ctor": "Cons",
                  "args": [
                    { "t": "lit", "lit": { "kind": "int", "value": 3 } },
                    {
                      "t": "ctor",
                      "type": "IntList",
                      "ctor": "Cons",
                      "args": [
                        { "t": "lit", "lit": { "kind": "int", "value": 4 } },
                        {
                          "t": "ctor",
                          "type": "IntList",
                          "ctor": "Cons",
                          "args": [
                            { "t": "lit", "lit": { "kind": "int", "value": 5 } },
                            {
                              "t": "ctor",
                              "type": "IntList",
                              "ctor": "Nil",
                              "args": []
                            }
                          ]
                        }
                      ]
                    }
                  ]
                }
              ]
            }
          ]
        },
        "body": {
          "t": "do",
          "op": "io/print_int",
          "args": [
            {
              "t": "app",
              "fn": { "t": "var", "name": "sum_list" },
              "args": [{ "t": "var", "name": "xs" }]
            }
          ]
        }
      }
    }
  ]
}
