feat(anf): Phase 145 P0/P1/P2 - ANF (A-Normal Form) transformation

Implement ANF transformation for impure expressions to fix evaluation order:

Phase 145 P0 (Skeleton):
- Add anf/ module with contract/plan/execute 3-layer separation
- AnfDiagnosticTag, AnfOutOfScopeReason, AnfPlan enums
- Stub execute_box (always returns Ok(None))
- 11 unit tests pass

Phase 145 P1 (Minimal success):
- String.length() whitelist implementation
- BinaryOp + MethodCall pattern: x + s.length() → t = s.length(); result = x + t
- Exit code 12 verification (VM + LLVM EXE)
- 17 unit tests pass

Phase 145 P2 (Generalization):
- Recursive ANF for compound expressions
- Left-to-right, depth-first evaluation order
- Patterns: x + s.length() + z, s1.length() + s2.length()
- ANF strict mode (HAKO_ANF_STRICT=1)
- Diagnostic tags (joinir/anf/*)
- 21 unit tests pass, 0 regression

Also includes Phase 143 P2 (else symmetry) completion.

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

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-19 16:19:49 +09:00
parent 845ae70cb7
commit 6a3b6deb20
34 changed files with 4549 additions and 39 deletions

View File

@ -46,14 +46,12 @@ Related:
- Smoke: VM + LLVM EXE
- Out-of-scope は `Ok(None)` のまま
- **Phase 143-loopvocab P2planned: else 対応break/continue 対称化)**
- 対象: `if(cond){break}else{continue}``if(cond){continue}else{break}` を追加
- 実装:
- LoopIfExitShape `has_else=true` + symmetric `then/else_` を許可
- Contract で 4パターンを明示P0: no-else, P1: no-else+continue, P2: with-else
- Fixtures: 2本対称ケース
- Smoke: VM/LLVM EXE
- 完了で「語彙として完成」に寄せる
DONEPhase 143-loopvocab P2: else 対称化B-C / C-B
- 記録: `docs/development/current/main/10-Now.md`
- **Phase 143-loopvocab P3+planned: impure conditions 対応**
- 目的: `if(cond_impure) break/continue` を ANF/順序固定の上で段階投入する
- 方針: Phase 145-anf の契約hoist + left-to-rightを条件式にも適用
- **real-app loop regression の横展開VM + LLVM EXE**
- ねらい: 実コード由来ループを 1 本ずつ最小抽出して fixture/smoke で固定する(段階投入)。