Files
AILang/examples/gc_stress.ailx
T
Brummel 41d406bcbb Iter 14g: Term::If restored (revert of 14d)
Reconsidered 14d's removal of Term::If. The decision was wrong.
"No redundancies" requires judgment; reducibility (if -> match)
is not redundancy in the strong sense. Term::If is a primitive
control-flow shape; bool branching is the second most common
shape after sequencing, and removing it cost 3x tokens on every
branch site (`(if c a b)` 4 tokens vs the match-on-Bool form
12 tokens).

Meta-pattern fixed: I had been treating user observations as
directives. User said "if is a subset of match"; I jumped to
remove it citing CLAUDE.md, with no independent conviction.
The leak appeared in 14f's JOURNAL prose ("three lines for what
if used to do in one"), which read as regret. Two feedback
memories saved (memory/feedback_user_suggestions_not_directives,
memory/feedback_no_nostalgia_for_removed_features) to head this
off.

Implementation: mechanical reverse-application of 14d's diff at
every site (AST, check including the 14e tail-position arm,
codegen 4 sites, surface parser/printer, pretty, CLI walker,
e2e test mutation). Removed lower_bool_match helper — it existed
only because 14d's migration shape needed codegen for non-ptr
match scrutinees; with Term::If back, match-on-Bool returns to
its pre-14d unsupported state. Three fixtures (sum, sort, max3)
restored to pre-14d shape. gc_stress (added in 14f) also
migrated back to (if ...) since it was authored under the wrong
constraint.

14e (musttail) and 14f (GC_malloc) verified intact in IR.

Hashes restored to pre-14d values:
- sum.sum: db33f57cb329935e
- sort.insert: 697fcb9f30f8633a
- max3.max: 65c45d6a45dd0a72
- max3.max3: 624b14429bf302f5

All other defs across all 18 fixtures keep their post-14f
hashes. Tests 80/80 green; cargo doc 0 warnings. LOC delta
+265/-295 net -30.

DESIGN.md Decision 7 preserved with a "Status: REVERTED" header
for audit trail. Form-(A) `if-term` production restored.

Plan: back to 15a (std_maybe stdlib module).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-07 17:45:33 +02:00

48 lines
1.3 KiB
Plaintext

; Iter 14f stress fixture for the Boehm conservative GC integration.
; Builds a List Int of length 50 by recursive Cons construction,
; sums it, prints the sum (1275 = 50*51/2).
;
; Bool branching uses the canonical `if` form (Decision 7, restored
; in Iter 14g): `(if (== n 0) Nil (Cons n (build (- n 1))))`.
(module gc_stress
(data List (vars a)
(doc "Polymorphic singly-linked list (re-declared locally).")
(ctor Nil)
(ctor Cons a (con List a)))
(fn build
(doc "Build [n, n-1, ..., 1] :: List Int via Cons recursion.")
(type
(fn-type
(params (con Int))
(ret (con List (con Int)))))
(params n)
(body
(if (app == n 0)
(term-ctor List Nil)
(term-ctor List Cons
n
(app build (app - n 1))))))
(fn sum_list
(doc "Recursively sum a List Int.")
(type
(fn-type
(params (con List (con Int)))
(ret (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 [50..1], sum, print 1275.")
(type (fn-type (params) (ret (con Unit)) (effects IO)))
(params)
(body
(do io/print_int (app sum_list (app build 50))))))