Skip to content

Commit ae242e9

Browse files
committed
IxVM kernel: hot/cold split try_extract_nat — extract App arm
`try_extract_nat` ran 1.12M rows at width 45, charging 2.68% of UTF-8 `_proof_1_8` total FFT. The App arm (list_lookup + address_eq + recursive try_extract_nat + klimbs_succ) is the widest match arm; the Lit / Const / default arms are leaf compares. Factor App into `try_extract_nat_app(f, a, addrs)`. Main extractor narrows to leaf-arm width. Cold fn only charges App-arm rows. Measured on UTF-8 `_proof_1_8`: 37.62B → 37.31B (-0.8%) Nat.add_comm unchanged.
1 parent 938dbc0 commit ae242e9

1 file changed

Lines changed: 18 additions & 12 deletions

File tree

Ix/IxVM/Kernel/Primitive.lean

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1293,19 +1293,25 @@ def primitive := ⟦
12931293
1 => (1, store(ListNode.Nil)),
12941294
0 => (0, store(ListNode.Nil)),
12951295
},
1296-
KExprNode.App(f, a) =>
1297-
match load(f) {
1298-
KExprNode.Const(idx, _) =>
1299-
let head_addr_ = list_lookup(addrs, idx);
1300-
match address_eq(head_addr_, nat_succ_addr()) {
1301-
1 =>
1302-
match try_extract_nat(a, addrs) {
1303-
(1, pred_limbs) => (1, klimbs_succ(pred_limbs)),
1304-
_ => (0, store(ListNode.Nil)),
1305-
},
1306-
0 => (0, store(ListNode.Nil)),
1296+
KExprNode.App(f, a) => try_extract_nat_app(f, a, addrs),
1297+
_ => (0, store(ListNode.Nil)),
1298+
}
1299+
}
1300+
1301+
-- Cold-extracted App arm: list_lookup + address_eq + recursive
1302+
-- try_extract_nat + klimbs_succ is the widest arm; pulling it out lets
1303+
-- `try_extract_nat`'s main width drop to the leaf-arm width.
1304+
fn try_extract_nat_app(f: KExpr, a: KExpr, addrs: List‹Addr›) -> (G, KLimbs) {
1305+
match load(f) {
1306+
KExprNode.Const(idx, _) =>
1307+
let head_addr_ = list_lookup(addrs, idx);
1308+
match address_eq(head_addr_, nat_succ_addr()) {
1309+
1 =>
1310+
match try_extract_nat(a, addrs) {
1311+
(1, pred_limbs) => (1, klimbs_succ(pred_limbs)),
1312+
_ => (0, store(ListNode.Nil)),
13071313
},
1308-
_ => (0, store(ListNode.Nil)),
1314+
0 => (0, store(ListNode.Nil)),
13091315
},
13101316
_ => (0, store(ListNode.Nil)),
13111317
}

0 commit comments

Comments
 (0)