Files
hakorune/docs/development/current/main/30-Backlog.md

188 lines
11 KiB
Markdown
Raw Normal View History

# 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
feat(anf): Phase 146/147 - Loop/If Condition ANF with Compare support ## Phase 146 P0: ANF Routing SSOT Unified **Goal**: Unify ANF routing in `lower_expr_with_scope()` L54-84, remove legacy lowering **Changes**: - expr_lowerer_box.rs: Added scope check (PureOnly → skip ANF, WithImpure → try ANF) - post_if_post_k.rs: Removed legacy inline lowering (L271-285), added `lower_condition_legacy()` helper - contract.rs: Already had `CondLoweringFailed` out-of-scope reason **Test Results**: ✅ Phase 146 P0 smoke (exit 7), 0 regressions ## Phase 146 P1: Compare Operator Support **Goal**: Enable ANF for condition expressions with Compare operators **Changes**: - joinir_dev.rs: Added `anf_allow_pure_enabled()` (HAKO_ANF_ALLOW_PURE=1) - expr_lowerer_box.rs: PureOnly scope ANF support (L56-66) - execute_box.rs: Compare operator support (+122 lines) - `execute_compare_hoist()`, `execute_compare_recursive()`, `ast_compare_to_joinir()` - Extended `normalize_and_lower()` for Compare **Test Results**: ✅ Phase 146 P1 smoke (exit 7 with flags), 0 regressions ## Phase 147 P0: Recursive Comparison ANF **Goal**: Extend recursive ANF to Compare operators **Changes**: - contract.rs: Added `AnfParentKind::Compare` variant - plan_box.rs: Compare case in BinaryOp routing (L68-79, L134-139) - Distinguishes Compare vs arithmetic BinaryOp **Benefits**: Enables recursive ANF for comparisons - `s.length() == 3` → `t = s.length(); if (t == 3)` ✅ - `s1.length() < s2.length()` → `t1 = s1.length(); t2 = s2.length(); if (t1 < t2)` ✅ ## Implementation Summary **Files Modified** (9 files, +253 lines, -25 lines = +228 net): 1. src/config/env/joinir_dev.rs (+28 lines) 2. src/mir/control_tree/normalized_shadow/anf/contract.rs (+2 lines) 3. src/mir/control_tree/normalized_shadow/anf/execute_box.rs (+122 lines) 4. src/mir/control_tree/normalized_shadow/anf/plan_box.rs (+18 lines) 5. src/mir/control_tree/normalized_shadow/common/expr_lowerer_box.rs (+18 lines, -0 lines) 6. src/mir/control_tree/normalized_shadow/post_if_post_k.rs (+44 lines, -25 lines) 7. CURRENT_TASK.md 8. docs/development/current/main/10-Now.md 9. docs/development/current/main/30-Backlog.md **Files Created** (7 files): - apps/tests/phase146_p0_if_cond_unified_min.hako - apps/tests/phase146_p1_if_cond_intrinsic_min.hako - tools/smokes/.../phase146_p0_if_cond_unified_vm.sh - tools/smokes/.../phase146_p0_if_cond_unified_llvm_exe.sh - tools/smokes/.../phase146_p1_if_cond_intrinsic_vm.sh - tools/smokes/.../phase146_p1_if_cond_intrinsic_llvm_exe.sh - docs/development/current/main/phases/phase-146/README.md **Acceptance Criteria**: ✅ All met - cargo build --release: PASS (0 errors, 0 warnings) - Phase 145 regressions: PASS (exit 12, 18, 5) - Phase 146 P0: PASS (exit 7) - Phase 146 P1: PASS (exit 7 with HAKO_ANF_ALLOW_PURE=1) **Architecture**: - SSOT: ANF routing only in `lower_expr_with_scope()` L54-84 - Box-First: Phase 145 `anf/` module extended - Legacy removed: post_if_post_k.rs unified with SSOT 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-19 17:03:56 +09:00
- **収束方針SSOT案: Expr/Condition/Control の 3 箱分割**
- ExprLowererBox式SSOT: `AST(expr)``(prelude, value)`ANF含む。pure/impure/whitelist/strict を集約入口SSOT
- ConditionLowererBox条件→分岐SSOT: `AST(cond)``BranchPlan`。評価順は ExprLowererBox に委譲し、`&&/||` は制御語彙で扱う。
- ControlLowererBox制御SSOT: `StepNode/ControlTree` → JoinIR継続 + env`if/loop` を担当し、条件は ConditionLowererBox に委譲。
- **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を条件式にも適用
- **Phase 263+planned: Pattern2 LoopBodyLocal promotionseg**
- 目的: StageB compilebundle_resolver系で露出している Pattern2 `LoopBodyLocal(seg)` を受理し、quick の first FAIL を進める
- 受け入れ条件:
- 最小再現 fixture + smoke で固定(先に失敗を SSOT 化)
- Pattern2 が不成立のときは “部分続行” せず `Ok(None)` で fallback既定挙動不変
- **DONEPhase 263 P0.2: Pattern2 PromoteDecision API hardening**
- 入口SSOT: `src/mir/builder/control_flow/joinir/patterns/pattern2/api/`
- `PromoteDecision::{Promoted, NotApplicable, Freeze}``try_promote(...)` に参照点を収束Option揺れを撤去
- **Phase 264✅ 入口作成完了): EdgeCFG Fragment 入口作成design-first**
- **ステータス**: ✅ 入口作成完了(適用は次フェーズ)
- **実装内容**:
- `edgecfg/api/` フォルダに SSOT 入口作成
- `ExitKind`, `EdgeStub`, `Frag` の型定義
- `seq`, `if_`, `loop_`, `cleanup` のシグネチャ固定pub(crate)
- 最小ユニットテスト 3個
- ドキュメント連動edgecfg-fragments.md
- **制約遵守**:
- 既存 pattern6/7/8 未改変
- merge/EdgeCFG 未改変
- cargo test -p nyash-rust --lib --no-run 成功確認
- **次フェーズへの橋渡し**:
- Phase 265 で Pattern8 適用時に `compose::loop_` を実装
- 再利用確認後、pattern番号分岐を段階的に削減
- **Phase 265 P0✅ 完了): compose/verify 最小実装**
- **目的**: 入口SSOTの形を固める迷子防止
- **実装**:
- compose::loop_() 最小実装exit集合分類のみ、配線なし
- verify_frag_invariants() 最小実装(デバッグガード付き)
- compose::loop_() ユニットテスト 2個追加
- **制約**:
- Pattern8 未改変P0では触らない、偽Frag回避
- 配線ロジックは P1 以降
- **次**: Phase 265 P1 で配線ロジック + Pattern8適用
- **Phase 265 P1✅ 完了): compose 配線ロジック実装**
- **目的**: Frag/ExitKind の配線能力を BasicBlockId 層で証明
- **実装**:
- EdgeStub.target 追加Option<BasicBlockId>
- compose::loop_() 配線ロジックContinue → header, Break → after
- verify_frag_invariants() 配線契約検証
- test-only PoC5個のテスト: 既存2個更新 + 新規3個追加
- **配線契約**:
- Continue(loop_id) の EdgeStub.target = Some(header)
- Break(loop_id) の EdgeStub.target = Some(after)
- Normal/Return/Unwind の EdgeStub.target = None上位へ伝搬
- **制約**:
- MIR 命令生成なしFrag 層のみ)
- NormalizedShadow 未適用Phase 267 に繰り越し)
feat(edgecfg): Phase 265 P2 - seq/if_ 実装(wires/exits 分離) ## 目的 「解決済み配線(wires)」と「未解決 exit(exits)」を分離し、 Frag 合成の基本パターンを完成させる。 ## 実装内容 ### 1. Frag 構造体の変更 - `wires: Vec<EdgeStub>` フィールド追加 - 不変条件: - exits: target = None のみ(未配線、外へ出る exit) - wires: target = Some(...) のみ(配線済み、内部配線) ### 2. loop_() の wires 対応 - Break/Continue を exits から wires に移動 - P1 テスト 3個を wires 検証に更新 ### 3. seq(a, b) 実装 - a.Normal → b.entry を wires に追加(内部配線) - seq の exits[Normal] は b の Normal のみ - 新規テスト 2個追加 ### 4. if_(header, cond, t, e, join_frag) 実装 - シグネチャ変更: join: BasicBlockId → join_frag: Frag - t/e.Normal → join_frag.entry を wires に追加 - if の exits は join_frag.exits - 新規テスト 2個追加 ### 5. verify_frag_invariants() 強化 - wires/exits 分離契約の検証追加(警告のみ) - Err 化は Phase 266 で実施 ## テスト結果 - edgecfg::api: 13/13 PASS(frag 3 + compose 9 + verify 1) - 全 lib テスト: 1388/1388 PASS(退行なし) ## 核心的な設計判断 1. **wires/exits 分離**: - 問題: 解決済み配線と未解決 exit を混ぜると再配線バグ - 解決: 分離して不変条件を強化 - 効果: Phase 266 で wires を MIR terminator に落とすだけ 2. **if_ は join_frag 受け取り**: - 問題: join: BasicBlockId では「join block」か「join 以降」か曖昧 - 解決: join_frag: Frag で「join 以降」を明確化 - 効果: PHI 生成の柔軟性確保 3. **verify は警告のみ**: - P2 の役割: wires/exits 分離の証明に集中 - Phase 266 で MIR 生成時に厳格化 ## 次フェーズへの橋渡し - Phase 266: wires を MIR terminator に落とす - Phase 267: Pattern6/7/8 を Frag 化 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-21 16:47:47 +09:00
- **(✅ 完了Phase 265 P2: seq/if_ 実装wires/exits 分離)**
- **目的**: 「解決済み配線wires」と「未解決 exitexits」を分離し、Frag 合成の基本パターンを完成
- **完了内容**:
- Frag に `wires: Vec<EdgeStub>` 追加
- wires/exits 分離設計確立exits = target None, wires = target Some
- loop_() を wires 対応に更新
- seq(a, b) 実装a.Normal → wires
- if_(header, cond, t, e, join_frag) 実装t/e.Normal → wires
- verify 強化wires/exits 分離契約、警告のみ)
- 全テスト PASS13個: frag 3 + compose 9 + verify 1
- **設計判断**:
- wires/exits 分離で再配線バグ防止
- if_ は join_frag: Frag で「join 以降」を明確化
- verify は警告のみErr 化は Phase 266 の strict 版で段階導入)
- **次**: Phase 266 で MIR 命令生成 PoCemit_wires、Phase 267 で NormalizedShadow/JoinIR へ実適用
- **(✅ 完了Phase 266: wires → MIR terminator 生成(最小 PoC**
- **目的**: wires を MIR terminator に変換する最小 PoC を実装し、Phase 267 での本格適用に備える
- **完了内容**:
- emit.rs 作成emit_wires 実装 + unit test 4個
- verify_frag_invariants_strict() 追加(段階導入を壊さない)
- Jump/Return 対応Branch は Phase 267
- mod.rs 更新emit module エクスポート)
- 全テスト PASS1392 passed: 既存 1388 + 新規 4個
- **核心原則**:
- from ごとにグループ化して1本だけ許可1 block = 1 terminator 制約)
- Return は target=None を許可(意味を持たない)
- verify_frag_invariants() は変更なし警告のまま、strict 版を別名で用意)
- Phase 260 terminator 語彙ルールを厳守
- **設計判断**:
- from グループ化で terminator 上書きバグ防止
- Return は target 不要(呼び出し元に戻る)
- verify strict 版で段階導入を壊さない
- **次**: Phase 267 で JoinIR Pattern への適用
- **real-app loop regression の横展開VM + LLVM EXE**
- ねらい: 実コード由来ループを 1 本ずつ最小抽出して fixture/smoke で固定する(段階投入)。
2025-12-17 23:30:13 +09:00
- 現状: 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 維持しつつ、解禁時の契約を先に固定
## 中期(制御の表現力)
北極星: `docs/development/current/main/design/join-explicit-cfg-construction.md`
設計メモ: `docs/development/current/main/design/exception-cleanup-async.md`
- **catch/cleanupInvoke**
- 追加語彙を `Invoke(ok_edge, err_edge)` に絞って例外 edge を明示する(例外値は edge-args で運ぶ)。
- 実装タイミング: Phase 260edge-args terminator 収束)の P1〜P2 以降が推奨。
- **cleanup/defercleanup normalizer**
- Return/Throw/Break/Continue を cleanup に寄せる “脱出 edge 正規化” を箱化するfinally の後継としての cleanup
- 実装タイミング: catch/cleanup の次(例外 edge も含めて正規化するため)。
- **async/awaitstate machine lowering**
- CFG語彙に混ぜず、AsyncLowerBox で state machine 化してから MIR に落とす。
- 実装タイミング: finally/defer の後cancel/drop と cleanup の接続を先に固める)。
## ドキュメント運用
- 重複が出たら「設計 SSOTdesign」に集約し、Phaseログphasesは “何をやったか/検証したか” に限定する
- 調査ログinvestigationsは結論を SSOT に反映してから Historical 化する