From e8ab1188d842024c64b48d4b49f00af62325bd87 Mon Sep 17 00:00:00 2001 From: Pragyansh Chaturvedi Date: Thu, 3 Sep 2026 07:23:27 +0530 Subject: [PATCH] Tests: Record the lower-do-not-desugar house style in the skill Captures the trade-off behind reworking augmented assignment: desugaring into synthetic AST is a legitimate compiler technique with real benefits, and it is still the wrong shape for this compiler, whose passes communicate through the source tree. Records both sides so the next person tempted by it declines for the right reasons, and states the idiom to reach for instead -- shared value-level helpers, not shared AST. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01L1PX8EuP9C3o3veWGA84RF --- .claude/skills/ir-first-feature/SKILL.md | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.claude/skills/ir-first-feature/SKILL.md b/.claude/skills/ir-first-feature/SKILL.md index 862a764..7372092 100644 --- a/.claude/skills/ir-first-feature/SKILL.md +++ b/.claude/skills/ir-first-feature/SKILL.md @@ -54,6 +54,33 @@ Emit IR through the existing passes (`globals_pass`, `expr_pass`, `assign_pass`, clang reference for the same shapes** — "it compiles and llc accepts it" is not the bar; llc accepts plenty of subtly wrong IR. +### House style: lower, don't desugar + +Handlers walk the AST the user wrote and emit IR directly. **Do not synthesize new AST +nodes mid-compilation and feed them back through other handlers** — no +`ast.Assign(ast.BinOp(...))` conjured to make `x += v` reuse the assignment path. + +The temptation is legitimate, so know the argument you are declining. Desugaring is a +standard compiler move (CPython itself lowers `x += v` this way), it guarantees semantic +agreement with the composed form, it is the smallest diff, and any later fix to the +composed path applies automatically. Those are real benefits. + +They lose in this codebase for structural reasons: the passes communicate through the +source tree. Allocation runs before codegen and walks `Assign` — a synthetic `Assign` +created during codegen is invisible to it, so the two passes silently disagree about +what the function contains (it happened to be harmless for augmented assignment only +because that statement never needs a fresh slot; that is luck, not design). Synthetic +nodes carry no source location, so diagnostics point nowhere. And `ast.dump` in the logs +shows statements the user never typed, which turns every debugging session into an +archaeology exercise. + +The resolution is to move sharing down a level: **equivalence should come from shared +value-level helpers, not shared AST.** When two constructs must agree, extract the common +logic into a helper both call — the way binary-op evaluation and augmented assignment +both use `apply_binop` for the operator table and `get_operand_value` for operands — +and let each handler resolve its own target and emit its own store. Two handlers calling +one helper is the idiom; one handler manufacturing input for another is not. + ## 6. Test at the right tier - Works now → `tests/passing_tests//`.