fix(joinir): Phase 241-EX - Remove hardcoded 'sum' check from Pattern3

Remove legacy hardcoded 'sum' carrier validation that was blocking
array_filter patterns with different accumulator names (e.g., 'out').

Before: Pattern3 required carrier named 'sum' to exist
After: Pattern3 uses carrier_info generically (any carrier name works)

Test results:
- phase49_joinir_array_filter_smoke: PASS 
- phase49_joinir_array_filter_fallback: PASS 
- phase49_joinir_array_filter_ab_comparison: PASS 
- Full suite: 909/909 PASS, 0 FAIL

Also: Archive old roadmap documentation (67k lines moved to docs/archive/)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
nyash-codex
2025-12-11 00:48:42 +09:00
parent a7dbc15878
commit 811dfebf98
387 changed files with 106 additions and 5551 deletions

View File

@ -0,0 +1,49 @@
# LoopForm Design — MacroDriven Loop Normalization
Goal
- ループで発生する「変数キャリアloopcarried values」を Nyash のユーザーマクロで前段正規化し、MIR/LLVM側は素直に最適化可能な形にする。
Key Idea
- ループ状態複数変数をタプルまたは専用Boxに束ねて“1個の搬送値carrier”として扱う。
- ループのヘッダで φ は常に“1つのタプル”にだけ付与される → PHIグルーピングの不変が自動で満たされる。
Normalization PatternwhileのMVP
```
// input
// i=0; sum=0; while (i<n) { sum = sum + a[i]; i = i + 1 }
// expanded
let __car0 = (i, sum);
head:
let (i, sum) = __car_phi;
if !(i < n) goto exit;
let __car1 = (i + 1, sum + a[i]);
__car_phi = φ(__car0, __car1);
goto head;
exit:
let (i, sum) = __car_phi;
```
Break/ContinueWeek2
- continue: “次のキャリア”を構築して head へ遷移。
- break: 現キャリアで exit へ遷移。
- ネスト時: 内側ループのcarrierと外側スコープの分解を明示する名称はgensym
for/foreachWeek3
- for (init; cond; step) は init→while(cond){ body; step } へ前処理後、同様に正規化。
- foreach は IteratorBoxMVP経由の while 形式へ前処理。
Constraints / Notes
- try/finally/throw との相互作用はMVPでは未対応将来ガイドで制約を明記
- キャリア自動抽出: 本体で再代入される変数集合を候補とし、ループ外で参照されるものを優先収集。
- 衛生: MacroCtx.gensym で __car_phi/__carK などの一意名を生成。
Integration
- ユーザーマクロ: `apps/macros/examples/loop_normalize_macro.hako`
- 事前展開: selfhostpreexpand autoPyVM限定で適用
- 検証: macrogolden + LLVM PHI健全性スモーク空PHIなし/先頭グループ化)
Future Work先の先
- MIRに LoopHeader/LoopLatch/LoopContinue/LoopExit の4命令を導入した正規形を検討最適化/解析の高速化)。
- Boxベースの LoopState/Carrier の型体系を整理(型推論との接続)。