Files
hakorune/docs/development/current/main/30-Backlog.md
tomoaki 6a3b6deb20 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>
2025-12-19 16:19:49 +09:00

81 lines
4.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Self Current Task — Backlog (main)
Status: Active
Scope: 「次にやる候補」を短く列挙するメモ。現状は `docs/development/current/main/10-Now.md` を入口にする。
Related:
- `docs/development/current/main/10-Now.md`
- `docs/development/current/main/DOCS_LAYOUT.md`
## 直近JoinIR/selfhost
- **Phase 141 P2+planned: Call/MethodCalleffects + typing を分離して段階投入)**
- ねらい: pure/impure 境界を壊さずに、impure lowering を段階投入する。
- 前提DONE:
- Phase 141 P1.5: known intrinsic allowlist + available_inputs 3-source merge + diagnostics
- 受け入れ条件:
- out-of-scope は `Ok(None)` でフォールバック(既定挙動不変)
- effects の順序付けは SSOT で固定してから解禁by-name 増殖禁止)
- **Phase 144-anfplanned: impure 式導入の順序固定ANF**
- ねらい: `x + f(y)` 等の “pure + impure 混在” で評価順が仕様になる前に、ANF で順序固定を SSOT 化する
- 入口: `docs/development/current/main/phases/phase-144-anf/INSTRUCTIONS.md`
- 受け入れ条件:
- impure を lowering できない場合は `Ok(None)` でフォールバック(既定挙動不変)
- dev/strict では「順序固定の欠落」を Fail-Fast診断に順序ログを含める
- **Phase 143-loopvocab R0planned: Contract SSOT 抽出refactor P0 → modular components**
- 目的: loop_true_if_break_continue.rs を「検出/契約/変換」に分割し、P1/P2 での if分岐増殖を防ぐ
- 実装:
- 新ファイル: `src/mir/control_tree/normalized_shadow/common/loop_if_exit_contract.rs`
- `enum LoopIfExitThen { Break, Continue }`
- `struct LoopIfExitShape { has_else: bool, then: LoopIfExitThen, else_: Option<LoopIfExitThen>, cond_scope: ExprLoweringScope }`
- `enum OutOfScopeReason { NotLoopTrue, BodyNotSingleIf, ThenNotExit, ElseNotSupported, CondOutOfScope(...) }`
- Refactor: loop_true_if_break_continue.rs は「shape抽出 → lower」だけに縮退SSOT は contract側
- Tests: unit test を dedicated module へ分離test maintainability
- 受け入れ条件:
- cargo check ✅no errors
- P1/P2 での if分岐を防ぐcontract で決定性を保証)
- out-of-scope は `Ok(None)` で一貫(既定挙動不変)
- **Phase 143-loopvocab P1planned: continue 語彙追加**
- 対象: `loop(true) { if(cond_pure) continue }` を same lowering に通す
- 実装:
- LoopIfExitShape で `LoopIfExitThen::Continue` を許可
- JoinModule: if true → loop_step (continue semantics)
- Fixtures: `phase143_loop_true_if_continue_min.hako`
- Smoke: VM + LLVM EXE
- Out-of-scope は `Ok(None)` のまま
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 で固定する(段階投入)。
- 現状: Phase 107find_balanced_array/object / json_cur 由来)まで固定済み。
- 次候補: JsonLoader/JsonCur から 1 本ずつfixture + integration smokeで増やす。
- **P5b “完全E2E”**escape skip の実ループを end-to-end で固定)
- 現状: Phase 94 で VM E2E まで固定済み。次は selfhost 実コード(`apps/selfhost-vm/json_loader.hako`)へ横展開して回帰を減らす。
- 入口: `docs/development/current/main/phases/phase-94/README.md`
- **制御の再帰合成docs-only → dev-only段階投入**
- ねらい: `loop/if` ネストの "構造" を SSOTControlTree/StepTreeで表せるようにする
- 注意: canonicalizer は観測/構造SSOTまでValueId/PHI配線は Normalized 側へ)
- 現状: Phase 119128if-only Normalized: reads/inputs/unknown-read/partial-assign keep/mergeまで完了
- ✅ 完了: Phase 129-Cpost-if を post_k continuation で表現)
- 入口: `docs/development/current/main/design/control-tree.md`
## 中期(ループ在庫の残り)
- **P5guard-bounded**: 大型ループを “小粒度” に割ってから取り込む(分割 or 新契約)
- **P6nested loops**: capability guard で Fail-Fast 維持しつつ、解禁時の契約を先に固定
## ドキュメント運用
- 重複が出たら「設計 SSOTdesign」に集約し、Phaseログphasesは “何をやったか/検証したか” に限定する
- 調査ログinvestigationsは結論を SSOT に反映してから Historical 化する